From 70ee37f212fcf36e572e7955a35ae796933f2f9f Mon Sep 17 00:00:00 2001 From: Adubbz Date: Thu, 24 Sep 2020 14:32:54 +1000 Subject: [PATCH] Fixed grass/foliage colours --- .../common/biome/BiomeMetadata.java | 12 ++++- .../common/biome/BiomeTemplate.java | 8 ++- .../biome/overworld/FungalJungleBiome.java | 7 +-- .../biome/overworld/RainbowValleyBiome.java | 6 +-- .../biome/overworld/SilkgladeBiome.java | 1 - .../common/util/biome/BiomeUtil.java | 6 +++ .../java/biomesoplenty/init/ModBiomes.java | 49 +++++++++++++++++++ .../resources/META-INF/accesstransformer.cfg | 1 + 8 files changed, 81 insertions(+), 9 deletions(-) diff --git a/src/main/java/biomesoplenty/common/biome/BiomeMetadata.java b/src/main/java/biomesoplenty/common/biome/BiomeMetadata.java index 42ebd2a21..b391f1345 100644 --- a/src/main/java/biomesoplenty/common/biome/BiomeMetadata.java +++ b/src/main/java/biomesoplenty/common/biome/BiomeMetadata.java @@ -35,13 +35,17 @@ public class BiomeMetadata @Nullable private final BiFunction grassColorFunction; - protected BiomeMetadata(Map weights, @Nullable RegistryKey beachBiome, @Nullable RegistryKey riverBiome, BiFunction foliageColorFunction, BiFunction grassColorFunction) + @Nullable + private final BiFunction waterColorFunction; + + protected BiomeMetadata(Map weights, @Nullable RegistryKey beachBiome, @Nullable RegistryKey riverBiome, BiFunction foliageColorFunction, BiFunction grassColorFunction, BiFunction waterColorFunction) { this.weightMap = ImmutableMap.copyOf(weights); this.beachBiome = beachBiome; this.riverBiome = riverBiome; this.foliageColorFunction = foliageColorFunction; this.grassColorFunction = grassColorFunction; + this.waterColorFunction = waterColorFunction; } public Map getWeightMap() @@ -73,6 +77,12 @@ public class BiomeMetadata return this.grassColorFunction; } + @Nullable + public BiFunction getWaterColorFunction() + { + return this.waterColorFunction; + } + public boolean hasWeights() { return !this.weightMap.isEmpty() && !this.weightMap.entrySet().stream().allMatch((entry) -> entry.getValue().equals(0)); diff --git a/src/main/java/biomesoplenty/common/biome/BiomeTemplate.java b/src/main/java/biomesoplenty/common/biome/BiomeTemplate.java index 3c9e6fb03..d92fbaab9 100644 --- a/src/main/java/biomesoplenty/common/biome/BiomeTemplate.java +++ b/src/main/java/biomesoplenty/common/biome/BiomeTemplate.java @@ -34,6 +34,7 @@ public class BiomeTemplate private RegistryKey riverBiome = Biomes.RIVER; private BiFunction foliageColorFunction; private BiFunction grassColorFunction; + private BiFunction waterColorFunction; protected void configureBiome(Biome.Builder builder) {} protected void configureGeneration(BiomeGenerationSettingsRegistryBuilder builder) {} @@ -66,7 +67,7 @@ public class BiomeTemplate public final BiomeMetadata buildMetadata() { - return new BiomeMetadata(this.weightMap, this.beachBiome, this.riverBiome, this.foliageColorFunction, this.grassColorFunction); + return new BiomeMetadata(this.weightMap, this.beachBiome, this.riverBiome, this.foliageColorFunction, this.grassColorFunction, this.waterColorFunction); } public void addWeight(BOPClimates climate, int weight) @@ -94,6 +95,11 @@ public class BiomeTemplate this.grassColorFunction = func; } + public void setWaterColorFunction(BiFunction func) + { + this.waterColorFunction = func; + } + public static int calculateSkyColor(float temperature) { float lvt_1_1_ = temperature / 3.0F; diff --git a/src/main/java/biomesoplenty/common/biome/overworld/FungalJungleBiome.java b/src/main/java/biomesoplenty/common/biome/overworld/FungalJungleBiome.java index b3b5e88a5..54491c629 100644 --- a/src/main/java/biomesoplenty/common/biome/overworld/FungalJungleBiome.java +++ b/src/main/java/biomesoplenty/common/biome/overworld/FungalJungleBiome.java @@ -31,6 +31,7 @@ public class FungalJungleBiome extends BiomeTemplate { this.addWeight(BOPClimates.TROPICAL, 1); this.setBeachBiome(null); + this.setGrassColorFunction(this::getGrassColor); } @Override @@ -96,9 +97,9 @@ public class FungalJungleBiome extends BiomeTemplate builder.addSpawn(EntityClassification.MONSTER, new MobSpawnInfo.Spawners(EntityType.WITCH, 5, 1, 1)); } - //TODO: Change grass color to use new system in special effects - /*public int getGrassColor(double x, double z) { + public int getGrassColor(double x, double z) + { double d0 = Biome.BIOME_INFO_NOISE.getValue(x * 0.0225D, z * 0.0225D, false); return d0 < -0.1D ? 0x4AA2F9 : 0x4DD6CA; - }*/ + } } diff --git a/src/main/java/biomesoplenty/common/biome/overworld/RainbowValleyBiome.java b/src/main/java/biomesoplenty/common/biome/overworld/RainbowValleyBiome.java index 9a9e9ce4f..11ee34fcb 100644 --- a/src/main/java/biomesoplenty/common/biome/overworld/RainbowValleyBiome.java +++ b/src/main/java/biomesoplenty/common/biome/overworld/RainbowValleyBiome.java @@ -30,6 +30,7 @@ public class RainbowValleyBiome extends BiomeTemplate public RainbowValleyBiome() { this.setBeachBiome(null); + this.setGrassColorFunction(this::getGrassColor); } @Override @@ -91,14 +92,13 @@ public class RainbowValleyBiome extends BiomeTemplate builder.addSpawn(EntityClassification.AMBIENT, new MobSpawnInfo.Spawners(EntityType.BAT, 10, 8, 8)); } - //TODO: Change grass/foliage color to use new system in special effects - /*public int getGrassColor(double x, double z) + public int getGrassColor(double x, double z) { if (ClientProxy.isAprilFools) { return 0xFFFFFF; } double d0 = Biome.BIOME_INFO_NOISE.getValue(x * 0.0225D, z * 0.0225D, false); return d0 < -0.1D ? 0x77CE7F : 0x75CE8D; - }*/ + } public int getFoliageColor() { diff --git a/src/main/java/biomesoplenty/common/biome/overworld/SilkgladeBiome.java b/src/main/java/biomesoplenty/common/biome/overworld/SilkgladeBiome.java index 487d0a96d..cdebee0a5 100644 --- a/src/main/java/biomesoplenty/common/biome/overworld/SilkgladeBiome.java +++ b/src/main/java/biomesoplenty/common/biome/overworld/SilkgladeBiome.java @@ -93,7 +93,6 @@ public class SilkgladeBiome extends BiomeTemplate private int getGrassColor(double x, double z) { - BiomesOPlenty.logger.info("Color!"); double d0 = Biome.BIOME_INFO_NOISE.getValue(x * 0.0225D, z * 0.0225D, false); return d0 < -0.1D ? 0xB2B39F : 0x939F76; } diff --git a/src/main/java/biomesoplenty/common/util/biome/BiomeUtil.java b/src/main/java/biomesoplenty/common/util/biome/BiomeUtil.java index b3bd7ad19..2a8099ef3 100644 --- a/src/main/java/biomesoplenty/common/util/biome/BiomeUtil.java +++ b/src/main/java/biomesoplenty/common/util/biome/BiomeUtil.java @@ -10,6 +10,7 @@ package biomesoplenty.common.util.biome; import biomesoplenty.common.biome.BiomeMetadata; import biomesoplenty.core.BiomesOPlenty; import biomesoplenty.init.ModBiomes; +import net.minecraft.client.Minecraft; import net.minecraft.util.RegistryKey; import net.minecraft.util.registry.DynamicRegistries; import net.minecraft.util.registry.Registry; @@ -84,4 +85,9 @@ public class BiomeUtil { return getBiome(id) != null; } + + public static RegistryKey getClientKey(Biome biome) + { + return Minecraft.getInstance().level.registryAccess().registryOrThrow(Registry.BIOME_REGISTRY).getResourceKey(biome).get(); + } } diff --git a/src/main/java/biomesoplenty/init/ModBiomes.java b/src/main/java/biomesoplenty/init/ModBiomes.java index 8dde5353c..f5027f338 100644 --- a/src/main/java/biomesoplenty/init/ModBiomes.java +++ b/src/main/java/biomesoplenty/init/ModBiomes.java @@ -7,6 +7,7 @@ ******************************************************************************/ package biomesoplenty.init; +import biomesoplenty.api.biome.BOPBiomes; import biomesoplenty.api.enums.BOPClimates; import biomesoplenty.common.biome.BiomeMetadata; import biomesoplenty.common.biome.BiomeRegistry; @@ -20,16 +21,21 @@ import biomesoplenty.common.util.biome.BiomeUtil; import biomesoplenty.common.world.BOPBiomeGeneratorTypeScreen; import biomesoplenty.common.world.BOPBiomeProvider; import biomesoplenty.common.world.BOPNetherBiomeProvider; +import biomesoplenty.core.BiomesOPlenty; import com.google.common.collect.HashMultimap; import com.google.common.collect.Lists; import com.google.common.collect.Maps; import com.google.common.collect.Multimap; +import net.minecraft.client.Minecraft; import net.minecraft.client.gui.screen.BiomeGeneratorTypeScreens; import net.minecraft.entity.villager.VillagerType; import net.minecraft.util.RegistryKey; +import net.minecraft.util.math.BlockPos; import net.minecraft.util.registry.Registry; import net.minecraft.world.biome.Biome; +import net.minecraft.world.biome.BiomeColors; import net.minecraft.world.biome.Biomes; +import net.minecraft.world.level.ColorResolver; import net.minecraftforge.api.distmarker.Dist; import net.minecraftforge.event.RegistryEvent; import net.minecraftforge.eventbus.api.SubscribeEvent; @@ -56,6 +62,49 @@ public class ModBiomes { biomeGeneratorTypeScreenBOP = new BOPBiomeGeneratorTypeScreen(); BiomeGeneratorTypeScreens.PRESETS.add(biomeGeneratorTypeScreenBOP); + + ColorResolver grassColorResolver = BiomeColors.GRASS_COLOR_RESOLVER; + ColorResolver foliageColorResolver = BiomeColors.FOLIAGE_COLOR_RESOLVER; + ColorResolver waterColorResolver = BiomeColors.WATER_COLOR_RESOLVER; + + BiomeColors.GRASS_COLOR_RESOLVER = (biome, posX, posZ) -> + { + RegistryKey key = BiomeUtil.getClientKey(biome); + BiomeMetadata meta = BiomeUtil.getMetadata(key); + + if (meta != null && meta.getGrassColorFunction() != null) + { + return meta.getGrassColorFunction().apply(posX, posZ); + } + + return grassColorResolver.getColor(biome, posX, posZ); + }; + + BiomeColors.FOLIAGE_COLOR_RESOLVER = (biome, posX, posZ) -> + { + RegistryKey key = BiomeUtil.getClientKey(biome); + BiomeMetadata meta = BiomeUtil.getMetadata(key); + + if (meta != null && meta.getFoliageColorFunction() != null) + { + return meta.getGrassColorFunction().apply(posX, posZ); + } + + return foliageColorResolver.getColor(biome, posX, posZ); + }; + + BiomeColors.WATER_COLOR_RESOLVER = (biome, posX, posZ) -> + { + RegistryKey key = BiomeUtil.getClientKey(biome); + BiomeMetadata meta = BiomeUtil.getMetadata(key); + + if (meta != null && meta.getGrassColorFunction() != null) + { + return meta.getGrassColorFunction().apply(posX, posZ); + } + + return waterColorResolver.getColor(biome, posX, posZ); + }; } // Register biome providers diff --git a/src/main/resources/META-INF/accesstransformer.cfg b/src/main/resources/META-INF/accesstransformer.cfg index c98b3dab2..0ae39b994 100644 --- a/src/main/resources/META-INF/accesstransformer.cfg +++ b/src/main/resources/META-INF/accesstransformer.cfg @@ -6,6 +6,7 @@ public net.minecraft.client.gui.screen.BiomeGeneratorTypeScreens (Ljava/la public net.minecraft.block.Blocks *() public net.minecraft.client.Minecraft$PackManager *() public-f net.minecraft.entity.villager.VillagerType field_221180_h +public-f net.minecraft.world.biome.BiomeColors * # Set worldtype as default and skip the confirm backup screen public-f net.minecraft.client.gui.screen.ConfirmBackupScreen *