Search in sources :

Example 1 with MessageFlooParticles

use of lumien.randomthings.network.messages.MessageFlooParticles in project Random-Things by lumien231.

the class FlooNetworkHandler method teleport.

public boolean teleport(World world, BlockPos originPos, TileEntityFlooBrick originTE, EntityPlayerMP player, String enteredDestination) {
    FlooFireplace targetFirePlace = null;
    double closest = Double.MAX_VALUE;
    for (FlooFireplace firePlace : firePlaces) {
        String firePlaceName = firePlace.getName();
        if (firePlaceName != null) {
            double sim = stringSim.distance(firePlaceName, enteredDestination);
            if (sim < closest) {
                closest = sim;
                targetFirePlace = firePlace;
            }
        }
    }
    if (targetFirePlace != null) {
        if (originPos != null && targetFirePlace.lastKnownPosition.equals(originPos)) {
            player.sendMessage(new TextComponentTranslation("floo.info.same"));
            return false;
        } else {
            BlockPos targetPos = targetFirePlace.getLastKnownPosition();
            TileEntity te = world.getTileEntity(targetPos);
            if (te instanceof TileEntityFlooBrick) {
                TileEntityFlooBrick targetTE = (TileEntityFlooBrick) te;
                if (targetTE.isMaster()) {
                    EnumFacing tpFacing = targetTE.getFacing();
                    BlockPos teleportTarget = targetPos.up();
                    player.connection.setPlayerLocation(teleportTarget.getX() + 0.5, teleportTarget.getY(), teleportTarget.getZ() + 0.5, tpFacing.getHorizontalAngle(), 0);
                    player.sendMessage(new TextComponentTranslation("floo.info.teleport", targetFirePlace.getName()));
                    // Particles
                    if (originPos != null && originTE != null) {
                        List<BlockPos> originPositions = new ArrayList<BlockPos>();
                        originPositions.add(originPos);
                        originPositions.addAll(originTE.getChildren());
                        MessageFlooParticles p1 = new MessageFlooParticles(originPositions);
                        MessageUtil.sendToAllWatchingPos(player.world, originPos, p1);
                    }
                    List<BlockPos> destinationPositions = new ArrayList<BlockPos>();
                    destinationPositions.add(targetPos);
                    destinationPositions.addAll(targetTE.getChildren());
                    MessageFlooParticles p2 = new MessageFlooParticles(destinationPositions);
                    MessageUtil.sendToAllWatchingPos(player.world, targetPos, p2);
                    PacketHandler.INSTANCE.sendTo(p2, player);
                    return true;
                }
            }
            firePlaces.remove(targetFirePlace);
            this.markDirty();
            return teleport(world, originPos, originTE, player, enteredDestination);
        }
    }
    return false;
}
Also used : TileEntity(net.minecraft.tileentity.TileEntity) TextComponentTranslation(net.minecraft.util.text.TextComponentTranslation) MessageFlooParticles(lumien.randomthings.network.messages.MessageFlooParticles) EnumFacing(net.minecraft.util.EnumFacing) ArrayList(java.util.ArrayList) BlockPos(net.minecraft.util.math.BlockPos) TileEntityFlooBrick(lumien.randomthings.tileentity.TileEntityFlooBrick)

Aggregations

ArrayList (java.util.ArrayList)1 MessageFlooParticles (lumien.randomthings.network.messages.MessageFlooParticles)1 TileEntityFlooBrick (lumien.randomthings.tileentity.TileEntityFlooBrick)1 TileEntity (net.minecraft.tileentity.TileEntity)1 EnumFacing (net.minecraft.util.EnumFacing)1 BlockPos (net.minecraft.util.math.BlockPos)1 TextComponentTranslation (net.minecraft.util.text.TextComponentTranslation)1