Search in sources :

Example 1 with TileEntityTeleporter

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;
}
Also used : Entity(net.minecraft.entity.Entity) TileEntity(net.minecraft.tileentity.TileEntity) EntityPlayer(net.minecraft.entity.player.EntityPlayer) WorldServer(net.minecraft.world.WorldServer) TileEntityTeleporter(net.dyeo.teleporter.tileentity.TileEntityTeleporter)

Example 2 with TileEntityTeleporter

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;
}
Also used : TileEntity(net.minecraft.tileentity.TileEntity) ContainerTeleporter(net.dyeo.teleporter.inventory.ContainerTeleporter) BlockPos(net.minecraft.util.math.BlockPos) TileEntityTeleporter(net.dyeo.teleporter.tileentity.TileEntityTeleporter)

Example 3 with TileEntityTeleporter

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);
        }
    }
}
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 4 with TileEntityTeleporter

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);
    }
}
Also used : IItemHandler(net.minecraftforge.items.IItemHandler) ItemStack(net.minecraft.item.ItemStack) TileEntityTeleporter(net.dyeo.teleporter.tileentity.TileEntityTeleporter)

Example 5 with TileEntityTeleporter

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();
        }
    }
}
Also used : TextComponentTranslation(net.minecraft.util.text.TextComponentTranslation) EntityPlayer(net.minecraft.entity.player.EntityPlayer) TileEntityTeleporter(net.dyeo.teleporter.tileentity.TileEntityTeleporter)

Aggregations

TileEntityTeleporter (net.dyeo.teleporter.tileentity.TileEntityTeleporter)7 TileEntity (net.minecraft.tileentity.TileEntity)3 EntityPlayer (net.minecraft.entity.player.EntityPlayer)2 ItemStack (net.minecraft.item.ItemStack)2 BlockPos (net.minecraft.util.math.BlockPos)2 WorldServer (net.minecraft.world.WorldServer)2 IItemHandler (net.minecraftforge.items.IItemHandler)2 ITeleportHandler (net.dyeo.teleporter.capabilities.ITeleportHandler)1 GuiTeleporter (net.dyeo.teleporter.client.gui.inventory.GuiTeleporter)1 ContainerTeleporter (net.dyeo.teleporter.inventory.ContainerTeleporter)1 TeleporterNode (net.dyeo.teleporter.teleport.TeleporterNode)1 IBlockState (net.minecraft.block.state.IBlockState)1 Entity (net.minecraft.entity.Entity)1 EntityLivingBase (net.minecraft.entity.EntityLivingBase)1 EntityMob (net.minecraft.entity.monster.EntityMob)1 EntityAnimal (net.minecraft.entity.passive.EntityAnimal)1 EntityWolf (net.minecraft.entity.passive.EntityWolf)1 EntityPlayerMP (net.minecraft.entity.player.EntityPlayerMP)1 TextComponentTranslation (net.minecraft.util.text.TextComponentTranslation)1