Land and void generation
This commit is contained in:
parent
84e26e1f5c
commit
e3c3d23a8f
6 changed files with 61 additions and 29 deletions
|
@ -14,39 +14,49 @@ import net.minecraft.world.biome.BiomeKeys;
|
|||
import ru.betterend.world.biome.BiomeDefinition;
|
||||
import ru.betterend.world.biome.EndBiome;
|
||||
import ru.betterend.world.generator.BiomePicker;
|
||||
import ru.betterend.world.generator.BiomeType;
|
||||
|
||||
public class BiomeRegistry {
|
||||
private static final Map<EndBiome, RegistryKey<Biome>> KEYS = Maps.newHashMap();
|
||||
public static final HashMap<Biome, EndBiome> MUTABLE = Maps.newHashMap();
|
||||
public static final BiomePicker LAND_BIOMES = new BiomePicker();
|
||||
public static final BiomePicker VOID_BIOMES = new BiomePicker();
|
||||
|
||||
public static final EndBiome END = registerBiome(BiomeKeys.THE_END);
|
||||
public static final EndBiome END_BARRENS = registerBiome(BiomeKeys.END_BARRENS);
|
||||
public static final EndBiome END_HIGHLANDS = registerBiome(BiomeKeys.END_HIGHLANDS);
|
||||
public static final EndBiome END_MIDLANDS = registerBiome(BiomeKeys.END_MIDLANDS);
|
||||
public static final EndBiome SMALL_END_ISLANDS = registerBiome(BiomeKeys.SMALL_END_ISLANDS);
|
||||
public static final EndBiome TEST = registerBiome(new EndBiome(new BiomeDefinition("test").setFogColor(255, 0, 0)));
|
||||
public static final EndBiome END = registerBiome(BiomeKeys.THE_END, BiomeType.LAND);
|
||||
public static final EndBiome END_BARRENS = registerBiome(BiomeKeys.END_BARRENS, BiomeType.VOID);
|
||||
public static final EndBiome END_HIGHLANDS = registerBiome(BiomeKeys.END_HIGHLANDS, BiomeType.LAND);
|
||||
public static final EndBiome END_MIDLANDS = registerBiome(BiomeKeys.END_MIDLANDS, BiomeType.LAND);
|
||||
public static final EndBiome SMALL_END_ISLANDS = registerBiome(BiomeKeys.SMALL_END_ISLANDS, BiomeType.VOID);
|
||||
public static final EndBiome TEST = registerBiome(new EndBiome(new BiomeDefinition("test").setFogColor(255, 0, 0)), BiomeType.VOID);
|
||||
|
||||
public static void register() {}
|
||||
|
||||
public static EndBiome registerBiome(RegistryKey<Biome> key) {
|
||||
public static EndBiome registerBiome(RegistryKey<Biome> key, BiomeType type) {
|
||||
EndBiome endBiome = new EndBiome(BuiltinRegistries.BIOME.get(key));
|
||||
BiomePicker.addBiome(endBiome);
|
||||
addToPicker(endBiome, type);
|
||||
makeLink(endBiome);
|
||||
return endBiome;
|
||||
}
|
||||
|
||||
public static EndBiome registerBiome(Biome biome) {
|
||||
public static EndBiome registerBiome(Biome biome, BiomeType type) {
|
||||
EndBiome endBiome = new EndBiome(biome);
|
||||
BiomePicker.addBiome(endBiome);
|
||||
addToPicker(endBiome, type);
|
||||
makeLink(endBiome);
|
||||
return endBiome;
|
||||
}
|
||||
|
||||
public static EndBiome registerBiome(EndBiome biome) {
|
||||
BiomePicker.addBiome(biome);
|
||||
public static EndBiome registerBiome(EndBiome biome, BiomeType type) {
|
||||
registerBiomeDirect(biome);
|
||||
addToPicker(biome, type);
|
||||
return biome;
|
||||
}
|
||||
|
||||
private static void addToPicker(EndBiome biome, BiomeType type) {
|
||||
if (type == BiomeType.LAND)
|
||||
LAND_BIOMES.addBiome(biome);
|
||||
else
|
||||
VOID_BIOMES.addBiome(biome);
|
||||
}
|
||||
|
||||
private static void registerBiomeDirect(EndBiome biome) {
|
||||
Registry.register(BuiltinRegistries.BIOME, biome.getID(), biome.getBiome());
|
||||
|
|
|
@ -6,11 +6,14 @@ import com.mojang.serialization.Codec;
|
|||
import com.mojang.serialization.codecs.RecordCodecBuilder;
|
||||
|
||||
import net.minecraft.util.Identifier;
|
||||
import net.minecraft.util.math.noise.SimplexNoiseSampler;
|
||||
import net.minecraft.util.registry.Registry;
|
||||
import net.minecraft.util.registry.RegistryLookupCodec;
|
||||
import net.minecraft.world.biome.Biome;
|
||||
import net.minecraft.world.biome.BiomeKeys;
|
||||
import net.minecraft.world.biome.source.BiomeSource;
|
||||
import net.minecraft.world.biome.source.TheEndBiomeSource;
|
||||
import net.minecraft.world.gen.ChunkRandom;
|
||||
import ru.betterend.BetterEnd;
|
||||
import ru.betterend.registry.BiomeRegistry;
|
||||
import ru.betterend.world.biome.EndBiome;
|
||||
|
@ -23,20 +26,28 @@ public class BetterEndBiomeSource extends BiomeSource {
|
|||
return theEndBiomeSource.seed;
|
||||
})).apply(instance, instance.stable(BetterEndBiomeSource::new));
|
||||
});
|
||||
private BiomeMap map;
|
||||
private final long seed;
|
||||
private final Registry<Biome> biomeRegistry;
|
||||
private final SimplexNoiseSampler noise;
|
||||
private final Biome centerBiome;
|
||||
private BiomeMap mapLand;
|
||||
private BiomeMap mapVoid;
|
||||
|
||||
public BetterEndBiomeSource(Registry<Biome> biomeRegistry, long seed) {
|
||||
super(Collections.emptyList());
|
||||
this.seed = seed;
|
||||
this.map = new BiomeMap(seed, 50);
|
||||
this.mapLand = new BiomeMap(seed, 50, BiomeRegistry.LAND_BIOMES);
|
||||
this.mapVoid = new BiomeMap(seed, 50, BiomeRegistry.VOID_BIOMES);
|
||||
this.biomeRegistry = biomeRegistry;
|
||||
this.centerBiome = biomeRegistry.getOrThrow(BiomeKeys.THE_END);
|
||||
ChunkRandom chunkRandom = new ChunkRandom(seed);
|
||||
chunkRandom.consume(17292);
|
||||
this.noise = new SimplexNoiseSampler(chunkRandom);
|
||||
|
||||
BiomeRegistry.MUTABLE.clear();
|
||||
for (EndBiome biome : BiomePicker.getBiomes())
|
||||
for (EndBiome biome : BiomeRegistry.LAND_BIOMES.getBiomes())
|
||||
BiomeRegistry.MUTABLE.put(biomeRegistry.getOrThrow(BiomeRegistry.getBiomeKey(biome)), biome);
|
||||
for (EndBiome biome : BiomeRegistry.VOID_BIOMES.getBiomes())
|
||||
BiomeRegistry.MUTABLE.put(biomeRegistry.getOrThrow(BiomeRegistry.getBiomeKey(biome)), biome);
|
||||
}
|
||||
|
||||
|
@ -45,10 +56,13 @@ public class BetterEndBiomeSource extends BiomeSource {
|
|||
long i = biomeX >> 2;
|
||||
long j = biomeZ >> 2;
|
||||
if (i * i + j * j <= 4096L) return this.centerBiome;
|
||||
|
||||
float height = TheEndBiomeSource.getNoiseAt(noise, (int) i * 2 + 1, (int) j * 2 + 1);
|
||||
|
||||
EndBiome netherBiome = map.getBiome(biomeX << 2, biomeZ << 2);
|
||||
EndBiome netherBiome = height < 20.0F ? mapVoid.getBiome(biomeX << 2, biomeZ << 2) : mapLand.getBiome(biomeX << 2, biomeZ << 2);
|
||||
if (biomeX == 0 && biomeZ == 0) {
|
||||
map.clearCache();
|
||||
mapLand.clearCache();
|
||||
mapVoid.clearCache();
|
||||
}
|
||||
return biomeRegistry.getOrThrow(BiomeRegistry.getBiomeKey(netherBiome));
|
||||
}
|
||||
|
|
|
@ -13,14 +13,14 @@ public class BiomeChunk
|
|||
|
||||
private final EndBiome[][] biomes;
|
||||
|
||||
public BiomeChunk(BiomeMap map, Random random)
|
||||
public BiomeChunk(BiomeMap map, Random random, BiomePicker picker)
|
||||
{
|
||||
EndBiome[][] PreBio = new EndBiome[SM_WIDTH][SM_WIDTH];
|
||||
biomes = new EndBiome[WIDTH][WIDTH];
|
||||
|
||||
for (int x = 0; x < SM_WIDTH; x++)
|
||||
for (int z = 0; z < SM_WIDTH; z++)
|
||||
PreBio[x][z] = BiomePicker.getBiome(random);
|
||||
PreBio[x][z] = picker.getBiome(random);
|
||||
|
||||
for (int x = 0; x < WIDTH; x++)
|
||||
for (int z = 0; z < WIDTH; z++)
|
||||
|
|
|
@ -18,8 +18,9 @@ public class BiomeMap
|
|||
private final int depth;
|
||||
private final OpenSimplexNoise noiseX;;
|
||||
private final OpenSimplexNoise noiseZ;
|
||||
private final BiomePicker picker;
|
||||
|
||||
public BiomeMap(long seed, int size)
|
||||
public BiomeMap(long seed, int size, BiomePicker picker)
|
||||
{
|
||||
RANDOM.setSeed(seed);
|
||||
noiseX = new OpenSimplexNoise(RANDOM.nextLong());
|
||||
|
@ -27,6 +28,7 @@ public class BiomeMap
|
|||
this.sizeXZ = size;
|
||||
depth = (int) Math.ceil(Math.log(size) / Math.log(2)) - 2;
|
||||
this.size = 1 << depth;
|
||||
this.picker = picker;
|
||||
}
|
||||
|
||||
public void clearCache()
|
||||
|
@ -62,7 +64,7 @@ public class BiomeMap
|
|||
if (chunk == null)
|
||||
{
|
||||
RANDOM.setTerrainSeed(cpos.x, cpos.z);
|
||||
chunk = new BiomeChunk(this, RANDOM);
|
||||
chunk = new BiomeChunk(this, RANDOM, picker);
|
||||
MAPS.put(cpos, chunk);
|
||||
}
|
||||
|
||||
|
|
|
@ -9,23 +9,23 @@ import ru.betterend.registry.BiomeRegistry;
|
|||
import ru.betterend.world.biome.EndBiome;
|
||||
|
||||
public class BiomePicker {
|
||||
private static final List<EndBiome> BIOMES = Lists.newArrayList();
|
||||
private static float maxChance = 0;
|
||||
private final List<EndBiome> biomes = Lists.newArrayList();
|
||||
private float maxChance = 0;
|
||||
|
||||
public static void addBiome(EndBiome biome) {
|
||||
BIOMES.add(biome);
|
||||
public void addBiome(EndBiome biome) {
|
||||
biomes.add(biome);
|
||||
maxChance = biome.setGenChance(maxChance);
|
||||
}
|
||||
|
||||
public static EndBiome getBiome(Random random) {
|
||||
public EndBiome getBiome(Random random) {
|
||||
float chance = random.nextFloat() * maxChance;
|
||||
for (EndBiome biome: BIOMES)
|
||||
for (EndBiome biome: biomes)
|
||||
if (biome.canGenerate(chance))
|
||||
return biome;
|
||||
return BiomeRegistry.END;
|
||||
}
|
||||
|
||||
public static List<EndBiome> getBiomes() {
|
||||
return BIOMES;
|
||||
public List<EndBiome> getBiomes() {
|
||||
return biomes;
|
||||
}
|
||||
}
|
||||
|
|
|
@ -0,0 +1,6 @@
|
|||
package ru.betterend.world.generator;
|
||||
|
||||
public enum BiomeType {
|
||||
LAND,
|
||||
VOID;
|
||||
}
|
Loading…
Add table
Add a link
Reference in a new issue