only gzip changed regions
This commit is contained in:
parent
a64e07685b
commit
800078a75c
@ -17,8 +17,8 @@
|
|||||||
|
|
||||||
package baritone.bot.chunk;
|
package baritone.bot.chunk;
|
||||||
|
|
||||||
import baritone.bot.utils.pathing.PathingBlockType;
|
|
||||||
import baritone.bot.utils.GZIPUtils;
|
import baritone.bot.utils.GZIPUtils;
|
||||||
|
import baritone.bot.utils.pathing.PathingBlockType;
|
||||||
|
|
||||||
import java.io.FileInputStream;
|
import java.io.FileInputStream;
|
||||||
import java.io.FileOutputStream;
|
import java.io.FileOutputStream;
|
||||||
@ -52,9 +52,15 @@ public final class CachedRegion implements ICachedChunkAccess {
|
|||||||
*/
|
*/
|
||||||
private final int z;
|
private final int z;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Has this region been modified since its most recent load or save
|
||||||
|
*/
|
||||||
|
private boolean hasUnsavedChanges;
|
||||||
|
|
||||||
CachedRegion(int x, int z) {
|
CachedRegion(int x, int z) {
|
||||||
this.x = x;
|
this.x = x;
|
||||||
this.z = z;
|
this.z = z;
|
||||||
|
this.hasUnsavedChanges = false;
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
@ -74,6 +80,7 @@ public final class CachedRegion implements ICachedChunkAccess {
|
|||||||
} else {
|
} else {
|
||||||
chunk.updateContents(data);
|
chunk.updateContents(data);
|
||||||
}
|
}
|
||||||
|
hasUnsavedChanges = true;
|
||||||
}
|
}
|
||||||
|
|
||||||
private CachedChunk getChunk(int chunkX, int chunkZ) {
|
private CachedChunk getChunk(int chunkX, int chunkZ) {
|
||||||
@ -92,6 +99,9 @@ public final class CachedRegion implements ICachedChunkAccess {
|
|||||||
}
|
}
|
||||||
|
|
||||||
public final void save(String directory) {
|
public final void save(String directory) {
|
||||||
|
if (!hasUnsavedChanges) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
try {
|
try {
|
||||||
Path path = Paths.get(directory);
|
Path path = Paths.get(directory);
|
||||||
if (!Files.exists(path))
|
if (!Files.exists(path))
|
||||||
@ -115,6 +125,7 @@ public final class CachedRegion implements ICachedChunkAccess {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
hasUnsavedChanges = false;
|
||||||
} catch (IOException ignored) {}
|
} catch (IOException ignored) {}
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -148,6 +159,7 @@ public final class CachedRegion implements ICachedChunkAccess {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
hasUnsavedChanges = false;
|
||||||
} catch (IOException ignored) {}
|
} catch (IOException ignored) {}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -54,19 +54,14 @@ public final class CachedWorld implements ICachedChunkAccess {
|
|||||||
@Override
|
@Override
|
||||||
public final PathingBlockType getBlockType(int x, int y, int z) {
|
public final PathingBlockType getBlockType(int x, int y, int z) {
|
||||||
CachedRegion region = getOrCreateRegion(x >> 9, z >> 9);
|
CachedRegion region = getOrCreateRegion(x >> 9, z >> 9);
|
||||||
if (region != null) {
|
|
||||||
return region.getBlockType(x & 511, y, z & 511);
|
return region.getBlockType(x & 511, y, z & 511);
|
||||||
}
|
}
|
||||||
return null;
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public final void updateCachedChunk(int chunkX, int chunkZ, BitSet data) {
|
public final void updateCachedChunk(int chunkX, int chunkZ, BitSet data) {
|
||||||
CachedRegion region = getOrCreateRegion(chunkX >> 5, chunkZ >> 5);
|
CachedRegion region = getOrCreateRegion(chunkX >> 5, chunkZ >> 5);
|
||||||
if (region != null) {
|
|
||||||
region.updateCachedChunk(chunkX & 31, chunkZ & 31, data);
|
region.updateCachedChunk(chunkX & 31, chunkZ & 31, data);
|
||||||
}
|
}
|
||||||
}
|
|
||||||
|
|
||||||
public final void save() {
|
public final void save() {
|
||||||
this.cachedRegions.values().forEach(region -> {
|
this.cachedRegions.values().forEach(region -> {
|
||||||
@ -75,13 +70,6 @@ public final class CachedWorld implements ICachedChunkAccess {
|
|||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
public final void load() {
|
|
||||||
this.cachedRegions.values().forEach(region -> {
|
|
||||||
if (region != null)
|
|
||||||
region.load(this.directory);
|
|
||||||
});
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Returns the region at the specified region coordinates
|
* Returns the region at the specified region coordinates
|
||||||
*
|
*
|
||||||
|
Loading…
Reference in New Issue
Block a user