private void processChunk( int x, int z, byte[] data, int bitmask, int additionalBitmask, boolean addSkylight, boolean addBiomes) { if (data == null) return; int chunksChanged = 0; for (int i = 0; i < 16; i++) if ((bitmask & (1 << i)) != 0) chunksChanged++; if (chunksChanged == 0) return; byte[] biomes = new byte[256]; synchronized (chunks) { int i = 0; for (int y = 0; y < 16; y++) { if ((bitmask & (1 << y)) == 0) continue; int dataIndex = i * 4096; byte[] blocks = Arrays.copyOfRange(data, dataIndex, dataIndex + 4096); dataIndex += ((chunksChanged - i) * 4096) + (i * 2048); byte[] metadata = Arrays.copyOfRange(data, dataIndex, dataIndex + 2048); dataIndex += chunksChanged * 2048; byte[] light = Arrays.copyOfRange(data, dataIndex, dataIndex + 2048); dataIndex += chunksChanged * 2048; byte[] skylight = null; if (addSkylight) skylight = Arrays.copyOfRange(data, dataIndex, dataIndex + 2048); byte[] perBlockMetadata = new byte[4096]; byte[] perBlockLight = new byte[4096]; byte[] perBlockSkylight = new byte[4096]; for (int j = 0; j < 2048; j++) { int k = j * 2; perBlockMetadata[k] = (byte) (metadata[j] & 0x0F); perBlockLight[k] = (byte) (light[j] & 0x0F); if (addSkylight) perBlockSkylight[k] = (byte) (skylight[j] & 0x0F); k++; perBlockMetadata[k] = (byte) (metadata[j] >> 4); perBlockLight[k] = (byte) (light[j] >> 4); if (addSkylight) perBlockSkylight[k] = (byte) (skylight[j] >> 4); } ChunkLocation newLocation = new ChunkLocation(x, y, z); Chunk chunk = new Chunk( this, newLocation, blocks, perBlockMetadata, perBlockLight, perBlockSkylight, biomes); chunks.put(newLocation, chunk); bot.getEventManager().sendEvent(new ChunkLoadEvent(this, chunk)); i++; } System.arraycopy(data, data.length - 256, biomes, 0, 256); } }