geforkt von Mirrors/FastAsyncWorldEdit
Added support for 4096 ID blocks (theoretically) in snapshots.
Also cleaned up the mess that was AnvilChunk's code.
Dieser Commit ist enthalten in:
Ursprung
e08e40bce8
Commit
1fb69b06f7
@ -21,6 +21,7 @@ public class AnvilChunk implements Chunk {
|
|||||||
|
|
||||||
private CompoundTag rootTag;
|
private CompoundTag rootTag;
|
||||||
private byte[][] blocks;
|
private byte[][] blocks;
|
||||||
|
private byte[][] blocksAdd;
|
||||||
private byte[][] data;
|
private byte[][] data;
|
||||||
private int rootX;
|
private int rootX;
|
||||||
private int rootZ;
|
private int rootZ;
|
||||||
@ -32,41 +33,65 @@ public class AnvilChunk implements Chunk {
|
|||||||
/**
|
/**
|
||||||
* Construct the chunk with a compound tag.
|
* Construct the chunk with a compound tag.
|
||||||
*
|
*
|
||||||
* @param tag
|
* @param world the world to construct the chunk for
|
||||||
* @throws DataException
|
* @param tag the tag to read
|
||||||
|
* @throws DataException on a data error
|
||||||
*/
|
*/
|
||||||
public AnvilChunk(LocalWorld world, CompoundTag tag) throws DataException {
|
public AnvilChunk(LocalWorld world, CompoundTag tag) throws DataException {
|
||||||
rootTag = tag;
|
rootTag = tag;
|
||||||
this.world = world;
|
this.world = world;
|
||||||
|
|
||||||
rootX = NBTUtils.getChildTag( rootTag.getValue(), "xPos", IntTag.class).getValue();
|
rootX = NBTUtils.getChildTag(rootTag.getValue(), "xPos", IntTag.class).getValue();
|
||||||
rootZ = NBTUtils.getChildTag( rootTag.getValue(), "zPos", IntTag.class).getValue();
|
rootZ = NBTUtils.getChildTag(rootTag.getValue(), "zPos", IntTag.class).getValue();
|
||||||
|
|
||||||
|
blocks = new byte[16][16 * 16 * 16];
|
||||||
|
blocksAdd = new byte[16][16 * 16 * 8];
|
||||||
|
data = new byte[16][16 * 16 * 8];
|
||||||
|
|
||||||
blocks = new byte[16][16*16*16];
|
|
||||||
data = new byte[16][16*16*8];
|
|
||||||
List<Tag> sections = NBTUtils.getChildTag(rootTag.getValue(), "Sections", ListTag.class).getValue();
|
List<Tag> sections = NBTUtils.getChildTag(rootTag.getValue(), "Sections", ListTag.class).getValue();
|
||||||
for(Tag section : sections) {
|
|
||||||
if(!(section instanceof CompoundTag)) continue;
|
for (Tag rawSectionTag : sections) {
|
||||||
CompoundTag compoundsection = (CompoundTag) section;
|
if (!(rawSectionTag instanceof CompoundTag)) {
|
||||||
if(!compoundsection.getValue().containsKey("Y")) continue; // Empty section.
|
continue;
|
||||||
int y = NBTUtils.getChildTag(compoundsection.getValue(), "Y", ByteTag.class).getValue();
|
|
||||||
if(y < 0 || y >= 16) continue;
|
|
||||||
blocks[y] = NBTUtils.getChildTag(compoundsection.getValue(), "Blocks", ByteArrayTag.class).getValue();
|
|
||||||
data[y] = NBTUtils.getChildTag(compoundsection.getValue(), "Data", ByteArrayTag.class).getValue();
|
|
||||||
}
|
}
|
||||||
|
|
||||||
int sectionsize = 16*16*16;
|
CompoundTag sectionTag = (CompoundTag) rawSectionTag;
|
||||||
for(int i = 0; i < blocks.length; i++) {
|
if (!sectionTag.getValue().containsKey("Y")) {
|
||||||
|
continue; // Empty section.
|
||||||
|
}
|
||||||
|
|
||||||
|
int y = NBTUtils.getChildTag(sectionTag.getValue(), "Y", ByteTag.class).getValue();
|
||||||
|
if (y < 0 || y >= 16) {
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
|
||||||
|
blocks[y] = NBTUtils.getChildTag(sectionTag.getValue(),
|
||||||
|
"Blocks", ByteArrayTag.class).getValue();
|
||||||
|
data[y] = NBTUtils.getChildTag(sectionTag.getValue(), "Data",
|
||||||
|
ByteArrayTag.class).getValue();
|
||||||
|
|
||||||
|
// 4096 ID block support
|
||||||
|
if (sectionTag.getValue().containsKey("Add")) {
|
||||||
|
blocksAdd[y] = NBTUtils.getChildTag(sectionTag.getValue(),
|
||||||
|
"Add", ByteArrayTag.class).getValue();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
int sectionsize = 16 * 16 * 16;
|
||||||
|
for (int i = 0; i < blocks.length; i++) {
|
||||||
if (blocks[i].length != sectionsize) {
|
if (blocks[i].length != sectionsize) {
|
||||||
throw new InvalidFormatException("Chunk blocks byte array expected "
|
throw new InvalidFormatException(
|
||||||
+ "to be " + sectionsize + " bytes; found " + blocks[i].length);
|
"Chunk blocks byte array expected " + "to be "
|
||||||
|
+ sectionsize + " bytes; found "
|
||||||
|
+ blocks[i].length);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
for(int i = 0; i < data.length; i++) {
|
for (int i = 0; i < data.length; i++) {
|
||||||
if (data[i].length != (sectionsize/2)) {
|
if (data[i].length != (sectionsize / 2)) {
|
||||||
throw new InvalidFormatException("Chunk block data byte array "
|
throw new InvalidFormatException("Chunk block data byte array "
|
||||||
+ "expected to be " + sectionsize + " bytes; found " + data[i].length);
|
+ "expected to be " + sectionsize + " bytes; found "
|
||||||
|
+ data[i].length);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -78,14 +103,28 @@ public class AnvilChunk implements Chunk {
|
|||||||
int z = pos.getBlockZ() - rootZ * 16;
|
int z = pos.getBlockZ() - rootZ * 16;
|
||||||
|
|
||||||
int section = y >> 4;
|
int section = y >> 4;
|
||||||
if(section < 0 || section >= blocks.length) throw new DataException("Chunk does not contain position " + pos);
|
if (section < 0 || section >= blocks.length) {
|
||||||
int yindex = y & 0x0F;
|
throw new DataException("Chunk does not contain position " + pos);
|
||||||
if(yindex < 0 || yindex >= 16) throw new DataException("Chunk does not contain position " + pos);
|
}
|
||||||
|
|
||||||
|
int yindex = y & 0x0F;
|
||||||
|
if (yindex < 0 || yindex >= 16) {
|
||||||
|
throw new DataException("Chunk does not contain position " + pos);
|
||||||
|
}
|
||||||
|
|
||||||
int index = x + (z * 16 + (yindex * 16 * 16));
|
int index = x + (z * 16 + (yindex * 16 * 16));
|
||||||
|
|
||||||
try {
|
try {
|
||||||
return blocks[section][index];
|
int addId = 0;
|
||||||
|
|
||||||
|
// 4 bits, so we have to divide by 2 and get the right 4 bits
|
||||||
|
if (index % 2 == 0) {
|
||||||
|
addId = (blocksAdd[section][index >> 2] >> 4) << 8;
|
||||||
|
} else {
|
||||||
|
addId = (blocksAdd[section][index >> 2] & 0xF) << 8;
|
||||||
|
}
|
||||||
|
|
||||||
|
return blocks[section][index] + addId;
|
||||||
} catch (IndexOutOfBoundsException e) {
|
} catch (IndexOutOfBoundsException e) {
|
||||||
throw new DataException("Chunk does not contain position " + pos);
|
throw new DataException("Chunk does not contain position " + pos);
|
||||||
}
|
}
|
||||||
@ -98,12 +137,17 @@ public class AnvilChunk implements Chunk {
|
|||||||
int z = pos.getBlockZ() - rootZ * 16;
|
int z = pos.getBlockZ() - rootZ * 16;
|
||||||
|
|
||||||
int section = y >> 4;
|
int section = y >> 4;
|
||||||
if(section < 0 || section >= blocks.length) throw new DataException("Chunk does not contain position " + pos);
|
int yIndex = y & 0x0F;
|
||||||
int yindex = y & 0x0F;
|
|
||||||
if(yindex < 0 || yindex >= 16) throw new DataException("Chunk does not contain position " + pos);
|
|
||||||
|
|
||||||
|
if (section < 0 || section >= blocks.length) {
|
||||||
|
throw new DataException("Chunk does not contain position " + pos);
|
||||||
|
}
|
||||||
|
|
||||||
int index = x + (z * 16 + (yindex * 16 * 16));
|
if (yIndex < 0 || yIndex >= 16) {
|
||||||
|
throw new DataException("Chunk does not contain position " + pos);
|
||||||
|
}
|
||||||
|
|
||||||
|
int index = x + (z * 16 + (yIndex * 16 * 16));
|
||||||
boolean shift = index % 2 == 0;
|
boolean shift = index % 2 == 0;
|
||||||
index /= 2;
|
index /= 2;
|
||||||
|
|
||||||
@ -124,15 +168,15 @@ public class AnvilChunk implements Chunk {
|
|||||||
* @throws DataException
|
* @throws DataException
|
||||||
*/
|
*/
|
||||||
private void populateTileEntities() throws DataException {
|
private void populateTileEntities() throws DataException {
|
||||||
List<Tag> tags = NBTUtils.getChildTag(
|
List<Tag> tags = NBTUtils.getChildTag(rootTag.getValue(),
|
||||||
rootTag.getValue(), "TileEntities", ListTag.class)
|
"TileEntities", ListTag.class).getValue();
|
||||||
.getValue();
|
|
||||||
|
|
||||||
tileEntities = new HashMap<BlockVector, Map<String, Tag>>();
|
tileEntities = new HashMap<BlockVector, Map<String, Tag>>();
|
||||||
|
|
||||||
for (Tag tag : tags) {
|
for (Tag tag : tags) {
|
||||||
if (!(tag instanceof CompoundTag)) {
|
if (!(tag instanceof CompoundTag)) {
|
||||||
throw new InvalidFormatException("CompoundTag expected in TileEntities");
|
throw new InvalidFormatException(
|
||||||
|
"CompoundTag expected in TileEntities");
|
||||||
}
|
}
|
||||||
|
|
||||||
CompoundTag t = (CompoundTag) tag;
|
CompoundTag t = (CompoundTag) tag;
|
||||||
|
Laden…
In neuem Issue referenzieren
Einen Benutzer sperren