us.myles.ViaVersion.api.minecraft.chunks.Chunk Java Examples
The following examples show how to use
us.myles.ViaVersion.api.minecraft.chunks.Chunk.
You can vote up the ones you like or vote down the ones you don't like,
and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example #1
Source File: Chunk1_15Type.java From ViaVersion with MIT License | 5 votes |
@Override public void write(ByteBuf output, ClientWorld world, Chunk chunk) throws Exception { output.writeInt(chunk.getX()); output.writeInt(chunk.getZ()); output.writeBoolean(chunk.isFullChunk()); Type.VAR_INT.writePrimitive(output, chunk.getBitmask()); Type.NBT.write(output, chunk.getHeightMap()); // Write biome data if (chunk.isBiomeData()) { for (int value : chunk.getBiomeData()) { output.writeInt(value); } } ByteBuf buf = output.alloc().buffer(); try { for (int i = 0; i < 16; i++) { ChunkSection section = chunk.getSections()[i]; if (section == null) continue; // Section not set buf.writeShort(section.getNonAirBlocksCount()); Types1_13.CHUNK_SECTION.write(buf, section); } buf.readerIndex(0); Type.VAR_INT.writePrimitive(output, buf.readableBytes()); output.writeBytes(buf); } finally { buf.release(); // release buffer } // Write Block Entities Type.NBT_ARRAY.write(output, chunk.getBlockEntities().toArray(EMPTY_COMPOUNDS)); }
Example #2
Source File: Chunk1_9to1_8Type.java From ViaVersion with MIT License | 5 votes |
@Override public void write(ByteBuf output, ClientChunks param, Chunk input) throws Exception { if (!(input instanceof Chunk1_8)) throw new Exception("Incompatible chunk, " + input.getClass()); Chunk1_8 chunk = (Chunk1_8) input; // Write primary info output.writeInt(chunk.getX()); output.writeInt(chunk.getZ()); if (chunk.isUnloadPacket()) return; output.writeByte(chunk.isFullChunk() ? 0x01 : 0x00); Type.VAR_INT.writePrimitive(output, chunk.getBitmask()); ByteBuf buf = output.alloc().buffer(); try { for (int i = 0; i < SECTION_COUNT; i++) { ChunkSection section = chunk.getSections()[i]; if (section == null) continue; // Section not set Types1_9.CHUNK_SECTION.write(buf, section); section.writeBlockLight(buf); if (!section.hasSkyLight()) continue; // No sky light, we're done here. section.writeSkyLight(buf); } buf.readerIndex(0); Type.VAR_INT.writePrimitive(output, buf.readableBytes() + (chunk.hasBiomeData() ? 256 : 0)); output.writeBytes(buf); } finally { buf.release(); // release buffer } // Write biome data if (chunk.hasBiomeData()) { for (int biome : chunk.getBiomeData()) { output.writeByte((byte) biome); } } }
Example #3
Source File: Chunk1_14Type.java From ViaVersion with MIT License | 5 votes |
@Override public void write(ByteBuf output, ClientWorld world, Chunk chunk) throws Exception { output.writeInt(chunk.getX()); output.writeInt(chunk.getZ()); output.writeBoolean(chunk.isFullChunk()); Type.VAR_INT.writePrimitive(output, chunk.getBitmask()); Type.NBT.write(output, chunk.getHeightMap()); ByteBuf buf = output.alloc().buffer(); try { for (int i = 0; i < 16; i++) { ChunkSection section = chunk.getSections()[i]; if (section == null) continue; // Section not set buf.writeShort(section.getNonAirBlocksCount()); Types1_13.CHUNK_SECTION.write(buf, section); } buf.readerIndex(0); Type.VAR_INT.writePrimitive(output, buf.readableBytes() + (chunk.isBiomeData() ? 1024 : 0)); // 256 * 4 output.writeBytes(buf); } finally { buf.release(); // release buffer } // Write biome data if (chunk.isBiomeData()) { for (int value : chunk.getBiomeData()) { output.writeInt(value & 0xFF); // This is a temporary workaround, we'll look into fixing this soon :) } } // Write Block Entities Type.NBT_ARRAY.write(output, chunk.getBlockEntities().toArray(new CompoundTag[0])); }
Example #4
Source File: Chunk1_16Type.java From ViaVersion with MIT License | 5 votes |
@Override public void write(ByteBuf output, ClientWorld world, Chunk chunk) throws Exception { output.writeInt(chunk.getX()); output.writeInt(chunk.getZ()); output.writeBoolean(chunk.isFullChunk()); output.writeBoolean(chunk.isIgnoreOldLightData()); Type.VAR_INT.writePrimitive(output, chunk.getBitmask()); Type.NBT.write(output, chunk.getHeightMap()); // Write biome data if (chunk.isBiomeData()) { for (int value : chunk.getBiomeData()) { output.writeInt(value); } } ByteBuf buf = output.alloc().buffer(); try { for (int i = 0; i < 16; i++) { ChunkSection section = chunk.getSections()[i]; if (section == null) continue; // Section not set buf.writeShort(section.getNonAirBlocksCount()); Types1_16.CHUNK_SECTION.write(buf, section); } buf.readerIndex(0); Type.VAR_INT.writePrimitive(output, buf.readableBytes()); output.writeBytes(buf); } finally { buf.release(); // release buffer } // Write Block Entities Type.NBT_ARRAY.write(output, chunk.getBlockEntities().toArray(EMPTY_COMPOUNDS)); }
Example #5
Source File: Chunk1_9_3_4Type.java From ViaVersion with MIT License | 5 votes |
@Override public void write(ByteBuf output, ClientWorld world, Chunk chunk) throws Exception { output.writeInt(chunk.getX()); output.writeInt(chunk.getZ()); output.writeBoolean(chunk.isFullChunk()); Type.VAR_INT.writePrimitive(output, chunk.getBitmask()); ByteBuf buf = output.alloc().buffer(); try { for (int i = 0; i < 16; i++) { ChunkSection section = chunk.getSections()[i]; if (section == null) continue; // Section not set Types1_9.CHUNK_SECTION.write(buf, section); section.writeBlockLight(buf); if (!section.hasSkyLight()) continue; // No sky light, we're done here. section.writeSkyLight(buf); } buf.readerIndex(0); Type.VAR_INT.writePrimitive(output, buf.readableBytes() + (chunk.isBiomeData() ? 256 : 0)); output.writeBytes(buf); } finally { buf.release(); // release buffer } // Write biome data if (chunk.isBiomeData()) { for (int biome : chunk.getBiomeData()) { output.writeByte((byte) biome); } } // Write Block Entities Type.NBT_ARRAY.write(output, chunk.getBlockEntities().toArray(new CompoundTag[0])); }
Example #6
Source File: Chunk1_13Type.java From ViaVersion with MIT License | 5 votes |
@Override public void write(ByteBuf output, ClientWorld world, Chunk chunk) throws Exception { output.writeInt(chunk.getX()); output.writeInt(chunk.getZ()); output.writeBoolean(chunk.isFullChunk()); Type.VAR_INT.writePrimitive(output, chunk.getBitmask()); ByteBuf buf = output.alloc().buffer(); try { for (int i = 0; i < 16; i++) { ChunkSection section = chunk.getSections()[i]; if (section == null) continue; // Section not set Types1_13.CHUNK_SECTION.write(buf, section); section.writeBlockLight(buf); if (!section.hasSkyLight()) continue; // No sky light, we're done here. section.writeSkyLight(buf); } buf.readerIndex(0); Type.VAR_INT.writePrimitive(output, buf.readableBytes() + (chunk.isBiomeData() ? 1024 : 0)); output.writeBytes(buf); } finally { buf.release(); // release buffer } // Write biome data if (chunk.isBiomeData()) { for (int value : chunk.getBiomeData()) { output.writeInt(value); } } // Write Block Entities Type.NBT_ARRAY.write(output, chunk.getBlockEntities().toArray(new CompoundTag[0])); }
Example #7
Source File: ConnectionData.java From ViaVersion with MIT License | 5 votes |
public static void connectBlocks(UserConnection user, Chunk chunk) { long xOff = chunk.getX() << 4; long zOff = chunk.getZ() << 4; for (int i = 0; i < chunk.getSections().length; i++) { ChunkSection section = chunk.getSections()[i]; if (section == null) continue; boolean willConnect = false; for (int p = 0; p < section.getPaletteSize(); p++) { int id = section.getPaletteEntry(p); if (ConnectionData.connects(id)) { willConnect = true; break; } } if (!willConnect) continue; long yOff = i << 4; for (int y = 0; y < 16; y++) { for (int z = 0; z < 16; z++) { for (int x = 0; x < 16; x++) { int block = section.getFlatBlock(x, y, z); ConnectionHandler handler = ConnectionData.getConnectionHandler(block); if (handler != null) { block = handler.connect(user, new Position( (int) (xOff + x), (short) (yOff + y), (int) (zOff + z) ), block); section.setFlatBlock(x, y, z, block); } } } } } }
Example #8
Source File: Chunk1_8Type.java From ViaRewind with MIT License | 5 votes |
@Override public void write(ByteBuf output, ClientWorld world, Chunk chunk) throws Exception { ByteBuf buf = output.alloc().buffer(); for (int i = 0; i < chunk.getSections().length; i++) { if ((chunk.getBitmask() & 1 << i) == 0) continue; CHUNK_SECTION_TYPE.write(buf, chunk.getSections()[i]); } for (int i = 0; i < chunk.getSections().length; i++) { if ((chunk.getBitmask() & 1 << i) == 0) continue; chunk.getSections()[i].writeBlockLight(buf); } boolean skyLight = world.getEnvironment() == Environment.NORMAL; if (skyLight) { for (int i = 0; i < chunk.getSections().length; i++) { if ((chunk.getBitmask() & 1 << i) == 0) continue; chunk.getSections()[i].writeSkyLight(buf); } } if (chunk.isGroundUp() && chunk.isBiomeData()) { for (int biome : chunk.getBiomeData()) { buf.writeByte((byte) biome); } } output.writeInt(chunk.getX()); output.writeInt(chunk.getZ()); output.writeBoolean(chunk.isGroundUp()); output.writeShort(chunk.getBitmask()); Type.VAR_INT.write(output, buf.readableBytes()); output.writeBytes(buf, buf.readableBytes()); buf.release(); }
Example #9
Source File: Chunk1_9_1_2Type.java From ViaVersion with MIT License | 5 votes |
@Override public void write(ByteBuf output, ClientWorld world, Chunk chunk) throws Exception { output.writeInt(chunk.getX()); output.writeInt(chunk.getZ()); output.writeBoolean(chunk.isFullChunk()); Type.VAR_INT.writePrimitive(output, chunk.getBitmask()); ByteBuf buf = output.alloc().buffer(); try { for (int i = 0; i < 16; i++) { ChunkSection section = chunk.getSections()[i]; if (section == null) continue; // Section not set Types1_9.CHUNK_SECTION.write(buf, section); section.writeBlockLight(buf); if (!section.hasSkyLight()) continue; // No sky light, we're done here. section.writeSkyLight(buf); } buf.readerIndex(0); Type.VAR_INT.writePrimitive(output, buf.readableBytes() + (chunk.isBiomeData() ? 256 : 0)); output.writeBytes(buf); } finally { buf.release(); // release buffer } // Write biome data if (chunk.isBiomeData()) { for (int biome : chunk.getBiomeData()) { output.writeByte((byte) biome); } } }
Example #10
Source File: WorldPackets1_13_1.java From ViaBackwards with MIT License | 5 votes |
public static void register(Protocol protocol) { BlockRewriter blockRewriter = new BlockRewriter(protocol, Type.POSITION, Protocol1_13To1_13_1::getNewBlockStateId, Protocol1_13To1_13_1::getNewBlockId); protocol.registerOutgoing(ClientboundPackets1_13.CHUNK_DATA, new PacketRemapper() { @Override public void registerMap() { handler(new PacketHandler() { @Override public void handle(PacketWrapper wrapper) throws Exception { ClientWorld clientWorld = wrapper.user().get(ClientWorld.class); Chunk chunk = wrapper.passthrough(new Chunk1_13Type(clientWorld)); for (ChunkSection section : chunk.getSections()) { if (section != null) { for (int i = 0; i < section.getPaletteSize(); i++) { section.setPaletteEntry(i, Protocol1_13To1_13_1.getNewBlockStateId(section.getPaletteEntry(i))); } } } } }); } }); blockRewriter.registerBlockAction(ClientboundPackets1_13.BLOCK_ACTION); blockRewriter.registerBlockChange(ClientboundPackets1_13.BLOCK_CHANGE); blockRewriter.registerMultiBlockChange(ClientboundPackets1_13.MULTI_BLOCK_CHANGE); blockRewriter.registerEffect(ClientboundPackets1_13.EFFECT, 1010, 2001, InventoryPackets1_13_1::getOldItemId); blockRewriter.registerSpawnParticle(ClientboundPackets1_13.SPAWN_PARTICLE, 3, 20, 27, InventoryPackets1_13_1::toClient, Type.FLAT_ITEM, Type.FLOAT); }
Example #11
Source File: Chunk1_9_1_2Type.java From ViaVersion with MIT License | 4 votes |
public Chunk1_9_1_2Type(ClientWorld clientWorld) { super(clientWorld, Chunk.class); }
Example #12
Source File: Chunk1_13Type.java From ViaVersion with MIT License | 4 votes |
@Override public Chunk read(ByteBuf input, ClientWorld world) throws Exception { int chunkX = input.readInt(); int chunkZ = input.readInt(); boolean fullChunk = input.readBoolean(); int primaryBitmask = Type.VAR_INT.readPrimitive(input); ByteBuf data = input.readSlice(Type.VAR_INT.readPrimitive(input)); // Read sections ChunkSection[] sections = new ChunkSection[16]; for (int i = 0; i < 16; i++) { if ((primaryBitmask & (1 << i)) == 0) continue; // Section not set ChunkSection section = Types1_13.CHUNK_SECTION.read(data); sections[i] = section; section.readBlockLight(data); if (world.getEnvironment() == Environment.NORMAL) { section.readSkyLight(data); } } int[] biomeData = fullChunk ? new int[256] : null; if (fullChunk) { if (data.readableBytes() >= 256 * 4) { for (int i = 0; i < 256; i++) { biomeData[i] = data.readInt(); } } else { Via.getPlatform().getLogger().log(Level.WARNING, "Chunk x=" + chunkX + " z=" + chunkZ + " doesn't have biome data!"); } } List<CompoundTag> nbtData = new ArrayList<>(Arrays.asList(Type.NBT_ARRAY.read(input))); // Read all the remaining bytes (workaround for #681) if (input.readableBytes() > 0) { byte[] array = Type.REMAINING_BYTES.read(input); if (Via.getManager().isDebug()) { Via.getPlatform().getLogger().warning("Found " + array.length + " more bytes than expected while reading the chunk: " + chunkX + "/" + chunkZ); } } return new BaseChunk(chunkX, chunkZ, fullChunk, false, primaryBitmask, sections, biomeData, nbtData); }
Example #13
Source File: WorldPackets.java From ViaVersion with MIT License | 4 votes |
private static void setNonFullLight(Chunk chunk, ChunkSection section, int ySection, int x, int y, int z) { int skyLight = 0; int blockLight = 0; for (BlockFace blockFace : BlockFace.values()) { NibbleArray skyLightArray = section.getSkyLightNibbleArray(); NibbleArray blockLightArray = section.getBlockLightNibbleArray(); int neighbourX = x + blockFace.getModX(); int neighbourY = y + blockFace.getModY(); int neighbourZ = z + blockFace.getModZ(); if (blockFace.getModX() != 0) { // Another chunk, nothing we can do without an unnecessary amount of caching if (neighbourX == 16 || neighbourX == -1) continue; } else if (blockFace.getModY() != 0) { if (neighbourY == 16 || neighbourY == -1) { if (neighbourY == 16) { ySection += 1; neighbourY = 0; } else { ySection -= 1; neighbourY = 15; } if (ySection == 16 || ySection == -1) continue; ChunkSection newSection = chunk.getSections()[ySection]; if (newSection == null) continue; skyLightArray = newSection.getSkyLightNibbleArray(); blockLightArray = newSection.getBlockLightNibbleArray(); } } else if (blockFace.getModZ() != 0) { // Another chunk, nothing we can do without an unnecessary amount of caching if (neighbourZ == 16 || neighbourZ == -1) continue; } if (blockLightArray != null && blockLight != 15) { int neighbourBlockLight = blockLightArray.get(neighbourX, neighbourY, neighbourZ); if (neighbourBlockLight == 15) { blockLight = 14; } else if (neighbourBlockLight > blockLight) { blockLight = neighbourBlockLight - 1; // lower light level by one } } if (skyLightArray != null && skyLight != 15) { int neighbourSkyLight = skyLightArray.get(neighbourX, neighbourY, neighbourZ); if (neighbourSkyLight == 15) { if (blockFace.getModY() == 1) { // Keep 15 if block is exposed to sky skyLight = 15; continue; } skyLight = 14; } else if (neighbourSkyLight > skyLight) { skyLight = neighbourSkyLight - 1; // lower light level by one } } } if (skyLight != 0) { if (!section.hasSkyLight()) { byte[] newSkyLight = new byte[2028]; section.setSkyLight(newSkyLight); } section.getSkyLightNibbleArray().set(x, y, z, skyLight); } if (blockLight != 0) { section.getBlockLightNibbleArray().set(x, y, z, blockLight); } }
Example #14
Source File: Chunk1_13Type.java From ViaVersion with MIT License | 4 votes |
public Chunk1_13Type(ClientWorld param) { super(param, Chunk.class); }
Example #15
Source File: WorldPackets.java From ViaVersion with MIT License | 4 votes |
public static void register(Protocol protocol) { BlockRewriter blockRewriter = new BlockRewriter(protocol, Type.POSITION1_14, Protocol1_16To1_15_2::getNewBlockStateId, Protocol1_16To1_15_2::getNewBlockId); blockRewriter.registerBlockAction(ClientboundPackets1_15.BLOCK_ACTION); blockRewriter.registerBlockChange(ClientboundPackets1_15.BLOCK_CHANGE); blockRewriter.registerMultiBlockChange(ClientboundPackets1_15.MULTI_BLOCK_CHANGE); blockRewriter.registerAcknowledgePlayerDigging(ClientboundPackets1_15.ACKNOWLEDGE_PLAYER_DIGGING); protocol.registerOutgoing(ClientboundPackets1_15.UPDATE_LIGHT, new PacketRemapper() { @Override public void registerMap() { map(Type.VAR_INT); // x map(Type.VAR_INT); // y handler(wrapper -> wrapper.write(Type.BOOLEAN, true)); // Take neighbour's light into account as well } }); protocol.registerOutgoing(ClientboundPackets1_15.CHUNK_DATA, new PacketRemapper() { @Override public void registerMap() { handler(wrapper -> { ClientWorld clientWorld = wrapper.user().get(ClientWorld.class); Chunk chunk = wrapper.read(new Chunk1_15Type(clientWorld)); wrapper.write(new Chunk1_16Type(clientWorld), chunk); chunk.setIgnoreOldLightData(chunk.isFullChunk()); for (int s = 0; s < 16; s++) { ChunkSection section = chunk.getSections()[s]; if (section == null) continue; for (int i = 0; i < section.getPaletteSize(); i++) { int old = section.getPaletteEntry(i); section.setPaletteEntry(i, Protocol1_16To1_15_2.getNewBlockStateId(old)); } } CompoundTag heightMaps = chunk.getHeightMap(); for (Tag heightMapTag : heightMaps) { LongArrayTag heightMap = (LongArrayTag) heightMapTag; int[] heightMapData = new int[256]; CompactArrayUtil.iterateCompactArray(9, heightMapData.length, heightMap.getValue(), (i, v) -> heightMapData[i] = v); heightMap.setValue(CompactArrayUtil.createCompactArrayWithPadding(9, heightMapData.length, i -> heightMapData[i])); } if (chunk.getBlockEntities() == null) return; for (CompoundTag blockEntity : chunk.getBlockEntities()) { handleBlockEntity(blockEntity); } }); } }); protocol.registerOutgoing(ClientboundPackets1_15.BLOCK_ENTITY_DATA, new PacketRemapper() { @Override public void registerMap() { handler(wrapper -> { Position position = wrapper.passthrough(Type.POSITION1_14); short action = wrapper.passthrough(Type.UNSIGNED_BYTE); CompoundTag tag = wrapper.passthrough(Type.NBT); handleBlockEntity(tag); }); } }); blockRewriter.registerEffect(ClientboundPackets1_15.EFFECT, 1010, 2001, InventoryPackets::getNewItemId); blockRewriter.registerSpawnParticle(ClientboundPackets1_15.SPAWN_PARTICLE, 3, 23, 32, WorldPackets::getNewParticleId, InventoryPackets::toClient, Type.FLAT_VAR_INT_ITEM, Type.DOUBLE); }
Example #16
Source File: Chunk1_9_1_2Type.java From ViaVersion with MIT License | 4 votes |
@Override public Chunk read(ByteBuf input, ClientWorld world) throws Exception { boolean replacePistons = world.getUser().getProtocolInfo().getPipeline().contains(Protocol1_10To1_9_3_4.class) && Via.getConfig().isReplacePistons(); int replacementId = Via.getConfig().getPistonReplacementId(); int chunkX = input.readInt(); int chunkZ = input.readInt(); boolean groundUp = input.readBoolean(); int primaryBitmask = Type.VAR_INT.readPrimitive(input); // Size (unused) Type.VAR_INT.readPrimitive(input); BitSet usedSections = new BitSet(16); ChunkSection[] sections = new ChunkSection[16]; // Calculate section count from bitmask for (int i = 0; i < 16; i++) { if ((primaryBitmask & (1 << i)) != 0) { usedSections.set(i); } } // Read sections for (int i = 0; i < 16; i++) { if (!usedSections.get(i)) continue; // Section not set ChunkSection section = Types1_9.CHUNK_SECTION.read(input); sections[i] = section; section.readBlockLight(input); if (world.getEnvironment() == Environment.NORMAL) { section.readSkyLight(input); } if (replacePistons) { section.replacePaletteEntry(36, replacementId); } } int[] biomeData = groundUp ? new int[256] : null; if (groundUp) { for (int i = 0; i < 256; i++) { biomeData[i] = input.readByte() & 0xFF; } } return new BaseChunk(chunkX, chunkZ, groundUp, false, primaryBitmask, sections, biomeData, new ArrayList<CompoundTag>()); }
Example #17
Source File: Chunk1_16Type.java From ViaVersion with MIT License | 4 votes |
@Override public Chunk read(ByteBuf input, ClientWorld world) throws Exception { int chunkX = input.readInt(); int chunkZ = input.readInt(); boolean fullChunk = input.readBoolean(); boolean ignoreOldLightData = input.readBoolean(); int primaryBitmask = Type.VAR_INT.readPrimitive(input); CompoundTag heightMap = Type.NBT.read(input); int[] biomeData = fullChunk ? new int[1024] : null; if (fullChunk) { for (int i = 0; i < 1024; i++) { biomeData[i] = input.readInt(); } } Type.VAR_INT.readPrimitive(input); // data size in bytes // Read sections ChunkSection[] sections = new ChunkSection[16]; for (int i = 0; i < 16; i++) { if ((primaryBitmask & (1 << i)) == 0) continue; // Section not set short nonAirBlocksCount = input.readShort(); ChunkSection section = Types1_16.CHUNK_SECTION.read(input); section.setNonAirBlocksCount(nonAirBlocksCount); sections[i] = section; } List<CompoundTag> nbtData = new ArrayList<>(Arrays.asList(Type.NBT_ARRAY.read(input))); // Read all the remaining bytes (workaround for #681) if (input.readableBytes() > 0) { byte[] array = Type.REMAINING_BYTES.read(input); if (Via.getManager().isDebug()) { Via.getPlatform().getLogger().warning("Found " + array.length + " more bytes than expected while reading the chunk: " + chunkX + "/" + chunkZ); } } return new BaseChunk(chunkX, chunkZ, fullChunk, ignoreOldLightData, primaryBitmask, sections, biomeData, heightMap, nbtData); }
Example #18
Source File: Chunk1_16Type.java From ViaVersion with MIT License | 4 votes |
public Chunk1_16Type(ClientWorld param) { super(param, Chunk.class); }
Example #19
Source File: Chunk1_9to1_8Type.java From ViaVersion with MIT License | 4 votes |
@Override public Chunk read(ByteBuf input, ClientChunks param) throws Exception { boolean replacePistons = param.getUser().getProtocolInfo().getPipeline().contains(Protocol1_10To1_9_3_4.class) && Via.getConfig().isReplacePistons(); int replacementId = Via.getConfig().getPistonReplacementId(); int chunkX = input.readInt(); int chunkZ = input.readInt(); long chunkHash = toLong(chunkX, chunkZ); boolean fullChunk = input.readByte() != 0; int bitmask = input.readUnsignedShort(); int dataLength = Type.VAR_INT.readPrimitive(input); // Data to be read BitSet usedSections = new BitSet(16); ChunkSection[] sections = new ChunkSection[16]; int[] biomeData = null; // Calculate section count from bitmask for (int i = 0; i < 16; i++) { if ((bitmask & (1 << i)) != 0) { usedSections.set(i); } } int sectionCount = usedSections.cardinality(); // the amount of sections set // If the chunks is from a chunks bulk, it is never an unload packet // Other wise, if it has no data, it is :) boolean isBulkPacket = param.getBulkChunks().remove(chunkHash); if (sectionCount == 0 && fullChunk && !isBulkPacket && param.getLoadedChunks().contains(chunkHash)) { // This is a chunks unload packet param.getLoadedChunks().remove(chunkHash); return new Chunk1_8(chunkX, chunkZ); } int startIndex = input.readerIndex(); param.getLoadedChunks().add(chunkHash); // mark chunks as loaded // Read blocks for (int i = 0; i < SECTION_COUNT; i++) { if (!usedSections.get(i)) continue; // Section not set ChunkSection section = Types1_8.CHUNK_SECTION.read(input); sections[i] = section; if (replacePistons) { section.replacePaletteEntry(36, replacementId); } } // Read block light for (int i = 0; i < SECTION_COUNT; i++) { if (!usedSections.get(i)) continue; // Section not set, has no light sections[i].readBlockLight(input); } // Read sky light int bytesLeft = dataLength - (input.readerIndex() - startIndex); if (bytesLeft >= ChunkSection.LIGHT_LENGTH) { for (int i = 0; i < SECTION_COUNT; i++) { if (!usedSections.get(i)) continue; // Section not set, has no light sections[i].readSkyLight(input); bytesLeft -= ChunkSection.LIGHT_LENGTH; } } // Read biome data if (bytesLeft >= BIOME_DATA_LENGTH) { biomeData = new int[BIOME_DATA_LENGTH]; for (int i = 0; i < BIOME_DATA_LENGTH; i++) { biomeData[i] = input.readByte() & 0xFF; } bytesLeft -= BIOME_DATA_LENGTH; } // Check remaining bytes if (bytesLeft > 0) { Via.getPlatform().getLogger().log(Level.WARNING, bytesLeft + " Bytes left after reading chunks! (" + fullChunk + ")"); } // Return chunks return new Chunk1_8(chunkX, chunkZ, fullChunk, bitmask, sections, biomeData, new ArrayList<CompoundTag>()); }
Example #20
Source File: Chunk1_9to1_8Type.java From ViaVersion with MIT License | 4 votes |
public Chunk1_9to1_8Type(ClientChunks chunks) { super(chunks, Chunk.class); }
Example #21
Source File: Chunk1_7_10Type.java From ViaRewind with MIT License | 4 votes |
public Chunk1_7_10Type(ClientWorld param) { super(param, Chunk.class); }
Example #22
Source File: Chunk1_14Type.java From ViaVersion with MIT License | 4 votes |
@Override public Chunk read(ByteBuf input, ClientWorld world) throws Exception { int chunkX = input.readInt(); int chunkZ = input.readInt(); boolean fullChunk = input.readBoolean(); int primaryBitmask = Type.VAR_INT.readPrimitive(input); CompoundTag heightMap = Type.NBT.read(input); Type.VAR_INT.readPrimitive(input); // Read sections ChunkSection[] sections = new ChunkSection[16]; for (int i = 0; i < 16; i++) { if ((primaryBitmask & (1 << i)) == 0) continue; // Section not set short nonAirBlocksCount = input.readShort(); ChunkSection section = Types1_13.CHUNK_SECTION.read(input); section.setNonAirBlocksCount(nonAirBlocksCount); sections[i] = section; } int[] biomeData = fullChunk ? new int[256] : null; if (fullChunk) { for (int i = 0; i < 256; i++) { biomeData[i] = input.readInt(); } } List<CompoundTag> nbtData = new ArrayList<>(Arrays.asList(Type.NBT_ARRAY.read(input))); // Read all the remaining bytes (workaround for #681) if (input.readableBytes() > 0) { byte[] array = Type.REMAINING_BYTES.read(input); if (Via.getManager().isDebug()) { Via.getPlatform().getLogger().warning("Found " + array.length + " more bytes than expected while reading the chunk: " + chunkX + "/" + chunkZ); } } return new BaseChunk(chunkX, chunkZ, fullChunk, false, primaryBitmask, sections, biomeData, heightMap, nbtData); }
Example #23
Source File: Chunk1_14Type.java From ViaVersion with MIT License | 4 votes |
public Chunk1_14Type(ClientWorld param) { super(param, Chunk.class); }
Example #24
Source File: Chunk1_9_3_4Type.java From ViaVersion with MIT License | 4 votes |
@Override public Chunk read(ByteBuf input, ClientWorld world) throws Exception { int chunkX = input.readInt(); int chunkZ = input.readInt(); boolean fullChunk = input.readBoolean(); int primaryBitmask = Type.VAR_INT.readPrimitive(input); Type.VAR_INT.readPrimitive(input); // Read sections ChunkSection[] sections = new ChunkSection[16]; for (int i = 0; i < 16; i++) { if ((primaryBitmask & (1 << i)) == 0) continue; // Section not set ChunkSection section = Types1_9.CHUNK_SECTION.read(input); sections[i] = section; section.readBlockLight(input); if (world.getEnvironment() == Environment.NORMAL) { section.readSkyLight(input); } } int[] biomeData = fullChunk ? new int[256] : null; if (fullChunk) { for (int i = 0; i < 256; i++) { biomeData[i] = input.readByte() & 0xFF; } } List<CompoundTag> nbtData = new ArrayList<>(Arrays.asList(Type.NBT_ARRAY.read(input))); // Read all the remaining bytes (workaround for #681) if (input.readableBytes() > 0) { byte[] array = Type.REMAINING_BYTES.read(input); if (Via.getManager().isDebug()) { Via.getPlatform().getLogger().warning("Found " + array.length + " more bytes than expected while reading the chunk: " + chunkX + "/" + chunkZ); } } return new BaseChunk(chunkX, chunkZ, fullChunk, false, primaryBitmask, sections, biomeData, nbtData); }
Example #25
Source File: Chunk1_9_3_4Type.java From ViaVersion with MIT License | 4 votes |
public Chunk1_9_3_4Type(ClientWorld param) { super(param, Chunk.class); }
Example #26
Source File: Chunk1_15Type.java From ViaVersion with MIT License | 4 votes |
@Override public Chunk read(ByteBuf input, ClientWorld world) throws Exception { int chunkX = input.readInt(); int chunkZ = input.readInt(); boolean fullChunk = input.readBoolean(); int primaryBitmask = Type.VAR_INT.readPrimitive(input); CompoundTag heightMap = Type.NBT.read(input); int[] biomeData = fullChunk ? new int[1024] : null; if (fullChunk) { for (int i = 0; i < 1024; i++) { biomeData[i] = input.readInt(); } } Type.VAR_INT.readPrimitive(input); // data size in bytes // Read sections ChunkSection[] sections = new ChunkSection[16]; for (int i = 0; i < 16; i++) { if ((primaryBitmask & (1 << i)) == 0) continue; // Section not set short nonAirBlocksCount = input.readShort(); ChunkSection section = Types1_13.CHUNK_SECTION.read(input); section.setNonAirBlocksCount(nonAirBlocksCount); sections[i] = section; } List<CompoundTag> nbtData = new ArrayList<>(Arrays.asList(Type.NBT_ARRAY.read(input))); // Read all the remaining bytes (workaround for #681) if (input.readableBytes() > 0) { byte[] array = Type.REMAINING_BYTES.read(input); if (Via.getManager().isDebug()) { Via.getPlatform().getLogger().warning("Found " + array.length + " more bytes than expected while reading the chunk: " + chunkX + "/" + chunkZ); } } return new BaseChunk(chunkX, chunkZ, fullChunk, false, primaryBitmask, sections, biomeData, heightMap, nbtData); }
Example #27
Source File: Chunk1_15Type.java From ViaVersion with MIT License | 4 votes |
public Chunk1_15Type(ClientWorld param) { super(param, Chunk.class); }
Example #28
Source File: BaseChunkType.java From ViaVersion with MIT License | 4 votes |
public BaseChunkType(String typeName) { super(typeName, Chunk.class); }
Example #29
Source File: BaseChunkType.java From ViaVersion with MIT License | 4 votes |
public BaseChunkType() { super(Chunk.class); }
Example #30
Source File: Chunk1_8Type.java From ViaRewind with MIT License | 4 votes |
@Override public Chunk read(ByteBuf input, ClientWorld world) throws Exception { // Copied from ViaVersion, removed some things int chunkX = input.readInt(); int chunkZ = input.readInt(); boolean groundUp = input.readByte() != 0; int bitmask = input.readUnsignedShort(); int dataLength = Type.VAR_INT.read(input); if (bitmask == 0 && groundUp) { // This is a chunks unload packet if (dataLength >= 256) { //1.8 likes to send biome data in unload packets?! input.readerIndex(input.readerIndex() + 256); } return new Chunk1_8(chunkX, chunkZ); } // Data to be read ChunkSection[] sections = new ChunkSection[16]; int[] biomeData = null; int startIndex = input.readerIndex(); // Read blocks for (int i = 0; i < 16; i++) { if ((bitmask & 1 << i) == 0) continue; sections[i] = CHUNK_SECTION_TYPE.read(input); } // Read block light for (int i = 0; i < 16; i++) { if ((bitmask & 1 << i) == 0) continue; sections[i].readBlockLight(input); } // Read sky light int bytesLeft = dataLength - (input.readerIndex() - startIndex); if (bytesLeft >= ChunkSection.LIGHT_LENGTH) { for (int i = 0; i < 16; i++) { if ((bitmask & 1 << i) == 0) continue; sections[i].readSkyLight(input); bytesLeft -= ChunkSection.LIGHT_LENGTH; } } // Read biome data if (bytesLeft >= 256) { biomeData = new int[256]; for (int i = 0; i < 256; i++) { biomeData[i] = input.readByte() & 0xFF; } bytesLeft -= 256; } // Check remaining bytes if (bytesLeft > 0) { Via.getPlatform().getLogger().log(Level.WARNING, bytesLeft + " Bytes left after reading chunks! (" + groundUp + ")"); } // Return chunks return new Chunk1_8(chunkX, chunkZ, groundUp, bitmask, sections, biomeData, new ArrayList<>()); }