Search in sources :

Example 6 with ChunkCoordinate

use of com.denizenscript.denizen.utilities.blocks.ChunkCoordinate in project Denizen-For-Bukkit by DenizenScript.

the class BlockLightImpl method checkIfLightsBrokenByPacket.

public static void checkIfLightsBrokenByPacket(ClientboundLightUpdatePacket packet, Level world) {
    if (doNotCheck) {
        return;
    }
    try {
        int cX = packet.getX();
        int cZ = packet.getZ();
        BitSet bitMask = packet.getBlockYMask();
        List<byte[]> blockData = packet.getBlockUpdates();
        Bukkit.getScheduler().scheduleSyncDelayedTask(NMSHandler.getJavaPlugin(), () -> {
            ChunkAccess chk = world.getChunk(cX, cZ, ChunkStatus.FULL, false);
            if (!(chk instanceof LevelChunk)) {
                return;
            }
            List<BlockLight> lights = lightsByChunk.get(new ChunkCoordinate(((LevelChunk) chk).bukkitChunk));
            if (lights == null) {
                return;
            }
            boolean any = false;
            for (BlockLight light : lights) {
                if (((BlockLightImpl) light).checkIfChangedBy(bitMask, blockData)) {
                    Bukkit.getScheduler().scheduleSyncDelayedTask(NMSHandler.getJavaPlugin(), () -> light.update(light.intendedLevel, false), 1);
                    any = true;
                }
            }
            if (any) {
                Bukkit.getScheduler().scheduleSyncDelayedTask(NMSHandler.getJavaPlugin(), () -> sendNearbyChunkUpdates((LevelChunk) chk), 3);
            }
        }, 1);
    } catch (Exception ex) {
        Debug.echoError(ex);
    }
}
Also used : ChunkAccess(net.minecraft.world.level.chunk.ChunkAccess) LevelChunk(net.minecraft.world.level.chunk.LevelChunk) ChunkCoordinate(com.denizenscript.denizen.utilities.blocks.ChunkCoordinate) BitSet(java.util.BitSet) BlockLight(com.denizenscript.denizen.nms.abstracts.BlockLight)

Example 7 with ChunkCoordinate

use of com.denizenscript.denizen.utilities.blocks.ChunkCoordinate in project Denizen-For-Bukkit by DenizenScript.

the class BlockLightImpl method checkIfLightsBrokenByPacket.

public static void checkIfLightsBrokenByPacket(ClientboundLightUpdatePacket packet, Level world) {
    if (doNotCheck) {
        return;
    }
    try {
        int cX = packet.getX();
        int cZ = packet.getZ();
        BitSet bitMask = packet.getLightData().getBlockYMask();
        List<byte[]> blockData = packet.getLightData().getBlockUpdates();
        Bukkit.getScheduler().scheduleSyncDelayedTask(NMSHandler.getJavaPlugin(), () -> {
            ChunkAccess chk = world.getChunk(cX, cZ, ChunkStatus.FULL, false);
            if (!(chk instanceof LevelChunk)) {
                return;
            }
            List<BlockLight> lights = lightsByChunk.get(new ChunkCoordinate(((LevelChunk) chk).bukkitChunk));
            if (lights == null) {
                return;
            }
            boolean any = false;
            for (BlockLight light : lights) {
                if (((BlockLightImpl) light).checkIfChangedBy(bitMask, blockData)) {
                    Bukkit.getScheduler().scheduleSyncDelayedTask(NMSHandler.getJavaPlugin(), () -> light.update(light.intendedLevel, false), 1);
                    any = true;
                }
            }
            if (any) {
                Bukkit.getScheduler().scheduleSyncDelayedTask(NMSHandler.getJavaPlugin(), () -> sendNearbyChunkUpdates((LevelChunk) chk), 3);
            }
        }, 1);
    } catch (Exception ex) {
        Debug.echoError(ex);
    }
}
Also used : ChunkAccess(net.minecraft.world.level.chunk.ChunkAccess) LevelChunk(net.minecraft.world.level.chunk.LevelChunk) ChunkCoordinate(com.denizenscript.denizen.utilities.blocks.ChunkCoordinate) BitSet(java.util.BitSet) BlockLight(com.denizenscript.denizen.nms.abstracts.BlockLight)

Example 8 with ChunkCoordinate

use of com.denizenscript.denizen.utilities.blocks.ChunkCoordinate in project Denizen-For-Bukkit by DenizenScript.

the class BlockLightImpl method checkIfLightsBrokenByPacket.

public static void checkIfLightsBrokenByPacket(PacketPlayOutBlockChange packet, World world) {
    try {
        BlockPosition pos = (BlockPosition) PACKETPLAYOUTBLOCKCHANGE_POSITION.get(packet);
        int chunkX = pos.getX() >> 4;
        int chunkZ = pos.getZ() >> 4;
        Bukkit.getScheduler().scheduleSyncDelayedTask(NMSHandler.getJavaPlugin(), () -> {
            Chunk chunk = world.getChunkAt(chunkX, chunkZ);
            boolean any = false;
            for (Vector vec : RELATIVE_CHUNKS) {
                IChunkAccess other = world.getChunkAt(chunkX + vec.getBlockX(), chunkZ + vec.getBlockZ(), ChunkStatus.FULL, false);
                if (other instanceof Chunk) {
                    List<BlockLight> lights = lightsByChunk.get(new ChunkCoordinate(((Chunk) other).bukkitChunk));
                    if (lights != null) {
                        any = true;
                        for (BlockLight light : lights) {
                            Bukkit.getScheduler().scheduleSyncDelayedTask(NMSHandler.getJavaPlugin(), () -> light.update(light.intendedLevel, false), 1);
                        }
                    }
                }
            }
            if (any) {
                Bukkit.getScheduler().scheduleSyncDelayedTask(NMSHandler.getJavaPlugin(), () -> sendNearbyChunkUpdates(chunk), 3);
            }
        }, 1);
    } catch (Exception ex) {
        Debug.echoError(ex);
    }
}
Also used : ChunkCoordinate(com.denizenscript.denizen.utilities.blocks.ChunkCoordinate) BlockLight(com.denizenscript.denizen.nms.abstracts.BlockLight) CraftChunk(org.bukkit.craftbukkit.v1_16_R3.CraftChunk) Vector(org.bukkit.util.Vector)

Example 9 with ChunkCoordinate

use of com.denizenscript.denizen.utilities.blocks.ChunkCoordinate in project Denizen-For-Bukkit by DenizenScript.

the class DenizenNetworkManagerImpl method processShowFakeForPacket.

public boolean processShowFakeForPacket(Packet<?> packet, GenericFutureListener<? extends Future<? super Void>> genericfuturelistener) {
    if (FakeBlock.blocks.isEmpty()) {
        return false;
    }
    try {
        if (packet instanceof ClientboundLevelChunkWithLightPacket) {
            FakeBlock.FakeBlockMap map = FakeBlock.blocks.get(player.getUUID());
            if (map == null) {
                return false;
            }
            int chunkX = ((ClientboundLevelChunkWithLightPacket) packet).getX();
            int chunkZ = ((ClientboundLevelChunkWithLightPacket) packet).getZ();
            ChunkCoordinate chunkCoord = new ChunkCoordinate(chunkX, chunkZ, player.getLevel().getWorld().getName());
            List<FakeBlock> blocks = FakeBlock.getFakeBlocksFor(player.getUUID(), chunkCoord);
            if (blocks == null || blocks.isEmpty()) {
                return false;
            }
            ClientboundLevelChunkWithLightPacket newPacket = FakeBlockHelper.handleMapChunkPacket(player.getBukkitEntity().getWorld(), (ClientboundLevelChunkWithLightPacket) packet, chunkX, chunkZ, blocks);
            oldManager.send(newPacket, genericfuturelistener);
            return true;
        } else if (packet instanceof ClientboundSectionBlocksUpdatePacket) {
            FakeBlock.FakeBlockMap map = FakeBlock.blocks.get(player.getUUID());
            if (map == null) {
                return false;
            }
            SectionPos coord = (SectionPos) SECTIONPOS_MULTIBLOCKCHANGE.get(packet);
            ChunkCoordinate coordinateDenizen = new ChunkCoordinate(coord.getX(), coord.getZ(), player.getLevel().getWorld().getName());
            if (!map.byChunk.containsKey(coordinateDenizen)) {
                return false;
            }
            ClientboundSectionBlocksUpdatePacket newPacket = new ClientboundSectionBlocksUpdatePacket(copyPacket(packet));
            LocationTag location = new LocationTag(player.getLevel().getWorld(), 0, 0, 0);
            short[] originalOffsetArray = (short[]) OFFSETARRAY_MULTIBLOCKCHANGE.get(newPacket);
            BlockState[] originalDataArray = (BlockState[]) BLOCKARRAY_MULTIBLOCKCHANGE.get(newPacket);
            short[] offsetArray = Arrays.copyOf(originalOffsetArray, originalOffsetArray.length);
            BlockState[] dataArray = Arrays.copyOf(originalDataArray, originalDataArray.length);
            OFFSETARRAY_MULTIBLOCKCHANGE.set(newPacket, offsetArray);
            BLOCKARRAY_MULTIBLOCKCHANGE.set(newPacket, dataArray);
            for (int i = 0; i < offsetArray.length; i++) {
                short offset = offsetArray[i];
                BlockPos pos = coord.relativeToBlockPos(offset);
                location.setX(pos.getX());
                location.setY(pos.getY());
                location.setZ(pos.getZ());
                FakeBlock block = map.byLocation.get(location);
                if (block != null) {
                    dataArray[i] = FakeBlockHelper.getNMSState(block);
                }
            }
            oldManager.send(newPacket, genericfuturelistener);
            return true;
        } else if (packet instanceof ClientboundBlockUpdatePacket) {
            BlockPos pos = ((ClientboundBlockUpdatePacket) packet).getPos();
            LocationTag loc = new LocationTag(player.getLevel().getWorld(), pos.getX(), pos.getY(), pos.getZ());
            FakeBlock block = FakeBlock.getFakeBlockFor(player.getUUID(), loc);
            if (block != null) {
                ClientboundBlockUpdatePacket newPacket = new ClientboundBlockUpdatePacket(((ClientboundBlockUpdatePacket) packet).getPos(), FakeBlockHelper.getNMSState(block));
                oldManager.send(newPacket, genericfuturelistener);
                return true;
            }
        } else if (packet instanceof ClientboundBlockBreakAckPacket) {
            ClientboundBlockBreakAckPacket origPack = (ClientboundBlockBreakAckPacket) packet;
            BlockPos pos = origPack.pos();
            LocationTag loc = new LocationTag(player.getLevel().getWorld(), pos.getX(), pos.getY(), pos.getZ());
            FakeBlock block = FakeBlock.getFakeBlockFor(player.getUUID(), loc);
            if (block != null) {
                ClientboundBlockBreakAckPacket newPacket = new ClientboundBlockBreakAckPacket(origPack.pos(), FakeBlockHelper.getNMSState(block), origPack.action(), false);
                oldManager.send(newPacket, genericfuturelistener);
                return true;
            }
        }
    } catch (Throwable ex) {
        Debug.echoError(ex);
    }
    return false;
}
Also used : ChunkCoordinate(com.denizenscript.denizen.utilities.blocks.ChunkCoordinate) FakeBlock(com.denizenscript.denizen.utilities.blocks.FakeBlock) LocationTag(com.denizenscript.denizen.objects.LocationTag) BlockState(net.minecraft.world.level.block.state.BlockState) BlockPos(net.minecraft.core.BlockPos) SectionPos(net.minecraft.core.SectionPos)

Example 10 with ChunkCoordinate

use of com.denizenscript.denizen.utilities.blocks.ChunkCoordinate in project Denizen-For-Bukkit by DenizenScript.

the class BlockLightImpl method checkIfLightsBrokenByPacket.

public static void checkIfLightsBrokenByPacket(ClientboundBlockUpdatePacket packet, Level world) {
    try {
        BlockPos pos = packet.getPos();
        int chunkX = pos.getX() >> 4;
        int chunkZ = pos.getZ() >> 4;
        Bukkit.getScheduler().scheduleSyncDelayedTask(NMSHandler.getJavaPlugin(), () -> {
            LevelChunk chunk = world.getChunk(chunkX, chunkZ);
            boolean any = false;
            for (Vector vec : RELATIVE_CHUNKS) {
                ChunkAccess other = world.getChunk(chunkX + vec.getBlockX(), chunkZ + vec.getBlockZ(), ChunkStatus.FULL, false);
                if (other instanceof LevelChunk) {
                    List<BlockLight> lights = lightsByChunk.get(new ChunkCoordinate(((LevelChunk) other).bukkitChunk));
                    if (lights != null) {
                        any = true;
                        for (BlockLight light : lights) {
                            Bukkit.getScheduler().scheduleSyncDelayedTask(NMSHandler.getJavaPlugin(), () -> light.update(light.intendedLevel, false), 1);
                        }
                    }
                }
            }
            if (any) {
                Bukkit.getScheduler().scheduleSyncDelayedTask(NMSHandler.getJavaPlugin(), () -> sendNearbyChunkUpdates(chunk), 3);
            }
        }, 1);
    } catch (Exception ex) {
        Debug.echoError(ex);
    }
}
Also used : ChunkAccess(net.minecraft.world.level.chunk.ChunkAccess) LevelChunk(net.minecraft.world.level.chunk.LevelChunk) ChunkCoordinate(com.denizenscript.denizen.utilities.blocks.ChunkCoordinate) BlockLight(com.denizenscript.denizen.nms.abstracts.BlockLight) BlockPos(net.minecraft.core.BlockPos) Vector(org.bukkit.util.Vector)

Aggregations

ChunkCoordinate (com.denizenscript.denizen.utilities.blocks.ChunkCoordinate)10 BlockLight (com.denizenscript.denizen.nms.abstracts.BlockLight)6 BlockPos (net.minecraft.core.BlockPos)4 ChunkAccess (net.minecraft.world.level.chunk.ChunkAccess)4 LevelChunk (net.minecraft.world.level.chunk.LevelChunk)4 LocationTag (com.denizenscript.denizen.objects.LocationTag)3 FakeBlock (com.denizenscript.denizen.utilities.blocks.FakeBlock)3 Vector (org.bukkit.util.Vector)3 BitSet (java.util.BitSet)2 SectionPos (net.minecraft.core.SectionPos)2 BlockState (net.minecraft.world.level.block.state.BlockState)2 CraftChunk (org.bukkit.craftbukkit.v1_16_R3.CraftChunk)2 DurationTag (com.denizenscript.denizencore.objects.core.DurationTag)1 ElementTag (com.denizenscript.denizencore.objects.core.ElementTag)1 ListTag (com.denizenscript.denizencore.objects.core.ListTag)1 IOException (java.io.IOException)1 ArrayList (java.util.ArrayList)1 List (java.util.List)1 Chunk (org.bukkit.Chunk)1