Search in sources :

Example 1 with ChunkAccess

use of net.minecraft.world.level.chunk.ChunkAccess 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 2 with ChunkAccess

use of net.minecraft.world.level.chunk.ChunkAccess 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 3 with ChunkAccess

use of net.minecraft.world.level.chunk.ChunkAccess 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 4 with ChunkAccess

use of net.minecraft.world.level.chunk.ChunkAccess 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)

Example 5 with ChunkAccess

use of net.minecraft.world.level.chunk.ChunkAccess in project MinecraftForge by MinecraftForge.

the class ChunkGenWorker method doWork.

@Override
public boolean doWork() {
    /* TODO: Check how many things are pending save, and slow down world gen if to many
        AnvilChunkLoader loader = dim.getChunkProvider().chunkLoader instanceof AnvilChunkLoader ? (AnvilChunkLoader)world.getChunkProvider().chunkLoader : null;
        if (loader != null && loader.getPendingSaveCount() > 100)
        {

            if (lastNotifcationTime < System.currentTimeMillis() - 10*1000)
            {
                listener.sendFeedback(new TranslationTextComponent("commands.forge.gen.progress", total - queue.size(), total), true);
                lastNotifcationTime = System.currentTimeMillis();
            }
            return false;
        }
        */
    BlockPos next = queue.poll();
    if (next != null) {
        if (++lastNotification >= notificationFrequency || lastNotifcationTime < System.currentTimeMillis() - 60 * 1000) {
            listener.sendSuccess(new TranslatableComponent("commands.forge.gen.progress", total - queue.size(), total), true);
            lastNotification = 0;
            lastNotifcationTime = System.currentTimeMillis();
        }
        int x = next.getX();
        int z = next.getZ();
        if (!dim.hasChunk(x, z)) {
            // Chunk is unloaded
            ChunkAccess chunk = dim.getChunk(x, z, ChunkStatus.EMPTY, true);
            if (!chunk.getStatus().isOrAfter(ChunkStatus.FULL)) {
                chunk = dim.getChunk(x, z, ChunkStatus.FULL);
                // There isn't a way to check if the chunk is actually created just if it was loaded
                genned++;
            }
        }
    }
    if (queue.size() == 0) {
        listener.sendSuccess(new TranslatableComponent("commands.forge.gen.complete", genned, total, dim.dimension().location()), true);
        /* TODO: Readd if/when we introduce world unloading, or get Mojang to do it.
            if (keepingLoaded != null && !keepingLoaded)
                DimensionManager.keepLoaded(dim, false);
            */
        return false;
    }
    return true;
}
Also used : ChunkAccess(net.minecraft.world.level.chunk.ChunkAccess) TranslatableComponent(net.minecraft.network.chat.TranslatableComponent) BlockPos(net.minecraft.core.BlockPos)

Aggregations

ChunkAccess (net.minecraft.world.level.chunk.ChunkAccess)5 BlockLight (com.denizenscript.denizen.nms.abstracts.BlockLight)4 ChunkCoordinate (com.denizenscript.denizen.utilities.blocks.ChunkCoordinate)4 LevelChunk (net.minecraft.world.level.chunk.LevelChunk)4 BlockPos (net.minecraft.core.BlockPos)3 BitSet (java.util.BitSet)2 Vector (org.bukkit.util.Vector)2 TranslatableComponent (net.minecraft.network.chat.TranslatableComponent)1