Search in sources :

Example 11 with ServerChunkProvider

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

the class MinecraftServerMixin method loadInitialChunks.

/**
 * @author IzzelAliz
 * @reason
 */
@Overwrite
public void loadInitialChunks(IChunkStatusListener listener) {
    this.setUserMessage(new TranslationTextComponent("menu.generatingTerrain"));
    ServerWorld serverworld = this.getWorld(DimensionType.OVERWORLD);
    this.forceTicks = true;
    LOGGER.info("Preparing start region for dimension " + DimensionType.getKey(serverworld.dimension.getType()));
    BlockPos blockpos = serverworld.getSpawnPoint();
    listener.start(new ChunkPos(blockpos));
    ServerChunkProvider serverchunkprovider = serverworld.getChunkProvider();
    serverchunkprovider.getLightManager().func_215598_a(500);
    this.serverTime = Util.milliTime();
    serverchunkprovider.registerTicket(TicketType.START, new ChunkPos(blockpos), 11, Unit.INSTANCE);
    while (serverchunkprovider.getLoadedChunksCount() != 441) {
        this.executeModerately();
    }
    this.executeModerately();
    for (DimensionType dimensiontype : DimensionType.getAll()) {
        ServerWorld serverWorld = this.getWorld(dimensiontype);
        if (((WorldBridge) serverWorld).bridge$getWorld().getKeepSpawnInMemory()) {
            ForcedChunksSaveData forcedchunkssavedata = serverWorld.getSavedData().get(ForcedChunksSaveData::new, "chunks");
            if (forcedchunkssavedata != null) {
                LongIterator longiterator = forcedchunkssavedata.getChunks().iterator();
                while (longiterator.hasNext()) {
                    long i = longiterator.nextLong();
                    ChunkPos chunkpos = new ChunkPos(i);
                    serverWorld.getChunkProvider().forceChunk(chunkpos, true);
                }
            }
        }
        Bukkit.getPluginManager().callEvent(new WorldLoadEvent(((WorldBridge) serverWorld).bridge$getWorld()));
    }
    this.executeModerately();
    listener.stop();
    serverchunkprovider.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) ForcedChunksSaveData(net.minecraft.world.ForcedChunksSaveData) TranslationTextComponent(net.minecraft.util.text.TranslationTextComponent) BlockPos(net.minecraft.util.math.BlockPos) ChunkPos(net.minecraft.util.math.ChunkPos) WorldLoadEvent(org.bukkit.event.world.WorldLoadEvent) LongIterator(it.unimi.dsi.fastutil.longs.LongIterator) ServerChunkProvider(net.minecraft.world.server.ServerChunkProvider) Overwrite(org.spongepowered.asm.mixin.Overwrite)

Example 12 with ServerChunkProvider

use of net.minecraft.world.server.ServerChunkProvider in project Mekanism by mekanism.

the class TileEntityTeleporter method teleportEntityTo.

@Nullable
public static Entity teleportEntityTo(Entity entity, World targetWorld, BlockPos target) {
    if (entity.getCommandSenderWorld().dimension() == targetWorld.dimension()) {
        entity.teleportTo(target.getX() + 0.5, target.getY(), target.getZ() + 0.5);
        if (!entity.getPassengers().isEmpty()) {
            // Force re-apply any passengers so that players don't get "stuck" outside what they may be riding
            ((ServerChunkProvider) entity.getCommandSenderWorld().getChunkSource()).broadcast(entity, new SSetPassengersPacket(entity));
            Entity controller = entity.getControllingPassenger();
            if (controller != entity && controller instanceof ServerPlayerEntity && !(controller instanceof FakePlayer)) {
                ServerPlayerEntity player = (ServerPlayerEntity) controller;
                if (player.connection != null) {
                    // Force sync the fact that the vehicle moved to the client that is controlling it
                    // so that it makes sure to use the correct positions when sending move packets
                    // back to the server instead of running into moved wrongly issues
                    player.connection.send(new SMoveVehiclePacket(entity));
                }
            }
        }
        return entity;
    }
    Vector3d destination = new Vector3d(target.getX() + 0.5, target.getY(), target.getZ() + 0.5);
    // Note: We grab the passengers here instead of in placeEntity as changeDimension starts by removing any passengers
    List<Entity> passengers = entity.getPassengers();
    return entity.changeDimension((ServerWorld) targetWorld, new ITeleporter() {

        @Override
        public Entity placeEntity(Entity entity, ServerWorld currentWorld, ServerWorld destWorld, float yaw, Function<Boolean, Entity> repositionEntity) {
            Entity repositionedEntity = repositionEntity.apply(false);
            if (repositionedEntity != null) {
                // Teleport all passengers to the other dimension and then make them start riding the entity again
                for (Entity passenger : passengers) {
                    teleportPassenger(destWorld, destination, repositionedEntity, passenger);
                }
            }
            return repositionedEntity;
        }

        @Override
        public PortalInfo getPortalInfo(Entity entity, ServerWorld destWorld, Function<ServerWorld, PortalInfo> defaultPortalInfo) {
            return new PortalInfo(destination, entity.getDeltaMovement(), entity.yRot, entity.xRot);
        }

        @Override
        public boolean playTeleportSound(ServerPlayerEntity player, ServerWorld sourceWorld, ServerWorld destWorld) {
            return false;
        }
    });
}
Also used : ServerPlayerEntity(net.minecraft.entity.player.ServerPlayerEntity) Entity(net.minecraft.entity.Entity) PartEntity(net.minecraftforge.entity.PartEntity) SSetPassengersPacket(net.minecraft.network.play.server.SSetPassengersPacket) PortalInfo(net.minecraft.block.PortalInfo) ServerPlayerEntity(net.minecraft.entity.player.ServerPlayerEntity) SMoveVehiclePacket(net.minecraft.network.play.server.SMoveVehiclePacket) FakePlayer(net.minecraftforge.common.util.FakePlayer) ServerWorld(net.minecraft.world.server.ServerWorld) Vector3d(net.minecraft.util.math.vector.Vector3d) ITeleporter(net.minecraftforge.common.util.ITeleporter) ServerChunkProvider(net.minecraft.world.server.ServerChunkProvider) Nullable(javax.annotation.Nullable)

Example 13 with ServerChunkProvider

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

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 14 with ServerChunkProvider

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

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)

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