From 97bd12fc33be1fb4f9c5036606f13b6f9fa83812 Mon Sep 17 00:00:00 2001 From: Gerrygames Date: Mon, 21 Jan 2019 16:24:05 +0100 Subject: [PATCH] use BLOCK_CHANGE_RECORD_ARRAY --- .../packets/BlockItemPackets1_11.java | 12 ++++-------- .../packets/BlockItemPackets1_12.java | 12 ++++-------- .../packets/BlockItemPackets1_10.java | 12 ++++-------- 3 files changed, 12 insertions(+), 24 deletions(-) diff --git a/core/src/main/java/nl/matsv/viabackwards/protocol/protocol1_10to1_11/packets/BlockItemPackets1_11.java b/core/src/main/java/nl/matsv/viabackwards/protocol/protocol1_10to1_11/packets/BlockItemPackets1_11.java index 10519452..27ca1f29 100644 --- a/core/src/main/java/nl/matsv/viabackwards/protocol/protocol1_10to1_11/packets/BlockItemPackets1_11.java +++ b/core/src/main/java/nl/matsv/viabackwards/protocol/protocol1_10to1_11/packets/BlockItemPackets1_11.java @@ -22,6 +22,7 @@ import nl.matsv.viabackwards.protocol.protocol1_12to1_11_1.data.BlockColors; import nl.matsv.viabackwards.utils.Block; import us.myles.ViaVersion.api.PacketWrapper; import us.myles.ViaVersion.api.data.UserConnection; +import us.myles.ViaVersion.api.minecraft.BlockChangeRecord; import us.myles.ViaVersion.api.minecraft.chunks.Chunk; import us.myles.ViaVersion.api.minecraft.item.Item; import us.myles.ViaVersion.api.minecraft.metadata.Metadata; @@ -269,18 +270,13 @@ public class BlockItemPackets1_11 extends BlockItemRewriter public void registerMap() { map(Type.INT); // 0 - Chunk X map(Type.INT); // 1 - Chunk Z + map(Type.BLOCK_CHANGE_RECORD_ARRAY); handler(new PacketHandler() { @Override public void handle(PacketWrapper wrapper) throws Exception { - int count = wrapper.passthrough(Type.VAR_INT); // Array length - - for (int i = 0; i < count; i++) { - wrapper.passthrough(Type.UNSIGNED_BYTE); // Horizontal position - wrapper.passthrough(Type.UNSIGNED_BYTE); // Y coords - - int id = wrapper.read(Type.VAR_INT); // Block ID - wrapper.write(Type.VAR_INT, handleBlockID(id)); + for (BlockChangeRecord record : wrapper.get(Type.BLOCK_CHANGE_RECORD_ARRAY, 0)) { + record.setBlockId(handleBlockID(record.getBlockId())); } } }); diff --git a/core/src/main/java/nl/matsv/viabackwards/protocol/protocol1_12to1_11_1/packets/BlockItemPackets1_12.java b/core/src/main/java/nl/matsv/viabackwards/protocol/protocol1_12to1_11_1/packets/BlockItemPackets1_12.java index 354dd452..603f6949 100644 --- a/core/src/main/java/nl/matsv/viabackwards/protocol/protocol1_12to1_11_1/packets/BlockItemPackets1_12.java +++ b/core/src/main/java/nl/matsv/viabackwards/protocol/protocol1_12to1_11_1/packets/BlockItemPackets1_12.java @@ -16,6 +16,7 @@ import nl.matsv.viabackwards.protocol.protocol1_12to1_11_1.data.BlockColors; import nl.matsv.viabackwards.protocol.protocol1_12to1_11_1.data.MapColorMapping; import nl.matsv.viabackwards.utils.Block; import us.myles.ViaVersion.api.PacketWrapper; +import us.myles.ViaVersion.api.minecraft.BlockChangeRecord; import us.myles.ViaVersion.api.minecraft.chunks.Chunk; import us.myles.ViaVersion.api.minecraft.item.Item; import us.myles.ViaVersion.api.minecraft.metadata.Metadata; @@ -242,18 +243,13 @@ public class BlockItemPackets1_12 extends BlockItemRewriter public void registerMap() { map(Type.INT); // 0 - Chunk X map(Type.INT); // 1 - Chunk Z + map(Type.BLOCK_CHANGE_RECORD_ARRAY); handler(new PacketHandler() { @Override public void handle(PacketWrapper wrapper) throws Exception { - int count = wrapper.passthrough(Type.VAR_INT); // Array length - - for (int i = 0; i < count; i++) { - wrapper.passthrough(Type.UNSIGNED_BYTE); // Horizontal position - wrapper.passthrough(Type.UNSIGNED_BYTE); // Y coords - - int id = wrapper.read(Type.VAR_INT); // Block ID - wrapper.write(Type.VAR_INT, handleBlockID(id)); + for (BlockChangeRecord record : wrapper.get(Type.BLOCK_CHANGE_RECORD_ARRAY, 0)) { + record.setBlockId(handleBlockID(record.getBlockId())); } } });