Mutable registry
This commit is contained in:
parent
de7c7e1cdb
commit
b89afced36
4 changed files with 42 additions and 0 deletions
|
@ -10,6 +10,7 @@ import net.minecraft.util.registry.BuiltinRegistries;
|
||||||
import net.minecraft.util.registry.Registry;
|
import net.minecraft.util.registry.Registry;
|
||||||
import net.minecraft.util.registry.RegistryKey;
|
import net.minecraft.util.registry.RegistryKey;
|
||||||
import net.minecraft.world.biome.Biome;
|
import net.minecraft.world.biome.Biome;
|
||||||
|
import net.minecraft.world.biome.Biome.Category;
|
||||||
import net.minecraft.world.biome.BiomeKeys;
|
import net.minecraft.world.biome.BiomeKeys;
|
||||||
import ru.betterend.world.biome.BiomeFoggyMushroomland;
|
import ru.betterend.world.biome.BiomeFoggyMushroomland;
|
||||||
import ru.betterend.world.biome.EndBiome;
|
import ru.betterend.world.biome.EndBiome;
|
||||||
|
@ -33,10 +34,22 @@ public class BiomeRegistry {
|
||||||
|
|
||||||
public static void mutateRegistry(Registry<Biome> biomeRegistry) {
|
public static void mutateRegistry(Registry<Biome> biomeRegistry) {
|
||||||
BiomeRegistry.MUTABLE.clear();
|
BiomeRegistry.MUTABLE.clear();
|
||||||
|
LAND_BIOMES.clearMutables();
|
||||||
|
|
||||||
for (EndBiome biome : BiomeRegistry.LAND_BIOMES.getBiomes())
|
for (EndBiome biome : BiomeRegistry.LAND_BIOMES.getBiomes())
|
||||||
BiomeRegistry.MUTABLE.put(biomeRegistry.getOrThrow(BiomeRegistry.getBiomeKey(biome)), biome);
|
BiomeRegistry.MUTABLE.put(biomeRegistry.getOrThrow(BiomeRegistry.getBiomeKey(biome)), biome);
|
||||||
for (EndBiome biome : BiomeRegistry.VOID_BIOMES.getBiomes())
|
for (EndBiome biome : BiomeRegistry.VOID_BIOMES.getBiomes())
|
||||||
BiomeRegistry.MUTABLE.put(biomeRegistry.getOrThrow(BiomeRegistry.getBiomeKey(biome)), biome);
|
BiomeRegistry.MUTABLE.put(biomeRegistry.getOrThrow(BiomeRegistry.getBiomeKey(biome)), biome);
|
||||||
|
|
||||||
|
biomeRegistry.forEach((biome) -> {
|
||||||
|
if (biome.getCategory() == Category.THEEND) {
|
||||||
|
if (!MUTABLE.containsKey(biome) && !biomeRegistry.getId(biome).getNamespace().equals("minecraft")) {
|
||||||
|
EndBiome endBiome = new EndBiome(biome);
|
||||||
|
LAND_BIOMES.addBiomeMutable(endBiome);
|
||||||
|
KEYS.put(endBiome, biomeRegistry.getKey(biome).get());
|
||||||
|
}
|
||||||
|
}
|
||||||
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
public static EndBiome registerBiome(RegistryKey<Biome> key, BiomeType type, boolean addToGen) {
|
public static EndBiome registerBiome(RegistryKey<Biome> key, BiomeType type, boolean addToGen) {
|
||||||
|
|
|
@ -51,6 +51,7 @@ public class BiomeDefinition {
|
||||||
private float fogDensity = 1F;
|
private float fogDensity = 1F;
|
||||||
|
|
||||||
private final Identifier id;
|
private final Identifier id;
|
||||||
|
private float genChance = 1F;
|
||||||
|
|
||||||
private ConfiguredSurfaceBuilder<?> surface;
|
private ConfiguredSurfaceBuilder<?> surface;
|
||||||
|
|
||||||
|
@ -86,6 +87,11 @@ public class BiomeDefinition {
|
||||||
this.particleConfig = config;
|
this.particleConfig = config;
|
||||||
return this;
|
return this;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public BiomeDefinition setGenChance(float genChance) {
|
||||||
|
this.genChance = genChance;
|
||||||
|
return this;
|
||||||
|
}
|
||||||
|
|
||||||
public BiomeDefinition addMobSpawn(EntityType<?> type, int weight, int minGroupSize, int maxGroupSize) {
|
public BiomeDefinition addMobSpawn(EntityType<?> type, int weight, int minGroupSize, int maxGroupSize) {
|
||||||
Identifier eID = Registry.ENTITY_TYPE.getId(type);
|
Identifier eID = Registry.ENTITY_TYPE.getId(type);
|
||||||
|
@ -223,4 +229,8 @@ public class BiomeDefinition {
|
||||||
public float getFodDensity() {
|
public float getFodDensity() {
|
||||||
return fogDensity;
|
return fogDensity;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public float getGenChance() {
|
||||||
|
return genChance;
|
||||||
|
}
|
||||||
}
|
}
|
|
@ -21,6 +21,7 @@ public class EndBiome {
|
||||||
|
|
||||||
protected EndBiome biomeParent;
|
protected EndBiome biomeParent;
|
||||||
protected float maxSubBiomeChance = 1;
|
protected float maxSubBiomeChance = 1;
|
||||||
|
protected final float genChanceUnmutable;
|
||||||
protected float genChance = 1;
|
protected float genChance = 1;
|
||||||
|
|
||||||
private final float fogDensity;
|
private final float fogDensity;
|
||||||
|
@ -29,12 +30,14 @@ public class EndBiome {
|
||||||
biome = definition.build();
|
biome = definition.build();
|
||||||
mcID = definition.getID();
|
mcID = definition.getID();
|
||||||
fogDensity = definition.getFodDensity();
|
fogDensity = definition.getFodDensity();
|
||||||
|
genChanceUnmutable = definition.getGenChance();
|
||||||
}
|
}
|
||||||
|
|
||||||
public EndBiome(Biome biome) {
|
public EndBiome(Biome biome) {
|
||||||
this.biome = biome;
|
this.biome = biome;
|
||||||
mcID = BuiltinRegistries.BIOME.getId(biome);
|
mcID = BuiltinRegistries.BIOME.getId(biome);
|
||||||
fogDensity = 1;
|
fogDensity = 1;
|
||||||
|
genChanceUnmutable = 1;
|
||||||
}
|
}
|
||||||
|
|
||||||
public void genSurfColumn(WorldAccess world, BlockPos pos, Random random) {
|
public void genSurfColumn(WorldAccess world, BlockPos pos, Random random) {
|
||||||
|
@ -106,6 +109,7 @@ public class EndBiome {
|
||||||
}
|
}
|
||||||
|
|
||||||
public float setGenChance(float chance) {
|
public float setGenChance(float chance) {
|
||||||
|
genChance = genChanceUnmutable;
|
||||||
genChance += chance;
|
genChance += chance;
|
||||||
return genChance;
|
return genChance;
|
||||||
}
|
}
|
||||||
|
|
|
@ -10,11 +10,26 @@ import ru.betterend.world.biome.EndBiome;
|
||||||
|
|
||||||
public class BiomePicker {
|
public class BiomePicker {
|
||||||
private final List<EndBiome> biomes = Lists.newArrayList();
|
private final List<EndBiome> biomes = Lists.newArrayList();
|
||||||
|
private float maxChanceUnmutable = 0;
|
||||||
private float maxChance = 0;
|
private float maxChance = 0;
|
||||||
|
private int biomeCount = 0;
|
||||||
|
|
||||||
public void addBiome(EndBiome biome) {
|
public void addBiome(EndBiome biome) {
|
||||||
biomes.add(biome);
|
biomes.add(biome);
|
||||||
maxChance = biome.setGenChance(maxChance);
|
maxChance = biome.setGenChance(maxChance);
|
||||||
|
biomeCount ++;
|
||||||
|
maxChanceUnmutable = maxChance;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void addBiomeMutable(EndBiome biome) {
|
||||||
|
biomes.add(biome);
|
||||||
|
maxChance = biome.setGenChance(maxChance);
|
||||||
|
}
|
||||||
|
|
||||||
|
public void clearMutables() {
|
||||||
|
maxChance = maxChanceUnmutable;
|
||||||
|
for (int i = biomes.size() - 1; i >= biomeCount; i--)
|
||||||
|
biomes.remove(i);
|
||||||
}
|
}
|
||||||
|
|
||||||
public EndBiome getBiome(Random random) {
|
public EndBiome getBiome(Random random) {
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue