Fix world gen for 1.16

This commit is contained in:
James Seibel
2023-08-05 11:27:23 -05:00
parent 9c73443aa2
commit 18b0b8c6f4
7 changed files with 66 additions and 34 deletions
@@ -94,8 +94,8 @@ public class WrapperFactory implements IWrapperFactory
}
}
// MC 1.18, 1.19, 1.20
#if POST_MC_1_17_1
// MC 1.16, 1.18, 1.19, 1.20
#if POST_MC_1_17_1 || MC_1_16_5
else if (objectArray.length == 2)
{
// correct number of parameters from the API
@@ -143,8 +143,8 @@ public class WrapperFactory implements IWrapperFactory
"Chunk wrapper creation failed. \n" +
"Expected parameters: \n");
// MC 1.18, 1.19, 1.20
#if POST_MC_1_17_1
// MC 1.16, 1.18, 1.19, 1.20
#if POST_MC_1_17_1 || MC_1_16_5
message.append("["+ChunkAccess.class.getName()+"], \n");
message.append("["+LevelReader.class.getName()+"]. \n");
#else
@@ -152,16 +152,16 @@ public class ChunkWrapper implements IChunkWrapper
//if (wrappedLevel != null) return wrappedLevel.getBiome(new DhBlockPos(x + getMinX(), y, z + getMinZ()));
#if PRE_MC_1_17_1
return BiomeWrapper.getBiomeWrapper(chunk.getBiomes().getNoiseBiome(
x >> 2, y >> 2, z >> 2));
return BiomeWrapper.getBiomeWrapper(this.chunk.getBiomes().getNoiseBiome(
relX >> 2, relY >> 2, relZ >> 2));
#elif PRE_MC_1_18_2
return BiomeWrapper.getBiomeWrapper(chunk.getBiomes().getNoiseBiome(
QuartPos.fromBlock(x), QuartPos.fromBlock(y), QuartPos.fromBlock(z)));
return BiomeWrapper.getBiomeWrapper(this.chunk.getBiomes().getNoiseBiome(
QuartPos.fromBlock(relX), QuartPos.fromBlock(relY), QuartPos.fromBlock(relZ)));
#elif PRE_MC_1_18_2
return BiomeWrapper.getBiomeWrapper(chunk.getNoiseBiome(
QuartPos.fromBlock(x), QuartPos.fromBlock(y), QuartPos.fromBlock(z)));
return BiomeWrapper.getBiomeWrapper(this.chunk.getNoiseBiome(
QuartPos.fromBlock(relX), QuartPos.fromBlock(relY), QuartPos.fromBlock(relZ)));
#else //Now returns a Holder<Biome> instead of Biome
return BiomeWrapper.getBiomeWrapper(chunk.getNoiseBiome(
return BiomeWrapper.getBiomeWrapper(this.chunk.getNoiseBiome(
QuartPos.fromBlock(relX), QuartPos.fromBlock(relY), QuartPos.fromBlock(relZ)));
#endif
}
@@ -369,7 +369,8 @@ public class ChunkWrapper implements IChunkWrapper
#endif
// Should be called after client light updates are triggered.
private static boolean updateClientLightReady(ChunkAccess chunk, boolean oldValue) {
private static boolean updateClientLightReady(ChunkAccess chunk, boolean oldValue)
{
if (chunk instanceof LevelChunk && ((LevelChunk)chunk).getLevel() instanceof ClientLevel)
{
LevelChunk levelChunk = (LevelChunk)chunk;
@@ -88,7 +88,7 @@ public final class ThreadedParameters
}
#if PRE_MC_1_19_2
#if POST_MC_1_18_2
public void recreateStructureCheck()
{
if (previousGlobalParameters != null)
@@ -14,23 +14,28 @@ import java.nio.file.Files;
import java.nio.file.Path;
import java.util.concurrent.ConcurrentLinkedQueue;
public class RegionFileStorageExternalCache implements AutoCloseable {
public class RegionFileStorageExternalCache implements AutoCloseable
{
public final RegionFileStorage storage;
public static final int MAX_CACHE_SIZE = 16;
@Override
public void close() throws IOException {
public void close() throws IOException
{
RegionFileCache cache;
while ((cache = regionFileCache.poll()) != null) {
while ((cache = this.regionFileCache.poll()) != null)
{
cache.file.close();
}
}
static class RegionFileCache {
static class RegionFileCache
{
public final long pos;
public final RegionFile file;
public RegionFileCache(long pos, RegionFile file) {
public RegionFileCache(long pos, RegionFile file)
{
this.pos = pos;
this.file = file;
}
@@ -38,9 +43,7 @@ public class RegionFileStorageExternalCache implements AutoCloseable {
public ConcurrentLinkedQueue<RegionFileCache> regionFileCache = new ConcurrentLinkedQueue<>();
public RegionFileStorageExternalCache(RegionFileStorage storage) {
this.storage = storage;
}
public RegionFileStorageExternalCache(RegionFileStorage storage) { this.storage = storage; }
@Nullable
public RegionFile getRegionFile(ChunkPos pos) throws IOException
@@ -53,7 +56,12 @@ public class RegionFileStorageExternalCache implements AutoCloseable {
{
try
{
rFile = this.storage.regionCache.getOrDefault(posLong, null);
#if MC_1_16_5
rFile = this.storage.getRegionFile(pos);
#else
rFile = this.storage.regionCache.getOrDefault(posLong, null);
#endif
break;
}
catch (ArrayIndexOutOfBoundsException e)
@@ -77,18 +85,29 @@ public class RegionFileStorageExternalCache implements AutoCloseable {
}
// Otherwise, check if file exist, and if so, add it to the cache
Path p = storage.folder;
if (!Files.exists(p))
Path storageFolderPath;
#if MC_1_16_5
storageFolderPath = this.storage.folder.toPath();
#else
storageFolderPath = this.storage.folder;
#endif
if (!Files.exists(storageFolderPath))
{
return null;
}
Path rFilePath = p.resolve("r." + pos.getRegionX() + "." + pos.getRegionZ() + ".mca");
rFile = new RegionFile(rFilePath, p, false);
regionFileCache.add(new RegionFileCache(ChunkPos.asLong(pos.getRegionX(), pos.getRegionZ()), rFile));
while (regionFileCache.size() > MAX_CACHE_SIZE)
Path regionFilePath = storageFolderPath.resolve("r." + pos.getRegionX() + "." + pos.getRegionZ() + ".mca");
#if MC_1_16_5
rFile = new RegionFile(regionFilePath.toFile(), storageFolderPath.toFile(), false);
#else
rFile = new RegionFile(regionFilePath, storageFolderPath, false);
#endif
this.regionFileCache.add(new RegionFileCache(ChunkPos.asLong(pos.getRegionX(), pos.getRegionZ()), rFile));
while (this.regionFileCache.size() > MAX_CACHE_SIZE)
{
regionFileCache.poll().file.close();
this.regionFileCache.poll().file.close();
}
return rFile;
@@ -50,13 +50,17 @@ import net.minecraft.world.level.StructureManager;
#if POST_MC_1_18_2
import net.minecraft.world.level.levelgen.structure.StructureCheck;
#endif
import net.minecraft.world.level.levelgen.structure.StructureStart;
#if PRE_MC_1_19_2
public class WorldGenStructFeatManager extends StructureFeatureManager {
#else
public class WorldGenStructFeatManager extends StructureManager {
#endif
#if PRE_MC_1_18_2
import net.minecraft.world.level.levelgen.feature.StructureFeature;
#endif
public class WorldGenStructFeatManager extends #if PRE_MC_1_19_2 StructureFeatureManager #else StructureManager #endif
{
final WorldGenLevel genLevel;
#if PRE_MC_1_19_4
@@ -29,7 +29,11 @@ import net.minecraft.world.level.chunk.ChunkAccess;
import net.minecraft.world.level.chunk.ChunkStatus;
import net.minecraft.world.level.chunk.LevelChunk;
import net.minecraft.world.level.chunk.ProtoChunk;
#if PRE_MC_1_17_1
import net.minecraft.world.level.lighting.LevelLightEngine;
#else
import net.minecraft.world.level.lighting.LightEventListener;
#endif
public final class StepLight {
/**
@@ -35,6 +35,10 @@ accessible method net/minecraft/world/level/lighting/LayerLightEngine queueSecti
# lod generation from save file
accessible field net/minecraft/server/level/ChunkMap mainThreadExecutor Lnet/minecraft/util/thread/BlockableEventLoop;
accessible method net/minecraft/server/level/ChunkMap readChunk (Lnet/minecraft/world/level/ChunkPos;)Lnet/minecraft/nbt/CompoundTag;
accessible method net/minecraft/world/level/chunk/storage/RegionFileStorage getRegionFile (Lnet/minecraft/world/level/ChunkPos;)Lnet/minecraft/world/level/chunk/storage/RegionFile;
accessible field net/minecraft/world/level/chunk/storage/RegionFileStorage folder Ljava/io/File;
accessible field net/minecraft/world/level/chunk/storage/ChunkStorage worker Lnet/minecraft/world/level/chunk/storage/IOWorker;
accessible field net/minecraft/world/level/chunk/storage/IOWorker storage Lnet/minecraft/world/level/chunk/storage/RegionFileStorage;
# grabbing textures
accessible field net/minecraft/client/renderer/block/model/BakedQuad sprite Lnet/minecraft/client/renderer/texture/TextureAtlasSprite;