From d1e3567c6b1c4ccd94ff9bf469c62e7933ec2bec Mon Sep 17 00:00:00 2001 From: LexManos Date: Wed, 23 Sep 2020 23:35:34 -0700 Subject: [PATCH] Revive BiomeManager and BiomeLayer hooks. --- .../world/gen/layer/BiomeLayer.java.patch | 64 ++++++++++ .../minecraftforge/common/BiomeManager.java | 114 ++++++++---------- .../NamespacedDefaultedWrapper.java | 7 ++ .../registries/NamespacedWrapper.java | 7 ++ 4 files changed, 130 insertions(+), 62 deletions(-) create mode 100644 patches/minecraft/net/minecraft/world/gen/layer/BiomeLayer.java.patch diff --git a/patches/minecraft/net/minecraft/world/gen/layer/BiomeLayer.java.patch b/patches/minecraft/net/minecraft/world/gen/layer/BiomeLayer.java.patch new file mode 100644 index 000000000..27038ad81 --- /dev/null +++ b/patches/minecraft/net/minecraft/world/gen/layer/BiomeLayer.java.patch @@ -0,0 +1,64 @@ +--- a/net/minecraft/world/gen/layer/BiomeLayer.java ++++ b/net/minecraft/world/gen/layer/BiomeLayer.java +@@ -10,12 +10,13 @@ + private static final int[] field_202746_t = new int[]{4, 3, 5, 1}; + private static final int[] field_202747_u = new int[]{12, 12, 12, 30}; + private int[] field_151623_c = field_202744_r; ++ private final boolean legacyDesert; ++ private java.util.List[] biomes = new java.util.ArrayList[net.minecraftforge.common.BiomeManager.BiomeType.values().length]; + + public BiomeLayer(boolean p_i232147_1_) { +- if (p_i232147_1_) { +- this.field_151623_c = field_202743_q; +- } +- ++ this.legacyDesert = p_i232147_1_; ++ for (net.minecraftforge.common.BiomeManager.BiomeType type : net.minecraftforge.common.BiomeManager.BiomeType.values()) ++ biomes[type.ordinal()] = new java.util.ArrayList<>(net.minecraftforge.common.BiomeManager.getBiomes(type)); + } + + public int func_202726_a(INoiseRandom p_202726_1_, int p_202726_2_) { +@@ -28,21 +29,21 @@ + return p_202726_1_.func_202696_a(3) == 0 ? 39 : 38; + } + +- return this.field_151623_c[p_202726_1_.func_202696_a(this.field_151623_c.length)]; ++ return getBiomeId(net.minecraftforge.common.BiomeManager.BiomeType.DESERT, p_202726_1_); + case 2: + if (i > 0) { + return 21; + } + +- return field_202745_s[p_202726_1_.func_202696_a(field_202745_s.length)]; ++ return getBiomeId(net.minecraftforge.common.BiomeManager.BiomeType.WARM, p_202726_1_); + case 3: + if (i > 0) { + return 32; + } + +- return field_202746_t[p_202726_1_.func_202696_a(field_202746_t.length)]; ++ return getBiomeId(net.minecraftforge.common.BiomeManager.BiomeType.COOL, p_202726_1_); + case 4: +- return field_202747_u[p_202726_1_.func_202696_a(field_202747_u.length)]; ++ return getBiomeId(net.minecraftforge.common.BiomeManager.BiomeType.ICY, p_202726_1_); + default: + return 14; + } +@@ -50,4 +51,17 @@ + return p_202726_2_; + } + } ++ ++ private int getBiomeId(net.minecraftforge.common.BiomeManager.BiomeType type, INoiseRandom context) { ++ return net.minecraft.util.registry.WorldGenRegistries.field_243657_i.func_148757_b( ++ net.minecraft.util.registry.WorldGenRegistries.field_243657_i.func_230516_a_(getBiome(type, context))); ++ } ++ protected net.minecraft.util.RegistryKey getBiome(net.minecraftforge.common.BiomeManager.BiomeType type, INoiseRandom context) { ++ if (type == net.minecraftforge.common.BiomeManager.BiomeType.DESERT && this.legacyDesert) ++ type = net.minecraftforge.common.BiomeManager.BiomeType.DESERT_LEGACY; ++ java.util.List biomeList = biomes[type.ordinal()]; ++ int totalWeight = net.minecraft.util.WeightedRandom.func_76272_a(biomeList); ++ int weight = net.minecraftforge.common.BiomeManager.isTypeListModded(type) ? context.func_202696_a(totalWeight) : context.func_202696_a(totalWeight / 10) * 10; ++ return net.minecraft.util.WeightedRandom.func_180166_a(biomeList, weight).getKey(); ++ } + } diff --git a/src/main/java/net/minecraftforge/common/BiomeManager.java b/src/main/java/net/minecraftforge/common/BiomeManager.java index 6e02afe67..78884fb79 100644 --- a/src/main/java/net/minecraftforge/common/BiomeManager.java +++ b/src/main/java/net/minecraftforge/common/BiomeManager.java @@ -17,71 +17,69 @@ * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA */ -/* Biomes are completely redone in 1.16.2, reevaluate package net.minecraftforge.common; import java.util.ArrayList; +import java.util.Arrays; import java.util.Collection; import java.util.List; import com.google.common.collect.ImmutableList; import net.minecraft.world.biome.Biomes; +import net.minecraft.util.RegistryKey; import net.minecraft.util.WeightedRandom; import net.minecraft.world.biome.Biome; -import net.minecraft.world.biome.provider.BiomeProvider; -import net.minecraft.world.gen.INoiseRandom; - -import javax.annotation.Nullable; public class BiomeManager { private static TrackedList[] biomes = setupBiomes(); - public static List oceanBiomes = new ArrayList(); - - static - { - oceanBiomes.add(Biomes.OCEAN); - oceanBiomes.add(Biomes.DEEP_OCEAN); - oceanBiomes.add(Biomes.FROZEN_OCEAN); - } - private static TrackedList[] setupBiomes() { @SuppressWarnings("unchecked") TrackedList[] currentBiomes = new TrackedList[BiomeType.values().length]; - List list = new ArrayList(); - list.add(new BiomeEntry(Biomes.FOREST, 10)); - list.add(new BiomeEntry(Biomes.DARK_FOREST, 10)); - list.add(new BiomeEntry(Biomes.MOUNTAINS, 10)); - list.add(new BiomeEntry(Biomes.PLAINS, 10)); - list.add(new BiomeEntry(Biomes.BIRCH_FOREST, 10)); - list.add(new BiomeEntry(Biomes.SWAMP, 10)); + currentBiomes[BiomeType.DESERT_LEGACY.ordinal()] = new TrackedList<>( + new BiomeEntry(Biomes.DESERT, 10), + new BiomeEntry(Biomes.FOREST, 10), + new BiomeEntry(Biomes.MOUNTAINS, 10), + new BiomeEntry(Biomes.SWAMP, 10), + new BiomeEntry(Biomes.PLAINS, 10), + new BiomeEntry(Biomes.TAIGA, 10) + ); - currentBiomes[BiomeType.WARM.ordinal()] = new TrackedList(list); - list.clear(); + currentBiomes[BiomeType.DESERT.ordinal()] = new TrackedList<>( + new BiomeEntry(Biomes.DESERT, 30), + new BiomeEntry(Biomes.SAVANNA, 20), + new BiomeEntry(Biomes.PLAINS, 10) + ); - list.add(new BiomeEntry(Biomes.FOREST, 10)); - list.add(new BiomeEntry(Biomes.MOUNTAINS, 10)); - list.add(new BiomeEntry(Biomes.TAIGA, 10)); - list.add(new BiomeEntry(Biomes.PLAINS, 10)); + currentBiomes[BiomeType.WARM.ordinal()] = new TrackedList<>( + new BiomeEntry(Biomes.FOREST, 10), + new BiomeEntry(Biomes.DARK_FOREST, 10), + new BiomeEntry(Biomes.MOUNTAINS, 10), + new BiomeEntry(Biomes.PLAINS, 10), + new BiomeEntry(Biomes.BIRCH_FOREST, 10), + new BiomeEntry(Biomes.SWAMP, 10) + ); - currentBiomes[BiomeType.COOL.ordinal()] = new TrackedList(list); - list.clear(); + currentBiomes[BiomeType.COOL.ordinal()] = new TrackedList<>( + new BiomeEntry(Biomes.FOREST, 10), + new BiomeEntry(Biomes.MOUNTAINS, 10), + new BiomeEntry(Biomes.TAIGA, 10), + new BiomeEntry(Biomes.PLAINS, 10) + ); - list.add(new BiomeEntry(Biomes.SNOWY_TUNDRA, 30)); - list.add(new BiomeEntry(Biomes.SNOWY_TAIGA, 10)); - - currentBiomes[BiomeType.ICY.ordinal()] = new TrackedList(list); - list.clear(); - - currentBiomes[BiomeType.DESERT.ordinal()] = new TrackedList(list); + currentBiomes[BiomeType.ICY.ordinal()] = new TrackedList<>( + new BiomeEntry(Biomes.SNOWY_TUNDRA, 30), + new BiomeEntry(Biomes.SNOWY_TAIGA, 10) + ); return currentBiomes; } + /* public static void addSpawnBiome(Biome biome) { if (!BiomeProvider.BIOMES_TO_SPAWN_IN.contains(biome)) @@ -97,62 +95,54 @@ public class BiomeManager BiomeProvider.BIOMES_TO_SPAWN_IN.remove(biome); } } + */ - public static void addBiome(BiomeType type, BiomeEntry entry) + public static boolean addBiome(BiomeType type, BiomeEntry entry) { int idx = type.ordinal(); List list = idx > biomes.length ? null : biomes[idx]; - if (list != null) list.add(entry); + return list == null ? false : list.add(entry); } - public static void removeBiome(BiomeType type, BiomeEntry entry) + public static boolean removeBiome(BiomeType type, BiomeEntry entry) { int idx = type.ordinal(); List list = idx > biomes.length ? null : biomes[idx]; - - if (list != null && list.contains(entry)) - { - list.remove(entry); - } + return list == null ? false : list.remove(entry); } - @Nullable public static ImmutableList getBiomes(BiomeType type) { int idx = type.ordinal(); List list = idx >= biomes.length ? null : biomes[idx]; - - return list != null ? ImmutableList.copyOf(list) : null; + return list != null ? ImmutableList.copyOf(list) : ImmutableList.of(); } public static boolean isTypeListModded(BiomeType type) { int idx = type.ordinal(); TrackedList list = idx > biomes.length ? null : biomes[idx]; - - if (list != null) return list.isModded(); - - return false; + return list == null ? false : list.isModded(); } public static enum BiomeType { - DESERT, WARM, COOL, ICY; - - public static BiomeType create(String name) { - return null; - } + DESERT, DESERT_LEGACY, WARM, COOL, ICY; } public static class BiomeEntry extends WeightedRandom.Item { - public final Biome biome; + private final RegistryKey key; - public BiomeEntry(Biome biome, int weight) + public BiomeEntry(RegistryKey key, int weight) { super(weight); + this.key = key; + } - this.biome = biome; + public RegistryKey getKey() + { + return this.key; } } @@ -161,9 +151,10 @@ public class BiomeManager private static final long serialVersionUID = 1L; private boolean isModded = false; - public TrackedList(Collection c) + @SafeVarargs + private TrackedList(T... c) { - super(c); + super(Arrays.asList(c)); } @Override @@ -242,4 +233,3 @@ public class BiomeManager } } } -*/ diff --git a/src/main/java/net/minecraftforge/registries/NamespacedDefaultedWrapper.java b/src/main/java/net/minecraftforge/registries/NamespacedDefaultedWrapper.java index 177eea661..4d4cc6bc2 100644 --- a/src/main/java/net/minecraftforge/registries/NamespacedDefaultedWrapper.java +++ b/src/main/java/net/minecraftforge/registries/NamespacedDefaultedWrapper.java @@ -96,6 +96,13 @@ class NamespacedDefaultedWrapper> extends Defau return this.delegate.getValue(name); //getOrDefault } + @Override + @Nullable + public T func_230516_a_(@Nullable RegistryKey name) + { + return name == null ? null : this.delegate.getRaw(name.func_240901_a_()); //get without default + } + @Override @Nullable public ResourceLocation getKey(T value) diff --git a/src/main/java/net/minecraftforge/registries/NamespacedWrapper.java b/src/main/java/net/minecraftforge/registries/NamespacedWrapper.java index 535c019a8..51fc1e2ef 100644 --- a/src/main/java/net/minecraftforge/registries/NamespacedWrapper.java +++ b/src/main/java/net/minecraftforge/registries/NamespacedWrapper.java @@ -94,6 +94,13 @@ class NamespacedWrapper> extends SimpleRegistry return Optional.ofNullable( this.delegate.getRaw(name)); //get without default } + @Override + @Nullable + public T func_230516_a_(@Nullable RegistryKey name) + { + return name == null ? null : this.delegate.getRaw(name.func_240901_a_()); //get without default + } + @Override @Nullable public ResourceLocation getKey(T value)