use of thpmc.vanilla_source.api.world.parallel.ParallelWorld in project VanillaSource by TheHollowPlanetMC.
the class PacketManager method createMultiBlockChangePacket.
public static Set<Object> createMultiBlockChangePacket(ParallelWorld parallelWorld, Set<BlockPosition3i> blocks) {
Map<BlockPosition3i, Set<BlockPosition3i>> chunkMap = new HashMap<>();
for (BlockPosition3i bp : blocks) {
chunkMap.computeIfAbsent(new BlockPosition3i(bp.getX() >> 4, bp.getY() >> 4, bp.getZ() >> 4), cp -> new HashSet<>()).add(bp);
}
Set<Object> packets = new HashSet<>();
for (Map.Entry<BlockPosition3i, Set<BlockPosition3i>> entry : chunkMap.entrySet()) {
BlockPosition3i sectionPosition = entry.getKey();
Set<BlockPosition3i> bps = entry.getValue();
ParallelChunk parallelChunk = parallelWorld.getChunk(sectionPosition.getX(), sectionPosition.getZ());
if (parallelChunk == null)
continue;
SectionTypeArray sectionTypeArray = parallelChunk.getSectionTypeArray(sectionPosition.getY());
if (sectionTypeArray == null)
continue;
List<Short> coordList = new ArrayList<>();
List<IBlockData> dataList = new ArrayList<>();
for (BlockPosition3i bp : bps) {
IBlockData iBlockData = (IBlockData) sectionTypeArray.getType(bp.getX() & 0xF, bp.getY() & 0xF, bp.getZ() & 0xF);
if (iBlockData == null)
continue;
coordList.add((short) ((bp.getX() & 0xF) << 8 | (bp.getZ() & 0xF) << 4 | bp.getY() & 0xF));
dataList.add(iBlockData);
}
short[] coordArray = new short[coordList.size()];
IBlockData[] dataArray = new IBlockData[dataList.size()];
for (int i = 0; i < coordList.size(); i++) {
coordArray[i] = coordList.get(i);
dataArray[i] = dataList.get(i);
}
try {
PacketPlayOutMultiBlockChange packet = new PacketPlayOutMultiBlockChange();
MultiBlockChangePacketHandler.a.set(packet, SectionPosition.a(sectionPosition.getX(), sectionPosition.getY(), sectionPosition.getZ()));
MultiBlockChangePacketHandler.b.set(packet, coordArray);
MultiBlockChangePacketHandler.c.set(packet, dataArray);
MultiBlockChangePacketHandler.d.setBoolean(packet, true);
packets.add(packet);
} catch (Exception e) {
e.printStackTrace();
}
}
return packets;
}
Aggregations