Search in sources :

Example 6 with ChunkHolder

use of net.minecraft.server.world.ChunkHolder 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_17_1.mixin.ThreadedAnvilChunkStorageAccessor)

Example 7 with ChunkHolder

use of net.minecraft.server.world.ChunkHolder in project roadrunner by MaxNeedsSnacks.

the class ThreadedAnvilChunkStorageMixin method startWatchingChunk.

protected void startWatchingChunk(ServerPlayerEntity player, int x, int z) {
    ForgeEventFactory.fireChunkWatch(true, player, new ChunkPos(x, z), this.world);
    ChunkHolder holder = this.getChunkHolder(ChunkPos.toLong(x, z));
    if (holder != null) {
        WorldChunk chunk = holder.getWorldChunk();
        if (chunk != null) {
            this.sendChunkDataPackets(player, new Packet[2], chunk);
        }
    }
}
Also used : WorldChunk(net.minecraft.world.chunk.WorldChunk) ChunkHolder(net.minecraft.server.world.ChunkHolder) ChunkPos(net.minecraft.util.math.ChunkPos)

Aggregations

ChunkHolder (net.minecraft.server.world.ChunkHolder)7 ChunkPos (net.minecraft.util.math.ChunkPos)6 WorldChunk (net.minecraft.world.chunk.WorldChunk)5 CommandSyntaxException (com.mojang.brigadier.exceptions.CommandSyntaxException)4 Long2ObjectLinkedOpenHashMap (it.unimi.dsi.fastutil.longs.Long2ObjectLinkedOpenHashMap)4 ServerWorld (net.minecraft.server.world.ServerWorld)4 Chunk (net.minecraft.world.chunk.Chunk)4 ChunkStatus (net.minecraft.world.chunk.ChunkStatus)4 BiomeMap (org.dynmap.common.BiomeMap)4 IEThreadedAnvilChunkStorage (com.qouteall.immersive_portals.ducks.IEThreadedAnvilChunkStorage)2 Either (com.mojang.datafixers.util.Either)1 DimensionalChunkPos (com.qouteall.immersive_portals.chunk_loading.DimensionalChunkPos)1 ThreadedAnvilChunkStorage (net.minecraft.server.world.ThreadedAnvilChunkStorage)1 Vec3d (net.minecraft.util.math.Vec3d)1 ThreadedAnvilChunkStorageAccessor (org.dynmap.fabric_1_14_4.mixin.ThreadedAnvilChunkStorageAccessor)1 ThreadedAnvilChunkStorageAccessor (org.dynmap.fabric_1_15_2.mixin.ThreadedAnvilChunkStorageAccessor)1 ThreadedAnvilChunkStorageAccessor (org.dynmap.fabric_1_16_4.mixin.ThreadedAnvilChunkStorageAccessor)1 ThreadedAnvilChunkStorageAccessor (org.dynmap.fabric_1_17_1.mixin.ThreadedAnvilChunkStorageAccessor)1