From c761a9b12783bb075efb79d5185f51167ad217ab Mon Sep 17 00:00:00 2001 From: Leijurv Date: Tue, 28 Aug 2018 11:28:36 -0700 Subject: [PATCH] better chunk saving and loading --- src/main/java/baritone/behavior/impl/MineBehavior.java | 4 ++++ src/main/java/baritone/chunk/CachedRegion.java | 8 ++++---- src/main/java/baritone/chunk/CachedWorld.java | 3 ++- 3 files changed, 10 insertions(+), 5 deletions(-) create mode 100644 src/main/java/baritone/behavior/impl/MineBehavior.java diff --git a/src/main/java/baritone/behavior/impl/MineBehavior.java b/src/main/java/baritone/behavior/impl/MineBehavior.java new file mode 100644 index 00000000..01dd4137 --- /dev/null +++ b/src/main/java/baritone/behavior/impl/MineBehavior.java @@ -0,0 +1,4 @@ +package baritone.behavior.impl; + +public class MineBehavior { +} diff --git a/src/main/java/baritone/chunk/CachedRegion.java b/src/main/java/baritone/chunk/CachedRegion.java index 7d2ed3dc..66204d5a 100644 --- a/src/main/java/baritone/chunk/CachedRegion.java +++ b/src/main/java/baritone/chunk/CachedRegion.java @@ -117,8 +117,8 @@ public final class CachedRegion implements IBlockTypeAccess { Files.createFile(regionFile); try ( FileOutputStream fileOut = new FileOutputStream(regionFile.toFile()); - GZIPOutputStream gzipOut = new GZIPOutputStream(fileOut); - DataOutputStream out = new DataOutputStream(gzipOut); + GZIPOutputStream gzipOut = new GZIPOutputStream(fileOut, 16384); + DataOutputStream out = new DataOutputStream(gzipOut) ) { out.writeInt(CACHED_REGION_MAGIC); for (int z = 0; z < 32; z++) { @@ -183,8 +183,8 @@ public final class CachedRegion implements IBlockTypeAccess { try ( FileInputStream fileIn = new FileInputStream(regionFile.toFile()); - GZIPInputStream gzipIn = new GZIPInputStream(fileIn); - DataInputStream in = new DataInputStream(gzipIn); + GZIPInputStream gzipIn = new GZIPInputStream(fileIn, 32768); + DataInputStream in = new DataInputStream(gzipIn) ) { int magic = in.readInt(); if (magic != CACHED_REGION_MAGIC) { diff --git a/src/main/java/baritone/chunk/CachedWorld.java b/src/main/java/baritone/chunk/CachedWorld.java index b24857de..42b4c13d 100644 --- a/src/main/java/baritone/chunk/CachedWorld.java +++ b/src/main/java/baritone/chunk/CachedWorld.java @@ -69,6 +69,7 @@ public final class CachedWorld implements IBlockTypeAccess { new Thread() { public void run() { try { + Thread.sleep(30000); while (true) { // since a region only saves if it's been modified since its last save // saving every 10 minutes means that once it's time to exit @@ -141,7 +142,7 @@ public final class CachedWorld implements IBlockTypeAccess { return; } long start = System.currentTimeMillis(); - this.cachedRegions.values().forEach(region -> { + this.cachedRegions.values().parallelStream().forEach(region -> { if (region != null) region.save(this.directory); });