Improved biome generator

This commit is contained in:
paulevsGitch 2020-10-24 11:11:21 +03:00
parent cfba07ba6d
commit 3cefefc409
2 changed files with 24 additions and 27 deletions

View file

@ -6,6 +6,7 @@ import java.util.Optional;
import com.google.common.collect.Maps; import com.google.common.collect.Maps;
import net.minecraft.util.Identifier;
import net.minecraft.util.registry.BuiltinRegistries; 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;
@ -22,11 +23,14 @@ import ru.betterend.world.generator.BiomeType;
public class BiomeRegistry { public class BiomeRegistry {
private static final Map<EndBiome, RegistryKey<Biome>> KEYS = Maps.newHashMap(); private static final Map<EndBiome, RegistryKey<Biome>> KEYS = Maps.newHashMap();
private static final HashMap<Identifier, EndBiome> ID_MAP = Maps.newHashMap();
private static final HashMap<Biome, EndBiome> MUTABLE = Maps.newHashMap(); private static final HashMap<Biome, EndBiome> MUTABLE = Maps.newHashMap();
private static final HashMap<Biome, EndBiome> CLIENT = Maps.newHashMap();
public static final BiomePicker LAND_BIOMES = new BiomePicker(); public static final BiomePicker LAND_BIOMES = new BiomePicker();
public static final BiomePicker VOID_BIOMES = new BiomePicker(); public static final BiomePicker VOID_BIOMES = new BiomePicker();
private static Registry<Biome> biomeRegistry;
public static final EndBiome END = registerBiome(BiomeKeys.THE_END, BiomeType.LAND, true); public static final EndBiome END = registerBiome(BiomeKeys.THE_END, BiomeType.LAND, true);
public static final EndBiome END_BARRENS = registerBiome(BiomeKeys.END_BARRENS, BiomeType.VOID, true); public static final EndBiome END_BARRENS = registerBiome(BiomeKeys.END_BARRENS, BiomeType.VOID, true);
public static final EndBiome END_HIGHLANDS = registerBiome(BiomeKeys.END_HIGHLANDS, BiomeType.LAND, true); public static final EndBiome END_HIGHLANDS = registerBiome(BiomeKeys.END_HIGHLANDS, BiomeType.LAND, true);
@ -40,6 +44,8 @@ public class BiomeRegistry {
public static void register() {} public static void register() {}
public static void mutateRegistry(Registry<Biome> biomeRegistry) { public static void mutateRegistry(Registry<Biome> biomeRegistry) {
BiomeRegistry.biomeRegistry = biomeRegistry;
BiomeRegistry.MUTABLE.clear(); BiomeRegistry.MUTABLE.clear();
LAND_BIOMES.clearMutables(); LAND_BIOMES.clearMutables();
@ -76,7 +82,7 @@ public class BiomeRegistry {
public static EndBiome registerBiome(EndBiome biome, BiomeType type) { public static EndBiome registerBiome(EndBiome biome, BiomeType type) {
registerBiomeDirect(biome); registerBiomeDirect(biome);
addToPicker(biome, type); addToPicker(biome, type);
CLIENT.put(biome.getBiome(), biome); ID_MAP.put(biome.getID(), biome);
return biome; return biome;
} }
@ -102,28 +108,10 @@ public class BiomeRegistry {
return KEYS.get(biome); return KEYS.get(biome);
} }
private static boolean equals(Biome biome1, Biome biome2) {
return (biome1.getDepth() - biome2.getDepth() == 0) &&
(biome1.getDownfall() - biome2.getDownfall() == 0) &&
(biome1.getScale() - biome2.getScale() == 0) &&
(biome1.getCategory() == biome2.getCategory()) &&
(biome1.getFogColor() == biome2.getFogColor()) &&
(biome1.getSkyColor() == biome2.getSkyColor()) &&
(biome1.getWaterColor() == biome2.getWaterColor()) &&
(biome1.getWaterFogColor() == biome2.getWaterFogColor()) &&
(biome1.getPrecipitation().equals(biome2.getPrecipitation()));
}
public static EndBiome getFromBiome(Biome biome) { public static EndBiome getFromBiome(Biome biome) {
EndBiome endBiome = MUTABLE.get(biome); EndBiome endBiome = MUTABLE.get(biome);
if (endBiome == null) { if (endBiome == null) {
for (Biome key: CLIENT.keySet()) { endBiome = ID_MAP.getOrDefault(biomeRegistry.getId(biome), END);
if (equals(key, biome)) {
endBiome = CLIENT.get(key);
MUTABLE.put(biome, endBiome);
return endBiome;
}
}
MUTABLE.put(biome, END); MUTABLE.put(biome, END);
return END; return END;
} }

View file

@ -16,6 +16,7 @@ import net.minecraft.world.biome.source.BiomeSource;
import net.minecraft.world.biome.source.TheEndBiomeSource; import net.minecraft.world.biome.source.TheEndBiomeSource;
import net.minecraft.world.gen.ChunkRandom; import net.minecraft.world.gen.ChunkRandom;
import ru.betterend.BetterEnd; import ru.betterend.BetterEnd;
import ru.betterend.noise.OpenSimplexNoise;
import ru.betterend.registry.BiomeRegistry; import ru.betterend.registry.BiomeRegistry;
import ru.betterend.registry.BlockTagRegistry; import ru.betterend.registry.BlockTagRegistry;
import ru.betterend.util.FeaturesHelper; import ru.betterend.util.FeaturesHelper;
@ -29,9 +30,11 @@ public class BetterEndBiomeSource extends BiomeSource {
return theEndBiomeSource.seed; return theEndBiomeSource.seed;
})).apply(instance, instance.stable(BetterEndBiomeSource::new)); })).apply(instance, instance.stable(BetterEndBiomeSource::new));
}); });
private static final OpenSimplexNoise SMALL_NOISE = new OpenSimplexNoise(8324);
private final Registry<Biome> biomeRegistry; private final Registry<Biome> biomeRegistry;
private final SimplexNoiseSampler noise; private final SimplexNoiseSampler noise;
private final Biome centerBiome; private final Biome centerBiome;
private final Biome barrens;
private BiomeMap mapLand; private BiomeMap mapLand;
private BiomeMap mapVoid; private BiomeMap mapVoid;
private final long seed; private final long seed;
@ -42,6 +45,7 @@ public class BetterEndBiomeSource extends BiomeSource {
this.mapLand = new BiomeMap(seed, 256, BiomeRegistry.LAND_BIOMES); this.mapLand = new BiomeMap(seed, 256, BiomeRegistry.LAND_BIOMES);
this.mapVoid = new BiomeMap(seed, 256, BiomeRegistry.VOID_BIOMES); this.mapVoid = new BiomeMap(seed, 256, BiomeRegistry.VOID_BIOMES);
this.centerBiome = biomeRegistry.getOrThrow(BiomeKeys.THE_END); this.centerBiome = biomeRegistry.getOrThrow(BiomeKeys.THE_END);
this.barrens = biomeRegistry.getOrThrow(BiomeKeys.END_BARRENS);
this.biomeRegistry = biomeRegistry; this.biomeRegistry = biomeRegistry;
this.seed = seed; this.seed = seed;
@ -66,17 +70,22 @@ public class BetterEndBiomeSource extends BiomeSource {
@Override @Override
public Biome getBiomeForNoiseGen(int biomeX, int biomeY, int biomeZ) { public Biome getBiomeForNoiseGen(int biomeX, int biomeY, int biomeZ) {
long i = biomeX >> 2; long i = (long) biomeX * (long) biomeX;
long j = biomeZ >> 2; long j = (long) biomeZ * (long) biomeZ;
if (i * i + j * j <= 4096L) return this.centerBiome; if (i + j <= 65536L) return this.centerBiome;
float height = TheEndBiomeSource.getNoiseAt(noise, (int) i * 2 + 1, (int) j * 2 + 1); float height = TheEndBiomeSource.getNoiseAt(noise, (biomeX >> 1) + 1, (biomeZ >> 1) + 1) + (float) SMALL_NOISE.eval(biomeX, biomeZ) * 5;
EndBiome netherBiome = height < -2.0F ? mapVoid.getBiome(biomeX << 2, biomeZ << 2) : mapLand.getBiome(biomeX << 2, biomeZ << 2); if (height > -20F && height < -5F) {
return barrens;
}
EndBiome netherBiome = height < -10F ? mapVoid.getBiome(biomeX << 2, biomeZ << 2) : mapLand.getBiome(biomeX << 2, biomeZ << 2);
if (biomeX == 0 && biomeZ == 0) { if (biomeX == 0 && biomeZ == 0) {
mapLand.clearCache(); mapLand.clearCache();
mapVoid.clearCache(); mapVoid.clearCache();
} }
return biomeRegistry.getOrThrow(BiomeRegistry.getBiomeKey(netherBiome)); return biomeRegistry.getOrThrow(BiomeRegistry.getBiomeKey(netherBiome));
} }