This commit is contained in:
MattBDev
2019-06-25 13:07:47 -04:00
parent a1c15e1c39
commit a69b239848
143 changed files with 1042 additions and 2405 deletions

View File

@ -28,7 +28,6 @@ import com.sk89q.jnbt.NBTUtils;
import com.sk89q.jnbt.Tag;
import com.sk89q.worldedit.WorldEdit;
import com.sk89q.worldedit.math.BlockVector3;
import com.sk89q.worldedit.world.block.BaseBlock;
import com.sk89q.worldedit.world.DataException;
import com.sk89q.worldedit.world.World;
import com.sk89q.worldedit.world.block.BaseBlock;
@ -55,7 +54,7 @@ public class AnvilChunk implements Chunk {
/**
* Construct the chunk with a compound tag.
*
*
* @param world the world to construct the chunk for
* @param tag the tag to read
* @throws DataException on a data error
@ -69,19 +68,19 @@ public class AnvilChunk implements Chunk {
blocks = new byte[16][16 * 16 * 16];
blocksAdd = new byte[16][16 * 16 * 8];
data = new byte[16][16 * 16 * 8];
List<Tag> sections = NBTUtils.getChildTag(rootTag.getValue(), "Sections", ListTag.class).getValue();
for (Tag rawSectionTag : sections) {
if (!(rawSectionTag instanceof CompoundTag)) {
continue;
}
CompoundTag sectionTag = (CompoundTag) rawSectionTag;
if (!sectionTag.getValue().containsKey("Y")) {
continue; // Empty section.
}
int y = NBTUtils.getChildTag(sectionTag.getValue(), "Y", ByteTag.class).getValue();
if (y < 0 || y >= 16) {
continue;
@ -117,7 +116,7 @@ public class AnvilChunk implements Chunk {
}
}
}
private int getBlockID(BlockVector3 position) throws DataException {
int x = position.getX() - rootX * 16;
int y = position.getY();
@ -127,14 +126,14 @@ public class AnvilChunk implements Chunk {
if (section < 0 || section >= blocks.length) {
throw new DataException("Chunk does not contain position " + position);
}
int yindex = y & 0x0F;
int index = x + (z * 16 + (yindex * 16 * 16));
try {
int addId = 0;
// The block ID is the combination of the Blocks byte array with the
// Add byte array. 'Blocks' stores the lowest 8 bits of a block's ID, and
// 'Add' stores the highest 4 bits of the ID. The first block is stored
@ -144,7 +143,7 @@ public class AnvilChunk implements Chunk {
} else {
addId = (blocksAdd[section][index >> 1] & 0xF0) << 4;
}
return (blocks[section][index] & 0xFF) + addId;
} catch (IndexOutOfBoundsException e) {
throw new DataException("Chunk does not contain position " + position);
@ -158,7 +157,7 @@ public class AnvilChunk implements Chunk {
int section = y >> 4;
int yIndex = y & 0x0F;
if (section < 0 || section >= blocks.length) {
throw new DataException("Chunk does not contain position " + position);
}
@ -264,10 +263,12 @@ public class AnvilChunk implements Chunk {
}
if (state.getMaterial().hasContainer()) {
CompoundTag tileEntity = getBlockTileEntity(position);
if (tileEntity != null) {
return state.toBaseBlock(tileEntity);
}
}
return state.toBaseBlock();
}

View File

@ -54,7 +54,7 @@ public class AnvilChunk13 implements Chunk {
/**
* Construct the chunk with a compound tag.
*
*
* @param tag the tag to read
* @throws DataException on a data error
*/
@ -159,13 +159,14 @@ public class AnvilChunk13 implements Chunk {
* @throws DataException
*/
private void populateTileEntities() throws DataException {
tileEntities = new HashMap<>();
if (!rootTag.getValue().containsKey("TileEntities")) {
return;
}
List<Tag> tags = NBTUtils.getChildTag(rootTag.getValue(),
"TileEntities", ListTag.class).getValue();
tileEntities = new HashMap<>();
for (Tag tag : tags) {
if (!(tag instanceof CompoundTag)) {
throw new InvalidFormatException("CompoundTag expected in TileEntities");
@ -221,6 +222,7 @@ public class AnvilChunk13 implements Chunk {
BlockState[] sectionBlocks = blocks[section];
BlockState state = sectionBlocks != null ? sectionBlocks[(yIndex << 8) | (z << 4) | x] : BlockTypes.AIR.getDefaultState();
if (state.getMaterial().hasContainer()) {
CompoundTag tileEntity = getBlockTileEntity(position);
return state.toBaseBlock(tileEntity);

View File

@ -20,7 +20,6 @@
package com.sk89q.worldedit.world.chunk;
import com.sk89q.worldedit.math.BlockVector3;
import com.sk89q.worldedit.world.block.BaseBlock;
import com.sk89q.worldedit.world.DataException;
import com.sk89q.worldedit.world.block.BaseBlock;

View File

@ -61,7 +61,7 @@ public class OldChunk implements Chunk {
*/
public OldChunk(World world, CompoundTag tag) throws DataException {
rootTag = tag;
blocks = NBTUtils.getChildTag(rootTag.getValue(), "Blocks", ByteArrayTag.class).getValue();
data = NBTUtils.getChildTag(rootTag.getValue(), "Data", ByteArrayTag.class).getValue();
rootX = NBTUtils.getChildTag(rootTag.getValue(), "xPos", IntTag.class).getValue();
@ -191,6 +191,7 @@ public class OldChunk implements Chunk {
return state.toBaseBlock(tileEntity);
}
}
return state.toBaseBlock();
}