Revive BiomeManager and BiomeLayer hooks.

This commit is contained in:
LexManos 2020-09-23 23:35:34 -07:00
parent af75547d37
commit d1e3567c6b
4 changed files with 130 additions and 62 deletions

View file

@ -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<net.minecraftforge.common.BiomeManager.BiomeEntry>[] 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<net.minecraft.world.biome.Biome> 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<net.minecraftforge.common.BiomeManager.BiomeEntry> 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();
+ }
}

View file

@ -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<BiomeEntry>[] biomes = setupBiomes();
public static List<Biome> oceanBiomes = new ArrayList<Biome>();
static
{
oceanBiomes.add(Biomes.OCEAN);
oceanBiomes.add(Biomes.DEEP_OCEAN);
oceanBiomes.add(Biomes.FROZEN_OCEAN);
}
private static TrackedList<BiomeEntry>[] setupBiomes()
{
@SuppressWarnings("unchecked")
TrackedList<BiomeEntry>[] currentBiomes = new TrackedList[BiomeType.values().length];
List<BiomeEntry> list = new ArrayList<BiomeEntry>();
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<BiomeEntry>(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<BiomeEntry>(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<BiomeEntry>(list);
list.clear();
currentBiomes[BiomeType.DESERT.ordinal()] = new TrackedList<BiomeEntry>(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<BiomeEntry> 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<BiomeEntry> 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<BiomeEntry> getBiomes(BiomeType type)
{
int idx = type.ordinal();
List<BiomeEntry> 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<BiomeEntry> 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<Biome> key;
public BiomeEntry(Biome biome, int weight)
public BiomeEntry(RegistryKey<Biome> key, int weight)
{
super(weight);
this.key = key;
}
this.biome = biome;
public RegistryKey<Biome> getKey()
{
return this.key;
}
}
@ -161,9 +151,10 @@ public class BiomeManager
private static final long serialVersionUID = 1L;
private boolean isModded = false;
public TrackedList(Collection<? extends E> c)
@SafeVarargs
private <T extends E> TrackedList(T... c)
{
super(c);
super(Arrays.asList(c));
}
@Override
@ -242,4 +233,3 @@ public class BiomeManager
}
}
}
*/

View file

@ -96,6 +96,13 @@ class NamespacedDefaultedWrapper<T extends IForgeRegistryEntry<T>> extends Defau
return this.delegate.getValue(name); //getOrDefault
}
@Override
@Nullable
public T func_230516_a_(@Nullable RegistryKey<T> name)
{
return name == null ? null : this.delegate.getRaw(name.func_240901_a_()); //get without default
}
@Override
@Nullable
public ResourceLocation getKey(T value)

View file

@ -94,6 +94,13 @@ class NamespacedWrapper<T extends IForgeRegistryEntry<T>> extends SimpleRegistry
return Optional.ofNullable( this.delegate.getRaw(name)); //get without default
}
@Override
@Nullable
public T func_230516_a_(@Nullable RegistryKey<T> name)
{
return name == null ? null : this.delegate.getRaw(name.func_240901_a_()); //get without default
}
@Override
@Nullable
public ResourceLocation getKey(T value)