fix headless chunk offset

This commit is contained in:
Julian Krings
2024-08-17 15:23:23 +02:00
parent 70aa607e5b
commit bbf42d1af0
2 changed files with 7 additions and 19 deletions
@@ -40,6 +40,7 @@ import com.volmit.iris.util.mantle.MantleFlag;
import com.volmit.iris.util.math.RNG; import com.volmit.iris.util.math.RNG;
import com.volmit.iris.util.parallel.MultiBurst; import com.volmit.iris.util.parallel.MultiBurst;
import com.volmit.iris.util.scheduling.PrecisionStopwatch; import com.volmit.iris.util.scheduling.PrecisionStopwatch;
import lombok.Getter;
import net.minecraft.core.Holder; import net.minecraft.core.Holder;
import net.minecraft.core.QuartPos; import net.minecraft.core.QuartPos;
import net.minecraft.nbt.CompoundTag; import net.minecraft.nbt.CompoundTag;
@@ -68,6 +69,8 @@ public class Headless implements IHeadless, LevelHeightAccessor {
private final KMap<String, Holder<Biome>> customBiomes = new KMap<>(); private final KMap<String, Holder<Biome>> customBiomes = new KMap<>();
private final KMap<org.bukkit.block.Biome, Holder<Biome>> minecraftBiomes = new KMap<>(); private final KMap<org.bukkit.block.Biome, Holder<Biome>> minecraftBiomes = new KMap<>();
private final RNG BIOME_RNG; private final RNG BIOME_RNG;
private final @Getter int minBuildHeight;
private final @Getter int height;
private boolean closed = false; private boolean closed = false;
public Headless(NMSBinding binding, Engine engine) { public Headless(NMSBinding binding, Engine engine) {
@@ -75,6 +78,8 @@ public class Headless implements IHeadless, LevelHeightAccessor {
this.engine = engine; this.engine = engine;
this.storage = new RegionFileStorage(new File(engine.getWorld().worldFolder(), "region").toPath(), true); this.storage = new RegionFileStorage(new File(engine.getWorld().worldFolder(), "region").toPath(), true);
this.BIOME_RNG = new RNG(engine.getSeedManager().getBiome()); this.BIOME_RNG = new RNG(engine.getSeedManager().getBiome());
this.minBuildHeight = engine.getDimension().getMinHeight();
this.height = engine.getDimension().getMaxHeight() - minBuildHeight;
engine.getWorld().headless(this); engine.getWorld().headless(this);
var dimKey = engine.getDimension().getLoadKey(); var dimKey = engine.getDimension().getLoadKey();
@@ -107,6 +112,8 @@ public class Headless implements IHeadless, LevelHeightAccessor {
@Override @Override
public boolean exists(int x, int z) { public boolean exists(int x, int z) {
if (closed) return false; if (closed) return false;
if (engine.getWorld().hasRealWorld() && engine.getWorld().realWorld().isChunkLoaded(x, z))
return true;
try { try {
CompoundTag tag = storage.read(new ChunkPos(x, z)); CompoundTag tag = storage.read(new ChunkPos(x, z));
return tag != null && !"empty".equals(tag.getString("Status")); return tag != null && !"empty".equals(tag.getString("Status"));
@@ -270,14 +277,4 @@ public class Headless implements IHeadless, LevelHeightAccessor {
minecraftBiomes.clear(); minecraftBiomes.clear();
} }
} }
@Override
public int getHeight() {
return engine.getHeight();
}
@Override
public int getMinBuildHeight() {
return engine.getMinHeight();
}
} }
@@ -60,8 +60,6 @@ public record MCATerrainChunk(ChunkAccess chunk) implements TerrainChunk {
@Override @Override
public void setBiome(int x, int y, int z, Biome bio) { public void setBiome(int x, int y, int z, Biome bio) {
if (y < 0) return;
y += getMinHeight();
if (y > getMaxHeight()) return; if (y > getMaxHeight()) return;
chunk.setBiome(x & 15, y, z & 15, CraftBiome.bukkitToMinecraftHolder(bio)); chunk.setBiome(x & 15, y, z & 15, CraftBiome.bukkitToMinecraftHolder(bio));
} }
@@ -82,10 +80,6 @@ public record MCATerrainChunk(ChunkAccess chunk) implements TerrainChunk {
@Override @Override
public void setBlock(int x, int y, int z, BlockData blockData) { public void setBlock(int x, int y, int z, BlockData blockData) {
if (y < 0) return;
y += getMinHeight();
if (y > getMaxHeight()) return;
if (blockData == null) { if (blockData == null) {
Iris.error("NULL BD"); Iris.error("NULL BD");
} }
@@ -97,9 +91,6 @@ public record MCATerrainChunk(ChunkAccess chunk) implements TerrainChunk {
} }
private BlockState getBlockState(int x, int y, int z) { private BlockState getBlockState(int x, int y, int z) {
if (y < 0) {
y = 0;
}
y += getMinHeight(); y += getMinHeight();
if (y > getMaxHeight()) { if (y > getMaxHeight()) {
y = getMaxHeight(); y = getMaxHeight();