use of cn.nukkit.utils.ChunkException in project Nukkit by Nukkit.
the class McRegion method requestChunkTask.
@Override
public AsyncTask requestChunkTask(int x, int z) throws ChunkException {
BaseFullChunk chunk = this.getChunk(x, z, false);
if (chunk == null) {
throw new ChunkException("Invalid Chunk Sent");
}
long timestamp = chunk.getChanges();
byte[] tiles = new byte[0];
if (!chunk.getBlockEntities().isEmpty()) {
List<CompoundTag> tagList = new ArrayList<>();
for (BlockEntity blockEntity : chunk.getBlockEntities().values()) {
if (blockEntity instanceof BlockEntitySpawnable) {
tagList.add(((BlockEntitySpawnable) blockEntity).getSpawnCompound());
}
}
try {
tiles = NBTIO.write(tagList, ByteOrder.LITTLE_ENDIAN, true);
} catch (IOException e) {
throw new RuntimeException(e);
}
}
Map<Integer, Integer> extra = chunk.getBlockExtraDataArray();
BinaryStream extraData;
if (!extra.isEmpty()) {
extraData = new BinaryStream();
extraData.putLInt(extra.size());
for (Map.Entry<Integer, Integer> entry : extra.entrySet()) {
extraData.putLInt(entry.getKey());
extraData.putLShort(entry.getValue());
}
} else {
extraData = null;
}
BinaryStream stream = new BinaryStream();
stream.put(chunk.getBlockIdArray());
stream.put(chunk.getBlockDataArray());
stream.put(chunk.getBlockSkyLightArray());
stream.put(chunk.getBlockLightArray());
stream.put(chunk.getHeightMapArray());
for (int color : chunk.getBiomeColorArray()) {
stream.put(Binary.writeInt(color));
}
if (extraData != null) {
stream.put(extraData.getBuffer());
} else {
stream.putLInt(0);
}
stream.put(tiles);
this.getLevel().chunkRequestCallback(timestamp, x, z, stream.getBuffer());
return null;
}
use of cn.nukkit.utils.ChunkException in project Nukkit by Nukkit.
the class Anvil method requestChunkTask.
@Override
public AsyncTask requestChunkTask(int x, int z) throws ChunkException {
Chunk chunk = (Chunk) this.getChunk(x, z, false);
if (chunk == null) {
throw new ChunkException("Invalid Chunk Set");
}
long timestamp = chunk.getChanges();
byte[] blockEntities = new byte[0];
if (!chunk.getBlockEntities().isEmpty()) {
List<CompoundTag> tagList = new ArrayList<>();
for (BlockEntity blockEntity : chunk.getBlockEntities().values()) {
if (blockEntity instanceof BlockEntitySpawnable) {
tagList.add(((BlockEntitySpawnable) blockEntity).getSpawnCompound());
}
}
try {
blockEntities = NBTIO.write(tagList, ByteOrder.LITTLE_ENDIAN, true);
} catch (IOException e) {
throw new RuntimeException(e);
}
}
Map<Integer, Integer> extra = chunk.getBlockExtraDataArray();
BinaryStream extraData;
if (!extra.isEmpty()) {
extraData = new BinaryStream();
extraData.putVarInt(extra.size());
for (Map.Entry<Integer, Integer> entry : extra.entrySet()) {
extraData.putVarInt(entry.getKey());
extraData.putLShort(entry.getValue());
}
} else {
extraData = null;
}
BinaryStream stream = ThreadCache.binaryStream.get().reset();
int count = 0;
cn.nukkit.level.format.ChunkSection[] sections = chunk.getSections();
for (int i = sections.length - 1; i >= 0; i--) {
if (!sections[i].isEmpty()) {
count = i + 1;
break;
}
}
stream.putByte((byte) count);
for (int i = 0; i < count; i++) {
stream.putByte((byte) 0);
stream.put(sections[i].getBytes());
}
for (byte height : chunk.getHeightMapArray()) {
stream.putByte(height);
}
stream.put(PAD_256);
stream.put(chunk.getBiomeIdArray());
stream.putByte((byte) 0);
if (extraData != null) {
stream.put(extraData.getBuffer());
} else {
stream.putVarInt(0);
}
stream.put(blockEntities);
this.getLevel().chunkRequestCallback(timestamp, x, z, stream.getBuffer());
return null;
}
Aggregations