Search in sources :

Example 1 with ChunkStatus

use of net.minecraft.world.chunk.ChunkStatus in project dynmap by webbukkit.

the class DynmapPlugin method registerEvents.

private void registerEvents() {
    // To trigger rendering.
    onblockchange = core.isTrigger("blockupdate");
    onchunkpopulate = core.isTrigger("chunkpopulate");
    onchunkgenerate = core.isTrigger("chunkgenerate");
    onblockchange_with_id = core.isTrigger("blockupdate-with-id");
    if (onblockchange_with_id)
        onblockchange = true;
    if ((worldTracker == null) && (onblockchange || onchunkpopulate || onchunkgenerate)) {
        worldTracker = new WorldTracker();
        ServerWorldEvents.LOAD.register((server, world) -> worldTracker.handleWorldLoad(server, world));
        ServerWorldEvents.UNLOAD.register((server, world) -> worldTracker.handleWorldUnload(server, world));
        ServerChunkEvents.CHUNK_LOAD.register((world, chunk) -> worldTracker.handleChunkLoad(world, chunk));
        ServerChunkEvents.CHUNK_UNLOAD.register((world, chunk) -> worldTracker.handleChunkUnload(world, chunk));
        ChunkDataEvents.SAVE.register((world, chunk) -> worldTracker.handleChunkDataSave(world, chunk));
        BlockEvents.EVENT.register((world, pos) -> worldTracker.handleBlockEvent(world, pos));
    }
    // Prime the known full chunks
    if (onchunkgenerate && (server.getWorlds() != null)) {
        for (ServerWorld world : server.getWorlds()) {
            FabricWorld fw = getWorld(world);
            if (fw == null)
                continue;
            Long2ObjectLinkedOpenHashMap<ChunkHolder> chunks = ((ThreadedAnvilChunkStorageAccessor) world.getChunkManager().threadedAnvilChunkStorage).getChunkHolders();
            for (Map.Entry<Long, ChunkHolder> k : chunks.long2ObjectEntrySet()) {
                long key = k.getKey();
                ChunkHolder ch = k.getValue();
                Chunk c = null;
                try {
                    c = ch.getSavingFuture().getNow(null);
                } catch (Exception x) {
                }
                if (c == null)
                    continue;
                ChunkStatus cs = c.getStatus();
                ChunkPos pos = ch.getPos();
                if (cs == ChunkStatus.FULL) {
                    // Cooked?
                    // Add it as known
                    addKnownChunk(fw, pos);
                }
            }
        }
    }
}
Also used : ChunkHolder(net.minecraft.server.world.ChunkHolder) Chunk(net.minecraft.world.chunk.Chunk) WorldChunk(net.minecraft.world.chunk.WorldChunk) CommandSyntaxException(com.mojang.brigadier.exceptions.CommandSyntaxException) ServerWorld(net.minecraft.server.world.ServerWorld) ChunkStatus(net.minecraft.world.chunk.ChunkStatus) ChunkPos(net.minecraft.util.math.ChunkPos) BiomeMap(org.dynmap.common.BiomeMap) Long2ObjectLinkedOpenHashMap(it.unimi.dsi.fastutil.longs.Long2ObjectLinkedOpenHashMap) ThreadedAnvilChunkStorageAccessor(org.dynmap.fabric_1_16_4.mixin.ThreadedAnvilChunkStorageAccessor)

Example 2 with ChunkStatus

use of net.minecraft.world.chunk.ChunkStatus in project dynmap by webbukkit.

the class DynmapPlugin method registerEvents.

private void registerEvents() {
    // To trigger rendering.
    onblockchange = core.isTrigger("blockupdate");
    onchunkpopulate = core.isTrigger("chunkpopulate");
    onchunkgenerate = core.isTrigger("chunkgenerate");
    onblockchange_with_id = core.isTrigger("blockupdate-with-id");
    if (onblockchange_with_id)
        onblockchange = true;
    if ((worldTracker == null) && (onblockchange || onchunkpopulate || onchunkgenerate)) {
        worldTracker = new WorldTracker();
        ServerWorldEvents.LOAD.register((server, world) -> worldTracker.handleWorldLoad(server, world));
        ServerWorldEvents.UNLOAD.register((server, world) -> worldTracker.handleWorldUnload(server, world));
        ServerChunkEvents.CHUNK_LOAD.register((world, chunk) -> worldTracker.handleChunkLoad(world, chunk));
        ServerChunkEvents.CHUNK_UNLOAD.register((world, chunk) -> worldTracker.handleChunkUnload(world, chunk));
        ChunkDataEvents.SAVE.register((world, chunk) -> worldTracker.handleChunkDataSave(world, chunk));
        BlockEvents.EVENT.register((world, pos) -> worldTracker.handleBlockEvent(world, pos));
    }
    // Prime the known full chunks
    if (onchunkgenerate && (server.getWorlds() != null)) {
        for (ServerWorld world : server.getWorlds()) {
            FabricWorld fw = getWorld(world);
            if (fw == null)
                continue;
            Long2ObjectLinkedOpenHashMap<ChunkHolder> chunks = ((ThreadedAnvilChunkStorageAccessor) world.getChunkManager().threadedAnvilChunkStorage).getChunkHolders();
            for (Map.Entry<Long, ChunkHolder> k : chunks.long2ObjectEntrySet()) {
                long key = k.getKey();
                ChunkHolder ch = k.getValue();
                Chunk c = null;
                try {
                    c = ch.getFuture().getNow(null);
                } catch (Exception x) {
                }
                if (c == null)
                    continue;
                ChunkStatus cs = c.getStatus();
                ChunkPos pos = ch.getPos();
                if (cs == ChunkStatus.FULL) {
                    // Cooked?
                    // Add it as known
                    addKnownChunk(fw, pos);
                }
            }
        }
    }
}
Also used : ChunkHolder(net.minecraft.server.world.ChunkHolder) Chunk(net.minecraft.world.chunk.Chunk) WorldChunk(net.minecraft.world.chunk.WorldChunk) CommandSyntaxException(com.mojang.brigadier.exceptions.CommandSyntaxException) ServerWorld(net.minecraft.server.world.ServerWorld) ChunkStatus(net.minecraft.world.chunk.ChunkStatus) ChunkPos(net.minecraft.util.math.ChunkPos) BiomeMap(org.dynmap.common.BiomeMap) Long2ObjectLinkedOpenHashMap(it.unimi.dsi.fastutil.longs.Long2ObjectLinkedOpenHashMap) ThreadedAnvilChunkStorageAccessor(org.dynmap.fabric_1_15_2.mixin.ThreadedAnvilChunkStorageAccessor)

Example 3 with ChunkStatus

use of net.minecraft.world.chunk.ChunkStatus in project dynmap by webbukkit.

the class DynmapPlugin method registerEvents.

private void registerEvents() {
    // To trigger rendering.
    onblockchange = core.isTrigger("blockupdate");
    onchunkpopulate = core.isTrigger("chunkpopulate");
    onchunkgenerate = core.isTrigger("chunkgenerate");
    onblockchange_with_id = core.isTrigger("blockupdate-with-id");
    if (onblockchange_with_id)
        onblockchange = true;
    if ((worldTracker == null) && (onblockchange || onchunkpopulate || onchunkgenerate)) {
        worldTracker = new WorldTracker();
        ServerWorldEvents.LOAD.register((server, world) -> worldTracker.handleWorldLoad(server, world));
        ServerWorldEvents.UNLOAD.register((server, world) -> worldTracker.handleWorldUnload(server, world));
        ServerChunkEvents.CHUNK_LOAD.register((world, chunk) -> worldTracker.handleChunkLoad(world, chunk));
        ServerChunkEvents.CHUNK_UNLOAD.register((world, chunk) -> worldTracker.handleChunkUnload(world, chunk));
        ChunkDataEvents.SAVE.register((world, chunk) -> worldTracker.handleChunkDataSave(world, chunk));
        BlockEvents.EVENT.register((world, pos) -> worldTracker.handleBlockEvent(world, pos));
    }
    // Prime the known full chunks
    if (onchunkgenerate && (server.getWorlds() != null)) {
        for (ServerWorld world : server.getWorlds()) {
            FabricWorld fw = getWorld(world);
            if (fw == null)
                continue;
            Long2ObjectLinkedOpenHashMap<ChunkHolder> chunks = ((ThreadedAnvilChunkStorageAccessor) world.getChunkManager().threadedAnvilChunkStorage).getChunkHolders();
            for (Map.Entry<Long, ChunkHolder> k : chunks.long2ObjectEntrySet()) {
                long key = k.getKey();
                ChunkHolder ch = k.getValue();
                Chunk c = null;
                try {
                    c = ch.getFuture().getNow(null);
                } catch (Exception x) {
                }
                if (c == null)
                    continue;
                ChunkStatus cs = c.getStatus();
                ChunkPos pos = ch.getPos();
                if (cs == ChunkStatus.FULL) {
                    // Cooked?
                    // Add it as known
                    addKnownChunk(fw, pos);
                }
            }
        }
    }
}
Also used : ChunkHolder(net.minecraft.server.world.ChunkHolder) Chunk(net.minecraft.world.chunk.Chunk) WorldChunk(net.minecraft.world.chunk.WorldChunk) CommandSyntaxException(com.mojang.brigadier.exceptions.CommandSyntaxException) ServerWorld(net.minecraft.server.world.ServerWorld) ChunkStatus(net.minecraft.world.chunk.ChunkStatus) ChunkPos(net.minecraft.util.math.ChunkPos) BiomeMap(org.dynmap.common.BiomeMap) Long2ObjectLinkedOpenHashMap(it.unimi.dsi.fastutil.longs.Long2ObjectLinkedOpenHashMap) ThreadedAnvilChunkStorageAccessor(org.dynmap.fabric_1_14_4.mixin.ThreadedAnvilChunkStorageAccessor)

Example 4 with ChunkStatus

use of net.minecraft.world.chunk.ChunkStatus in project dynmap by webbukkit.

the class DynmapExpCommand method registerEvents.

private void registerEvents() {
    // To trigger rendering.
    onblockchange = core.isTrigger("blockupdate");
    onchunkpopulate = core.isTrigger("chunkpopulate");
    onchunkgenerate = core.isTrigger("chunkgenerate");
    onblockchange_with_id = core.isTrigger("blockupdate-with-id");
    if (onblockchange_with_id)
        onblockchange = true;
    if ((worldTracker == null) && (onblockchange || onchunkpopulate || onchunkgenerate)) {
        worldTracker = new WorldTracker();
        MinecraftForge.EVENT_BUS.register(worldTracker);
    }
    // Prime the known full chunks
    if (onchunkgenerate && (server.getWorlds() != null)) {
        for (ServerWorld world : server.getWorlds()) {
            ForgeWorld fw = getWorld(world);
            if (fw == null)
                continue;
            Long2ObjectLinkedOpenHashMap<ChunkHolder> chunks = world.getChunkProvider().chunkManager.immutableLoadedChunks;
            for (Entry<Long, ChunkHolder> k : chunks.long2ObjectEntrySet()) {
                long key = k.getKey().longValue();
                ChunkHolder ch = k.getValue();
                IChunk c = null;
                try {
                    c = ch.func_219302_f().getNow(null);
                } catch (Exception x) {
                }
                if (c == null)
                    continue;
                ChunkStatus cs = c.getStatus();
                ChunkPos pos = ch.getPosition();
                if (cs == ChunkStatus.FULL) {
                    // Cooked?
                    // Add it as known
                    addKnownChunk(fw, pos);
                }
            }
        }
    }
}
Also used : ServerWorld(net.minecraft.world.server.ServerWorld) ChunkHolder(net.minecraft.world.server.ChunkHolder) IChunk(net.minecraft.world.chunk.IChunk) ChunkStatus(net.minecraft.world.chunk.ChunkStatus) ChunkPos(net.minecraft.util.math.ChunkPos) CommandException(net.minecraft.command.CommandException) CancellationException(java.util.concurrent.CancellationException) ExecutionException(java.util.concurrent.ExecutionException) CommandSyntaxException(com.mojang.brigadier.exceptions.CommandSyntaxException) JsonParseException(com.google.gson.JsonParseException)

Example 5 with ChunkStatus

use of net.minecraft.world.chunk.ChunkStatus in project dynmap by webbukkit.

the class ForgeMapChunkCache method readChunk.

public CompoundNBT readChunk(int x, int z) {
    try {
        ChunkManager acl = cps.chunkManager;
        ChunkPos coord = new ChunkPos(x, z);
        CompoundNBT rslt = acl.readChunk(coord);
        if (rslt != null) {
            rslt = rslt.getCompound("Level");
            // Don't load uncooked chunks
            String stat = rslt.getString("Status");
            ChunkStatus cs = ChunkStatus.byName(stat);
            if ((stat == null) || // Needs to be at least lighted
            (!cs.isAtLeast(ChunkStatus.LIGHT))) {
                rslt = null;
            }
        }
        // Log.info(String.format("loadChunk(%d,%d)=%s", x, z, (rslt != null) ? rslt.toString() : "null"));
        return rslt;
    } catch (Exception exc) {
        Log.severe(String.format("Error reading chunk: %s,%d,%d", dw.getName(), x, z), exc);
        return null;
    }
}
Also used : CompoundNBT(net.minecraft.nbt.CompoundNBT) ChunkStatus(net.minecraft.world.chunk.ChunkStatus) ChunkPos(net.minecraft.util.math.ChunkPos) ChunkManager(net.minecraft.world.server.ChunkManager) InvocationTargetException(java.lang.reflect.InvocationTargetException)

Aggregations

ChunkPos (net.minecraft.util.math.ChunkPos)9 ChunkStatus (net.minecraft.world.chunk.ChunkStatus)9 CommandSyntaxException (com.mojang.brigadier.exceptions.CommandSyntaxException)7 Long2ObjectLinkedOpenHashMap (it.unimi.dsi.fastutil.longs.Long2ObjectLinkedOpenHashMap)4 ChunkHolder (net.minecraft.server.world.ChunkHolder)4 ServerWorld (net.minecraft.server.world.ServerWorld)4 Chunk (net.minecraft.world.chunk.Chunk)4 WorldChunk (net.minecraft.world.chunk.WorldChunk)4 BiomeMap (org.dynmap.common.BiomeMap)4 JsonParseException (com.google.gson.JsonParseException)3 CancellationException (java.util.concurrent.CancellationException)3 ExecutionException (java.util.concurrent.ExecutionException)3 CommandException (net.minecraft.command.CommandException)3 IChunk (net.minecraft.world.chunk.IChunk)3 ChunkHolder (net.minecraft.world.server.ChunkHolder)3 ServerWorld (net.minecraft.world.server.ServerWorld)3 InvocationTargetException (java.lang.reflect.InvocationTargetException)2 CompoundNBT (net.minecraft.nbt.CompoundNBT)2 ChunkManager (net.minecraft.world.server.ChunkManager)2 IServerWorld (net.minecraft.world.IServerWorld)1