Search in sources :

Example 1 with ITeleportHandler

use of net.dyeo.teleporter.capabilities.ITeleportHandler in project VanillaTeleporter by dyeo.

the class TeleporterUtility method teleport.

public static TeleporterNode teleport(EntityLivingBase entity, BlockPos pos) {
    boolean teleportSuccess = false;
    TeleporterNetwork netWrapper = TeleporterNetwork.get(entity.world);
    TeleporterNode sourceNode = netWrapper.getNode(pos, entity.world.provider.getDimension());
    TeleporterNode destinationNode = netWrapper.getNextNode(entity, sourceNode);
    if (destinationNode != null) {
        double x = destinationNode.pos.getX() + (BlockTeleporter.TELEPORTER_AABB.maxX * 0.5D);
        double y = destinationNode.pos.getY() + (BlockTeleporter.TELEPORTER_AABB.maxY);
        double z = destinationNode.pos.getZ() + (BlockTeleporter.TELEPORTER_AABB.maxZ * 0.5D);
        float yaw = entity.rotationYaw;
        float pitch = entity.rotationPitch;
        if (// if (sourceNode.type == BlockTeleporter.EnumType.REGULAR || entity.dimension == destinationNode.dimension)
        !sourceNode.type.isEnder() || entity.dimension == destinationNode.dimension) {
            if (entity instanceof EntityPlayerMP) {
                teleportSuccess = setPlayerPosition((EntityPlayerMP) entity, x, y, z, yaw, pitch);
            } else {
                teleportSuccess = setEntityPosition(entity, x, y, z, yaw, pitch);
            }
        } else if (!(sourceNode.dimension != destinationNode.dimension && !entity.getPassengers().isEmpty())) {
            if (entity instanceof EntityPlayerMP) {
                teleportSuccess = transferPlayerToDimension((EntityPlayerMP) entity, x, y, z, yaw, pitch, destinationNode.dimension);
            } else {
                teleportSuccess = transferEntityToDimension(entity, x, y, z, yaw, pitch, destinationNode.dimension);
            }
        }
    }
    if (teleportSuccess) {
        entity.world.playSound(null, sourceNode.pos.getX(), sourceNode.pos.getY(), sourceNode.pos.getZ(), ModSounds.PORTAL_ENTER, SoundCategory.BLOCKS, 0.9f, 1.0f);
        entity.world.playSound(null, destinationNode.pos.getX(), destinationNode.pos.getY(), destinationNode.pos.getZ(), ModSounds.PORTAL_EXIT, SoundCategory.BLOCKS, 0.9f, 1.0f);
    } else {
        entity.world.playSound(null, sourceNode.pos.getX(), sourceNode.pos.getY(), sourceNode.pos.getZ(), ModSounds.PORTAL_ERROR, SoundCategory.BLOCKS, 0.9f, 1.0f);
        ITeleportHandler handler = entity.getCapability(CapabilityTeleportHandler.TELEPORT_CAPABILITY, null);
        handler.setTeleportStatus(EnumTeleportStatus.FAILED);
    }
    MinecraftForge.EVENT_BUS.post(new TeleportEvent.EntityTeleportedEvent(entity));
    return destinationNode;
}
Also used : ITeleportHandler(net.dyeo.teleporter.capabilities.ITeleportHandler) TeleportEvent(net.dyeo.teleporter.event.TeleportEvent) EntityPlayerMP(net.minecraft.entity.player.EntityPlayerMP)

Example 2 with ITeleportHandler

use of net.dyeo.teleporter.capabilities.ITeleportHandler in project VanillaTeleporter by dyeo.

the class BlockTeleporter method onEntityWalk.

@Override
public void onEntityWalk(World world, BlockPos pos, Entity entity) {
    TeleporterNode destinationNode = null;
    IBlockState state = world.getBlockState(pos);
    EnumType type = EnumType.byMetadata(getMetaFromState(state));
    if (entity instanceof EntityLivingBase && entity.hasCapability(CapabilityTeleportHandler.TELEPORT_CAPABILITY, null)) {
        ITeleportHandler teleportHandler = entity.getCapability(CapabilityTeleportHandler.TELEPORT_CAPABILITY, null);
        if (!world.isRemote) {
            if (teleportHandler.getTeleportStatus() == EnumTeleportStatus.INACTIVE) {
                teleportHandler.setOnTeleporter(entity.getPosition().distanceSq(pos) <= 1);
                teleportHandler.setDimension(entity.dimension);
                if (teleportHandler.getOnTeleporter()) {
                    boolean isHostile = (entity instanceof EntityMob) || (entity instanceof EntityWolf && ((EntityWolf) entity).isAngry());
                    boolean isPassive = (entity instanceof EntityAnimal);
                    if ((isHostile == false || isHostile == ModConfiguration.teleportHostileMobs) && (isPassive == false || isPassive == ModConfiguration.teleportPassiveMobs)) {
                        destinationNode = TeleporterUtility.teleport((EntityLivingBase) entity, pos);
                    }
                }
            }
        }
        if (teleportHandler.getTeleportStatus() == EnumTeleportStatus.INACTIVE) {
            TileEntityTeleporter tEnt = (TileEntityTeleporter) world.getTileEntity(pos);
            if (tEnt != null) {
                tEnt.spawnParticles();
            }
        }
        if (type.isRecall() && entity instanceof EntityPlayerMP && destinationNode != null) {
            WorldServer nextWorld = world.getMinecraftServer().worldServerForDimension(destinationNode.dimension);
            breakBlockRecall(world, nextWorld, pos, destinationNode.pos, state, (EntityPlayerMP) entity);
        }
    }
}
Also used : EntityMob(net.minecraft.entity.monster.EntityMob) IBlockState(net.minecraft.block.state.IBlockState) TeleporterNode(net.dyeo.teleporter.teleport.TeleporterNode) ITeleportHandler(net.dyeo.teleporter.capabilities.ITeleportHandler) EntityLivingBase(net.minecraft.entity.EntityLivingBase) EntityPlayerMP(net.minecraft.entity.player.EntityPlayerMP) WorldServer(net.minecraft.world.WorldServer) EntityWolf(net.minecraft.entity.passive.EntityWolf) EntityAnimal(net.minecraft.entity.passive.EntityAnimal) TileEntityTeleporter(net.dyeo.teleporter.tileentity.TileEntityTeleporter)

Example 3 with ITeleportHandler

use of net.dyeo.teleporter.capabilities.ITeleportHandler in project VanillaTeleporter by dyeo.

the class TeleporterUtility method setPlayerPosition.

/**
	 * Sets the player's position in a minecraft server-friendly way
	 */
private static boolean setPlayerPosition(EntityPlayerMP player, double x, double y, double z, float yaw, float pitch) {
    ITeleportHandler handler = player.getCapability(CapabilityTeleportHandler.TELEPORT_CAPABILITY, null);
    handler.setTeleportStatus(EnumTeleportStatus.IN_PROGRESS);
    player.connection.setPlayerLocation(x, y, z, yaw, pitch);
    player.setRotationYawHead(yaw);
    return true;
}
Also used : ITeleportHandler(net.dyeo.teleporter.capabilities.ITeleportHandler)

Example 4 with ITeleportHandler

use of net.dyeo.teleporter.capabilities.ITeleportHandler in project VanillaTeleporter by dyeo.

the class TeleporterUtility method setEntityPosition.

/**
	 * Sets the entity's position in a minecraft server-friendly way
	 */
private static boolean setEntityPosition(Entity entity, double x, double y, double z, float yaw, float pitch) {
    ITeleportHandler handler = entity.getCapability(CapabilityTeleportHandler.TELEPORT_CAPABILITY, null);
    handler.setTeleportStatus(EnumTeleportStatus.IN_PROGRESS);
    //;(x, y, z, yaw, pitch);
    entity.setPositionAndRotation(x, y, z, yaw, pitch);
    entity.setRotationYawHead(yaw);
    return true;
}
Also used : ITeleportHandler(net.dyeo.teleporter.capabilities.ITeleportHandler)

Example 5 with ITeleportHandler

use of net.dyeo.teleporter.capabilities.ITeleportHandler in project VanillaTeleporter by dyeo.

the class TeleportEventHandler method onEntityJoinWorld.

@SubscribeEvent
public void onEntityJoinWorld(EntityJoinWorldEvent event) {
    if (event.getEntity() instanceof EntityLivingBase) {
        EntityLivingBase entity = (EntityLivingBase) event.getEntity();
        if (entity.hasCapability(CapabilityTeleportHandler.TELEPORT_CAPABILITY, null)) {
            ITeleportHandler handler = ((ITeleportHandler) entity.getCapability(CapabilityTeleportHandler.TELEPORT_CAPABILITY, null));
            if (handler.getTeleportStatus() == EnumTeleportStatus.IN_PROGRESS) {
                if (!entities.contains(entity)) {
                    entities.add(entity);
                }
                if (entities.size() == 1) {
                    MinecraftForge.EVENT_BUS.register(updateHandler);
                }
            } else {
                handler.setOnTeleporter(false);
                handler.setTeleportStatus(EnumTeleportStatus.INACTIVE);
            }
        }
    }
}
Also used : ITeleportHandler(net.dyeo.teleporter.capabilities.ITeleportHandler) EntityLivingBase(net.minecraft.entity.EntityLivingBase) SubscribeEvent(net.minecraftforge.fml.common.eventhandler.SubscribeEvent)

Aggregations

ITeleportHandler (net.dyeo.teleporter.capabilities.ITeleportHandler)6 EntityPlayerMP (net.minecraft.entity.player.EntityPlayerMP)3 EntityLivingBase (net.minecraft.entity.EntityLivingBase)2 TeleportEvent (net.dyeo.teleporter.event.TeleportEvent)1 TeleporterNode (net.dyeo.teleporter.teleport.TeleporterNode)1 TileEntityTeleporter (net.dyeo.teleporter.tileentity.TileEntityTeleporter)1 IBlockState (net.minecraft.block.state.IBlockState)1 EntityMob (net.minecraft.entity.monster.EntityMob)1 EntityAnimal (net.minecraft.entity.passive.EntityAnimal)1 EntityWolf (net.minecraft.entity.passive.EntityWolf)1 WorldServer (net.minecraft.world.WorldServer)1 SubscribeEvent (net.minecraftforge.fml.common.eventhandler.SubscribeEvent)1