This commit is contained in:
Aleksey 2020-10-16 16:24:09 +03:00
commit 9d467a4d03
5 changed files with 85 additions and 16 deletions

View file

@ -0,0 +1,46 @@
package ru.betterend.mixin.common;
import java.util.Iterator;
import java.util.Map;
import java.util.Map.Entry;
import org.spongepowered.asm.mixin.Mixin;
import org.spongepowered.asm.mixin.Overwrite;
import it.unimi.dsi.fastutil.longs.LongSet;
import net.minecraft.nbt.CompoundTag;
import net.minecraft.nbt.LongArrayTag;
import net.minecraft.structure.StructureStart;
import net.minecraft.util.math.ChunkPos;
import net.minecraft.world.ChunkSerializer;
import net.minecraft.world.gen.feature.StructureFeature;
@Mixin(ChunkSerializer.class)
public class ChunkSerializerMixin {
@Overwrite
private static CompoundTag writeStructures(ChunkPos pos, Map<StructureFeature<?>, StructureStart<?>> structureStarts, Map<StructureFeature<?>, LongSet> structureReferences) {
CompoundTag tagResult = new CompoundTag();
CompoundTag tagStarts = new CompoundTag();
Iterator<Entry<StructureFeature<?>, StructureStart<?>>> startsIterator = structureStarts.entrySet().iterator();
while (startsIterator.hasNext()) {
Entry<StructureFeature<?>, StructureStart<?>> start = startsIterator.next();
tagStarts.put((start.getKey()).getName(), (start.getValue()).toTag(pos.x, pos.z));
}
tagResult.put("Starts", tagStarts);
CompoundTag tagReferences = new CompoundTag();
Iterator<Entry<StructureFeature<?>, LongSet>> refIterator = structureReferences.entrySet().iterator();
while (refIterator.hasNext()) {
Entry<StructureFeature<?>, LongSet> feature = refIterator.next();
// Structures sometimes can be null
if (feature.getKey() != null) {
tagReferences.put((feature.getKey()).getName(), new LongArrayTag(feature.getValue()));
}
}
tagResult.put("References", tagReferences);
return tagResult;
}
}

View file

@ -1,7 +1,8 @@
package ru.betterend.world.generator; 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.Codec;
import com.mojang.serialization.codecs.RecordCodecBuilder; 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.Registry;
import net.minecraft.util.registry.RegistryLookupCodec; import net.minecraft.util.registry.RegistryLookupCodec;
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 net.minecraft.world.biome.source.BiomeSource; import net.minecraft.world.biome.source.BiomeSource;
import net.minecraft.world.biome.source.TheEndBiomeSource; import net.minecraft.world.biome.source.TheEndBiomeSource;
@ -33,10 +35,10 @@ public class BetterEndBiomeSource extends BiomeSource {
private final long seed; private final long seed;
public BetterEndBiomeSource(Registry<Biome> biomeRegistry, 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.mapLand = new BiomeMap(seed, 256, BiomeRegistry.LAND_BIOMES);
this.mapVoid = new BiomeMap(seed, 250, 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.biomeRegistry = biomeRegistry; this.biomeRegistry = biomeRegistry;
this.seed = seed; this.seed = seed;
@ -48,6 +50,16 @@ public class BetterEndBiomeSource extends BiomeSource {
BiomeRegistry.mutateRegistry(biomeRegistry); 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 @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 = biomeX >> 2;
@ -56,7 +68,7 @@ public class BetterEndBiomeSource extends BiomeSource {
float height = TheEndBiomeSource.getNoiseAt(noise, (int) i * 2 + 1, (int) j * 2 + 1); 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) { if (biomeX == 0 && biomeZ == 0) {
mapLand.clearCache(); mapLand.clearCache();
mapVoid.clearCache(); mapVoid.clearCache();

View file

@ -8,8 +8,8 @@ public class BiomeChunk
{ {
protected static final int WIDTH = 16; protected static final int WIDTH = 16;
private static final int SM_WIDTH = WIDTH >> 1; private static final int SM_WIDTH = WIDTH >> 1;
private static final int MASK_A = SM_WIDTH - 1; private static final int MASK_OFFSET = SM_WIDTH - 1;
private static final int MASK_C = WIDTH - 1; protected static final int MASK_WIDTH = WIDTH - 1;
private final EndBiome[][] biomes; private final EndBiome[][] biomes;
@ -29,11 +29,11 @@ public class BiomeChunk
public EndBiome getBiome(int x, int z) 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) private int offsetXZ(int x, Random random)
{ {
return ((x + random.nextInt(2)) >> 1) & MASK_A; return ((x + random.nextInt(2)) >> 1) & MASK_OFFSET;
} }
} }

View file

@ -10,19 +10,19 @@ import ru.betterend.world.biome.EndBiome;
public class BiomeMap public class BiomeMap
{ {
private static final HashMap<ChunkPos, BiomeChunk> MAPS = new HashMap<ChunkPos, BiomeChunk>();
private static final ChunkRandom RANDOM = new ChunkRandom(); private static final ChunkRandom RANDOM = new ChunkRandom();
private final HashMap<ChunkPos, BiomeChunk> maps = new HashMap<ChunkPos, BiomeChunk>();
private final int size; private final int size;
private final int sizeXZ; private final int sizeXZ;
private final int depth; private final int depth;
private final OpenSimplexNoise noiseX;; private final OpenSimplexNoise noiseX;
private final OpenSimplexNoise noiseZ; private final OpenSimplexNoise noiseZ;
private final BiomePicker picker; private final BiomePicker picker;
public BiomeMap(long seed, int size, BiomePicker picker) public BiomeMap(long seed, int size, BiomePicker picker)
{ {
MAPS.clear(); maps.clear();
RANDOM.setSeed(seed); RANDOM.setSeed(seed);
noiseX = new OpenSimplexNoise(RANDOM.nextLong()); noiseX = new OpenSimplexNoise(RANDOM.nextLong());
noiseZ = new OpenSimplexNoise(RANDOM.nextLong()); noiseZ = new OpenSimplexNoise(RANDOM.nextLong());
@ -34,8 +34,9 @@ public class BiomeMap
public void clearCache() public void clearCache()
{ {
if (MAPS.size() > 16) if (maps.size() > 32) {
MAPS.clear(); maps.clear();
}
} }
private EndBiome getRawBiome(int bx, int bz) private EndBiome getRawBiome(int bx, int bz)
@ -60,13 +61,22 @@ public class BiomeMap
pz = pz / 2 + i; 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)); 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) if (chunk == null)
{ {
RANDOM.setTerrainSeed(cpos.x, cpos.z); RANDOM.setTerrainSeed(cpos.x, cpos.z);
chunk = new BiomeChunk(this, RANDOM, picker); chunk = new BiomeChunk(this, RANDOM, picker);
MAPS.put(cpos, chunk); maps.put(cpos, chunk);
} }
return chunk.getBiome(MHelper.floor(x), MHelper.floor(z)); return chunk.getBiome(MHelper.floor(x), MHelper.floor(z));

View file

@ -13,6 +13,7 @@
"ChorusFlowerBlockMixin", "ChorusFlowerBlockMixin",
"ChorusPlantBlockMixin", "ChorusPlantBlockMixin",
"RecipeManagerAccessor", "RecipeManagerAccessor",
"ChunkSerializerMixin",
"MinecraftServerMixin", "MinecraftServerMixin",
"TagGroupLoaderMixin", "TagGroupLoaderMixin",
"EndermanEntityMixin", "EndermanEntityMixin",