mirror of
https://gitlab.bixilon.de/bixilon/minosoft.git
synced 2025-09-14 01:48:04 -04:00
1.16: PacketMultiBlockChange
This commit is contained in:
parent
a05a9ea8ac
commit
312677a007
@ -21,6 +21,7 @@ import de.bixilon.minosoft.logging.Log;
|
||||
import de.bixilon.minosoft.protocol.packets.ClientboundPacket;
|
||||
import de.bixilon.minosoft.protocol.protocol.InByteBuffer;
|
||||
import de.bixilon.minosoft.protocol.protocol.PacketHandler;
|
||||
import de.bixilon.minosoft.protocol.protocol.ProtocolVersion;
|
||||
|
||||
import java.util.HashMap;
|
||||
|
||||
@ -30,37 +31,44 @@ public class PacketMultiBlockChange implements ClientboundPacket {
|
||||
|
||||
@Override
|
||||
public boolean read(InByteBuffer buffer) {
|
||||
switch (buffer.getVersion()) {
|
||||
case VERSION_1_7_10: {
|
||||
location = new ChunkLocation(buffer.readInt(), buffer.readInt());
|
||||
short count = buffer.readShort();
|
||||
int dataSize = buffer.readInt(); // should be count * 4
|
||||
if (dataSize != count * 4) {
|
||||
throw new IllegalArgumentException(String.format("Not enough data (%d) for %d blocks", dataSize, count));
|
||||
}
|
||||
for (int i = 0; i < count; i++) {
|
||||
int raw = buffer.readInt();
|
||||
byte meta = (byte) (raw & 0xF);
|
||||
short blockId = (short) ((raw & 0xFF_F0) >>> 4);
|
||||
byte y = (byte) ((raw & 0xFF_00_00) >>> 16);
|
||||
byte z = (byte) ((raw & 0x0F_00_00_00) >>> 24);
|
||||
byte x = (byte) ((raw & 0xF0_00_00_00) >>> 28);
|
||||
blocks.put(new InChunkLocation(x, y, z), Blocks.getBlockByLegacy(blockId, meta));
|
||||
}
|
||||
return true;
|
||||
if (buffer.getVersion() == ProtocolVersion.VERSION_1_7_10) {
|
||||
location = new ChunkLocation(buffer.readInt(), buffer.readInt());
|
||||
short count = buffer.readShort();
|
||||
int dataSize = buffer.readInt(); // should be count * 4
|
||||
if (dataSize != count * 4) {
|
||||
throw new IllegalArgumentException(String.format("Not enough data (%d) for %d blocks", dataSize, count));
|
||||
}
|
||||
default: {
|
||||
location = new ChunkLocation(buffer.readInt(), buffer.readInt());
|
||||
int count = buffer.readVarInt();
|
||||
for (int i = 0; i < count; i++) {
|
||||
byte pos = buffer.readByte();
|
||||
byte y = buffer.readByte();
|
||||
int blockId = buffer.readVarInt();
|
||||
blocks.put(new InChunkLocation(((pos & 0xF0 >>> 4) & 0xF), y, (pos & 0xF)), Blocks.getBlock(blockId, buffer.getVersion()));
|
||||
}
|
||||
return true;
|
||||
for (int i = 0; i < count; i++) {
|
||||
int raw = buffer.readInt();
|
||||
byte meta = (byte) (raw & 0xF);
|
||||
short blockId = (short) ((raw & 0xFF_F0) >>> 4);
|
||||
byte y = (byte) ((raw & 0xFF_00_00) >>> 16);
|
||||
byte z = (byte) ((raw & 0x0F_00_00_00) >>> 24);
|
||||
byte x = (byte) ((raw & 0xF0_00_00_00) >>> 28);
|
||||
blocks.put(new InChunkLocation(x, y, z), Blocks.getBlockByLegacy(blockId, meta));
|
||||
}
|
||||
return true;
|
||||
}
|
||||
if (buffer.getVersion().getVersionNumber() < ProtocolVersion.VERSION_1_16_2.getVersionNumber()) {
|
||||
location = new ChunkLocation(buffer.readInt(), buffer.readInt());
|
||||
int count = buffer.readVarInt();
|
||||
for (int i = 0; i < count; i++) {
|
||||
byte pos = buffer.readByte();
|
||||
byte y = buffer.readByte();
|
||||
int blockId = buffer.readVarInt();
|
||||
blocks.put(new InChunkLocation((pos & 0xF0 >>> 4) & 0xF, y, pos & 0xF), Blocks.getBlock(blockId, buffer.getVersion()));
|
||||
}
|
||||
return true;
|
||||
}
|
||||
long rawPos = buffer.readLong();
|
||||
location = new ChunkLocation((int) (rawPos >> 42), (int) (rawPos << 22 >> 42));
|
||||
int yOffset = ((int) rawPos & 0xFFFFF) * 16;
|
||||
int count = buffer.readVarInt();
|
||||
for (int i = 0; i < count; i++) {
|
||||
long data = buffer.readVarLong();
|
||||
blocks.put(new InChunkLocation((int) ((data >> 8) & 0xF), yOffset + (int) ((data >> 4) & 0xF), (int) (data & 0xF)), Blocks.getBlock((int) (data >>> 12), buffer.getVersion()));
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
@Override
|
||||
|
Loading…
x
Reference in New Issue
Block a user