From 96e75a4cae58b4632c24b68a3b7e76c1be5a0054 Mon Sep 17 00:00:00 2001 From: sk89q Date: Wed, 9 Mar 2011 23:44:04 -0800 Subject: [PATCH] Made McRegion reading work. --- src/com/sk89q/worldedit/data/ForwardSeekableInputStream.java | 4 +++- src/com/sk89q/worldedit/data/McRegionChunkStore.java | 3 ++- src/com/sk89q/worldedit/data/McRegionReader.java | 4 ++-- 3 files changed, 7 insertions(+), 4 deletions(-) diff --git a/src/com/sk89q/worldedit/data/ForwardSeekableInputStream.java b/src/com/sk89q/worldedit/data/ForwardSeekableInputStream.java index 1ed26595b..e5ab66bb8 100644 --- a/src/com/sk89q/worldedit/data/ForwardSeekableInputStream.java +++ b/src/com/sk89q/worldedit/data/ForwardSeekableInputStream.java @@ -60,7 +60,9 @@ public class ForwardSeekableInputStream extends InputStream { @Override public int read(byte[] b, int off, int len) throws IOException { - throw new IOException("Offset not supported for read()"); + int read = super.read(b, off, len); + position += read; + return read; } @Override diff --git a/src/com/sk89q/worldedit/data/McRegionChunkStore.java b/src/com/sk89q/worldedit/data/McRegionChunkStore.java index 69b0d5b8a..665225a5b 100644 --- a/src/com/sk89q/worldedit/data/McRegionChunkStore.java +++ b/src/com/sk89q/worldedit/data/McRegionChunkStore.java @@ -48,11 +48,12 @@ public abstract class McRegionChunkStore extends ChunkStore { protected McRegionReader getReader(Vector2D pos) throws DataException, IOException { String filename = getFilename(pos); - if (curFilename.equals(filename)) { + if (curFilename != null && curFilename.equals(filename)) { return cachedReader; } InputStream stream = getInputStream(filename); cachedReader = new McRegionReader(stream); + //curFilename = filename; return cachedReader; } diff --git a/src/com/sk89q/worldedit/data/McRegionReader.java b/src/com/sk89q/worldedit/data/McRegionReader.java index d77e484e2..de0081f20 100644 --- a/src/com/sk89q/worldedit/data/McRegionReader.java +++ b/src/com/sk89q/worldedit/data/McRegionReader.java @@ -117,8 +117,8 @@ public class McRegionReader { public synchronized InputStream getChunkInputStream(Vector2D pos) throws IOException, DataException { - int x = pos.getBlockX(); - int z = pos.getBlockZ(); + int x = pos.getBlockX() & 31; + int z = pos.getBlockZ() & 31; if (x < 0 || x >= 32 || z < 0 || z >= 32) { throw new DataException("MCRegion file does not contain " + x + "," + z);