Added support for non-128 worldheights

This commit is contained in:
zml2008
2011-12-12 19:20:31 -08:00
committed by TomyLobo
parent e01aad00d8
commit 98216e2762
24 changed files with 190 additions and 102 deletions

View File

@ -37,7 +37,9 @@ public class Chunk {
private byte[] data;
private int rootX;
private int rootZ;
private Map<BlockVector, Map<String, Tag>> tileEntities;
private Map<BlockVector, Map<String,Tag>> tileEntities;
private LocalWorld world;
/**
* Construct the chunk with a compound tag.
@ -45,8 +47,9 @@ public class Chunk {
* @param tag
* @throws DataException
*/
public Chunk(CompoundTag tag) throws DataException {
public Chunk(LocalWorld world, CompoundTag tag) throws DataException {
rootTag = tag;
this.world = world;
blocks = getChildTag(
rootTag.getValue(), "Blocks", ByteArrayTag.class).getValue();
@ -57,14 +60,14 @@ public class Chunk {
rootZ = getChildTag(
rootTag.getValue(), "zPos", IntTag.class).getValue();
if (blocks.length != 32768) {
if (blocks.length != 16*16*(world.getMaxY() + 1)) {
throw new InvalidFormatException("Chunk blocks byte array expected "
+ "to be 32,768 bytes; found " + blocks.length);
+ "to be " + 16*16*(world.getMaxY() + 1) + " bytes; found " + blocks.length);
}
if (data.length != 16384) {
if (data.length != 16*16*((world.getMaxY() + 1)/2)) {
throw new InvalidFormatException("Chunk block data byte array "
+ "expected to be 16,384 bytes; found " + data.length);
+ "expected to be " + 16*16*((world.getMaxY() + 1)/2) + " bytes; found " + data.length);
}
}
@ -79,7 +82,7 @@ public class Chunk {
int x = pos.getBlockX() - rootX * 16;
int y = pos.getBlockY();
int z = pos.getBlockZ() - rootZ * 16;
int index = y + (z * 128 + (x * 128 * 16));
int index = y + (z * (world.getMaxY() + 1) + (x * (world.getMaxY() + 1) * 16));
try {
return blocks[index];
@ -99,7 +102,7 @@ public class Chunk {
int x = pos.getBlockX() - rootX * 16;
int y = pos.getBlockY();
int z = pos.getBlockZ() - rootZ * 16;
int index = y + (z * 128 + (x * 128 * 16));
int index = y + (z * (world.getMaxY() + 1) + (x * (world.getMaxY() + 1) * 16));
boolean shift = index % 2 == 0;
index /= 2;

View File

@ -50,7 +50,7 @@ public abstract class ChunkStore {
* @throws DataException
* @throws IOException
*/
public abstract CompoundTag getChunkTag(Vector2D pos, String world)
public abstract CompoundTag getChunkTag(Vector2D pos, LocalWorld world)
throws DataException, IOException;
/**
@ -62,9 +62,9 @@ public abstract class ChunkStore {
* @throws IOException
* @throws DataException
*/
public Chunk getChunk(Vector2D pos, String world)
public Chunk getChunk(Vector2D pos, LocalWorld world)
throws DataException, IOException {
return new Chunk(getChunkTag(pos, world));
return new Chunk(world, getChunkTag(pos, world));
}
/**

View File

@ -74,7 +74,7 @@ public abstract class LegacyChunkStore extends ChunkStore {
* @throws IOException
*/
@Override
public CompoundTag getChunkTag(Vector2D pos, String world)
public CompoundTag getChunkTag(Vector2D pos, LocalWorld world)
throws DataException, IOException {
int x = pos.getBlockX();
int z = pos.getBlockZ();

View File

@ -25,6 +25,7 @@ import java.util.Map;
import com.sk89q.jnbt.CompoundTag;
import com.sk89q.jnbt.NBTInputStream;
import com.sk89q.jnbt.Tag;
import com.sk89q.worldedit.LocalWorld;
import com.sk89q.worldedit.Vector2D;
public abstract class McRegionChunkStore extends ChunkStore {
@ -65,10 +66,11 @@ public abstract class McRegionChunkStore extends ChunkStore {
}
@Override
public CompoundTag getChunkTag(Vector2D pos, String worldname) throws DataException,
public CompoundTag getChunkTag(Vector2D pos, LocalWorld world) throws DataException,
IOException {
McRegionReader reader = getReader(pos, world.getName());
McRegionReader reader = getReader(pos, worldname);
InputStream stream = reader.getChunkInputStream(pos);
NBTInputStream nbt = new NBTInputStream(stream);
Tag tag;