Search in sources :

Example 1 with ServerChunkManager

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

the class LithiumServerTickScheduler method selectTicks.

/**
 * Enqueues all scheduled ticks before the specified time and prepares them for execution.
 */
public void selectTicks(long time) {
    // Calculates the maximum key value which includes all ticks scheduled before the specified time
    long headKey = getBucketKey(time + 1, TickPriority.EXTREMELY_HIGH) - 1;
    // [VanillaCopy] ServerTickScheduler#tick
    // In order to fulfill the promise of not breaking vanilla behaviour, we keep the vanilla artifact of
    // tick suppression.
    int limit = 65536;
    boolean canTick = true;
    long prevChunk = Long.MIN_VALUE;
    // Create an iterator over only
    Iterator<TickEntryQueue<T>> it = this.scheduledTicksOrdered.headMap(headKey).values().iterator();
    ServerChunkManager chunkManager = this.world.getChunkManager();
    // Iterate over all scheduled ticks and enqueue them for until we exceed our budget
    while (limit > 0 && it.hasNext()) {
        TickEntryQueue<T> list = it.next();
        // Pointer for writing scheduled ticks back into the queue
        int w = 0;
        // Re-builds the scheduled tick queue in-place
        for (int i = 0; i < list.size(); i++) {
            TickEntry<T> tick = list.getTickAtIndex(i);
            if (tick == null) {
                continue;
            }
            // properly, re-producing the vanilla issue of tick suppression.
            if (limit > 0) {
                long chunk = ChunkPos.toLong(tick.pos.getX() >> 4, tick.pos.getZ() >> 4);
                // in the same chunk can be updated. This avoids the more expensive check to the chunk manager.
                if (prevChunk != chunk) {
                    prevChunk = chunk;
                    canTick = chunkManager.shouldTickBlock(tick.pos);
                }
                // budget limit.
                if (canTick) {
                    this.scheduledTicks.remove(tick);
                    this.selectForExecution(tick);
                    limit--;
                    // Avoids the tick being kept in the scheduled queue
                    continue;
                }
            }
            // Nothing happened to this tick, so re-add it to the queue
            list.setTickAtIndex(w++, tick);
        }
        // Finalize our changes to the queue and notify it of the new length
        list.resize(w);
        // If the queue is empty, remove it from the map
        if (list.isEmpty()) {
            it.remove();
        }
    }
}
Also used : ServerChunkManager(net.minecraft.server.world.ServerChunkManager)

Example 2 with ServerChunkManager

use of net.minecraft.server.world.ServerChunkManager in project dynmap by webbukkit.

the class FabricMapChunkCache method setChunks.

public void setChunks(FabricWorld dw, List<DynmapChunk> chunks) {
    this.w = dw.getWorld();
    if (dw.isLoaded()) {
        /* Check if world's provider is ServerChunkManager */
        ChunkManager cp = this.w.getChunkManager();
        if (cp instanceof ServerChunkManager) {
            cps = (ServerChunkManager) cp;
        } else {
            Log.severe("Error: world " + dw.getName() + " has unsupported chunk provider");
        }
    }
    super.setChunks(dw, chunks);
}
Also used : ServerChunkManager(net.minecraft.server.world.ServerChunkManager) ChunkManager(net.minecraft.world.chunk.ChunkManager) ServerChunkManager(net.minecraft.server.world.ServerChunkManager)

Example 3 with ServerChunkManager

use of net.minecraft.server.world.ServerChunkManager in project dynmap by webbukkit.

the class FabricMapChunkCache method setChunks.

public void setChunks(FabricWorld dw, List<DynmapChunk> chunks) {
    this.w = dw.getWorld();
    if (dw.isLoaded()) {
        /* Check if world's provider is ServerChunkManager */
        ChunkManager cp = this.w.getChunkManager();
        if (cp instanceof ServerChunkManager) {
            cps = (ServerChunkManager) cp;
        } else {
            Log.severe("Error: world " + dw.getName() + " has unsupported chunk provider");
        }
    }
    super.setChunks(dw, chunks);
}
Also used : ServerChunkManager(net.minecraft.server.world.ServerChunkManager) ChunkManager(net.minecraft.world.chunk.ChunkManager) ServerChunkManager(net.minecraft.server.world.ServerChunkManager)

Example 4 with ServerChunkManager

use of net.minecraft.server.world.ServerChunkManager in project ImmersivePortalsMod by qouteall.

the class ChunkDataSyncManager method onPlayerRespawn.

public void onPlayerRespawn(ServerPlayerEntity oldPlayer) {
    SGlobal.chunkTrackingGraph.onPlayerRespawn(oldPlayer);
    McHelper.getServer().getWorlds().forEach(world -> {
        ServerChunkManager chunkManager = (ServerChunkManager) world.getChunkManager();
        IEThreadedAnvilChunkStorage storage = (IEThreadedAnvilChunkStorage) chunkManager.threadedAnvilChunkStorage;
        storage.onPlayerRespawn(oldPlayer);
    });
}
Also used : ServerChunkManager(net.minecraft.server.world.ServerChunkManager) IEThreadedAnvilChunkStorage(com.qouteall.immersive_portals.ducks.IEThreadedAnvilChunkStorage)

Example 5 with ServerChunkManager

use of net.minecraft.server.world.ServerChunkManager in project FastAsyncWorldEdit by IntellectualSites.

the class FabricWorld method regenerate.

@Override
public boolean regenerate(Region region, EditSession editSession) {
    // Don't even try to regen if it's going to fail.
    ChunkManager provider = getWorld().getChunkManager();
    if (!(provider instanceof ServerChunkManager)) {
        return false;
    }
    File saveFolder = Files.createTempDir();
    // register this just in case something goes wrong
    // normally it should be deleted at the end of this method
    saveFolder.deleteOnExit();
    try {
        ServerWorld originalWorld = (ServerWorld) getWorld();
        MinecraftServer server = originalWorld.getServer();
        WorldSaveHandler saveHandler = new WorldSaveHandler(saveFolder, originalWorld.getSaveHandler().getWorldDir().getName(), server, server.getDataFixer());
        World freshWorld = new ServerWorld(server, server.getWorkerExecutor(), saveHandler, originalWorld.getLevelProperties(), originalWorld.dimension.getType(), originalWorld.getProfiler(), new NoOpChunkStatusListener());
        // Pre-gen all the chunks
        // We need to also pull one more chunk in every direction
        CuboidRegion expandedPreGen = new CuboidRegion(region.getMinimumPoint().subtract(16, 0, 16), region.getMaximumPoint().add(16, 0, 16));
        for (BlockVector2 chunk : expandedPreGen.getChunks()) {
            freshWorld.getChunk(chunk.getBlockX(), chunk.getBlockZ());
        }
        FabricWorld from = new FabricWorld(freshWorld);
        for (BlockVector3 vec : region) {
            editSession.setBlock(vec, from.getFullBlock(vec));
        }
    } catch (MaxChangedBlocksException e) {
        throw new RuntimeException(e);
    } finally {
        saveFolder.delete();
    }
    return true;
}
Also used : ServerChunkManager(net.minecraft.server.world.ServerChunkManager) CuboidRegion(com.sk89q.worldedit.regions.CuboidRegion) ServerWorld(net.minecraft.server.world.ServerWorld) AbstractWorld(com.sk89q.worldedit.world.AbstractWorld) World(net.minecraft.world.World) BlockVector3(com.sk89q.worldedit.math.BlockVector3) BlockVector2(com.sk89q.worldedit.math.BlockVector2) MinecraftServer(net.minecraft.server.MinecraftServer) MaxChangedBlocksException(com.sk89q.worldedit.MaxChangedBlocksException) ServerWorld(net.minecraft.server.world.ServerWorld) File(java.io.File) ServerChunkManager(net.minecraft.server.world.ServerChunkManager) ChunkManager(net.minecraft.world.chunk.ChunkManager) WorldSaveHandler(net.minecraft.world.WorldSaveHandler)

Aggregations

ServerChunkManager (net.minecraft.server.world.ServerChunkManager)9 ChunkManager (net.minecraft.world.chunk.ChunkManager)7 IEThreadedAnvilChunkStorage (com.qouteall.immersive_portals.ducks.IEThreadedAnvilChunkStorage)1 MaxChangedBlocksException (com.sk89q.worldedit.MaxChangedBlocksException)1 BlockVector2 (com.sk89q.worldedit.math.BlockVector2)1 BlockVector3 (com.sk89q.worldedit.math.BlockVector3)1 CuboidRegion (com.sk89q.worldedit.regions.CuboidRegion)1 AbstractWorld (com.sk89q.worldedit.world.AbstractWorld)1 File (java.io.File)1 MinecraftServer (net.minecraft.server.MinecraftServer)1 ServerWorld (net.minecraft.server.world.ServerWorld)1 World (net.minecraft.world.World)1 WorldSaveHandler (net.minecraft.world.WorldSaveHandler)1