From 067c93a63a375fb2eb48fd99d147297a31e6f62b Mon Sep 17 00:00:00 2001 From: Nassim Jahnke Date: Sat, 25 Sep 2021 10:11:43 +0200 Subject: [PATCH] Cancel null block entity nbt updates --- .../packets/BlockItemPackets1_16_2.java | 19 ++++++------------- .../packets/BlockItemPackets1_18.java | 9 ++++++++- 2 files changed, 14 insertions(+), 14 deletions(-) diff --git a/common/src/main/java/com/viaversion/viabackwards/protocol/protocol1_16_1to1_16_2/packets/BlockItemPackets1_16_2.java b/common/src/main/java/com/viaversion/viabackwards/protocol/protocol1_16_1to1_16_2/packets/BlockItemPackets1_16_2.java index f3dd8e42..e290c1cb 100644 --- a/common/src/main/java/com/viaversion/viabackwards/protocol/protocol1_16_1to1_16_2/packets/BlockItemPackets1_16_2.java +++ b/common/src/main/java/com/viaversion/viabackwards/protocol/protocol1_16_1to1_16_2/packets/BlockItemPackets1_16_2.java @@ -21,14 +21,12 @@ import com.viaversion.viabackwards.api.rewriters.TranslatableRewriter; import com.viaversion.viabackwards.protocol.protocol1_16_1to1_16_2.Protocol1_16_1To1_16_2; import com.viaversion.viaversion.api.minecraft.BlockChangeRecord; import com.viaversion.viaversion.api.minecraft.BlockChangeRecord1_8; -import com.viaversion.viaversion.api.minecraft.Position; import com.viaversion.viaversion.api.minecraft.chunks.Chunk; import com.viaversion.viaversion.api.minecraft.chunks.ChunkSection; import com.viaversion.viaversion.api.protocol.remapper.PacketRemapper; import com.viaversion.viaversion.api.type.Type; import com.viaversion.viaversion.libs.opennbt.tag.builtin.CompoundTag; import com.viaversion.viaversion.libs.opennbt.tag.builtin.IntArrayTag; -import com.viaversion.viaversion.libs.opennbt.tag.builtin.IntTag; import com.viaversion.viaversion.libs.opennbt.tag.builtin.ListTag; import com.viaversion.viaversion.libs.opennbt.tag.builtin.StringTag; import com.viaversion.viaversion.libs.opennbt.tag.builtin.Tag; @@ -98,13 +96,8 @@ public class BlockItemPackets1_16_2 extends com.viaversion.viabackwards.api.rewr } for (CompoundTag blockEntity : chunk.getBlockEntities()) { - if (blockEntity == null) continue; - - IntTag x = blockEntity.get("x"); - IntTag y = blockEntity.get("y"); - IntTag z = blockEntity.get("z"); - if (x != null && y != null && z != null) { - handleBlockEntity(blockEntity, new Position(x.asInt(), y.asShort(), z.asInt())); + if (blockEntity != null) { + handleBlockEntity(blockEntity); } } }); @@ -114,10 +107,10 @@ public class BlockItemPackets1_16_2 extends com.viaversion.viabackwards.api.rewr protocol.registerClientbound(ClientboundPackets1_16_2.BLOCK_ENTITY_DATA, new PacketRemapper() { @Override public void registerMap() { + map(Type.POSITION1_14); + map(Type.UNSIGNED_BYTE); handler(wrapper -> { - Position position = wrapper.passthrough(Type.POSITION1_14); - wrapper.passthrough(Type.UNSIGNED_BYTE); - handleBlockEntity(wrapper.passthrough(Type.NBT), position); + handleBlockEntity(wrapper.passthrough(Type.NBT)); }); } }); @@ -161,7 +154,7 @@ public class BlockItemPackets1_16_2 extends com.viaversion.viabackwards.api.rewr }); } - private void handleBlockEntity(CompoundTag tag, Position position) { + private void handleBlockEntity(CompoundTag tag) { StringTag idTag = tag.get("id"); if (idTag == null) return; if (idTag.getValue().equals("minecraft:skull")) { diff --git a/common/src/main/java/com/viaversion/viabackwards/protocol/protocol1_17_1to1_18/packets/BlockItemPackets1_18.java b/common/src/main/java/com/viaversion/viabackwards/protocol/protocol1_17_1to1_18/packets/BlockItemPackets1_18.java index 3a89c90f..35a7ca1d 100644 --- a/common/src/main/java/com/viaversion/viabackwards/protocol/protocol1_17_1to1_18/packets/BlockItemPackets1_18.java +++ b/common/src/main/java/com/viaversion/viabackwards/protocol/protocol1_17_1to1_18/packets/BlockItemPackets1_18.java @@ -89,6 +89,13 @@ public final class BlockItemPackets1_18 extends ItemRewriter { final int id = wrapper.read(Type.VAR_INT); + final CompoundTag tag = wrapper.read(Type.NBT); + if (tag == null) { + // Cancel nbt-less updates (screw open commandblocks) + wrapper.cancel(); + return; + } + final int mappedId = BlockEntityIds.mappedId(id); if (mappedId == -1) { wrapper.cancel(); @@ -131,13 +138,13 @@ public final class BlockItemPackets1_18 extends ItemRewriter blockEntityTags = new ArrayList<>(oldChunk.blockEntities().size()); for (final BlockEntity blockEntity : oldChunk.blockEntities()) { - final CompoundTag tag = blockEntity.tag() != null ? blockEntity.tag() : new CompoundTag(); final String id = protocol.getMappingData().blockEntities().get(blockEntity.typeId()); if (id == null) { // Shrug continue; } + final CompoundTag tag = blockEntity.tag() != null ? blockEntity.tag() : new CompoundTag(); blockEntityTags.add(tag); tag.put("x", new IntTag((oldChunk.getX() << 4) + blockEntity.sectionX())); tag.put("y", new IntTag(blockEntity.y()));