use of thpmc.vanilla_source.util.ChunkPosition in project VanillaSource by TheHollowPlanetMC.
the class PacketManager method createMultiBlockChangePacket.
public static Set<Object> createMultiBlockChangePacket(ParallelWorld parallelWorld, Set<BlockPosition3i> blocks) {
Map<ChunkPosition, Set<BlockPosition3i>> chunkMap = new HashMap<>();
for (BlockPosition3i bp : blocks) {
chunkMap.computeIfAbsent(new ChunkPosition(bp.getX(), bp.getZ()), cp -> new HashSet<>()).add(bp);
}
Set<Object> packets = new HashSet<>();
for (Map.Entry<ChunkPosition, Set<BlockPosition3i>> entry : chunkMap.entrySet()) {
ChunkPosition chunkPosition = entry.getKey();
Set<BlockPosition3i> bps = entry.getValue();
ParallelChunk parallelChunk = parallelWorld.getChunk(chunkPosition.x, chunkPosition.z);
if (parallelChunk == null)
continue;
PacketPlayOutMultiBlockChange packet = new PacketPlayOutMultiBlockChange();
List<PacketPlayOutMultiBlockChange.MultiBlockChangeInfo> infoList = new ArrayList<>();
for (BlockPosition3i bp : bps) {
BlockData blockData = parallelChunk.getBlockData(bp.getX(), bp.getY(), bp.getZ());
if (blockData == null)
continue;
short loc = (short) ((bp.getX() & 0xF) << 12 | (bp.getZ() & 0xF) << 8 | bp.getY());
infoList.add(packet.new MultiBlockChangeInfo(loc, ((CraftBlockData) blockData).getState()));
}
PacketPlayOutMultiBlockChange.MultiBlockChangeInfo[] array = infoList.toArray(new PacketPlayOutMultiBlockChange.MultiBlockChangeInfo[infoList.size()]);
try {
MultiBlockChangePacketHandler.a.set(packet, new ChunkCoordIntPair(chunkPosition.x, chunkPosition.z));
MultiBlockChangePacketHandler.b.set(packet, array);
packets.add(packet);
} catch (Exception e) {
e.printStackTrace();
}
}
return packets;
}
Aggregations