Search in sources :

Example 1 with SectionTypeArray

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();
    }
}
Also used : SectionTypeArray(thpmc.vanilla_source.util.SectionTypeArray)

Example 2 with SectionTypeArray

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);
}
Also used : SectionTypeArray(thpmc.vanilla_source.util.SectionTypeArray) net.minecraft.server.v1_15_R1(net.minecraft.server.v1_15_R1) CraftChunk(org.bukkit.craftbukkit.v1_15_R1.CraftChunk)

Example 3 with SectionTypeArray

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;
}
Also used : SectionTypeArray(thpmc.vanilla_source.util.SectionTypeArray)

Example 4 with 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;
}
Also used : SectionTypeArray(thpmc.vanilla_source.util.SectionTypeArray)

Example 5 with SectionTypeArray

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);
}
Also used : SectionTypeArray(thpmc.vanilla_source.util.SectionTypeArray) Nullable(org.jetbrains.annotations.Nullable)

Aggregations

SectionTypeArray (thpmc.vanilla_source.util.SectionTypeArray)18 ParallelChunk (thpmc.vanilla_source.api.world.parallel.ParallelChunk)5 ParallelWorld (thpmc.vanilla_source.api.world.parallel.ParallelWorld)5 Nullable (org.jetbrains.annotations.Nullable)4 ParallelUniverse (thpmc.vanilla_source.api.world.parallel.ParallelUniverse)3 List (java.util.List)2 net.minecraft.server.v1_16_R3 (net.minecraft.server.v1_16_R3)2 ChunkSnapshot (org.bukkit.ChunkSnapshot)2 World (org.bukkit.World)2 CraftChunk (org.bukkit.craftbukkit.v1_16_R3.CraftChunk)2 CraftWorld (org.bukkit.craftbukkit.v1_16_R3.CraftWorld)2 CraftBlockData (org.bukkit.craftbukkit.v1_16_R3.block.data.CraftBlockData)2 SectionLevelArray (thpmc.vanilla_source.util.SectionLevelArray)2 java.util (java.util)1 net.minecraft.server.v1_15_R1 (net.minecraft.server.v1_15_R1)1 IBlockData (net.minecraft.server.v1_16_R3.IBlockData)1 PacketPlayOutMultiBlockChange (net.minecraft.server.v1_16_R3.PacketPlayOutMultiBlockChange)1 SectionPosition (net.minecraft.server.v1_16_R3.SectionPosition)1 Bukkit (org.bukkit.Bukkit)1 BlockData (org.bukkit.block.data.BlockData)1