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;
}
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);
}
}
}
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;
}
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;
}
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);
}
}
}
}
Aggregations