Search in sources :

Example 1 with TileTeleporter

use of net.silentchaos512.gems.tile.TileTeleporter in project SilentGems by SilentChaos512.

the class BlockTeleporter method clOnBlockActivated.

@Override
protected boolean clOnBlockActivated(World world, BlockPos pos, IBlockState state, EntityPlayer player, EnumHand hand, EnumFacing facing, float hitX, float hitY, float hitZ) {
    ItemStack heldItem = player.getHeldItem(hand);
    boolean holdingLinker = StackHelper.isValid(heldItem) && heldItem.getItem() == ModItems.teleporterLinker;
    boolean holdingReturnHome = StackHelper.isValid(heldItem) && heldItem.getItem() == ModItems.returnHomeCharm;
    if (world.isRemote) {
        return holdingLinker || holdingReturnHome ? true : !isAnchor;
    }
    TileTeleporter tile = (TileTeleporter) world.getTileEntity(pos);
    if (tile == null) {
        SilentGems.logHelper.warning("Teleporter tile at " + pos + " not found!");
        return false;
    }
    // Link teleporters with linker.
    if (holdingLinker) {
        return tile.linkTeleporters(player, world, pos, heldItem, hand);
    }
    // Link return home charm.
    if (holdingReturnHome) {
        return tile.linkReturnHomeCharm(player, world, pos, heldItem, hand);
    }
    // If this is an anchor, we're done.
    if (isAnchor) {
        return false;
    }
    LocalizationHelper loc = SilentGems.instance.localizationHelper;
    // Destination set?
    if (!tile.isDestinationSet()) {
        ChatHelper.sendMessage(player, loc.getBlockSubText(Names.TELEPORTER, "NoDestination"));
        return true;
    }
    // Safety checks before teleporting:
    if (!tile.isDestinationSane(player)) {
        ChatHelper.sendMessage(player, loc.getBlockSubText(Names.TELEPORTER, "NotSane"));
        return true;
    }
    if (!tile.isDestinationSafe(player)) {
        ChatHelper.sendMessage(player, loc.getBlockSubText(Names.TELEPORTER, "NotSafe"));
        return true;
    }
    if (!tile.isDestinationAllowedIfDumb(player)) {
        ChatHelper.sendMessage(player, loc.getBlockSubText(Names.TELEPORTER, "NoReceiver"));
        return true;
    }
    // Check available charge, drain if there is enough.
    if (!tile.checkAndDrainChaos(player)) {
        return true;
    }
    // Teleport player
    tile.teleportEntityToDestination(player);
    // Play sounds
    float pitch = 0.7f + 0.3f * SilentGems.instance.random.nextFloat();
    for (BlockPos p : new BlockPos[] { pos, tile.getDestination().toBlockPos() }) {
        world.playSound(null, p, SoundEvents.ENTITY_ENDERMEN_TELEPORT, SoundCategory.BLOCKS, 1.0f, pitch);
    }
    return true;
}
Also used : BlockPos(net.minecraft.util.math.BlockPos) TileTeleporter(net.silentchaos512.gems.tile.TileTeleporter) ItemStack(net.minecraft.item.ItemStack) LocalizationHelper(net.silentchaos512.lib.util.LocalizationHelper)

Example 2 with TileTeleporter

use of net.silentchaos512.gems.tile.TileTeleporter in project SilentGems by SilentChaos512.

the class BlockTeleporter method getWitLines.

@Override
public List<String> getWitLines(IBlockState state, BlockPos pos, EntityPlayer player, boolean advanced) {
    TileEntity tile = player.world.getTileEntity(pos);
    if (tile == null || !(tile instanceof TileTeleporter)) {
        return null;
    }
    TileTeleporter teleporter = (TileTeleporter) tile;
    DimensionalPosition destination = teleporter.getDestination();
    return Lists.newArrayList(destination != null ? destination.toString() : "null");
}
Also used : TileEntity(net.minecraft.tileentity.TileEntity) DimensionalPosition(net.silentchaos512.lib.util.DimensionalPosition) TileTeleporter(net.silentchaos512.gems.tile.TileTeleporter)

Example 3 with TileTeleporter

use of net.silentchaos512.gems.tile.TileTeleporter in project SilentGems by SilentChaos512.

the class BlockTeleporterRedstone method clOnNeighborChanged.

@Override
protected void clOnNeighborChanged(IBlockState state, World world, BlockPos pos, Block block) {
    final double searchRange = GemsConfig.TELEPORTER_REDSTONE_SEARCH_RADIUS * GemsConfig.TELEPORTER_REDSTONE_SEARCH_RADIUS;
    TileTeleporter tile = (TileTeleporter) world.getTileEntity(pos);
    if (!world.isRemote && world.isBlockIndirectlyGettingPowered(pos) != 0) {
        // Is this a "dumb" teleport and are they allowed if so?
        if (!tile.isDestinationAllowedIfDumb(null)) {
            String str = SilentGems.instance.localizationHelper.getBlockSubText(Names.TELEPORTER, "NoReceiver");
            return;
        }
        // Destination safe?
        if (!tile.isDestinationSafe(null)) {
            return;
        }
        boolean playSound = false;
        // Check all entities, teleport those close to the teleporter.
        DimensionalPosition source = null;
        for (Entity entity : world.getEntities(Entity.class, e -> e.getDistanceSqToCenter(pos) < searchRange)) {
            // Get source position (have to have the entity for this because dim?)
            if (source == null) {
                source = new DimensionalPosition(pos, entity.dimension);
            }
            if (entity instanceof EntityPlayer) {
                EntityPlayer player = (EntityPlayer) entity;
                // Chaos drain.
                if (!tile.checkAndDrainChaos(player)) {
                    continue;
                }
            }
            if (tile.teleportEntityToDestination(entity)) {
                playSound = true;
            }
        }
        if (playSound) {
            float pitch = 0.7f + 0.3f * SilentGems.instance.random.nextFloat();
            for (BlockPos p : new BlockPos[] { pos, tile.getDestination().toBlockPos() }) {
                world.playSound(null, p, SoundEvents.ENTITY_ENDERMEN_TELEPORT, SoundCategory.BLOCKS, 1.0f, pitch);
            }
        }
    }
}
Also used : Entity(net.minecraft.entity.Entity) DimensionalPosition(net.silentchaos512.lib.util.DimensionalPosition) EntityPlayer(net.minecraft.entity.player.EntityPlayer) BlockPos(net.minecraft.util.math.BlockPos) TileTeleporter(net.silentchaos512.gems.tile.TileTeleporter)

Example 4 with TileTeleporter

use of net.silentchaos512.gems.tile.TileTeleporter in project SilentGems by SilentChaos512.

the class TileTeleporter method linkTeleporters.

public boolean linkTeleporters(EntityPlayer player, World world, BlockPos pos, ItemStack heldItem, EnumHand hand) {
    if (world.isRemote) {
        return true;
    }
    LogHelper log = SilentGems.logHelper;
    LocalizationHelper loc = SilentGems.localizationHelper;
    ItemTeleporterLinker linker = ModItems.teleporterLinker;
    if (StackHelper.isEmpty(heldItem) || heldItem.getItem() != linker) {
        log.warning("TileTeleporter.linkTeleporters: heldItem is not a linker?");
        return false;
    }
    if (linker.isLinked(heldItem)) {
        // Active state: link teleporters and set inactive.
        DimensionalPosition position1 = linker.getLinkedPosition(heldItem);
        DimensionalPosition position2 = new DimensionalPosition(pos, player.dimension);
        if (position1 == null) {
            log.warning("Teleporter Linker tried to link with no position set?");
            return true;
        }
        TileTeleporter tile1 = (TileTeleporter) player.getServer().getWorld(position1.dim).getTileEntity(position1.toBlockPos());
        TileTeleporter tile2 = (TileTeleporter) player.getServer().getWorld(position2.dim).getTileEntity(position2.toBlockPos());
        if (tile1 == null || tile2 == null) {
            // Could not find a teleporter?
            ChatHelper.sendMessage(player, loc.getBlockSubText(Names.TELEPORTER, "LinkFail"));
            log.warning("Could not find teleporter when linking:" + "\nTeleporter1 @ " + position1.toString() + "\nTeleporter2 @ " + position2.toString());
            linker.setLinked(heldItem, false);
            return false;
        }
        // Create "link"
        tile1.destination = position2;
        tile2.destination = position1;
        ChatHelper.sendMessage(player, loc.getBlockSubText(Names.TELEPORTER, "LinkSuccess"));
        linker.setLinked(heldItem, false);
        tile1.markDirty();
        tile2.markDirty();
    } else {
        // Inactive state: set active and location.
        linker.setLinkedPosition(heldItem, new DimensionalPosition(pos, player.dimension));
        linker.setLinked(heldItem, true);
        ChatHelper.sendMessage(player, loc.getBlockSubText(Names.TELEPORTER, "LinkStart"));
    }
    return true;
}
Also used : DimensionalPosition(net.silentchaos512.lib.util.DimensionalPosition) LogHelper(net.silentchaos512.lib.util.LogHelper) LocalizationHelper(net.silentchaos512.lib.util.LocalizationHelper) ItemTeleporterLinker(net.silentchaos512.gems.item.ItemTeleporterLinker)

Aggregations

TileTeleporter (net.silentchaos512.gems.tile.TileTeleporter)3 DimensionalPosition (net.silentchaos512.lib.util.DimensionalPosition)3 BlockPos (net.minecraft.util.math.BlockPos)2 LocalizationHelper (net.silentchaos512.lib.util.LocalizationHelper)2 Entity (net.minecraft.entity.Entity)1 EntityPlayer (net.minecraft.entity.player.EntityPlayer)1 ItemStack (net.minecraft.item.ItemStack)1 TileEntity (net.minecraft.tileentity.TileEntity)1 ItemTeleporterLinker (net.silentchaos512.gems.item.ItemTeleporterLinker)1 LogHelper (net.silentchaos512.lib.util.LogHelper)1