Biome fixes
This commit is contained in:
parent
355054202a
commit
368d21a37e
3 changed files with 38 additions and 16 deletions
|
@ -1,7 +1,8 @@
|
|||
package ru.betterend.world.generator;
|
||||
|
||||
import java.util.Collections;
|
||||
import java.util.List;
|
||||
|
||||
import com.google.common.collect.Lists;
|
||||
import com.mojang.serialization.Codec;
|
||||
import com.mojang.serialization.codecs.RecordCodecBuilder;
|
||||
|
||||
|
@ -9,6 +10,7 @@ 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.Biome.Category;
|
||||
import net.minecraft.world.biome.BiomeKeys;
|
||||
import net.minecraft.world.biome.source.BiomeSource;
|
||||
import net.minecraft.world.biome.source.TheEndBiomeSource;
|
||||
|
@ -33,10 +35,10 @@ public class BetterEndBiomeSource extends BiomeSource {
|
|||
private final long seed;
|
||||
|
||||
public BetterEndBiomeSource(Registry<Biome> biomeRegistry, long seed) {
|
||||
super(Collections.emptyList());
|
||||
super(getBiomes(biomeRegistry));
|
||||
|
||||
this.mapLand = new BiomeMap(seed, 250, BiomeRegistry.LAND_BIOMES);
|
||||
this.mapVoid = new BiomeMap(seed, 250, BiomeRegistry.VOID_BIOMES);
|
||||
this.mapLand = new BiomeMap(seed, 256, BiomeRegistry.LAND_BIOMES);
|
||||
this.mapVoid = new BiomeMap(seed, 256, BiomeRegistry.VOID_BIOMES);
|
||||
this.centerBiome = biomeRegistry.getOrThrow(BiomeKeys.THE_END);
|
||||
this.biomeRegistry = biomeRegistry;
|
||||
this.seed = seed;
|
||||
|
@ -47,6 +49,16 @@ public class BetterEndBiomeSource extends BiomeSource {
|
|||
|
||||
BiomeRegistry.mutateRegistry(biomeRegistry);
|
||||
}
|
||||
|
||||
private static List<Biome> getBiomes(Registry<Biome> biomeRegistry) {
|
||||
List<Biome> list = Lists.newArrayList();
|
||||
biomeRegistry.forEach((biome) -> {
|
||||
if (biome.getCategory() == Category.THEEND) {
|
||||
list.add(biome);
|
||||
}
|
||||
});
|
||||
return list;
|
||||
}
|
||||
|
||||
@Override
|
||||
public Biome getBiomeForNoiseGen(int biomeX, int biomeY, int biomeZ) {
|
||||
|
@ -56,7 +68,7 @@ public class BetterEndBiomeSource extends BiomeSource {
|
|||
|
||||
float height = TheEndBiomeSource.getNoiseAt(noise, (int) i * 2 + 1, (int) j * 2 + 1);
|
||||
|
||||
EndBiome netherBiome = height < -20.0F ? mapVoid.getBiome(biomeX << 2, biomeZ << 2) : mapLand.getBiome(biomeX << 2, biomeZ << 2);
|
||||
EndBiome netherBiome = height < -2.0F ? mapVoid.getBiome(biomeX << 2, biomeZ << 2) : mapLand.getBiome(biomeX << 2, biomeZ << 2);
|
||||
if (biomeX == 0 && biomeZ == 0) {
|
||||
mapLand.clearCache();
|
||||
mapVoid.clearCache();
|
||||
|
|
|
@ -8,8 +8,8 @@ public class BiomeChunk
|
|||
{
|
||||
protected static final int WIDTH = 16;
|
||||
private static final int SM_WIDTH = WIDTH >> 1;
|
||||
private static final int MASK_A = SM_WIDTH - 1;
|
||||
private static final int MASK_C = WIDTH - 1;
|
||||
private static final int MASK_OFFSET = SM_WIDTH - 1;
|
||||
protected static final int MASK_WIDTH = WIDTH - 1;
|
||||
|
||||
private final EndBiome[][] biomes;
|
||||
|
||||
|
@ -29,11 +29,11 @@ public class BiomeChunk
|
|||
|
||||
public EndBiome getBiome(int x, int z)
|
||||
{
|
||||
return biomes[x & MASK_C][z & MASK_C];
|
||||
return biomes[x & MASK_WIDTH][z & MASK_WIDTH];
|
||||
}
|
||||
|
||||
private int offsetXZ(int x, Random random)
|
||||
{
|
||||
return ((x + random.nextInt(2)) >> 1) & MASK_A;
|
||||
return ((x + random.nextInt(2)) >> 1) & MASK_OFFSET;
|
||||
}
|
||||
}
|
||||
|
|
|
@ -10,19 +10,19 @@ import ru.betterend.world.biome.EndBiome;
|
|||
|
||||
public class BiomeMap
|
||||
{
|
||||
private static final HashMap<ChunkPos, BiomeChunk> MAPS = new HashMap<ChunkPos, BiomeChunk>();
|
||||
private static final ChunkRandom RANDOM = new ChunkRandom();
|
||||
|
||||
private final HashMap<ChunkPos, BiomeChunk> maps = new HashMap<ChunkPos, BiomeChunk>();
|
||||
private final int size;
|
||||
private final int sizeXZ;
|
||||
private final int depth;
|
||||
private final OpenSimplexNoise noiseX;;
|
||||
private final OpenSimplexNoise noiseX;
|
||||
private final OpenSimplexNoise noiseZ;
|
||||
private final BiomePicker picker;
|
||||
|
||||
public BiomeMap(long seed, int size, BiomePicker picker)
|
||||
{
|
||||
MAPS.clear();
|
||||
maps.clear();
|
||||
RANDOM.setSeed(seed);
|
||||
noiseX = new OpenSimplexNoise(RANDOM.nextLong());
|
||||
noiseZ = new OpenSimplexNoise(RANDOM.nextLong());
|
||||
|
@ -34,8 +34,9 @@ public class BiomeMap
|
|||
|
||||
public void clearCache()
|
||||
{
|
||||
if (MAPS.size() > 16)
|
||||
MAPS.clear();
|
||||
if (maps.size() > 32) {
|
||||
maps.clear();
|
||||
}
|
||||
}
|
||||
|
||||
private EndBiome getRawBiome(int bx, int bz)
|
||||
|
@ -60,13 +61,22 @@ public class BiomeMap
|
|||
pz = pz / 2 + i;
|
||||
}
|
||||
|
||||
bx = MHelper.floor(x);
|
||||
bz = MHelper.floor(z);
|
||||
if ((bx & BiomeChunk.MASK_WIDTH) == BiomeChunk.MASK_WIDTH) {
|
||||
x += (bz / 2) & 1;
|
||||
}
|
||||
if ((bz & BiomeChunk.MASK_WIDTH) == BiomeChunk.MASK_WIDTH) {
|
||||
z += (bx / 2) & 1;
|
||||
}
|
||||
|
||||
ChunkPos cpos = new ChunkPos(MHelper.floor(x / BiomeChunk.WIDTH), MHelper.floor(z / BiomeChunk.WIDTH));
|
||||
BiomeChunk chunk = MAPS.get(cpos);
|
||||
BiomeChunk chunk = maps.get(cpos);
|
||||
if (chunk == null)
|
||||
{
|
||||
RANDOM.setTerrainSeed(cpos.x, cpos.z);
|
||||
chunk = new BiomeChunk(this, RANDOM, picker);
|
||||
MAPS.put(cpos, chunk);
|
||||
maps.put(cpos, chunk);
|
||||
}
|
||||
|
||||
return chunk.getBiome(MHelper.floor(x), MHelper.floor(z));
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue