Search in sources :

Example 6 with ServerChunkProvider

use of net.minecraft.world.server.ServerChunkProvider in project minecolonies by Minecolonies.

the class Colony method updateChunkLoadTimer.

/**
 * Check if we can unload the colony now.
 * Update chunk unload timer and releases chunks when it hits 0.
 */
private void updateChunkLoadTimer() {
    if (getConfig().getServer().forceLoadColony.get()) {
        for (final ServerPlayerEntity sub : getPackageManager().getCloseSubscribers()) {
            if (getPermissions().hasPermission(sub, Action.CAN_KEEP_COLONY_ACTIVE_WHILE_AWAY)) {
                this.forceLoadTimer = CHUNK_UNLOAD_DELAY;
                for (final long pending : pendingChunks) {
                    checkChunkAndRegisterTicket(pending, world.getChunk(ChunkPos.getX(pending), ChunkPos.getZ(pending)));
                }
                pendingChunks.clear();
                return;
            }
        }
        if (this.forceLoadTimer > 0) {
            this.forceLoadTimer -= MAX_TICKRATE;
            if (this.forceLoadTimer <= 0) {
                for (final long chunkPos : this.ticketedChunks) {
                    final int chunkX = ChunkPos.getX(chunkPos);
                    final int chunkZ = ChunkPos.getZ(chunkPos);
                    if (world instanceof ServerWorld) {
                        final ChunkPos pos = new ChunkPos(chunkX, chunkZ);
                        ((ServerChunkProvider) world.getChunkSource()).removeRegionTicket(KEEP_LOADED_TYPE, pos, 2, pos);
                    }
                }
                ticketedChunks.clear();
                ticketedChunksDirty = true;
            }
        }
    }
}
Also used : ServerWorld(net.minecraft.world.server.ServerWorld) ServerPlayerEntity(net.minecraft.entity.player.ServerPlayerEntity) ChunkPos(net.minecraft.util.math.ChunkPos) ServerChunkProvider(net.minecraft.world.server.ServerChunkProvider)

Example 7 with ServerChunkProvider

use of net.minecraft.world.server.ServerChunkProvider in project minecolonies by Minecolonies.

the class CommandUnloadForcedChunks method onExecute.

/**
 * What happens when the command is executed
 *
 * @param context the context of the command execution
 */
@Override
public int onExecute(final CommandContext<CommandSource> context) {
    final Entity sender = context.getSource().getEntity();
    if (sender instanceof PlayerEntity) {
        final World world = sender.level;
        for (long chunk : ((ServerChunkProvider) sender.level.getChunkSource()).chunkMap.visibleChunkMap.keySet()) {
            ((ServerWorld) world).setChunkForced(ChunkPos.getX(chunk), ChunkPos.getZ(chunk), false);
        }
        sender.sendMessage(new StringTextComponent("Successfully removed forceload flag!"), sender.getUUID());
        return 1;
    }
    return 0;
}
Also used : ServerWorld(net.minecraft.world.server.ServerWorld) Entity(net.minecraft.entity.Entity) PlayerEntity(net.minecraft.entity.player.PlayerEntity) StringTextComponent(net.minecraft.util.text.StringTextComponent) ServerWorld(net.minecraft.world.server.ServerWorld) World(net.minecraft.world.World) PlayerEntity(net.minecraft.entity.player.PlayerEntity) ServerChunkProvider(net.minecraft.world.server.ServerChunkProvider)

Example 8 with ServerChunkProvider

use of net.minecraft.world.server.ServerChunkProvider in project endergetic by team-abnormals.

the class ServerWorldMixin method updateBalloons.

@SuppressWarnings("deprecation")
@Inject(at = @At(value = "FIELD", target = "Lnet/minecraft/entity/Entity;inChunk:Z", ordinal = 1, shift = At.Shift.AFTER), method = "tickNonPassenger")
private void updateBalloons(Entity entity, CallbackInfo info) {
    BalloonHolder balloonHolder = (BalloonHolder) entity;
    ServerChunkProvider chunkProvider = ((ServerWorld) (Object) this).getChunkSource();
    for (BolloomBalloonEntity balloon : balloonHolder.getBalloons()) {
        if (!balloon.removed && balloon.getAttachedEntity() == entity) {
            if (chunkProvider.isEntityTickingChunk(balloon)) {
                balloon.setPosAndOldPos(balloon.getX(), balloon.getY(), balloon.getZ());
                balloon.yRotO = balloon.yRot;
                balloon.xRotO = balloon.xRot;
                if (balloon.inChunk) {
                    balloon.tickCount++;
                    balloon.updateAttachedPosition();
                }
                ((ServerWorld) (Object) this).updateChunkPos(balloon);
            }
        } else {
            balloon.detachFromEntity();
        }
    }
}
Also used : ServerWorld(net.minecraft.world.server.ServerWorld) BalloonHolder(com.minecraftabnormals.endergetic.core.interfaces.BalloonHolder) ServerChunkProvider(net.minecraft.world.server.ServerChunkProvider) BolloomBalloonEntity(com.minecraftabnormals.endergetic.common.entities.bolloom.BolloomBalloonEntity) Inject(org.spongepowered.asm.mixin.injection.Inject)

Example 9 with ServerChunkProvider

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

the class ForgeMapChunkCache method setChunks.

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

Example 10 with ServerChunkProvider

use of net.minecraft.world.server.ServerChunkProvider in project Arclight by IzzelAliz.

the class MinecraftServerMixin method loadSpawn.

public void loadSpawn(IChunkStatusListener listener, ServerWorld serverWorld) {
    if (!((WorldBridge) serverWorld).bridge$getWorld().getKeepSpawnInMemory()) {
        return;
    }
    this.setUserMessage(new TranslationTextComponent("menu.generatingTerrain"));
    this.forceTicks = true;
    LOGGER.info("Preparing start region for dimension '{}'/{}", serverWorld.getWorldInfo().getWorldName(), DimensionType.getKey(((DimensionTypeBridge) serverWorld.dimension.getType()).bridge$getType()));
    BlockPos pos = serverWorld.getSpawnPoint();
    listener.start(new ChunkPos(pos));
    ServerChunkProvider chunkProvider = serverWorld.getChunkProvider();
    chunkProvider.getLightManager().func_215598_a(500);
    this.serverTime = Util.milliTime();
    chunkProvider.registerTicket(TicketType.START, new ChunkPos(pos), 11, Unit.INSTANCE);
    while (chunkProvider.getLoadedChunksCount() != 441) {
        this.executeModerately();
    }
    this.executeModerately();
    DimensionType type = serverWorld.dimension.getType();
    ForcedChunksSaveData chunks = serverWorld.getSavedData().get(ForcedChunksSaveData::new, "chunks");
    if (chunks != null) {
        ServerWorld world = this.getWorld(type);
        LongIterator iterator = chunks.getChunks().iterator();
        while (iterator.hasNext()) {
            long i = iterator.nextLong();
            ChunkPos chunkPos = new ChunkPos(i);
            world.getChunkProvider().forceChunk(chunkPos, true);
        }
    }
    this.executeModerately();
    listener.stop();
    chunkProvider.getLightManager().func_215598_a(5);
    this.forceTicks = false;
}
Also used : ServerWorld(net.minecraft.world.server.ServerWorld) DimensionType(net.minecraft.world.dimension.DimensionType) WorldBridge(io.izzel.arclight.common.bridge.world.WorldBridge) DimensionTypeBridge(io.izzel.arclight.common.bridge.world.dimension.DimensionTypeBridge) ForcedChunksSaveData(net.minecraft.world.ForcedChunksSaveData) TranslationTextComponent(net.minecraft.util.text.TranslationTextComponent) BlockPos(net.minecraft.util.math.BlockPos) ChunkPos(net.minecraft.util.math.ChunkPos) LongIterator(it.unimi.dsi.fastutil.longs.LongIterator) ServerChunkProvider(net.minecraft.world.server.ServerChunkProvider)

Aggregations

ServerChunkProvider (net.minecraft.world.server.ServerChunkProvider)14 ServerWorld (net.minecraft.world.server.ServerWorld)11 ChunkPos (net.minecraft.util.math.ChunkPos)4 AbstractChunkProvider (net.minecraft.world.chunk.AbstractChunkProvider)4 Entity (net.minecraft.entity.Entity)3 ServerPlayerEntity (net.minecraft.entity.player.ServerPlayerEntity)3 World (net.minecraft.world.World)3 BolloomBalloonEntity (com.minecraftabnormals.endergetic.common.entities.bolloom.BolloomBalloonEntity)2 BalloonHolder (com.minecraftabnormals.endergetic.core.interfaces.BalloonHolder)2 WorldBridge (io.izzel.arclight.common.bridge.world.WorldBridge)2 LongIterator (it.unimi.dsi.fastutil.longs.LongIterator)2 PlayerEntity (net.minecraft.entity.player.PlayerEntity)2 BlockPos (net.minecraft.util.math.BlockPos)2 StringTextComponent (net.minecraft.util.text.StringTextComponent)2 TranslationTextComponent (net.minecraft.util.text.TranslationTextComponent)2 ForcedChunksSaveData (net.minecraft.world.ForcedChunksSaveData)2 DimensionType (net.minecraft.world.dimension.DimensionType)2 DynmapChunk (org.dynmap.DynmapChunk)2 Inject (org.spongepowered.asm.mixin.injection.Inject)2 MaxChangedBlocksException (com.sk89q.worldedit.MaxChangedBlocksException)1