public class ChunkBulkHandler extends MessageHandler<ChunkBulkMessage> {
@Override
public void handleClient(ClientSession session, ChunkBulkMessage message) {
Player player = session.getPlayer();
World world = player.getEngine().getDefaultWorld();//player.getWorld();
RepositionManager rm = player.getNetwork().getRepositionManager();
for (int c = 0; c < message.getX().length; c++) {
int baseX = message.getX()[c] << Chunk.BLOCKS.BITS;
int baseZ = message.getZ()[c] << Chunk.BLOCKS.BITS;
final byte[][] data = message.getData()[c];
for (int i = 0; i < 16; i++) {
int baseY = i << Chunk.BLOCKS.BITS;
int index = 0;
for (int xx = 0; xx < Chunk.BLOCKS.SIZE; xx++) {
for (int yy = 0; yy < Chunk.BLOCKS.SIZE; yy++) {
for (int zz = 0; zz < Chunk.BLOCKS.SIZE; zz++) {
int x = rm.convertX(xx + baseX);
int y = rm.convertY(yy + baseY);
int z = rm.convertZ(zz + baseZ);
short type = data[i][index];
byte dat;
if (index % 2 == 0) {
dat = (byte) (data[i][(index / 2) + 4096] >> 4);
} else {
dat = (byte) (data[i][(index / 2) + 4096] & 0xF);
}
index++;
if (type > 0) {
BlockMaterial material = (BlockMaterial) VanillaMaterials.getMaterial(type, dat);
world.getChunkFromBlock(x, y, z).getBlock(x, y, z).setMaterial(material);
}
}
}
}
}