Search in sources :

Example 1 with BlockLight

use of com.denizenscript.denizen.nms.abstracts.BlockLight in project Denizen-For-Bukkit by DenizenScript.

the class BlockLightImpl method checkIfLightsBrokenByPacket.

public static void checkIfLightsBrokenByPacket(PacketPlayOutLightUpdate packet, World world) {
    if (doNotCheck) {
        return;
    }
    try {
        int cX = PACKETPLAYOUTLIGHTUPDATE_CHUNKX.getInt(packet);
        int cZ = PACKETPLAYOUTLIGHTUPDATE_CHUNKZ.getInt(packet);
        int bitMask = PACKETPLAYOUTLIGHTUPDATE_BLOCKLIGHT_BITMASK.getInt(packet);
        List<byte[]> blockData = (List<byte[]>) PACKETPLAYOUTLIGHTUPDATE_BLOCKLIGHT_DATA.get(packet);
        Bukkit.getScheduler().scheduleSyncDelayedTask(NMSHandler.getJavaPlugin(), () -> {
            IChunkAccess chk = world.getChunkAt(cX, cZ, ChunkStatus.FULL, false);
            if (!(chk instanceof Chunk)) {
                return;
            }
            List<BlockLight> lights = lightsByChunk.get(new ChunkCoordinate(((Chunk) 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((Chunk) chk), 3);
            }
        }, 1);
    } catch (Exception ex) {
        Debug.echoError(ex);
    }
}
Also used : ChunkCoordinate(com.denizenscript.denizen.utilities.blocks.ChunkCoordinate) BlockLight(com.denizenscript.denizen.nms.abstracts.BlockLight) ArrayList(java.util.ArrayList) List(java.util.List) CraftChunk(org.bukkit.craftbukkit.v1_16_R3.CraftChunk)

Example 2 with BlockLight

use of com.denizenscript.denizen.nms.abstracts.BlockLight 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.getChunkAt(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)

Example 3 with BlockLight

use of com.denizenscript.denizen.nms.abstracts.BlockLight 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 4 with BlockLight

use of com.denizenscript.denizen.nms.abstracts.BlockLight 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 5 with BlockLight

use of com.denizenscript.denizen.nms.abstracts.BlockLight in project Denizen-For-Bukkit by DenizenScript.

the class BlockLightImpl method createLight.

public static BlockLight createLight(Location location, int lightLevel, long ticks) {
    location = location.getBlock().getLocation();
    BlockLight blockLight;
    if (lightsByLocation.containsKey(location)) {
        blockLight = lightsByLocation.get(location);
        if (blockLight.removeTask != null) {
            blockLight.removeTask.cancel();
            blockLight.removeTask = null;
        }
        if (blockLight.updateTask != null) {
            blockLight.updateTask.cancel();
            blockLight.updateTask = null;
        }
        blockLight.removeLater(ticks);
    } else {
        blockLight = new BlockLightImpl(location, ticks);
        lightsByLocation.put(location, blockLight);
        if (!lightsByChunk.containsKey(blockLight.chunkCoord)) {
            lightsByChunk.put(blockLight.chunkCoord, new ArrayList<>());
        }
        lightsByChunk.get(blockLight.chunkCoord).add(blockLight);
    }
    blockLight.intendedLevel = lightLevel;
    blockLight.update(lightLevel, true);
    return blockLight;
}
Also used : BlockLight(com.denizenscript.denizen.nms.abstracts.BlockLight)

Aggregations

BlockLight (com.denizenscript.denizen.nms.abstracts.BlockLight)9 ChunkCoordinate (com.denizenscript.denizen.utilities.blocks.ChunkCoordinate)6 ChunkAccess (net.minecraft.world.level.chunk.ChunkAccess)4 LevelChunk (net.minecraft.world.level.chunk.LevelChunk)4 Vector (org.bukkit.util.Vector)3 BitSet (java.util.BitSet)2 BlockPos (net.minecraft.core.BlockPos)2 CraftChunk (org.bukkit.craftbukkit.v1_16_R3.CraftChunk)2 ArrayList (java.util.ArrayList)1 List (java.util.List)1