use of thpmc.vanilla_source.util.SectionTypeArray in project VanillaSource by TheHollowPlanetMC.
the class PacketManager method sendChunkMultiBlockChangeUpdatePacket.
public static void sendChunkMultiBlockChangeUpdatePacket(Player player, ParallelChunk parallelChunk, NMSHandler nmsHandler) {
PacketPlayOutMultiBlockChange packet = new PacketPlayOutMultiBlockChange();
List<PacketPlayOutMultiBlockChange.MultiBlockChangeInfo> infoList = new ArrayList<>();
boolean has = false;
for (int sectionIndex = 0; sectionIndex < 16; sectionIndex++) {
SectionTypeArray sectionTypeArray = parallelChunk.getSectionTypeArray(sectionIndex);
if (sectionTypeArray == null)
continue;
int finalSectionIndex = sectionIndex;
boolean notEmpty = sectionTypeArray.threadsafeIteration((x, y, z, iBlockData) -> {
short loc = (short) (x << 12 | z << 8 | (y + (finalSectionIndex << 4)));
infoList.add(packet.new MultiBlockChangeInfo(loc, (IBlockData) iBlockData));
});
if (notEmpty)
has = true;
}
if (!has)
return;
if (infoList.size() == 0)
return;
PacketPlayOutMultiBlockChange.MultiBlockChangeInfo[] array = infoList.toArray(new PacketPlayOutMultiBlockChange.MultiBlockChangeInfo[infoList.size()]);
try {
MultiBlockChangePacketHandler.a.set(packet, new ChunkCoordIntPair(parallelChunk.getChunkX(), parallelChunk.getChunkZ()));
MultiBlockChangePacketHandler.b.set(packet, array);
nmsHandler.sendPacket(player, packet);
} catch (Exception e) {
e.printStackTrace();
}
}
use of thpmc.vanilla_source.util.SectionTypeArray in project VanillaSource by TheHollowPlanetMC.
the class PacketManager method sendClearChunkMultiBlockChangePacketAtPrimaryThread.
public static void sendClearChunkMultiBlockChangePacketAtPrimaryThread(Player player, ParallelChunk parallelChunk, NMSHandler nmsHandler) {
if (!Bukkit.isPrimaryThread())
throw new IllegalStateException("DO NOT CALL FROM ASYNC THREAD!");
org.bukkit.World world = Bukkit.getWorld(parallelChunk.getWorld().getName());
if (world == null)
return;
if (player.getWorld() != world)
return;
List<Short> coordList = new ArrayList<>();
boolean has = false;
for (int sectionIndex = 0; sectionIndex < 16; sectionIndex++) {
SectionTypeArray sectionTypeArray = parallelChunk.getSectionTypeArray(sectionIndex);
if (sectionTypeArray == null)
continue;
int finalSectionIndex = sectionIndex;
boolean notEmpty = sectionTypeArray.threadsafeIteration((x, y, z, iBlockData) -> {
short loc = (short) (x << 12 | z << 8 | (y + (finalSectionIndex << 4)));
coordList.add(loc);
});
if (notEmpty)
has = true;
}
if (!has)
return;
if (coordList.size() == 0)
return;
org.bukkit.Chunk chunk = world.getChunkAt(parallelChunk.getChunkX(), parallelChunk.getChunkZ());
net.minecraft.server.v1_15_R1.Chunk nmsChunk = ((CraftChunk) chunk).getHandle();
short[] array = new short[coordList.size()];
for (int i = 0; i < coordList.size(); i++) {
array[i] = coordList.get(i);
}
PacketPlayOutMultiBlockChange packet = new PacketPlayOutMultiBlockChange(coordList.size(), array, nmsChunk);
nmsHandler.sendPacket(player, packet);
}
use of thpmc.vanilla_source.util.SectionTypeArray in project VanillaSource by TheHollowPlanetMC.
the class ImplParallelChunk method createSectionTypeArrayIfAbsent.
public SectionTypeArray createSectionTypeArrayIfAbsent(int sectionY) {
int sectionIndex = ChunkUtil.getSectionIndex(sectionY << 4);
SectionTypeArray sectionTypeArray = sectionTypeArrays[sectionIndex];
if (sectionTypeArray == null) {
sectionTypeArray = new SectionTypeArray();
sectionTypeArrays[sectionIndex] = sectionTypeArray;
}
return sectionTypeArray;
}
use of thpmc.vanilla_source.util.SectionTypeArray in project VanillaSource by TheHollowPlanetMC.
the class ImplParallelChunk method removeBlockData.
@Override
public void removeBlockData(int blockX, int blockY, int blockZ) {
int sectionIndex = ChunkUtil.getSectionIndex(blockY);
SectionTypeArray sectionTypeArray = sectionTypeArrays[sectionIndex];
if (sectionTypeArray == null)
return;
sectionTypeArray.remove(blockX & 0xF, blockY & 0xF, blockZ & 0xF);
mapChunkPacketCache = null;
}
use of thpmc.vanilla_source.util.SectionTypeArray in project VanillaSource by TheHollowPlanetMC.
the class ImplParallelChunk method getNMSBlockData.
@Override
@Nullable
public Object getNMSBlockData(int blockX, int blockY, int blockZ) {
int sectionIndex = ChunkUtil.getSectionIndex(blockY);
SectionTypeArray sectionTypeArray = sectionTypeArrays[sectionIndex];
if (sectionTypeArray == null)
return null;
return sectionTypeArray.getType(blockX & 0xF, blockY & 0xF, blockZ & 0xF);
}
Aggregations