use of com.viaversion.viaversion.api.minecraft.BlockChangeRecord1_16_2 in project ViaVersion by ViaVersion.
the class WorldPackets method register.
public static void register(Protocol protocol) {
BlockRewriter blockRewriter = new BlockRewriter(protocol, Type.POSITION1_14);
blockRewriter.registerBlockAction(ClientboundPackets1_16.BLOCK_ACTION);
blockRewriter.registerBlockChange(ClientboundPackets1_16.BLOCK_CHANGE);
blockRewriter.registerAcknowledgePlayerDigging(ClientboundPackets1_16.ACKNOWLEDGE_PLAYER_DIGGING);
protocol.registerClientbound(ClientboundPackets1_16.CHUNK_DATA, new PacketRemapper() {
@Override
public void registerMap() {
handler(wrapper -> {
Chunk chunk = wrapper.read(new Chunk1_16Type());
wrapper.write(new Chunk1_16_2Type(), chunk);
for (int s = 0; s < chunk.getSections().length; 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, protocol.getMappingData().getNewBlockStateId(old));
}
}
});
}
});
protocol.registerClientbound(ClientboundPackets1_16.MULTI_BLOCK_CHANGE, new PacketRemapper() {
@Override
public void registerMap() {
handler(wrapper -> {
wrapper.cancel();
int chunkX = wrapper.read(Type.INT);
int chunkZ = wrapper.read(Type.INT);
long chunkPosition = 0;
chunkPosition |= (chunkX & 0x3FFFFFL) << 42;
chunkPosition |= (chunkZ & 0x3FFFFFL) << 20;
List<BlockChangeRecord>[] sectionRecords = new List[16];
BlockChangeRecord[] blockChangeRecord = wrapper.read(Type.BLOCK_CHANGE_RECORD_ARRAY);
for (BlockChangeRecord record : blockChangeRecord) {
int chunkY = record.getY() >> 4;
List<BlockChangeRecord> list = sectionRecords[chunkY];
if (list == null) {
sectionRecords[chunkY] = (list = new ArrayList<>());
}
// Absolute y -> relative chunk section y
int blockId = protocol.getMappingData().getNewBlockStateId(record.getBlockId());
list.add(new BlockChangeRecord1_16_2(record.getSectionX(), record.getSectionY(), record.getSectionZ(), blockId));
}
// Now send separate packets for the different chunk sections
for (int chunkY = 0; chunkY < sectionRecords.length; chunkY++) {
List<BlockChangeRecord> sectionRecord = sectionRecords[chunkY];
if (sectionRecord == null)
continue;
PacketWrapper newPacket = wrapper.create(ClientboundPackets1_16_2.MULTI_BLOCK_CHANGE);
newPacket.write(Type.LONG, chunkPosition | (chunkY & 0xFFFFFL));
// Ignore light updates
newPacket.write(Type.BOOLEAN, false);
newPacket.write(Type.VAR_LONG_BLOCK_CHANGE_RECORD_ARRAY, sectionRecord.toArray(EMPTY_RECORDS));
newPacket.send(Protocol1_16_2To1_16_1.class);
}
});
}
});
blockRewriter.registerEffect(ClientboundPackets1_16.EFFECT, 1010, 2001);
}
use of com.viaversion.viaversion.api.minecraft.BlockChangeRecord1_16_2 in project ViaVersion by ViaVersion.
the class WorldPackets method writeMultiBlockChangePacket.
private static void writeMultiBlockChangePacket(PacketWrapper wrapper, Chunk chunk) throws Exception {
long chunkPosition = (chunk.getX() & 0x3FFFFFL) << 42;
chunkPosition |= (chunk.getZ() & 0x3FFFFFL) << 20;
ChunkSection[] sections = chunk.getSections();
for (int chunkY = 0; chunkY < sections.length; chunkY++) {
ChunkSection section = sections[chunkY];
if (section == null)
continue;
PacketWrapper blockChangePacket = wrapper.create(ClientboundPackets1_17.MULTI_BLOCK_CHANGE);
blockChangePacket.write(Type.LONG, chunkPosition | (chunkY & 0xFFFFFL));
// Suppress light updates
blockChangePacket.write(Type.BOOLEAN, true);
// TODO this can be optimized
BlockChangeRecord[] blockChangeRecords = new BlockChangeRecord[4096];
int j = 0;
for (int x = 0; x < 16; x++) {
for (int y = 0; y < 16; y++) {
for (int z = 0; z < 16; z++) {
int blockStateId = Protocol1_17To1_16_4.MAPPINGS.getNewBlockStateId(section.getFlatBlock(x, y, z));
blockChangeRecords[j++] = new BlockChangeRecord1_16_2(x, y, z, blockStateId);
}
}
}
blockChangePacket.write(Type.VAR_LONG_BLOCK_CHANGE_RECORD_ARRAY, blockChangeRecords);
blockChangePacket.send(Protocol1_17To1_16_4.class);
}
}
Aggregations