Merge remote-tracking branch 'wagyourtail/1.18.2/cached-chunk-oopsie' into rework-buildscript-117

This commit is contained in:
Wagyourtail
2022-05-31 01:58:12 -06:00
14 changed files with 86 additions and 69 deletions

View File

@@ -43,7 +43,7 @@ public final class CachedRegion implements ICachedRegion {
/**
* Magic value to detect invalid cache files, or incompatible cache files saved in an old version of Baritone
*/
private static final int CACHED_REGION_MAGIC = 456022910;
private static final int CACHED_REGION_MAGIC = 456022911;
/**
* All of the chunks in this region: A 32x32 array of them.
@@ -166,7 +166,7 @@ public final class CachedRegion implements ICachedRegion {
out.writeShort(entry.getValue().size());
for (BlockPos pos : entry.getValue()) {
out.writeByte((byte) (pos.getZ() << 4 | pos.getX()));
out.writeByte((byte) (pos.getY()));
out.writeInt(pos.getY()-dimension.minY());
}
}
}
@@ -270,8 +270,8 @@ public final class CachedRegion implements ICachedRegion {
byte xz = in.readByte();
int X = xz & 0x0f;
int Z = (xz >>> 4) & 0x0f;
int Y = in.readByte() & 0xff;
locs.add(new BlockPos(X, Y, Z));
int Y = in.readInt();
locs.add(new BlockPos(X, Y+dimension.minY(), Z));
}
}
}

View File

@@ -82,7 +82,7 @@ public final class ChunkPacker {
Block block = state.getBlock();
if (CachedChunk.BLOCKS_TO_KEEP_TRACK_OF.contains(block)) {
String name = BlockUtils.blockToString(block);
specialBlocks.computeIfAbsent(name, b -> new ArrayList<>()).add(new BlockPos(x, y, z));
specialBlocks.computeIfAbsent(name, b -> new ArrayList<>()).add(new BlockPos(x, y+chunk.getMinBuildHeight(), z));
}
}
}

View File

@@ -57,22 +57,22 @@ public class WorldProvider implements IWorldProvider, Helper {
* @param world The world's Registry Data
*/
public final void initWorld(ResourceKey<Level> worldKey, DimensionType world) {
File directory;
File readme;
Path directory;
Path readme;
IntegratedServer integratedServer = mc.getSingleplayerServer();
// If there is an integrated server running (Aka Singleplayer) then do magic to find the world save file
if (mc.hasSingleplayerServer()) {
directory = DimensionType.getStorageFolder(worldKey, integratedServer.getWorldPath(LevelResource.ROOT).toFile());
directory = DimensionType.getStorageFolder(worldKey, integratedServer.getWorldPath(LevelResource.ROOT));
// Gets the "depth" of this directory relative the the game's run directory, 2 is the location of the world
if (directory.toPath().relativize(mc.gameDirectory.toPath()).getNameCount() != 2) {
if (directory.relativize(mc.gameDirectory.toPath()).getNameCount() != 2) {
// subdirectory of the main save directory for this world
directory = directory.getParentFile();
directory = directory.getParent();
}
directory = new File(directory, "baritone");
directory = directory.resolve("baritone");
readme = directory;
} else { // Otherwise, the server must be remote...
String folderName;
@@ -90,12 +90,12 @@ public class WorldProvider implements IWorldProvider, Helper {
if (SystemUtils.IS_OS_WINDOWS) {
folderName = folderName.replace(":", "_");
}
directory = new File(Baritone.getDir(), folderName);
readme = Baritone.getDir();
directory = Baritone.getDir().toPath().resolve(folderName);
readme = Baritone.getDir().toPath();
}
// lol wtf is this baritone folder in my minecraft save?
try (FileOutputStream out = new FileOutputStream(new File(readme, "readme.txt"))) {
try (FileOutputStream out = new FileOutputStream(readme.resolve("readme.txt").toFile())) {
// good thing we have a readme
out.write("https://github.com/cabaletta/baritone\n".getBytes());
} catch (IOException ignored) {}
@@ -114,8 +114,8 @@ public class WorldProvider implements IWorldProvider, Helper {
}
}
public final Path getDimDir(ResourceKey<Level> level, int height, File directory) {
return directory.toPath().resolve(level.location().getNamespace()).resolve(level.location().getPath() + "_" + height);
public final Path getDimDir(ResourceKey<Level> level, int height, Path directory) {
return directory.resolve(level.location().getNamespace()).resolve(level.location().getPath() + "_" + height);
}
public final void closeWorld() {

View File

@@ -147,7 +147,7 @@ public enum WorldScanner implements IWorldScanner {
boolean foundWithinY = false;
for (int y0 : coordinateIterationOrder) {
LevelChunkSection section = chunkInternalStorageArray[y0];
if (section == null || LevelChunkSection.isEmpty(section)) {
if (section == null || section.hasOnlyAir()) {
continue;
}
int yReal = y0 << 4;

View File

@@ -169,7 +169,7 @@ public class BlockStateInterface {
// get the block at x,y,z from this chunk WITHOUT creating a single blockpos object
public static BlockState getFromChunk(LevelChunk chunk, int x, int y, int z) {
LevelChunkSection section = chunk.getSections()[y >> 4];
if (LevelChunkSection.isEmpty(section)) {
if (section.hasOnlyAir()) {
return AIR;
}
return section.getBlockState(x & 15, y & 15, z & 15);