From 8de4f1198a584201351159c869fad01452ca38ab Mon Sep 17 00:00:00 2001 From: OakLoaf Date: Sat, 26 Oct 2024 10:02:32 +0100 Subject: [PATCH 1/3] Started adding more biome settings to bukkit --- .../com/dfsek/terra/bukkit/BukkitAddon.java | 15 +- .../bukkit/config/VanillaBiomeProperties.java | 58 ------- .../dfsek/terra/bukkit/nms/Initializer.java | 4 +- .../terra/bukkit/nms/v1_21/NMSAddon.java | 31 ++++ .../bukkit/nms/v1_21/NMSBiomeInjector.java | 70 +++++--- .../bukkit/nms/v1_21/RegistryFetcher.java | 5 + .../v1_21/config/VanillaBiomeProperties.java | 164 ++++++++++++++++++ 7 files changed, 250 insertions(+), 97 deletions(-) delete mode 100644 platforms/bukkit/common/src/main/java/com/dfsek/terra/bukkit/config/VanillaBiomeProperties.java create mode 100644 platforms/bukkit/nms/v1_21/src/main/java/com/dfsek/terra/bukkit/nms/v1_21/NMSAddon.java create mode 100644 platforms/bukkit/nms/v1_21/src/main/java/com/dfsek/terra/bukkit/nms/v1_21/config/VanillaBiomeProperties.java diff --git a/platforms/bukkit/common/src/main/java/com/dfsek/terra/bukkit/BukkitAddon.java b/platforms/bukkit/common/src/main/java/com/dfsek/terra/bukkit/BukkitAddon.java index c8a59100d..1fba7bda8 100644 --- a/platforms/bukkit/common/src/main/java/com/dfsek/terra/bukkit/BukkitAddon.java +++ b/platforms/bukkit/common/src/main/java/com/dfsek/terra/bukkit/BukkitAddon.java @@ -4,18 +4,15 @@ import ca.solostudios.strata.version.Version; import com.dfsek.terra.api.addon.BaseAddon; -import com.dfsek.terra.api.event.events.config.ConfigurationLoadEvent; import com.dfsek.terra.api.event.events.config.pack.ConfigPackPreLoadEvent; import com.dfsek.terra.api.event.functional.FunctionalEventHandler; -import com.dfsek.terra.api.world.biome.Biome; import com.dfsek.terra.bukkit.config.PreLoadCompatibilityOptions; -import com.dfsek.terra.bukkit.config.VanillaBiomeProperties; public class BukkitAddon implements BaseAddon { private static final Version VERSION = Versions.getVersion(1, 0, 0); - private final PlatformImpl terraBukkitPlugin; + protected final PlatformImpl terraBukkitPlugin; public BukkitAddon(PlatformImpl terraBukkitPlugin) { this.terraBukkitPlugin = terraBukkitPlugin; @@ -28,16 +25,6 @@ public void initialize() { .register(this, ConfigPackPreLoadEvent.class) .then(event -> event.getPack().getContext().put(event.loadTemplate(new PreLoadCompatibilityOptions()))) .global(); - - terraBukkitPlugin.getEventManager() - .getHandler(FunctionalEventHandler.class) - .register(this, ConfigurationLoadEvent.class) - .then(event -> { - if(event.is(Biome.class)) { - event.getLoadedObject(Biome.class).getContext().put(event.load(new VanillaBiomeProperties())); - } - }) - .global(); } @Override diff --git a/platforms/bukkit/common/src/main/java/com/dfsek/terra/bukkit/config/VanillaBiomeProperties.java b/platforms/bukkit/common/src/main/java/com/dfsek/terra/bukkit/config/VanillaBiomeProperties.java deleted file mode 100644 index 628f329d5..000000000 --- a/platforms/bukkit/common/src/main/java/com/dfsek/terra/bukkit/config/VanillaBiomeProperties.java +++ /dev/null @@ -1,58 +0,0 @@ -package com.dfsek.terra.bukkit.config; - -import com.dfsek.tectonic.api.config.template.ConfigTemplate; -import com.dfsek.tectonic.api.config.template.annotations.Default; -import com.dfsek.tectonic.api.config.template.annotations.Value; - -import com.dfsek.terra.api.properties.Properties; - - -public class VanillaBiomeProperties implements ConfigTemplate, Properties { - @Value("colors.grass") - @Default - private Integer grassColor = null; - - @Value("colors.fog") - @Default - private Integer fogColor = null; - - @Value("colors.water") - @Default - private Integer waterColor = null; - - @Value("colors.water-fog") - @Default - private Integer waterFogColor = null; - - @Value("colors.foliage") - @Default - private Integer foliageColor = null; - - @Value("colors.sky") - @Default - private Integer skyColor = null; - - public Integer getFogColor() { - return fogColor; - } - - public Integer getFoliageColor() { - return foliageColor; - } - - public Integer getGrassColor() { - return grassColor; - } - - public Integer getWaterColor() { - return waterColor; - } - - public Integer getWaterFogColor() { - return waterFogColor; - } - - public Integer getSkyColor() { - return skyColor; - } -} diff --git a/platforms/bukkit/common/src/main/java/com/dfsek/terra/bukkit/nms/Initializer.java b/platforms/bukkit/common/src/main/java/com/dfsek/terra/bukkit/nms/Initializer.java index fc28e4bc3..b39b67d6b 100644 --- a/platforms/bukkit/common/src/main/java/com/dfsek/terra/bukkit/nms/Initializer.java +++ b/platforms/bukkit/common/src/main/java/com/dfsek/terra/bukkit/nms/Initializer.java @@ -15,8 +15,8 @@ static boolean init(PlatformImpl platform) { Logger logger = LoggerFactory.getLogger(Initializer.class); try { String packageVersion = NMS; - if(NMS.equals("v1_21_1")) { - packageVersion = "v1_21"; + if(NMS.equals("v1_21_3")) { + packageVersion = "v1_21"; // TODO: Refactor nms package to v1_21_3 } Class initializerClass = Class.forName(TERRA_PACKAGE + "." + packageVersion + ".NMSInitializer"); diff --git a/platforms/bukkit/nms/v1_21/src/main/java/com/dfsek/terra/bukkit/nms/v1_21/NMSAddon.java b/platforms/bukkit/nms/v1_21/src/main/java/com/dfsek/terra/bukkit/nms/v1_21/NMSAddon.java new file mode 100644 index 000000000..2c7944d12 --- /dev/null +++ b/platforms/bukkit/nms/v1_21/src/main/java/com/dfsek/terra/bukkit/nms/v1_21/NMSAddon.java @@ -0,0 +1,31 @@ +package com.dfsek.terra.bukkit.nms.v1_21; + +import com.dfsek.terra.api.event.events.config.ConfigurationLoadEvent; +import com.dfsek.terra.api.event.functional.FunctionalEventHandler; +import com.dfsek.terra.api.world.biome.Biome; +import com.dfsek.terra.bukkit.BukkitAddon; +import com.dfsek.terra.bukkit.PlatformImpl; +import com.dfsek.terra.bukkit.nms.v1_21.config.VanillaBiomeProperties; + + +public class NMSAddon extends BukkitAddon { + + public NMSAddon(PlatformImpl terraBukkitPlugin) { + super(terraBukkitPlugin); + } + + @Override + public void initialize() { + super.initialize(); + + terraBukkitPlugin.getEventManager() + .getHandler(FunctionalEventHandler.class) + .register(this, ConfigurationLoadEvent.class) + .then(event -> { + if(event.is(Biome.class)) { + event.getLoadedObject(Biome.class).getContext().put(event.load(new VanillaBiomeProperties())); + } + }) + .global(); + } +} diff --git a/platforms/bukkit/nms/v1_21/src/main/java/com/dfsek/terra/bukkit/nms/v1_21/NMSBiomeInjector.java b/platforms/bukkit/nms/v1_21/src/main/java/com/dfsek/terra/bukkit/nms/v1_21/NMSBiomeInjector.java index 8dea43a32..fbe937127 100644 --- a/platforms/bukkit/nms/v1_21/src/main/java/com/dfsek/terra/bukkit/nms/v1_21/NMSBiomeInjector.java +++ b/platforms/bukkit/nms/v1_21/src/main/java/com/dfsek/terra/bukkit/nms/v1_21/NMSBiomeInjector.java @@ -11,7 +11,7 @@ import java.util.Optional; import com.dfsek.terra.api.config.ConfigPack; -import com.dfsek.terra.bukkit.config.VanillaBiomeProperties; +import com.dfsek.terra.bukkit.nms.v1_21.config.VanillaBiomeProperties; public class NMSBiomeInjector { @@ -26,17 +26,8 @@ public static Biome createBiome(com.dfsek.terra.api.world.biome.Biome biome, Bio throws NoSuchFieldException, SecurityException, IllegalArgumentException, IllegalAccessException { Biome.BiomeBuilder builder = new Biome.BiomeBuilder(); - builder - .downfall(vanilla.climateSettings.downfall()) - .temperature(vanilla.getBaseTemperature()) - .mobSpawnSettings(vanilla.getMobSettings()) - .generationSettings(vanilla.getGenerationSettings()); - - BiomeSpecialEffects.Builder effects = new BiomeSpecialEffects.Builder(); - effects.grassColorModifier(vanilla.getSpecialEffects().getGrassColorModifier()); - VanillaBiomeProperties vanillaBiomeProperties = biome.getContext().get(VanillaBiomeProperties.class); effects.fogColor(Objects.requireNonNullElse(vanillaBiomeProperties.getFogColor(), vanilla.getFogColor())) @@ -45,13 +36,11 @@ public static Biome createBiome(com.dfsek.terra.api.world.biome.Biome biome, Bio .waterFogColor(Objects.requireNonNullElse(vanillaBiomeProperties.getWaterFogColor(), vanilla.getWaterFogColor())) - .skyColor(Objects.requireNonNullElse(vanillaBiomeProperties.getSkyColor(), vanilla.getSkyColor())); + .skyColor(Objects.requireNonNullElse(vanillaBiomeProperties.getSkyColor(), vanilla.getSkyColor())) - if(vanillaBiomeProperties.getFoliageColor() == null) { - vanilla.getSpecialEffects().getFoliageColorOverride().ifPresent(effects::foliageColorOverride); - } else { - effects.foliageColorOverride(vanillaBiomeProperties.getFoliageColor()); - } + .grassColorModifier(Objects.requireNonNullElse(vanillaBiomeProperties.getGrassColorModifier(), vanilla.getSpecialEffects().getGrassColorModifier())) + + .foliageColorOverride(Objects.requireNonNullElse(vanillaBiomeProperties.getFoliageColor(), vanilla.getFoliageColor())); if(vanillaBiomeProperties.getGrassColor() == null) { vanilla.getSpecialEffects().getGrassColorOverride().ifPresent(effects::grassColorOverride); @@ -60,15 +49,50 @@ public static Biome createBiome(com.dfsek.terra.api.world.biome.Biome biome, Bio effects.grassColorOverride(vanillaBiomeProperties.getGrassColor()); } - vanilla.getAmbientLoop().ifPresent(effects::ambientLoopSound); - vanilla.getAmbientAdditions().ifPresent(effects::ambientAdditionsSound); - vanilla.getAmbientMood().ifPresent(effects::ambientMoodSound); - vanilla.getBackgroundMusic().ifPresent(effects::backgroundMusic); - vanilla.getAmbientParticle().ifPresent(effects::ambientParticle); + if(vanillaBiomeProperties.getParticleConfig() == null) { + vanilla.getSpecialEffects().getAmbientParticleSettings().ifPresent(effects::ambientParticle); + } else { + effects.ambientParticle(vanillaBiomeProperties.getParticleConfig()); + } + + if(vanillaBiomeProperties.getLoopSound() == null) { + vanilla.getSpecialEffects().getAmbientLoopSoundEvent().ifPresent(effects::ambientLoopSound); + } else { + RegistryFetcher.soundEventRegistry().get(vanillaBiomeProperties.getLoopSound().location()).ifPresent(effects::ambientLoopSound); + } + + if(vanillaBiomeProperties.getMoodSound() == null) { + vanilla.getSpecialEffects().getAmbientMoodSettings().ifPresent(effects::ambientMoodSound); + } else { + effects.ambientMoodSound(vanillaBiomeProperties.getMoodSound()); + } + + if(vanillaBiomeProperties.getAdditionsSound() == null) { + vanilla.getSpecialEffects().getAmbientAdditionsSettings().ifPresent(effects::ambientAdditionsSound); + } else { + effects.ambientAdditionsSound(vanillaBiomeProperties.getAdditionsSound()); + } + + if(vanillaBiomeProperties.getMusic() == null) { + vanilla.getSpecialEffects().getBackgroundMusic().ifPresent(effects::backgroundMusic); + } else { + effects.backgroundMusic(vanillaBiomeProperties.getMusic()); + } + + builder.hasPrecipitation(Objects.requireNonNullElse(vanillaBiomeProperties.getPrecipitation(), vanilla.hasPrecipitation())); + + builder.temperature(Objects.requireNonNullElse(vanillaBiomeProperties.getTemperature(), vanilla.getBaseTemperature())); + + builder.downfall(Objects.requireNonNullElse(vanillaBiomeProperties.getDownfall(), vanilla.climateSettings.downfall())); + + builder.temperatureAdjustment(Objects.requireNonNullElse(vanillaBiomeProperties.getTemperatureModifier(), vanilla.climateSettings.temperatureModifier())); - builder.specialEffects(effects.build()); + builder.mobSpawnSettings(Objects.requireNonNullElse(vanillaBiomeProperties.getSpawnSettings(), vanilla.getMobSettings())); - return builder.build(); + return builder + .specialEffects(effects.build()) + .generationSettings(vanilla.getGenerationSettings()) + .build(); } public static String createBiomeID(ConfigPack pack, com.dfsek.terra.api.registry.key.RegistryKey biomeID) { diff --git a/platforms/bukkit/nms/v1_21/src/main/java/com/dfsek/terra/bukkit/nms/v1_21/RegistryFetcher.java b/platforms/bukkit/nms/v1_21/src/main/java/com/dfsek/terra/bukkit/nms/v1_21/RegistryFetcher.java index eecc28047..249703ca8 100644 --- a/platforms/bukkit/nms/v1_21/src/main/java/com/dfsek/terra/bukkit/nms/v1_21/RegistryFetcher.java +++ b/platforms/bukkit/nms/v1_21/src/main/java/com/dfsek/terra/bukkit/nms/v1_21/RegistryFetcher.java @@ -4,6 +4,7 @@ import net.minecraft.core.registries.Registries; import net.minecraft.resources.ResourceKey; import net.minecraft.server.dedicated.DedicatedServer; +import net.minecraft.sounds.SoundEvent; import net.minecraft.world.level.biome.Biome; import org.bukkit.Bukkit; import org.bukkit.craftbukkit.CraftServer; @@ -23,4 +24,8 @@ private static Registry getRegistry(ResourceKey> key) { public static Registry biomeRegistry() { return getRegistry(Registries.BIOME); } + + public static Registry soundEventRegistry() { + return getRegistry(Registries.SOUND_EVENT); + } } diff --git a/platforms/bukkit/nms/v1_21/src/main/java/com/dfsek/terra/bukkit/nms/v1_21/config/VanillaBiomeProperties.java b/platforms/bukkit/nms/v1_21/src/main/java/com/dfsek/terra/bukkit/nms/v1_21/config/VanillaBiomeProperties.java new file mode 100644 index 000000000..2fbf119a8 --- /dev/null +++ b/platforms/bukkit/nms/v1_21/src/main/java/com/dfsek/terra/bukkit/nms/v1_21/config/VanillaBiomeProperties.java @@ -0,0 +1,164 @@ +package com.dfsek.terra.bukkit.nms.v1_21.config; + +import com.dfsek.tectonic.api.config.template.ConfigTemplate; +import com.dfsek.tectonic.api.config.template.annotations.Default; +import com.dfsek.tectonic.api.config.template.annotations.Value; + +import com.dfsek.terra.api.properties.Properties; + +import net.minecraft.sounds.Music; +import net.minecraft.sounds.SoundEvent; +import net.minecraft.world.entity.npc.VillagerType; +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.Biome.TemperatureModifier; +import net.minecraft.world.level.biome.BiomeSpecialEffects.GrassColorModifier; +import net.minecraft.world.level.biome.MobSpawnSettings; + + +public class VanillaBiomeProperties implements ConfigTemplate, Properties { + @Value("colors.grass") + @Default + private Integer grassColor = null; + + @Value("colors.fog") + @Default + private Integer fogColor = null; + + @Value("colors.water") + @Default + private Integer waterColor = null; + + @Value("colors.water-fog") + @Default + private Integer waterFogColor = null; + + @Value("colors.foliage") + @Default + private Integer foliageColor = null; + + @Value("colors.sky") + @Default + private Integer skyColor = null; + + @Value("colors.modifier") + @Default + private GrassColorModifier grassColorModifier = null; + + @Value("particles") + @Default + private AmbientParticleSettings particleConfig = null; + + @Value("climate.precipitation") + @Default + private Boolean precipitation = true; + + @Value("climate.temperature") + @Default + private Float temperature = null; + + @Value("climate.temperature-modifier") + @Default + private TemperatureModifier temperatureModifier = null; + + @Value("climate.downfall") + @Default + private Float downfall = null; + + @Value("sound.loop-sound.sound") + @Default + private SoundEvent loopSound = null; + + @Value("sound.mood-sound") + @Default + private AmbientMoodSettings moodSound = null; + + @Value("sound.additions-sound") + @Default + private AmbientAdditionsSettings additionsSound = null; + + @Value("sound.music") + @Default + private Music music = null; + + @Value("spawning") + @Default + private MobSpawnSettings spawnSettings = null; + + @Value("villager-type") + @Default + private VillagerType villagerType = null; + + public Integer getFogColor() { + return fogColor; + } + + public Integer getFoliageColor() { + return foliageColor; + } + + public Integer getGrassColor() { + return grassColor; + } + + public Integer getWaterColor() { + return waterColor; + } + + public Integer getWaterFogColor() { + return waterFogColor; + } + + public Integer getSkyColor() { + return skyColor; + } + + public GrassColorModifier getGrassColorModifier() { + return grassColorModifier; + } + + public AmbientParticleSettings getParticleConfig() { + return particleConfig; + } + + public Boolean getPrecipitation() { + return precipitation; + } + + public Float getTemperature() { + return temperature; + } + + public TemperatureModifier getTemperatureModifier() { + return temperatureModifier; + } + + public Float getDownfall() { + return downfall; + } + + public SoundEvent getLoopSound() { + return loopSound; + } + + public AmbientMoodSettings getMoodSound() { + return moodSound; + } + + public AmbientAdditionsSettings getAdditionsSound() { + return additionsSound; + } + + public Music getMusic() { + return music; + } + + public MobSpawnSettings getSpawnSettings() { + return spawnSettings; + } + + public VillagerType getVillagerType() { + return villagerType; + } +} From afd2c81b1909151c8de16e6dd7b58a839ddc9c31 Mon Sep 17 00:00:00 2001 From: OakLoaf Date: Tue, 29 Oct 2024 18:31:37 +0000 Subject: [PATCH 2/3] Made grass colour use default if none is defined --- .../terra/bukkit/nms/v1_21/NMSBiomeInjector.java | 13 +------------ .../dfsek/terra/bukkit/nms/v1_21/Reflection.java | 10 ++++++++++ .../com/dfsek/terra/mod/util/MinecraftUtil.java | 6 +++--- 3 files changed, 14 insertions(+), 15 deletions(-) diff --git a/platforms/bukkit/nms/v1_21/src/main/java/com/dfsek/terra/bukkit/nms/v1_21/NMSBiomeInjector.java b/platforms/bukkit/nms/v1_21/src/main/java/com/dfsek/terra/bukkit/nms/v1_21/NMSBiomeInjector.java index fbe937127..d525f591e 100644 --- a/platforms/bukkit/nms/v1_21/src/main/java/com/dfsek/terra/bukkit/nms/v1_21/NMSBiomeInjector.java +++ b/platforms/bukkit/nms/v1_21/src/main/java/com/dfsek/terra/bukkit/nms/v1_21/NMSBiomeInjector.java @@ -31,24 +31,13 @@ public static Biome createBiome(com.dfsek.terra.api.world.biome.Biome biome, Bio VanillaBiomeProperties vanillaBiomeProperties = biome.getContext().get(VanillaBiomeProperties.class); effects.fogColor(Objects.requireNonNullElse(vanillaBiomeProperties.getFogColor(), vanilla.getFogColor())) - .waterColor(Objects.requireNonNullElse(vanillaBiomeProperties.getWaterColor(), vanilla.getWaterColor())) - .waterFogColor(Objects.requireNonNullElse(vanillaBiomeProperties.getWaterFogColor(), vanilla.getWaterFogColor())) - .skyColor(Objects.requireNonNullElse(vanillaBiomeProperties.getSkyColor(), vanilla.getSkyColor())) - .grassColorModifier(Objects.requireNonNullElse(vanillaBiomeProperties.getGrassColorModifier(), vanilla.getSpecialEffects().getGrassColorModifier())) - + .grassColorOverride(Objects.requireNonNullElse(vanillaBiomeProperties.getGrassColor(), vanilla.getSpecialEffects().getGrassColorOverride().orElseGet(() -> Reflection.BIOME.invokeGrassColorFromTexture(vanilla)))) .foliageColorOverride(Objects.requireNonNullElse(vanillaBiomeProperties.getFoliageColor(), vanilla.getFoliageColor())); - if(vanillaBiomeProperties.getGrassColor() == null) { - vanilla.getSpecialEffects().getGrassColorOverride().ifPresent(effects::grassColorOverride); - } else { - // grass - effects.grassColorOverride(vanillaBiomeProperties.getGrassColor()); - } - if(vanillaBiomeProperties.getParticleConfig() == null) { vanilla.getSpecialEffects().getAmbientParticleSettings().ifPresent(effects::ambientParticle); } else { diff --git a/platforms/bukkit/nms/v1_21/src/main/java/com/dfsek/terra/bukkit/nms/v1_21/Reflection.java b/platforms/bukkit/nms/v1_21/src/main/java/com/dfsek/terra/bukkit/nms/v1_21/Reflection.java index 13078e94d..8d29b5158 100644 --- a/platforms/bukkit/nms/v1_21/src/main/java/com/dfsek/terra/bukkit/nms/v1_21/Reflection.java +++ b/platforms/bukkit/nms/v1_21/src/main/java/com/dfsek/terra/bukkit/nms/v1_21/Reflection.java @@ -7,6 +7,7 @@ import net.minecraft.server.level.ChunkMap; import net.minecraft.world.level.LevelAccessor; import net.minecraft.world.level.StructureManager; +import net.minecraft.world.level.biome.Biome; import net.minecraft.world.level.chunk.status.WorldGenContext; import xyz.jpenilla.reflectionremapper.ReflectionRemapper; import xyz.jpenilla.reflectionremapper.proxy.ReflectionProxyFactory; @@ -24,8 +25,10 @@ public class Reflection { public static final ReferenceProxy REFERENCE; + public static final ChunkMapProxy CHUNKMAP; public static final HolderSetProxy HOLDER_SET; + public static final BiomeProxy BIOME; static { ReflectionRemapper reflectionRemapper = ReflectionRemapper.forReobfMappingsInPaperJar(); @@ -37,6 +40,7 @@ public class Reflection { REFERENCE = reflectionProxyFactory.reflectionProxy(ReferenceProxy.class); CHUNKMAP = reflectionProxyFactory.reflectionProxy(ChunkMapProxy.class); HOLDER_SET = reflectionProxyFactory.reflectionProxy(HolderSetProxy.class); + BIOME = reflectionProxyFactory.reflectionProxy(BiomeProxy.class); } @@ -74,4 +78,10 @@ public interface HolderSetProxy { @MethodName("contents") List> invokeContents(HolderSet instance); } + + @Proxies(Biome.class) + public interface BiomeProxy { + @MethodName("getGrassColorFromTexture") + int invokeGrassColorFromTexture(Biome instance); + } } diff --git a/platforms/mixin-common/src/main/java/com/dfsek/terra/mod/util/MinecraftUtil.java b/platforms/mixin-common/src/main/java/com/dfsek/terra/mod/util/MinecraftUtil.java index 7351eea9b..cf40eecd5 100644 --- a/platforms/mixin-common/src/main/java/com/dfsek/terra/mod/util/MinecraftUtil.java +++ b/platforms/mixin-common/src/main/java/com/dfsek/terra/mod/util/MinecraftUtil.java @@ -107,9 +107,9 @@ public static Biome createBiome(com.dfsek.terra.api.world.biome.Biome biome, Bio .waterFogColor(Objects.requireNonNullElse(vanillaBiomeProperties.getWaterFogColor(), vanilla.getWaterFogColor())) .fogColor(Objects.requireNonNullElse(vanillaBiomeProperties.getFogColor(), vanilla.getFogColor())) .skyColor(Objects.requireNonNullElse(vanillaBiomeProperties.getSkyColor(), vanilla.getSkyColor())) - .grassColorModifier( - Objects.requireNonNullElse(vanillaBiomeProperties.getGrassColorModifier(), - vanilla.getEffects().getGrassColorModifier())); + .grassColorModifier(Objects.requireNonNullElse(vanillaBiomeProperties.getGrassColorModifier(), vanilla.getEffects().getGrassColorModifier())) + .grassColor(Objects.requireNonNullElse(vanillaBiomeProperties.getGrassColor(), vanilla.getEffects().getGrassColor().orElseGet(vanilla.getDefaultGrassColor()))) + .foliageColor(Objects.requireNonNullElse(vanillaBiomeProperties.getFoliageColor(), vanilla.getFoliageColor())); if(vanillaBiomeProperties.getFoliageColor() == null) { vanilla.getEffects().getFoliageColor().ifPresent(effects::foliageColor); From 8df3a4dd029c3195923b5be4986e409a42ec0a73 Mon Sep 17 00:00:00 2001 From: OakLoaf Date: Tue, 29 Oct 2024 19:38:59 +0000 Subject: [PATCH 3/3] Added NMSAddon override for BukkitAddon --- .../com/dfsek/terra/bukkit/PlatformImpl.java | 5 ++- .../dfsek/terra/bukkit/nms/Initializer.java | 45 +++++++++++++------ .../terra/bukkit/nms/v1_21/NMSAddon.java | 4 +- .../bukkit/nms/v1_21/NMSInitializer.java | 7 +++ 4 files changed, 45 insertions(+), 16 deletions(-) diff --git a/platforms/bukkit/common/src/main/java/com/dfsek/terra/bukkit/PlatformImpl.java b/platforms/bukkit/common/src/main/java/com/dfsek/terra/bukkit/PlatformImpl.java index f26698b39..68ba921ad 100644 --- a/platforms/bukkit/common/src/main/java/com/dfsek/terra/bukkit/PlatformImpl.java +++ b/platforms/bukkit/common/src/main/java/com/dfsek/terra/bukkit/PlatformImpl.java @@ -20,6 +20,9 @@ import com.dfsek.tectonic.api.TypeRegistry; import com.dfsek.tectonic.api.depth.DepthTracker; import com.dfsek.tectonic.api.exception.LoadException; + +import com.dfsek.terra.bukkit.nms.Initializer; + import org.bukkit.Bukkit; import org.bukkit.entity.EntityType; import org.jetbrains.annotations.NotNull; @@ -96,7 +99,7 @@ public void runPossiblyUnsafeTask(@NotNull Runnable runnable) { @Override protected Iterable platformAddon() { - return List.of(new BukkitAddon(this)); + return List.of(Initializer.nmsAddon(this)); } @Override diff --git a/platforms/bukkit/common/src/main/java/com/dfsek/terra/bukkit/nms/Initializer.java b/platforms/bukkit/common/src/main/java/com/dfsek/terra/bukkit/nms/Initializer.java index b39b67d6b..c29fa1e1b 100644 --- a/platforms/bukkit/common/src/main/java/com/dfsek/terra/bukkit/nms/Initializer.java +++ b/platforms/bukkit/common/src/main/java/com/dfsek/terra/bukkit/nms/Initializer.java @@ -1,5 +1,7 @@ package com.dfsek.terra.bukkit.nms; +import com.dfsek.terra.bukkit.BukkitAddon; + import org.slf4j.Logger; import org.slf4j.LoggerFactory; @@ -13,20 +15,11 @@ public interface Initializer { static boolean init(PlatformImpl platform) { Logger logger = LoggerFactory.getLogger(Initializer.class); - try { - String packageVersion = NMS; - if(NMS.equals("v1_21_3")) { - packageVersion = "v1_21"; // TODO: Refactor nms package to v1_21_3 - } - Class initializerClass = Class.forName(TERRA_PACKAGE + "." + packageVersion + ".NMSInitializer"); - try { - Initializer initializer = (Initializer) initializerClass.getConstructor().newInstance(); - initializer.initialize(platform); - } catch(ReflectiveOperationException e) { - throw new RuntimeException("Error initializing NMS bindings. Report this to Terra.", e); - } - } catch(ClassNotFoundException e) { + Initializer initializer = constructInitializer(); + if(initializer != null) { + initializer.initialize(platform); + } else { logger.error("NMS bindings for version {} do not exist. Support for this version is limited.", NMS); logger.error("This is usually due to running Terra on an unsupported Minecraft version."); String bypassKey = "IKnowThereAreNoNMSBindingsFor" + NMS + "ButIWillProceedAnyway"; @@ -49,8 +42,34 @@ static boolean init(PlatformImpl platform) { logger.error("Since you enabled the \"{}\" flag, we won't disable Terra. But be warned.", bypassKey); } } + return true; } + static BukkitAddon nmsAddon(PlatformImpl platform) { + Initializer initializer = constructInitializer(); + return initializer != null ? initializer.getNMSAddon(platform) : new BukkitAddon(platform); + } + + private static Initializer constructInitializer() { + try { + String packageVersion = NMS; + if(NMS.equals("v1_21_3")) { + packageVersion = "v1_21"; // TODO: Refactor nms package to v1_21_3 + } + + Class initializerClass = Class.forName(TERRA_PACKAGE + "." + packageVersion + ".NMSInitializer"); + try { + return (Initializer) initializerClass.getConstructor().newInstance(); + } catch(ReflectiveOperationException e) { + throw new RuntimeException("Error initializing NMS bindings. Report this to Terra.", e); + } + } catch(ClassNotFoundException e) { + return null; + } + } + void initialize(PlatformImpl plugin); + + BukkitAddon getNMSAddon(PlatformImpl plugin); } diff --git a/platforms/bukkit/nms/v1_21/src/main/java/com/dfsek/terra/bukkit/nms/v1_21/NMSAddon.java b/platforms/bukkit/nms/v1_21/src/main/java/com/dfsek/terra/bukkit/nms/v1_21/NMSAddon.java index 2c7944d12..55be58c3b 100644 --- a/platforms/bukkit/nms/v1_21/src/main/java/com/dfsek/terra/bukkit/nms/v1_21/NMSAddon.java +++ b/platforms/bukkit/nms/v1_21/src/main/java/com/dfsek/terra/bukkit/nms/v1_21/NMSAddon.java @@ -10,8 +10,8 @@ public class NMSAddon extends BukkitAddon { - public NMSAddon(PlatformImpl terraBukkitPlugin) { - super(terraBukkitPlugin); + public NMSAddon(PlatformImpl platform) { + super(platform); } @Override diff --git a/platforms/bukkit/nms/v1_21/src/main/java/com/dfsek/terra/bukkit/nms/v1_21/NMSInitializer.java b/platforms/bukkit/nms/v1_21/src/main/java/com/dfsek/terra/bukkit/nms/v1_21/NMSInitializer.java index 18f1a058f..9e9ed7499 100644 --- a/platforms/bukkit/nms/v1_21/src/main/java/com/dfsek/terra/bukkit/nms/v1_21/NMSInitializer.java +++ b/platforms/bukkit/nms/v1_21/src/main/java/com/dfsek/terra/bukkit/nms/v1_21/NMSInitializer.java @@ -1,5 +1,7 @@ package com.dfsek.terra.bukkit.nms.v1_21; +import com.dfsek.terra.bukkit.BukkitAddon; + import org.bukkit.Bukkit; import com.dfsek.terra.bukkit.PlatformImpl; @@ -12,4 +14,9 @@ public void initialize(PlatformImpl platform) { AwfulBukkitHacks.registerBiomes(platform.getRawConfigRegistry()); Bukkit.getPluginManager().registerEvents(new NMSInjectListener(), platform.getPlugin()); } + + @Override + public BukkitAddon getNMSAddon(PlatformImpl plugin) { + return new NMSAddon(plugin); + } }