Architectury Update

- Cache fractions from -1024 to 1023
- Add BiomeModifications for platform-agnostic biome additions
- Add FluidStackHooksForge to convert architectury FluidStacks to forge FluidStacks
- Migrate to Forge Loom & Update Architect Plugin
- Mark several methods in Mod as NotNull
- Add Env as a replacement for EnvType
This commit is contained in:
shedaniel
2020-12-21 01:03:47 +08:00
parent fe2764823c
commit 67a1db1ccb
65 changed files with 2265 additions and 317 deletions

View File

@@ -21,6 +21,7 @@ package me.shedaniel.architectury.event;
import me.shedaniel.architectury.ExpectPlatform;
import me.shedaniel.architectury.platform.Platform;
import me.shedaniel.architectury.utils.Env;
import net.fabricmc.api.EnvType;
import net.fabricmc.api.Environment;
@@ -32,10 +33,10 @@ public final class EventHandler {
public static void init() {
if (initialized) return;
initialized = true;
if (Platform.getEnv() == EnvType.CLIENT)
if (Platform.getEnvironment() == Env.CLIENT)
registerClient();
registerCommon();
if (Platform.getEnv() == EnvType.SERVER)
if (Platform.getEnvironment() == Env.SERVER)
registerServer();
}

View File

@@ -0,0 +1,473 @@
/*
* This file is part of architectury.
* Copyright (C) 2020 shedaniel
*
* This program is free software; you can redistribute it and/or
* modify it under the terms of the GNU Lesser General Public
* License as published by the Free Software Foundation; either
* version 3 of the License, or (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
* Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public License
* along with this program; if not, write to the Free Software Foundation,
* Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
*/
package me.shedaniel.architectury.hooks.biome;
import net.minecraft.sounds.Music;
import net.minecraft.sounds.SoundEvent;
import net.minecraft.world.entity.EntityType;
import net.minecraft.world.entity.MobCategory;
import net.minecraft.world.level.biome.*;
import net.minecraft.world.level.biome.Biome.BiomeCategory;
import net.minecraft.world.level.biome.BiomeSpecialEffects.GrassColorModifier;
import net.minecraft.world.level.levelgen.GenerationStep;
import net.minecraft.world.level.levelgen.carver.ConfiguredWorldCarver;
import net.minecraft.world.level.levelgen.feature.ConfiguredFeature;
import net.minecraft.world.level.levelgen.feature.ConfiguredStructureFeature;
import net.minecraft.world.level.levelgen.surfacebuilders.ConfiguredSurfaceBuilder;
import org.jetbrains.annotations.NotNull;
import org.jetbrains.annotations.Nullable;
import java.util.List;
import java.util.Map;
import java.util.Optional;
import java.util.OptionalInt;
import java.util.function.Supplier;
public final class BiomeHooks {
@NotNull
public static BiomeProperties getBiomeProperties(Biome biome) {
return new BiomeWrapped(biome);
}
public static class BiomeWrapped implements BiomeProperties {
protected final Biome biome;
protected final ClimateProperties climateProperties;
protected final EffectsProperties effectsProperties;
protected final GenerationProperties generationProperties;
protected final SpawnProperties spawnProperties;
public BiomeWrapped(Biome biome) {
this(biome,
new ClimateWrapped(biome),
new EffectsWrapped(biome),
new GenerationSettingsWrapped(biome),
new SpawnSettingsWrapped(biome));
}
public BiomeWrapped(Biome biome,
ClimateProperties climateProperties,
EffectsProperties effectsProperties,
GenerationProperties generationProperties,
SpawnProperties spawnProperties) {
this.biome = biome;
this.climateProperties = climateProperties;
this.effectsProperties = effectsProperties;
this.generationProperties = generationProperties;
this.spawnProperties = spawnProperties;
}
@Override
@NotNull
public ClimateProperties getClimateProperties() {
return climateProperties;
}
@Override
@NotNull
public EffectsProperties getEffectsProperties() {
return effectsProperties;
}
@NotNull
@Override
public GenerationProperties getGenerationProperties() {
return generationProperties;
}
@NotNull
@Override
public SpawnProperties getSpawnProperties() {
return spawnProperties;
}
@Override
@NotNull
public BiomeCategory getCategory() {
return biome.biomeCategory;
}
@Override
public float getDepth() {
return biome.depth;
}
@Override
public float getScale() {
return biome.scale;
}
}
public static class MutableBiomeWrapped extends BiomeWrapped implements BiomeProperties.Mutable {
public MutableBiomeWrapped(Biome biome,
GenerationProperties.Mutable generationProperties,
SpawnProperties.Mutable spawnProperties) {
this(biome,
new ClimateWrapped(biome.climateSettings),
new EffectsWrapped(biome.getSpecialEffects()),
generationProperties,
spawnProperties);
}
public MutableBiomeWrapped(Biome biome,
ClimateProperties.Mutable climateProperties,
EffectsProperties.Mutable effectsProperties,
GenerationProperties.Mutable generationProperties,
SpawnProperties.Mutable spawnProperties) {
super(biome,
climateProperties,
effectsProperties,
generationProperties,
spawnProperties);
}
@Override
public @NotNull ClimateProperties.Mutable getClimateProperties() {
return (ClimateProperties.Mutable) super.getClimateProperties();
}
@Override
public @NotNull EffectsProperties.Mutable getEffectsProperties() {
return (EffectsProperties.Mutable) super.getEffectsProperties();
}
@Override
public @NotNull GenerationProperties.Mutable getGenerationProperties() {
return (GenerationProperties.Mutable) super.getGenerationProperties();
}
@Override
public @NotNull SpawnProperties.Mutable getSpawnProperties() {
return (SpawnProperties.Mutable) super.getSpawnProperties();
}
@Override
@NotNull
public Mutable setCategory(@NotNull BiomeCategory category) {
biome.biomeCategory = category;
return this;
}
@Override
@NotNull
public Mutable setDepth(float depth) {
biome.depth = depth;
return this;
}
@Override
@NotNull
public Mutable setScale(float scale) {
biome.scale = scale;
return this;
}
}
public static class ClimateWrapped implements ClimateProperties.Mutable {
protected final Biome.ClimateSettings climateSettings;
public ClimateWrapped(Biome biome) {
this(biome.climateSettings);
}
public ClimateWrapped(Biome.ClimateSettings climateSettings) {
this.climateSettings = climateSettings;
}
@Override
@NotNull
public Mutable setPrecipitation(@NotNull Biome.Precipitation precipitation) {
climateSettings.precipitation = precipitation;
return this;
}
@Override
@NotNull
public Mutable setTemperature(float temperature) {
climateSettings.temperature = temperature;
return this;
}
@Override
@NotNull
public Mutable setTemperatureModifier(@NotNull Biome.TemperatureModifier temperatureModifier) {
climateSettings.temperatureModifier = temperatureModifier;
return this;
}
@Override
@NotNull
public Mutable setDownfall(float downfall) {
climateSettings.downfall = downfall;
return this;
}
@Override
@NotNull
public Biome.Precipitation getPrecipitation() {
return climateSettings.precipitation;
}
@Override
public float getTemperature() {
return climateSettings.temperature;
}
@Override
@NotNull
public Biome.TemperatureModifier getTemperatureModifier() {
return climateSettings.temperatureModifier;
}
@Override
public float getDownfall() {
return climateSettings.downfall;
}
}
public static class EffectsWrapped implements EffectsProperties.Mutable {
protected final BiomeSpecialEffects effects;
public EffectsWrapped(Biome biome) {
this(biome.getSpecialEffects());
}
public EffectsWrapped(BiomeSpecialEffects effects) {
this.effects = effects;
}
@Override
@NotNull
public EffectsProperties.Mutable setFogColor(int color) {
effects.fogColor = color;
return this;
}
@Override
@NotNull
public EffectsProperties.Mutable setWaterColor(int color) {
effects.waterColor = color;
return this;
}
@Override
@NotNull
public EffectsProperties.Mutable setWaterFogColor(int color) {
effects.waterFogColor = color;
return this;
}
@Override
@NotNull
public EffectsProperties.Mutable setSkyColor(int color) {
effects.skyColor = color;
return this;
}
@Override
@NotNull
public EffectsProperties.Mutable setFoliageColorOverride(@Nullable Integer colorOverride) {
effects.foliageColorOverride = Optional.ofNullable(colorOverride);
return this;
}
@Override
@NotNull
public EffectsProperties.Mutable setGrassColorOverride(@Nullable Integer colorOverride) {
effects.grassColorOverride = Optional.ofNullable(colorOverride);
return this;
}
@Override
@NotNull
public EffectsProperties.Mutable setGrassColorModifier(@NotNull GrassColorModifier modifier) {
effects.grassColorModifier = modifier;
return this;
}
@Override
@NotNull
public EffectsProperties.Mutable setAmbientParticle(@Nullable AmbientParticleSettings settings) {
effects.ambientParticleSettings = Optional.ofNullable(settings);
return this;
}
@Override
@NotNull
public EffectsProperties.Mutable setAmbientLoopSound(@Nullable SoundEvent sound) {
effects.ambientLoopSoundEvent = Optional.ofNullable(sound);
return this;
}
@Override
@NotNull
public EffectsProperties.Mutable setAmbientMoodSound(@Nullable AmbientMoodSettings settings) {
effects.ambientMoodSettings = Optional.ofNullable(settings);
return this;
}
@Override
@NotNull
public EffectsProperties.Mutable setAmbientAdditionsSound(@Nullable AmbientAdditionsSettings settings) {
effects.ambientAdditionsSettings = Optional.ofNullable(settings);
return this;
}
@Override
@NotNull
public EffectsProperties.Mutable setBackgroundMusic(@Nullable Music music) {
effects.backgroundMusic = Optional.ofNullable(music);
return this;
}
@Override
public int getFogColor() {
return effects.fogColor;
}
@Override
public int getWaterColor() {
return effects.waterColor;
}
@Override
public int getWaterFogColor() {
return effects.waterFogColor;
}
@Override
public int getSkyColor() {
return effects.skyColor;
}
@Override
@NotNull
public OptionalInt getFoliageColorOverride() {
return effects.foliageColorOverride.map(OptionalInt::of).orElseGet(OptionalInt::empty);
}
@Override
@NotNull
public OptionalInt getGrassColorOverride() {
return effects.grassColorOverride.map(OptionalInt::of).orElseGet(OptionalInt::empty);
}
@Override
@NotNull
public GrassColorModifier getGrassColorModifier() {
return effects.grassColorModifier;
}
@Override
@NotNull
public Optional<AmbientParticleSettings> getAmbientParticle() {
return effects.ambientParticleSettings;
}
@Override
@NotNull
public Optional<SoundEvent> getAmbientLoopSound() {
return effects.ambientLoopSoundEvent;
}
@Override
@NotNull
public Optional<AmbientMoodSettings> getAmbientMoodSound() {
return effects.ambientMoodSettings;
}
@Override
@NotNull
public Optional<AmbientAdditionsSettings> getAmbientAdditionsSound() {
return effects.ambientAdditionsSettings;
}
@Override
@NotNull
public Optional<Music> getBackgroundMusic() {
return effects.backgroundMusic;
}
}
public static class GenerationSettingsWrapped implements GenerationProperties {
protected final BiomeGenerationSettings settings;
public GenerationSettingsWrapped(Biome biome) {
this(biome.getGenerationSettings());
}
public GenerationSettingsWrapped(BiomeGenerationSettings settings) {
this.settings = settings;
}
@Override
public @NotNull Optional<Supplier<ConfiguredSurfaceBuilder<?>>> getSurfaceBuilder() {
return Optional.ofNullable(settings.getSurfaceBuilder());
}
@Override
public @NotNull List<Supplier<ConfiguredWorldCarver<?>>> getCarvers(GenerationStep.Carving carving) {
return settings.getCarvers(carving);
}
@Override
public @NotNull List<List<Supplier<ConfiguredFeature<?, ?>>>> getFeatures() {
return settings.features();
}
@Override
public @NotNull List<Supplier<ConfiguredStructureFeature<?, ?>>> getStructureStarts() {
return (List<Supplier<ConfiguredStructureFeature<?, ?>>>) settings.structures();
}
}
public static class SpawnSettingsWrapped implements SpawnProperties {
protected final MobSpawnSettings settings;
public SpawnSettingsWrapped(Biome biome) {
this(biome.getMobSettings());
}
public SpawnSettingsWrapped(MobSpawnSettings settings) {
this.settings = settings;
}
@Override
public float getCreatureProbability() {
return this.settings.getCreatureProbability();
}
@Override
@NotNull
public Map<MobCategory, List<MobSpawnSettings.SpawnerData>> getSpawners() {
return null;
}
@Override
@NotNull
public Map<EntityType<?>, MobSpawnSettings.MobSpawnCost> getMobSpawnCosts() {
return null;
}
@Override
public boolean isPlayerSpawnFriendly() {
return this.settings.playerSpawnFriendly();
}
}
}

View File

@@ -0,0 +1,71 @@
/*
* This file is part of architectury.
* Copyright (C) 2020 shedaniel
*
* This program is free software; you can redistribute it and/or
* modify it under the terms of the GNU Lesser General Public
* License as published by the Free Software Foundation; either
* version 3 of the License, or (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
* Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public License
* along with this program; if not, write to the Free Software Foundation,
* Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
*/
package me.shedaniel.architectury.hooks.biome;
import net.minecraft.world.level.biome.Biome.BiomeCategory;
import org.jetbrains.annotations.NotNull;
public interface BiomeProperties {
@NotNull
ClimateProperties getClimateProperties();
@NotNull
EffectsProperties getEffectsProperties();
@NotNull
GenerationProperties getGenerationProperties();
@NotNull
SpawnProperties getSpawnProperties();
@NotNull
BiomeCategory getCategory();
float getDepth();
float getScale();
interface Mutable extends BiomeProperties {
@Override
@NotNull
ClimateProperties.Mutable getClimateProperties();
@Override
@NotNull
EffectsProperties.Mutable getEffectsProperties();
@Override
@NotNull
GenerationProperties.Mutable getGenerationProperties();
@Override
@NotNull
SpawnProperties.Mutable getSpawnProperties();
@NotNull
Mutable setCategory(@NotNull BiomeCategory category);
@NotNull
Mutable setDepth(float depth);
@NotNull
Mutable setScale(float scale);
}
}

View File

@@ -0,0 +1,50 @@
/*
* This file is part of architectury.
* Copyright (C) 2020 shedaniel
*
* This program is free software; you can redistribute it and/or
* modify it under the terms of the GNU Lesser General Public
* License as published by the Free Software Foundation; either
* version 3 of the License, or (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
* Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public License
* along with this program; if not, write to the Free Software Foundation,
* Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
*/
package me.shedaniel.architectury.hooks.biome;
import net.minecraft.world.level.biome.Biome.Precipitation;
import net.minecraft.world.level.biome.Biome.TemperatureModifier;
import org.jetbrains.annotations.NotNull;
public interface ClimateProperties {
@NotNull
Precipitation getPrecipitation();
float getTemperature();
@NotNull
TemperatureModifier getTemperatureModifier();
float getDownfall();
interface Mutable extends ClimateProperties {
@NotNull
Mutable setPrecipitation(@NotNull Precipitation precipitation);
@NotNull
Mutable setTemperature(float temperature);
@NotNull
Mutable setTemperatureModifier(@NotNull TemperatureModifier temperatureModifier);
@NotNull
Mutable setDownfall(float downfall);
}
}

View File

@@ -0,0 +1,104 @@
/*
* This file is part of architectury.
* Copyright (C) 2020 shedaniel
*
* This program is free software; you can redistribute it and/or
* modify it under the terms of the GNU Lesser General Public
* License as published by the Free Software Foundation; either
* version 3 of the License, or (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
* Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public License
* along with this program; if not, write to the Free Software Foundation,
* Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
*/
package me.shedaniel.architectury.hooks.biome;
import net.minecraft.sounds.Music;
import net.minecraft.sounds.SoundEvent;
import net.minecraft.world.level.biome.AmbientAdditionsSettings;
import net.minecraft.world.level.biome.AmbientMoodSettings;
import net.minecraft.world.level.biome.AmbientParticleSettings;
import net.minecraft.world.level.biome.BiomeSpecialEffects.GrassColorModifier;
import org.jetbrains.annotations.NotNull;
import org.jetbrains.annotations.Nullable;
import java.util.Optional;
import java.util.OptionalInt;
public interface EffectsProperties {
int getFogColor();
int getWaterColor();
int getWaterFogColor();
int getSkyColor();
@NotNull
OptionalInt getFoliageColorOverride();
@NotNull
OptionalInt getGrassColorOverride();
@NotNull
GrassColorModifier getGrassColorModifier();
@NotNull
Optional<AmbientParticleSettings> getAmbientParticle();
@NotNull
Optional<SoundEvent> getAmbientLoopSound();
@NotNull
Optional<AmbientMoodSettings> getAmbientMoodSound();
@NotNull
Optional<AmbientAdditionsSettings> getAmbientAdditionsSound();
@NotNull
Optional<Music> getBackgroundMusic();
interface Mutable extends EffectsProperties{
@NotNull
EffectsProperties.Mutable setFogColor(int color);
@NotNull
EffectsProperties.Mutable setWaterColor(int color);
@NotNull
EffectsProperties.Mutable setWaterFogColor(int color);
@NotNull
EffectsProperties.Mutable setSkyColor(int color);
@NotNull
EffectsProperties.Mutable setFoliageColorOverride(@Nullable Integer colorOverride);
@NotNull
EffectsProperties.Mutable setGrassColorOverride(@Nullable Integer colorOverride);
@NotNull
EffectsProperties.Mutable setGrassColorModifier(@NotNull GrassColorModifier modifier);
@NotNull
EffectsProperties.Mutable setAmbientParticle(@Nullable AmbientParticleSettings settings);
@NotNull
EffectsProperties.Mutable setAmbientLoopSound(@Nullable SoundEvent sound);
@NotNull
EffectsProperties.Mutable setAmbientMoodSound(@Nullable AmbientMoodSettings settings);
@NotNull
EffectsProperties.Mutable setAmbientAdditionsSound(@Nullable AmbientAdditionsSettings settings);
@NotNull
EffectsProperties.Mutable setBackgroundMusic(@Nullable Music music);
}
}

View File

@@ -0,0 +1,61 @@
/*
* This file is part of architectury.
* Copyright (C) 2020 shedaniel
*
* This program is free software; you can redistribute it and/or
* modify it under the terms of the GNU Lesser General Public
* License as published by the Free Software Foundation; either
* version 3 of the License, or (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
* Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public License
* along with this program; if not, write to the Free Software Foundation,
* Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
*/
package me.shedaniel.architectury.hooks.biome;
import net.minecraft.world.level.levelgen.GenerationStep;
import net.minecraft.world.level.levelgen.carver.ConfiguredWorldCarver;
import net.minecraft.world.level.levelgen.feature.ConfiguredFeature;
import net.minecraft.world.level.levelgen.feature.ConfiguredStructureFeature;
import net.minecraft.world.level.levelgen.surfacebuilders.ConfiguredSurfaceBuilder;
import org.jetbrains.annotations.NotNull;
import java.util.List;
import java.util.Optional;
import java.util.function.Supplier;
public interface GenerationProperties {
@NotNull
Optional<Supplier<ConfiguredSurfaceBuilder<?>>> getSurfaceBuilder();
@NotNull
List<Supplier<ConfiguredWorldCarver<?>>> getCarvers(GenerationStep.Carving carving);
@NotNull
List<List<Supplier<ConfiguredFeature<?, ?>>>> getFeatures();
@NotNull
List<Supplier<ConfiguredStructureFeature<?, ?>>> getStructureStarts();
interface Mutable extends GenerationProperties {
Mutable setSurfaceBuilder(ConfiguredSurfaceBuilder<?> builder);
Mutable addFeature(GenerationStep.Decoration decoration, ConfiguredFeature<?, ?> feature);
Mutable addCarver(GenerationStep.Carving carving, ConfiguredWorldCarver<?> feature);
Mutable addStructure(ConfiguredStructureFeature<?, ?> feature);
Mutable removeFeature(GenerationStep.Decoration decoration, ConfiguredFeature<?, ?> feature);
Mutable removeCarver(GenerationStep.Carving carving, ConfiguredWorldCarver<?> feature);
Mutable removeStructure(ConfiguredStructureFeature<?, ?> feature);
}
}

View File

@@ -0,0 +1,40 @@
package me.shedaniel.architectury.hooks.biome;
import net.minecraft.world.entity.EntityType;
import net.minecraft.world.entity.MobCategory;
import net.minecraft.world.level.biome.MobSpawnSettings;
import org.jetbrains.annotations.NotNull;
import java.util.List;
import java.util.Map;
import java.util.function.BiPredicate;
public interface SpawnProperties {
float getCreatureProbability();
@NotNull
Map<MobCategory, List<MobSpawnSettings.SpawnerData>> getSpawners();
@NotNull
Map<EntityType<?>, MobSpawnSettings.MobSpawnCost> getMobSpawnCosts();
boolean isPlayerSpawnFriendly();
interface Mutable extends SpawnProperties {
@NotNull
Mutable setCreatureProbability(float probability);
Mutable addSpawn(MobCategory category, MobSpawnSettings.SpawnerData data);
boolean removeSpawns(BiPredicate<MobCategory, MobSpawnSettings.SpawnerData> predicate);
Mutable setSpawnCost(EntityType<?> entityType, MobSpawnSettings.MobSpawnCost cost);
Mutable setSpawnCost(EntityType<?> entityType, double mass, double gravityLimit);
Mutable clearSpawnCost(EntityType<?> entityType);
@NotNull
Mutable setPlayerSpawnFriendly(boolean friendly);
}
}

View File

@@ -26,6 +26,7 @@ import it.unimi.dsi.fastutil.ints.IntOpenHashSet;
import it.unimi.dsi.fastutil.ints.IntSet;
import me.shedaniel.architectury.networking.NetworkManager.PacketContext;
import me.shedaniel.architectury.platform.Platform;
import me.shedaniel.architectury.utils.Env;
import net.fabricmc.api.EnvType;
import net.fabricmc.api.Environment;
import net.minecraft.client.Minecraft;
@@ -78,7 +79,7 @@ public final class NetworkChannel {
takenIds.add(id);
ResourceLocation messageId = new ResourceLocation(this.id.getNamespace(), this.id.getPath() + "_" + id);
if (!side.isPresent() || side.get() == NetworkManager.s2c()) {
if (Platform.getEnv() == EnvType.CLIENT) {
if (Platform.getEnvironment() == Env.CLIENT) {
NetworkManager.registerReceiver(NetworkManager.s2c(), messageId, (buf, context) -> {
messageConsumer.accept(decoder.apply(buf), () -> context);
});

View File

@@ -20,6 +20,7 @@
package me.shedaniel.architectury.networking;
import me.shedaniel.architectury.ExpectPlatform;
import me.shedaniel.architectury.utils.Env;
import net.fabricmc.api.EnvType;
import net.fabricmc.api.Environment;
import net.minecraft.client.Minecraft;
@@ -76,8 +77,12 @@ public final class NetworkManager {
Player getPlayer();
void queue(Runnable runnable);
Env getEnvironment();
EnvType getEnv();
default EnvType getEnv() {
return getEnvironment().toPlatform();
}
}
public static Side s2c() {

View File

@@ -42,6 +42,12 @@ public interface Mod {
@NotNull
String getDescription();
/**
* Gets the logo file path of the mod
*
* @param preferredSize the preferred logo size, only used in fabric
* @return the logo file path relative to the file
*/
@NotNull
Optional<String> getLogoFile(int preferredSize);
@@ -54,13 +60,13 @@ public interface Mod {
@Nullable
Collection<String> getLicense();
@Nullable
@NotNull
Optional<String> getHomepage();
@Nullable
@NotNull
Optional<String> getSources();
@Nullable
@NotNull
Optional<String> getIssueTracker();
@Environment(EnvType.CLIENT)

View File

@@ -21,6 +21,7 @@ package me.shedaniel.architectury.platform;
import me.shedaniel.architectury.Architectury;
import me.shedaniel.architectury.ExpectPlatform;
import me.shedaniel.architectury.utils.Env;
import net.fabricmc.api.EnvType;
import net.minecraft.SharedConstants;
import org.jetbrains.annotations.NotNull;
@@ -84,6 +85,12 @@ public final class Platform {
throw new AssertionError();
}
@NotNull
@ExpectPlatform
public static Env getEnvironment() {
throw new AssertionError();
}
@NotNull
@ExpectPlatform
public static EnvType getEnv() {

View File

@@ -0,0 +1,75 @@
/*
* This file is part of architectury.
* Copyright (C) 2020 shedaniel
*
* This program is free software; you can redistribute it and/or
* modify it under the terms of the GNU Lesser General Public
* License as published by the Free Software Foundation; either
* version 3 of the License, or (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
* Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public License
* along with this program; if not, write to the Free Software Foundation,
* Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
*/
package me.shedaniel.architectury.registry;
import com.google.common.base.Predicates;
import me.shedaniel.architectury.ExpectPlatform;
import me.shedaniel.architectury.hooks.biome.BiomeProperties;
import net.minecraft.resources.ResourceLocation;
import org.jetbrains.annotations.NotNull;
import java.util.function.BiConsumer;
import java.util.function.Predicate;
public final class BiomeModifications {
public static void addProperties(BiConsumer<BiomeContext, BiomeProperties.Mutable> modifier) {
BiomeModifications.addProperties(Predicates.alwaysTrue(), modifier);
}
@ExpectPlatform
public static void addProperties(Predicate<BiomeContext> predicate, BiConsumer<BiomeContext, BiomeProperties.Mutable> modifier) {
throw new AssertionError();
}
public static void postProcessProperties(BiConsumer<BiomeContext, BiomeProperties.Mutable> modifier) {
BiomeModifications.postProcessProperties(Predicates.alwaysTrue(), modifier);
}
@ExpectPlatform
public static void postProcessProperties(Predicate<BiomeContext> predicate, BiConsumer<BiomeContext, BiomeProperties.Mutable> modifier) {
throw new AssertionError();
}
public static void removeProperties(BiConsumer<BiomeContext, BiomeProperties.Mutable> modifier) {
BiomeModifications.removeProperties(Predicates.alwaysTrue(), modifier);
}
@ExpectPlatform
public static void removeProperties(Predicate<BiomeContext> predicate, BiConsumer<BiomeContext, BiomeProperties.Mutable> modifier) {
throw new AssertionError();
}
public static void replaceProperties(BiConsumer<BiomeContext, BiomeProperties.Mutable> modifier) {
BiomeModifications.replaceProperties(Predicates.alwaysTrue(), modifier);
}
@ExpectPlatform
public static void replaceProperties(Predicate<BiomeContext> predicate, BiConsumer<BiomeContext, BiomeProperties.Mutable> modifier) {
throw new AssertionError();
}
public interface BiomeContext {
@NotNull
ResourceLocation getKey();
@NotNull
BiomeProperties getProperties();
}
}

View File

@@ -22,13 +22,17 @@ package me.shedaniel.architectury.registry;
import me.shedaniel.architectury.ExpectPlatform;
import net.minecraft.resources.ResourceKey;
import net.minecraft.resources.ResourceLocation;
import org.jetbrains.annotations.ApiStatus;
import org.jetbrains.annotations.Nullable;
import java.util.HashMap;
import java.util.Map;
import java.util.concurrent.ConcurrentHashMap;
/**
* Platform-agnostic wrapper of minecraft registries, should be used to register content.
*/
public final class Registries {
private static final Map<String, Registries> REGISTRIES = new HashMap<>();
private static final Map<String, Registries> REGISTRIES = new ConcurrentHashMap<>();
private final RegistryProvider provider;
public static Registries get(String modId) {
@@ -84,6 +88,7 @@ public final class Registries {
throw new AssertionError();
}
@ApiStatus.Internal
public interface RegistryProvider {
<T> Registry<T> get(ResourceKey<net.minecraft.core.Registry<T>> key);

View File

@@ -0,0 +1,46 @@
/*
* This file is part of architectury.
* Copyright (C) 2020 shedaniel
*
* This program is free software; you can redistribute it and/or
* modify it under the terms of the GNU Lesser General Public
* License as published by the Free Software Foundation; either
* version 3 of the License, or (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
* Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public License
* along with this program; if not, write to the Free Software Foundation,
* Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
*/
package me.shedaniel.architectury.utils;
import net.fabricmc.api.EnvType;
public enum Env {
CLIENT,
SERVER;
/**
* Converts platform-specific environment enum to platform-agnostic environment enum.
*
* @param type the platform-specific environment enum, could be {@link net.fabricmc.api.EnvType} or {@link net.minecraftforge.api.distmarker.Dist}
* @return the platform-agnostic environment enum
*/
public static Env fromPlatform(Object type) {
return type == EnvType.CLIENT ? CLIENT : type == EnvType.SERVER ? SERVER : null;
}
/**
* Converts platform-agnostic environment enum to platform-specific environment enum.
*
* @return the platform-specific environment enum, could be {@link net.fabricmc.api.EnvType} or {@link net.minecraftforge.api.distmarker.Dist}
*/
public EnvType toPlatform() {
return this == CLIENT ? EnvType.CLIENT : EnvType.SERVER;
}
}

View File

@@ -27,13 +27,21 @@ import java.util.function.Supplier;
public final class EnvExecutor {
public static void runInEnv(EnvType type, Supplier<Runnable> runnableSupplier) {
if (Platform.getEnv() == type) {
runInEnv(Env.fromPlatform(type), runnableSupplier);
}
public static void runInEnv(Env type, Supplier<Runnable> runnableSupplier) {
if (Platform.getEnvironment() == type) {
runnableSupplier.get().run();
}
}
public static <T> Optional<T> getInEnv(EnvType type, Supplier<Supplier<T>> runnableSupplier) {
if (Platform.getEnv() == type) {
return getInEnv(Env.fromPlatform(type), runnableSupplier);
}
public static <T> Optional<T> getInEnv(Env type, Supplier<Supplier<T>> runnableSupplier) {
if (Platform.getEnvironment() == type) {
return Optional.ofNullable(runnableSupplier.get().get());
}
@@ -41,7 +49,7 @@ public final class EnvExecutor {
}
public static <T> T getEnvSpecific(Supplier<Supplier<T>> client, Supplier<Supplier<T>> server) {
if (Platform.getEnv() == EnvType.CLIENT) {
if (Platform.getEnvironment() == Env.CLIENT) {
return client.get().get();
} else {
return server.get().get();

View File

@@ -25,12 +25,19 @@ import org.jetbrains.annotations.NotNull;
import java.text.DecimalFormat;
public final class Fraction extends Number implements Comparable<Fraction> {
private static final Fraction[] SIMPLE_CACHE = new Fraction[2048];
private static final Fraction ZERO = ofWhole(0);
private static final DecimalFormat DECIMAL_FORMAT = new DecimalFormat("###.###");
private final long numerator;
private final long denominator;
private boolean simplified;
static {
for (int i = 0; i < 2048; i++) {
SIMPLE_CACHE[i] = new Fraction(i - 1024, 1);
}
}
private Fraction(long numerator, long denominator) {
if (denominator > 0) {
this.numerator = numerator;
@@ -49,10 +56,17 @@ public final class Fraction extends Number implements Comparable<Fraction> {
}
public static Fraction ofWhole(long whole) {
if (whole >= -1024 && whole < 1024) {
return SIMPLE_CACHE[(int) whole + 1024];
}
return new Fraction(whole, 1);
}
public static Fraction of(long numerator, long denominator) {
if (denominator == 1)
return ofWhole(numerator);
if (denominator == -1)
return ofWhole(-numerator);
return new Fraction(numerator, denominator);
}

View File

@@ -24,6 +24,7 @@ import net.fabricmc.api.EnvType;
import net.fabricmc.api.Environment;
import net.minecraft.client.Minecraft;
import net.minecraft.server.MinecraftServer;
import org.jetbrains.annotations.Nullable;
public final class GameInstance {
@Environment(EnvType.CLIENT)
@@ -31,6 +32,7 @@ public final class GameInstance {
return Minecraft.getInstance();
}
@Nullable
@ExpectPlatform
public static MinecraftServer getServer() {
throw new AssertionError();

View File

@@ -1,2 +0,0 @@
accessWidener v1 named
accessible method net/minecraft/world/level/block/state/BlockBehaviour$Properties <init> (Lnet/minecraft/world/level/material/Material;Ljava/util/function/Function;)V

View File

@@ -0,0 +1,41 @@
accessWidener v1 named
accessible method net/minecraft/world/level/block/state/BlockBehaviour$Properties <init> (Lnet/minecraft/world/level/material/Material;Ljava/util/function/Function;)V
accessible field net/minecraft/world/level/biome/Biome climateSettings Lnet/minecraft/world/level/biome/Biome$ClimateSettings;
accessible field net/minecraft/world/level/biome/Biome depth F
mutable field net/minecraft/world/level/biome/Biome depth F
accessible field net/minecraft/world/level/biome/Biome scale F
mutable field net/minecraft/world/level/biome/Biome scale F
accessible field net/minecraft/world/level/biome/Biome biomeCategory Lnet/minecraft/world/level/biome/Biome$BiomeCategory;
mutable field net/minecraft/world/level/biome/Biome biomeCategory Lnet/minecraft/world/level/biome/Biome$BiomeCategory;
accessible field net/minecraft/world/level/biome/Biome$ClimateSettings precipitation Lnet/minecraft/world/level/biome/Biome$Precipitation;
mutable field net/minecraft/world/level/biome/Biome$ClimateSettings precipitation Lnet/minecraft/world/level/biome/Biome$Precipitation;
accessible field net/minecraft/world/level/biome/Biome$ClimateSettings temperature F
mutable field net/minecraft/world/level/biome/Biome$ClimateSettings temperature F
accessible field net/minecraft/world/level/biome/Biome$ClimateSettings temperatureModifier Lnet/minecraft/world/level/biome/Biome$TemperatureModifier;
mutable field net/minecraft/world/level/biome/Biome$ClimateSettings temperatureModifier Lnet/minecraft/world/level/biome/Biome$TemperatureModifier;
accessible field net/minecraft/world/level/biome/Biome$ClimateSettings downfall F
mutable field net/minecraft/world/level/biome/Biome$ClimateSettings downfall F
accessible field net/minecraft/world/level/biome/BiomeSpecialEffects fogColor I
mutable field net/minecraft/world/level/biome/BiomeSpecialEffects fogColor I
accessible field net/minecraft/world/level/biome/BiomeSpecialEffects waterColor I
mutable field net/minecraft/world/level/biome/BiomeSpecialEffects waterColor I
accessible field net/minecraft/world/level/biome/BiomeSpecialEffects waterFogColor I
mutable field net/minecraft/world/level/biome/BiomeSpecialEffects waterFogColor I
accessible field net/minecraft/world/level/biome/BiomeSpecialEffects skyColor I
mutable field net/minecraft/world/level/biome/BiomeSpecialEffects skyColor I
accessible field net/minecraft/world/level/biome/BiomeSpecialEffects foliageColorOverride Ljava/util/Optional;
mutable field net/minecraft/world/level/biome/BiomeSpecialEffects foliageColorOverride Ljava/util/Optional;
accessible field net/minecraft/world/level/biome/BiomeSpecialEffects grassColorOverride Ljava/util/Optional;
mutable field net/minecraft/world/level/biome/BiomeSpecialEffects grassColorOverride Ljava/util/Optional;
accessible field net/minecraft/world/level/biome/BiomeSpecialEffects grassColorModifier Lnet/minecraft/world/level/biome/BiomeSpecialEffects$GrassColorModifier;
mutable field net/minecraft/world/level/biome/BiomeSpecialEffects grassColorModifier Lnet/minecraft/world/level/biome/BiomeSpecialEffects$GrassColorModifier;
accessible field net/minecraft/world/level/biome/BiomeSpecialEffects ambientParticleSettings Ljava/util/Optional;
mutable field net/minecraft/world/level/biome/BiomeSpecialEffects ambientParticleSettings Ljava/util/Optional;
accessible field net/minecraft/world/level/biome/BiomeSpecialEffects ambientLoopSoundEvent Ljava/util/Optional;
mutable field net/minecraft/world/level/biome/BiomeSpecialEffects ambientLoopSoundEvent Ljava/util/Optional;
accessible field net/minecraft/world/level/biome/BiomeSpecialEffects ambientMoodSettings Ljava/util/Optional;
mutable field net/minecraft/world/level/biome/BiomeSpecialEffects ambientMoodSettings Ljava/util/Optional;
accessible field net/minecraft/world/level/biome/BiomeSpecialEffects ambientAdditionsSettings Ljava/util/Optional;
mutable field net/minecraft/world/level/biome/BiomeSpecialEffects ambientAdditionsSettings Ljava/util/Optional;
accessible field net/minecraft/world/level/biome/BiomeSpecialEffects backgroundMusic Ljava/util/Optional;
mutable field net/minecraft/world/level/biome/BiomeSpecialEffects backgroundMusic Ljava/util/Optional;

View File

@@ -3,5 +3,5 @@
"schemaVersion": 1,
"id": "architectury-common",
"version": "0.0.1",
"accessWidener": "architectury-common.accessWidener"
"accessWidener": "architectury.accessWidener"
}