ProtocolLib

3M Downloads

How to create MultiBlockChangePacket in 1.16.2?

GorgeousOne opened this issue · 1 comments

commented

I wanted to know how to create the new MultiBlockChangePacket introduced in 1.16.2. I could not figure out yet how exactly to write the data for the changed blocks into it.

As I understood it from reading the PacketContainerTest the chunk in which the changes happen can be set with a BlockPosition of any position in the chunk like
packet.getSectionPositions().writeSafely(0, new BlockPosition(42, 43, 44));

And the different changed block data is as added with an array of WarappedBlockData like
packet.getBlockDataArrays().writeSafely(0, new WrappedBlockData[] { WrappedBlockData.createData(Material.IRON_BARS), WrappedBlockData.createData(Material.IRON_BLOCK) });

But didn’t understand how the position for each block can be defined. Is it connected to this line?
packet.getShortArrays().writeSafely(0, new short[] { 420, 69 });
how exactly would these integers connect to positions?

Thanks for reading

commented

Okay, got it. Each short is represents a x y and z coordinate relative to a chunk, ranging between 0 and 15 and they can be created like this:
(short) ((x & 0xF) << 8 | (z & 0xF) << 4 | (y & 0xF));