Search in sources :

Example 1 with TeleporterGems

use of net.silentchaos512.gems.world.TeleporterGems in project SilentGems by SilentChaos512.

the class TeleportUtil method teleportPlayerTo.

public static boolean teleportPlayerTo(EntityPlayerMP player, DimensionalPosition pos) {
    int oldDimension = player.dimension;
    // Debug line TODO: Remove later.
    String debugLine = "Teleporting %s from {%s} to {%s}.";
    debugLine = String.format(debugLine, player.getName(), new DimensionalPosition(player.getPosition(), player.dimension), pos);
    SilentGems.logHelper.info(debugLine);
    if (pos.dim != oldDimension) {
        WorldServer oldWorldServer = player.getServer().getWorld(oldDimension);
        WorldServer newWorldServer = player.getServer().getWorld(pos.dim);
        // Dismount and teleport mount
        if (player.getRidingEntity() != null) {
            Entity mount = player.getRidingEntity();
            player.dismountEntity(mount);
            teleportEntityTo(mount, pos);
        }
        // Teleport player to dimension, using a custom teleporter to prevent Nether portal spawns
        player.getServer().getPlayerList().transferPlayerToDimension(player, pos.dim, new TeleporterGems(newWorldServer));
        if (oldDimension == 1) {
            // Fixes world not loading when teleporting from the End.
            newWorldServer.spawnEntity(player);
        }
    }
    player.setPositionAndUpdate(pos.x + 0.5, pos.y + 1.0, pos.z + 0.5);
    return true;
}
Also used : TeleporterGems(net.silentchaos512.gems.world.TeleporterGems) Entity(net.minecraft.entity.Entity) DimensionalPosition(net.silentchaos512.lib.util.DimensionalPosition) WorldServer(net.minecraft.world.WorldServer)

Aggregations

Entity (net.minecraft.entity.Entity)1 WorldServer (net.minecraft.world.WorldServer)1 TeleporterGems (net.silentchaos512.gems.world.TeleporterGems)1 DimensionalPosition (net.silentchaos512.lib.util.DimensionalPosition)1