Search in sources :

Example 1 with IEServerPlayerEntity

use of com.qouteall.immersive_portals.ducks.IEServerPlayerEntity in project ImmersivePortalsMod by qouteall.

the class ServerTeleportationManager method changePlayerDimension.

/**
 * {@link ServerPlayerEntity#changeDimension(DimensionType)}
 */
private void changePlayerDimension(ServerPlayerEntity player, ServerWorld fromWorld, ServerWorld toWorld, Vec3d destination) {
    BlockPos oldPos = player.getBlockPos();
    teleportingEntities.add(player);
    // TODO fix travel when riding entity
    player.detach();
    fromWorld.removePlayer(player);
    player.removed = false;
    player.x = destination.x;
    player.y = destination.y;
    player.z = destination.z;
    player.world = toWorld;
    player.dimension = toWorld.dimension.getType();
    toWorld.respawnPlayer(player);
    toWorld.checkChunk(player);
    McHelper.getServer().getPlayerManager().sendWorldInfo(player, toWorld);
    player.interactionManager.setWorld(toWorld);
    Helper.log(String.format("%s teleported from %s %s to %s %s", player.getName().asString(), fromWorld.dimension.getType(), oldPos, toWorld.dimension.getType(), player.getBlockPos()));
    // and the advancement of travelling for long distance through nether
    if (toWorld.dimension.getType() == DimensionType.THE_NETHER) {
        // this is used for
        ((IEServerPlayerEntity) player).setEnteredNetherPos(player.getPos());
    }
    ((IEServerPlayerEntity) player).updateDimensionTravelAdvancements(fromWorld);
}
Also used : BlockPos(net.minecraft.util.math.BlockPos) IEServerPlayerEntity(com.qouteall.immersive_portals.ducks.IEServerPlayerEntity)

Example 2 with IEServerPlayerEntity

use of com.qouteall.immersive_portals.ducks.IEServerPlayerEntity in project ImmersivePortalsMod by qouteall.

the class ServerTeleportationManager method tick.

private void tick() {
    teleportingEntities = new HashSet<>();
    long tickTimeNow = McHelper.getServerGameTime();
    if (tickTimeNow % 10 == 7) {
        ArrayList<ServerPlayerEntity> copiedPlayerList = McHelper.getCopiedPlayerList();
        for (ServerPlayerEntity player : copiedPlayerList) {
            if (!player.notInAnyWorld) {
                Long lastTeleportGameTime = this.lastTeleportGameTime.getOrDefault(player, 0L);
                if (tickTimeNow - lastTeleportGameTime > 60) {
                    sendPositionConfirmMessage(player);
                    ((IEServerPlayerEntity) player).setIsInTeleportationState(false);
                } else {
                    ((IEServerPlayNetworkHandler) player.networkHandler).cancelTeleportRequest();
                }
            }
        }
    }
}
Also used : IEServerPlayNetworkHandler(com.qouteall.immersive_portals.ducks.IEServerPlayNetworkHandler) ServerPlayerEntity(net.minecraft.server.network.ServerPlayerEntity) IEServerPlayerEntity(com.qouteall.immersive_portals.ducks.IEServerPlayerEntity) IEServerPlayerEntity(com.qouteall.immersive_portals.ducks.IEServerPlayerEntity)

Example 3 with IEServerPlayerEntity

use of com.qouteall.immersive_portals.ducks.IEServerPlayerEntity in project ImmersivePortalsMod by qouteall.

the class ServerTeleportationManager method teleportPlayer.

private void teleportPlayer(ServerPlayerEntity player, DimensionType dimensionTo, Vec3d newPos) {
    ServerWorld fromWorld = (ServerWorld) player.world;
    ServerWorld toWorld = McHelper.getServer().getWorld(dimensionTo);
    if (player.dimension == dimensionTo) {
        player.setPosition(newPos.x, newPos.y, newPos.z);
    } else {
        changePlayerDimension(player, fromWorld, toWorld, newPos);
        ((IEServerPlayNetworkHandler) player.networkHandler).cancelTeleportRequest();
    }
    ((IEServerPlayerEntity) player).setIsInTeleportationState(true);
    player.networkHandler.syncWithPlayerPosition();
}
Also used : ServerWorld(net.minecraft.server.world.ServerWorld) IEServerPlayNetworkHandler(com.qouteall.immersive_portals.ducks.IEServerPlayNetworkHandler) IEServerPlayerEntity(com.qouteall.immersive_portals.ducks.IEServerPlayerEntity)

Aggregations

IEServerPlayerEntity (com.qouteall.immersive_portals.ducks.IEServerPlayerEntity)3 IEServerPlayNetworkHandler (com.qouteall.immersive_portals.ducks.IEServerPlayNetworkHandler)2 ServerPlayerEntity (net.minecraft.server.network.ServerPlayerEntity)1 ServerWorld (net.minecraft.server.world.ServerWorld)1 BlockPos (net.minecraft.util.math.BlockPos)1