Small ConnectionData cleanup

This commit is contained in:
Nassim Jahnke 2023-03-08 15:13:29 +01:00
parent d8a9480bf1
commit d180c8fe2f
No known key found for this signature in database
GPG Key ID: 6BE3B555EBC5982B
2 changed files with 21 additions and 11 deletions

View File

@ -58,22 +58,24 @@ public final class ConnectionData {
static Int2ObjectMap<BlockData> 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<BlockChangeRecord1_8> 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));
}
}
}
}

View File

@ -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);
}
}