Search in sources :

Example 1 with TeleporterNode

use of net.dyeo.teleporter.teleport.TeleporterNode 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 2 with TeleporterNode

use of net.dyeo.teleporter.teleport.TeleporterNode in project VanillaTeleporter by dyeo.

the class TileEntityTeleporter method update.

@Override
public void update() {
    if (!this.world.isRemote) {
        TeleporterNetwork netWrapper = TeleporterNetwork.get(this.world);
        int tileDim = this.world.provider.getDimension();
        TeleporterNode thisNode = netWrapper.getNode(this.pos, tileDim);
        if (thisNode == null) {
            thisNode = new TeleporterNode();
            thisNode.pos = this.pos;
            thisNode.dimension = tileDim;
            thisNode.type = this.getWorld().getBlockState(this.pos).getValue(BlockTeleporter.TYPE);
            thisNode.key = TeleporterNetwork.getItemKey(getCapability(CapabilityItemHandler.ITEM_HANDLER_CAPABILITY, null).getStackInSlot(0));
            netWrapper.addNode(thisNode);
            this.markDirty();
            netWrapper.markDirty();
        } else {
            netWrapper.updateNode(thisNode);
        }
    }
}
Also used : TeleporterNetwork(net.dyeo.teleporter.teleport.TeleporterNetwork) TeleporterNode(net.dyeo.teleporter.teleport.TeleporterNode)

Aggregations

TeleporterNode (net.dyeo.teleporter.teleport.TeleporterNode)2 ITeleportHandler (net.dyeo.teleporter.capabilities.ITeleportHandler)1 TeleporterNetwork (net.dyeo.teleporter.teleport.TeleporterNetwork)1 TileEntityTeleporter (net.dyeo.teleporter.tileentity.TileEntityTeleporter)1 IBlockState (net.minecraft.block.state.IBlockState)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 WorldServer (net.minecraft.world.WorldServer)1