Nether biome source (WIP)

This commit is contained in:
paulevsGitch 2021-08-13 21:55:40 +03:00
parent 34ecbb3f14
commit 683427c312
9 changed files with 215 additions and 12 deletions

View file

@ -42,6 +42,8 @@ public class BCLibEndBiomeSource extends BiomeSource {
public BCLibEndBiomeSource(Registry<Biome> biomeRegistry, long seed) {
super(getBiomes(biomeRegistry));
BiomeAPI.END_LAND_BIOME_PICKER.clearMutables();
BiomeAPI.END_VOID_BIOME_PICKER.clearMutables();
biomeRegistry.forEach(biome -> {
ResourceLocation key = biomeRegistry.getKey(biome);
BCLBiome bclBiome = BiomeAPI.getBiome(key);
@ -50,6 +52,8 @@ public class BCLibEndBiomeSource extends BiomeSource {
BiomeAPI.END_LAND_BIOME_PICKER.addBiomeMutable(bclBiome);
}
});
BiomeAPI.END_LAND_BIOME_PICKER.rebuild();
BiomeAPI.END_VOID_BIOME_PICKER.rebuild();
this.mapLand = new BiomeMap(seed, GeneratorOptions.getBiomeSizeEndLand(), BiomeAPI.END_LAND_BIOME_PICKER);
this.mapVoid = new BiomeMap(seed, GeneratorOptions.getBiomeSizeEndVoid(), BiomeAPI.END_VOID_BIOME_PICKER);
@ -74,6 +78,7 @@ public class BCLibEndBiomeSource extends BiomeSource {
public Biome getNoiseBiome(int biomeX, int biomeY, int biomeZ) {
long i = (long) biomeX * (long) biomeX;
long j = (long) biomeZ * (long) biomeZ;
long check = GeneratorOptions.isFarEndBiomes() ? 65536L : 625L;
long dist = i + j;
if ((biomeX & 31) == 0 && (biomeZ & 31) == 0) {
@ -81,9 +86,8 @@ public class BCLibEndBiomeSource extends BiomeSource {
mapVoid.clearCache();
}
BCLBiome endBiome = null;
if (endLandFunction == null) {
if (dist <= 65536L) return centerBiome;
if (dist <= check) return centerBiome;
float height = TheEndBiomeSource.getHeightValue(
noise,
(biomeX >> 1) + 1,
@ -104,10 +108,10 @@ public class BCLibEndBiomeSource extends BiomeSource {
else {
pos.setLocation(biomeX, biomeZ);
if (endLandFunction.apply(pos)) {
return dist <= 65536L ? centerBiome : mapLand.getBiome(biomeX << 2, biomeZ << 2).getActualBiome();
return dist <= check ? centerBiome : mapLand.getBiome(biomeX << 2, biomeZ << 2).getActualBiome();
}
else {
return dist <= 65536L ? barrens : mapVoid.getBiome(biomeX << 2, biomeZ << 2).getActualBiome();
return dist <= check ? barrens : mapVoid.getBiome(biomeX << 2, biomeZ << 2).getActualBiome();
}
}
}
@ -123,6 +127,6 @@ public class BCLibEndBiomeSource extends BiomeSource {
}
public static void register() {
Registry.register(Registry.BIOME_SOURCE, BCLib.makeID("better_end_biome_source"), CODEC);
Registry.register(Registry.BIOME_SOURCE, BCLib.makeID("end_biome_source"), CODEC);
}
}

View file

@ -0,0 +1,86 @@
package ru.bclib.world.generator;
import com.mojang.serialization.Codec;
import com.mojang.serialization.codecs.RecordCodecBuilder;
import net.minecraft.core.Registry;
import net.minecraft.resources.RegistryLookupCodec;
import net.minecraft.resources.ResourceLocation;
import net.minecraft.world.level.biome.Biome;
import net.minecraft.world.level.biome.BiomeSource;
import net.minecraft.world.level.biome.Biomes;
import net.minecraft.world.level.biome.TheEndBiomeSource;
import net.minecraft.world.level.levelgen.WorldgenRandom;
import net.minecraft.world.level.levelgen.synth.SimplexNoise;
import ru.bclib.BCLib;
import ru.bclib.api.BiomeAPI;
import ru.bclib.noise.OpenSimplexNoise;
import ru.bclib.world.biomes.BCLBiome;
import java.awt.Point;
import java.util.List;
import java.util.function.Function;
public class BCLibNetherBiomeSource extends BiomeSource {
public static final Codec<BCLibNetherBiomeSource> CODEC = RecordCodecBuilder.create((instance) -> {
return instance.group(RegistryLookupCodec.create(Registry.BIOME_REGISTRY).forGetter((theEndBiomeSource) -> {
return theEndBiomeSource.biomeRegistry;
}), Codec.LONG.fieldOf("seed").stable().forGetter((theEndBiomeSource) -> {
return theEndBiomeSource.seed;
})).apply(instance, instance.stable(BCLibNetherBiomeSource::new));
});
private final Registry<Biome> biomeRegistry;
private BiomeMap biomeMap;
private final long seed;
public BCLibNetherBiomeSource(Registry<Biome> biomeRegistry, long seed) {
super(getBiomes(biomeRegistry));
BiomeAPI.NETHER_BIOME_PICKER.clearMutables();
biomeRegistry.forEach(biome -> {
ResourceLocation key = biomeRegistry.getKey(biome);
BCLBiome bclBiome = BiomeAPI.getBiome(key);
bclBiome.updateActualBiomes(biomeRegistry);
if (!BiomeAPI.NETHER_BIOME_PICKER.containsImmutable(key)) {
BiomeAPI.NETHER_BIOME_PICKER.addBiomeMutable(bclBiome);
}
});
BiomeAPI.NETHER_BIOME_PICKER.rebuild();
this.biomeMap = new BiomeMap(seed, GeneratorOptions.getBiomeSizeEndLand(), BiomeAPI.NETHER_BIOME_PICKER);
this.biomeRegistry = biomeRegistry;
this.seed = seed;
WorldgenRandom chunkRandom = new WorldgenRandom(seed);
chunkRandom.consumeCount(17292);
}
private static List<Biome> getBiomes(Registry<Biome> biomeRegistry) {
return biomeRegistry.stream().filter(biome -> BiomeAPI.isEndBiome(biomeRegistry.getKey(biome))).toList();
}
@Override
public Biome getNoiseBiome(int biomeX, int biomeY, int biomeZ) {
long i = (long) biomeX * (long) biomeX;
long j = (long) biomeZ * (long) biomeZ;
if ((biomeX & 31) == 0 && (biomeZ & 31) == 0) {
biomeMap.clearCache();
}
return biomeMap.getBiome(biomeX << 2, biomeZ << 2).getActualBiome();
}
@Override
public BiomeSource withSeed(long seed) {
return new BCLibNetherBiomeSource(biomeRegistry, seed);
}
@Override
protected Codec<? extends BiomeSource> codec() {
return CODEC;
}
public static void register() {
Registry.register(Registry.BIOME_SOURCE, BCLib.makeID("nether_biome_source"), CODEC);
}
}

View file

@ -11,6 +11,7 @@ public class GeneratorOptions {
private static int biomeSizeEndLand;
private static int biomeSizeEndVoid;
private static Function<Point, Boolean> endLandFunction;
private static boolean farEndBiomes;
public static void init() {
biomeSizeNether = Configs.GENERATOR_CONFIG.getInt("nether.biomeMap", "biomeSize", 256);
@ -37,4 +38,12 @@ public class GeneratorOptions {
public static Function<Point, Boolean> getEndLandFunction() {
return endLandFunction;
}
public static boolean isFarEndBiomes() {
return farEndBiomes;
}
public static void setFarEndBiomes(boolean farEndBiomes) {
GeneratorOptions.farEndBiomes = farEndBiomes;
}
}