From d180c8fe2f66a7f174c0054b6166f814f8c0da4b Mon Sep 17 00:00:00 2001 From: Nassim Jahnke Date: Wed, 8 Mar 2023 15:13:29 +0100 Subject: [PATCH] Small ConnectionData cleanup --- .../blockconnections/ConnectionData.java | 24 ++++++++++++------- .../packets/WorldPackets.java | 8 +++++-- 2 files changed, 21 insertions(+), 11 deletions(-) diff --git a/common/src/main/java/com/viaversion/viaversion/protocols/protocol1_13to1_12_2/blockconnections/ConnectionData.java b/common/src/main/java/com/viaversion/viaversion/protocols/protocol1_13to1_12_2/blockconnections/ConnectionData.java index 5e24f1dfe..8a7f33720 100644 --- a/common/src/main/java/com/viaversion/viaversion/protocols/protocol1_13to1_12_2/blockconnections/ConnectionData.java +++ b/common/src/main/java/com/viaversion/viaversion/protocols/protocol1_13to1_12_2/blockconnections/ConnectionData.java @@ -58,22 +58,24 @@ public final class ConnectionData { static Int2ObjectMap blockConnectionData = new Int2ObjectOpenHashMap<>(1); static IntSet occludingStates = new IntOpenHashSet(377, .99F); - public static void update(UserConnection user, Position position) { + public static void update(UserConnection user, Position position) throws Exception { for (BlockFace face : BlockFace.values()) { Position pos = position.getRelative(face); int blockState = blockConnectionProvider.getBlockData(user, pos.x(), pos.y(), pos.z()); ConnectionHandler handler = connectionHandlerMap.get(blockState); - if (handler == null) continue; + if (handler == null) { + continue; + } int newBlockState = handler.connect(user, pos, blockState); + if (newBlockState == blockState) { + continue; + } + PacketWrapper blockUpdatePacket = PacketWrapper.create(ClientboundPackets1_13.BLOCK_CHANGE, null, user); blockUpdatePacket.write(Type.POSITION, pos); blockUpdatePacket.write(Type.VAR_INT, newBlockState); - try { - blockUpdatePacket.send(Protocol1_13To1_12_2.class); - } catch (Exception ex) { - ex.printStackTrace(); - } + blockUpdatePacket.send(Protocol1_13To1_12_2.class); } } @@ -693,11 +695,15 @@ public final class ConnectionData { private void updateBlock(int x, int y, int z, List records) { int blockState = userBlockData.getBlockData(x, y, z); ConnectionHandler handler = getConnectionHandler(blockState); - if (handler == null) return; + if (handler == null) { + return; + } Position pos = new Position(x, y, z); int newBlockState = handler.connect(user, pos, blockState); - records.add(new BlockChangeRecord1_8(pos.x() & 0xF, pos.y(), pos.z() & 0xF, newBlockState)); + if (blockState != newBlockState) { + records.add(new BlockChangeRecord1_8(x & 0xF, y, z & 0xF, newBlockState)); + } } } } 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 9398f6253..43fc0ce6d 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 @@ -34,6 +34,7 @@ import com.viaversion.viaversion.api.protocol.remapper.PacketHandlers; import com.viaversion.viaversion.api.type.Type; import com.viaversion.viaversion.api.type.types.Particle; import com.viaversion.viaversion.protocols.protocol1_12_1to1_12.ClientboundPackets1_12_1; +import com.viaversion.viaversion.protocols.protocol1_13to1_12_2.ClientboundPackets1_13; import com.viaversion.viaversion.protocols.protocol1_13to1_12_2.Protocol1_13To1_12_2; import com.viaversion.viaversion.protocols.protocol1_13to1_12_2.blockconnections.ConnectionData; import com.viaversion.viaversion.protocols.protocol1_13to1_12_2.blockconnections.ConnectionHandler; @@ -161,7 +162,7 @@ public class WorldPackets { blockId = blockId - 219 + 483; if (blockId == 73) { // Note block - PacketWrapper blockChange = wrapper.create(0x0B); // block change + PacketWrapper blockChange = wrapper.create(ClientboundPackets1_13.BLOCK_CHANGE); blockChange.write(Type.POSITION, pos); blockChange.write(Type.VAR_INT, 249 + (action * 24 * 2) + (param * 2)); blockChange.send(Protocol1_13To1_12_2.class); @@ -451,7 +452,10 @@ public class WorldPackets { ConnectionData.NeighbourUpdater updater = new ConnectionData.NeighbourUpdater(wrapper.user()); for (int i = 0; i < chunk.getSections().length; i++) { ChunkSection section = chunk.getSections()[i]; - if (section == null) continue; + if (section == null) { + continue; + } + updater.updateChunkSectionNeighbours(chunk.getX(), chunk.getZ(), i); } }