From 54724ac54097cf305ed058e70688e4cfd415f821 Mon Sep 17 00:00:00 2001 From: Nassim Jahnke Date: Wed, 1 Dec 2021 19:54:43 +0100 Subject: [PATCH] Fix 1.18 block entity warnings on <1.12 servers --- .../packets/WorldPackets.java | 19 +++++++++++++++++-- .../protocol1_18to1_17_1/BlockEntityIds.java | 1 + 2 files changed, 18 insertions(+), 2 deletions(-) diff --git a/common/src/main/java/com/viaversion/viaversion/protocols/protocol1_13to1_12_2/packets/WorldPackets.java b/common/src/main/java/com/viaversion/viaversion/protocols/protocol1_13to1_12_2/packets/WorldPackets.java index c33526eca..a4089d6e8 100644 --- a/common/src/main/java/com/viaversion/viaversion/protocols/protocol1_13to1_12_2/packets/WorldPackets.java +++ b/common/src/main/java/com/viaversion/viaversion/protocols/protocol1_13to1_12_2/packets/WorldPackets.java @@ -19,6 +19,8 @@ package com.viaversion.viaversion.protocols.protocol1_13to1_12_2.packets; import com.github.steveice10.opennbt.tag.builtin.CompoundTag; import com.github.steveice10.opennbt.tag.builtin.NumberTag; +import com.github.steveice10.opennbt.tag.builtin.StringTag; +import com.github.steveice10.opennbt.tag.builtin.Tag; import com.viaversion.viaversion.api.Via; import com.viaversion.viaversion.api.connection.UserConnection; import com.viaversion.viaversion.api.minecraft.BlockChangeRecord; @@ -46,6 +48,7 @@ import com.viaversion.viaversion.protocols.protocol1_9_3to1_9_1_2.storage.Client import it.unimi.dsi.fastutil.ints.IntOpenHashSet; import it.unimi.dsi.fastutil.ints.IntSet; +import java.util.Iterator; import java.util.List; import java.util.Optional; @@ -122,8 +125,9 @@ public class WorldPackets { } } - if (action == 5) // Set type of flower in flower pot + if (action == 5) { // Set type of flower in flower pot wrapper.cancel(); // Removed + } } }); } @@ -442,7 +446,9 @@ public class WorldPackets { // Rewrite BlockEntities to normal blocks BlockEntityProvider provider = Via.getManager().getProviders().get(BlockEntityProvider.class); - for (CompoundTag tag : chunk.getBlockEntities()) { + final Iterator iterator = chunk.getBlockEntities().iterator(); + while (iterator.hasNext()) { + CompoundTag tag = iterator.next(); int newId = provider.transform(wrapper.user(), null, tag, false); if (newId != -1) { int x = ((NumberTag) tag.get("x")).asInt(); @@ -458,6 +464,15 @@ public class WorldPackets { chunk.getSections()[y >> 4].setFlatBlock(x & 0xF, y & 0xF, z & 0xF, newId); } + + final Tag idTag = tag.get("id"); + if (idTag instanceof StringTag) { + // No longer block entities + final String id = ((StringTag) idTag).getValue(); + if (id.equals("minecraft:noteblock") || id.equals("minecraft:flower_pot")) { + iterator.remove(); + } + } } if (Via.getConfig().isServersideBlockConnections()) { diff --git a/common/src/main/java/com/viaversion/viaversion/protocols/protocol1_18to1_17_1/BlockEntityIds.java b/common/src/main/java/com/viaversion/viaversion/protocols/protocol1_18to1_17_1/BlockEntityIds.java index 83e53c2eb..ee3dc2bbe 100644 --- a/common/src/main/java/com/viaversion/viaversion/protocols/protocol1_18to1_17_1/BlockEntityIds.java +++ b/common/src/main/java/com/viaversion/viaversion/protocols/protocol1_18to1_17_1/BlockEntityIds.java @@ -37,6 +37,7 @@ public final class BlockEntityIds { IDS[7] = 19; // Structure block IDS[8] = 20; // End gateway IDS[9] = 7; // Sign + IDS[10] = 22; // Shulker box IDS[11] = 23; // Bed IDS[12] = 30; // Jigsaw IDS[13] = 31; // Campfire