use of net.dyeo.teleporter.tileentity.TileEntityTeleporter in project VanillaTeleporter by dyeo.
the class TeleporterNetwork method getNextNode.
/**
* Gets the next node that can be teleported to from the target teleporter
* @param entityIn The entity being teleported (for messaging purposes)
* @param sourceNode The beginning node
* @return A valid node if one exists, or null otherwise
*/
public TeleporterNode getNextNode(Entity entityIn, TeleporterNode sourceNode) {
// get the top-most entity (rider) for sending messages
Entity livingEntity = entityIn;
while (!livingEntity.getPassengers().isEmpty()) {
livingEntity = livingEntity.getControllingPassenger();
}
ArrayList<TeleporterNode> subnet = this.network.get(sourceNode.key);
System.out.println("Checking teleporter subnet " + sourceNode.key);
TeleporterNode destinationNode = null;
int sourceIndex = subnet.indexOf(sourceNode);
for (int i = (sourceIndex + 1) % subnet.size(); i != sourceIndex; i = (i + 1) % subnet.size()) {
TeleporterNode currentNode = subnet.get(i);
WorldServer destinationWorld = FMLCommonHandler.instance().getMinecraftServerInstance().worldServerForDimension(currentNode.dimension);
if (destinationWorld != null) {
// if a tile entity doesn't exist at the specified node location, remove the node and continue
TileEntityTeleporter tEntDest = currentNode.getTileEntity();
if (tEntDest == null) {
System.out.println("Invalid node found! Deleting...");
removeNode(currentNode);
continue;
}
// if the teleporter types are different, continue
if (sourceNode.type.isEnder() != currentNode.type.isEnder()) {
continue;
}
// if the teleporter isn't inter-dimensional and the dimensions are different, continue
if (!sourceNode.type.isEnder() && sourceNode.dimension != currentNode.dimension) {
continue;
}
// if the destination node is obstructed, continue
if (isObstructed(destinationWorld, currentNode)) {
if (livingEntity instanceof EntityPlayer) {
EntityPlayer entityPlayer = (EntityPlayer) livingEntity;
entityPlayer.sendMessage(this.getMessage("teleporterBlocked"));
}
continue;
}
// if the destination node is powered, continue
if (tEntDest.isPowered() == true) {
if (livingEntity instanceof EntityPlayer) {
EntityPlayer entityPlayer = (EntityPlayer) livingEntity;
entityPlayer.sendMessage(this.getMessage("teleporterDisabled"));
}
continue;
}
// if all above conditions are met, we've found a valid destination node.
destinationNode = currentNode;
break;
}
}
if (destinationNode == null && livingEntity instanceof EntityPlayer) {
EntityPlayer entityPlayer = (EntityPlayer) livingEntity;
entityPlayer.sendMessage(this.getMessage("teleporterNotFound"));
}
return destinationNode;
}
use of net.dyeo.teleporter.tileentity.TileEntityTeleporter in project VanillaTeleporter by dyeo.
the class GuiHandler method getServerGuiElement.
@Override
public Object getServerGuiElement(int ID, EntityPlayer player, World world, int x, int y, int z) {
if (ID == GUI_ID_TELEPORTER) {
BlockPos pos = new BlockPos(x, y, z);
TileEntity tileentity = world.getTileEntity(pos);
if (tileentity instanceof TileEntityTeleporter) {
TileEntityTeleporter tileentityteleporter = (TileEntityTeleporter) tileentity;
return new ContainerTeleporter(player.inventory, tileentityteleporter);
}
}
return null;
}
use of net.dyeo.teleporter.tileentity.TileEntityTeleporter 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.tileentity.TileEntityTeleporter in project VanillaTeleporter by dyeo.
the class BlockTeleporter method breakBlockRecall.
public void breakBlockRecall(World world, World nextWorld, BlockPos pos, BlockPos nextPos, IBlockState state, EntityPlayerMP player) {
TileEntityTeleporter tileEntityTeleporter = (TileEntityTeleporter) world.getTileEntity(pos);
if (tileEntityTeleporter != null) {
tileEntityTeleporter.removeFromNetwork();
if (tileEntityTeleporter.hasCapability(CapabilityItemHandler.ITEM_HANDLER_CAPABILITY, null)) {
IItemHandler handler = tileEntityTeleporter.getCapability(CapabilityItemHandler.ITEM_HANDLER_CAPABILITY, null);
ItemStack stack = handler.getStackInSlot(0);
if (!stack.isEmpty()) {
InventoryHelper.spawnItemStack(nextWorld, nextPos.getX(), nextPos.getY() + 1, nextPos.getZ(), stack);
}
}
}
InventoryHelper.spawnItemStack(nextWorld, nextPos.getX(), nextPos.getY() + 1, nextPos.getZ(), new ItemStack(ModBlocks.TELEPORTER, 1, getMetaFromState(state)));
world.setBlockToAir(pos);
while (world.getTileEntity(pos) != null) {
world.removeTileEntity(pos);
}
}
use of net.dyeo.teleporter.tileentity.TileEntityTeleporter in project VanillaTeleporter by dyeo.
the class BlockTeleporter method neighborChanged.
@Override
public void neighborChanged(IBlockState state, World world, BlockPos pos, Block neighbourBlock, BlockPos fromPos) {
if (!world.isRemote) {
TileEntityTeleporter tileentity = (TileEntityTeleporter) world.getTileEntity(pos);
if (tileentity != null) {
boolean isNowPowered = (world.isBlockIndirectlyGettingPowered(pos) > 0);
boolean isAlreadyPowered = tileentity.isPowered();
tileentity.setPowered(isNowPowered);
if (isNowPowered != isAlreadyPowered) {
// there is no way in forge to determine who activated/deactivated the teleporter, so we simply get the closest player
// works for _most_ cases
EntityPlayer player = world.getClosestPlayer(fromPos.getX(), fromPos.getY(), fromPos.getZ(), 32, false);
if (player != null) {
String translationKey = "message." + TeleporterMod.MODID + '_' + this.getClass().getSimpleName() + '.' + (isNowPowered ? "teleporterLocked" : "teleporterUnlocked");
TextComponentTranslation message = new TextComponentTranslation(translationKey);
player.sendMessage(message);
}
}
tileentity.markDirty();
}
}
}
Aggregations