Search in sources :

Example 1 with DimensionalPosition

use of net.silentchaos512.lib.util.DimensionalPosition in project SilentGems by SilentChaos512.

the class TileTeleporter method linkReturnHomeCharm.

public boolean linkReturnHomeCharm(EntityPlayer player, World world, BlockPos pos, ItemStack heldItem, EnumHand hand) {
    if (world.isRemote) {
        return true;
    }
    if (!heldItem.hasTagCompound()) {
        heldItem.setTagCompound(new NBTTagCompound());
    }
    DimensionalPosition position = new DimensionalPosition(pos, player.dimension);
    position.writeToNBT(heldItem.getTagCompound());
    ChatHelper.sendMessage(player, SilentGems.localizationHelper.getBlockSubText(Names.TELEPORTER, "ReturnHomeBound"));
    return true;
}
Also used : DimensionalPosition(net.silentchaos512.lib.util.DimensionalPosition) NBTTagCompound(net.minecraft.nbt.NBTTagCompound)

Example 2 with DimensionalPosition

use of net.silentchaos512.lib.util.DimensionalPosition 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 DimensionalPosition

use of net.silentchaos512.lib.util.DimensionalPosition 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 DimensionalPosition

use of net.silentchaos512.lib.util.DimensionalPosition in project SilentGems by SilentChaos512.

the class ItemReturnHome method clOnItemRightClick.

@Override
protected ActionResult<ItemStack> clOnItemRightClick(World world, EntityPlayer player, EnumHand hand) {
    ItemStack stack = player.getHeldItem(hand);
    DimensionalPosition pos = getBoundPosition(stack);
    if (pos != null) {
        player.setActiveHand(hand);
        return new ActionResult(EnumActionResult.SUCCESS, stack);
    } else {
        // SilentGems.instance.localizationHelper.getItemSubText(itemName, TEXT_NOT_BOUND));
        return new ActionResult(EnumActionResult.PASS, stack);
    }
}
Also used : DimensionalPosition(net.silentchaos512.lib.util.DimensionalPosition) ActionResult(net.minecraft.util.ActionResult) EnumActionResult(net.minecraft.util.EnumActionResult) ItemStack(net.minecraft.item.ItemStack)

Example 5 with DimensionalPosition

use of net.silentchaos512.lib.util.DimensionalPosition in project SilentGems by SilentChaos512.

the class ItemReturnHome method clAddInformation.

@Override
public void clAddInformation(ItemStack stack, World world, List list, boolean par4) {
    // Is ctrl key down?
    boolean modifier = Keyboard.isKeyDown(Keyboard.KEY_LCONTROL) || Keyboard.isKeyDown(Keyboard.KEY_RCONTROL);
    LocalizationHelper loc = SilentGems.instance.localizationHelper;
    // How to use
    list.addAll(loc.getItemDescriptionLines(itemName));
    // Display coordinates if modifier key is held.
    DimensionalPosition pos = getBoundPosition(stack);
    if (pos != null) {
        if (modifier) {
            list.add(loc.getItemSubText(itemName, TEXT_BOUND_TO, pos));
        } else {
            list.add(loc.getMiscText("PressCtrl"));
        }
    } else {
        list.add(loc.getItemSubText(itemName, TEXT_NOT_BOUND));
    }
}
Also used : DimensionalPosition(net.silentchaos512.lib.util.DimensionalPosition) LocalizationHelper(net.silentchaos512.lib.util.LocalizationHelper)

Aggregations

DimensionalPosition (net.silentchaos512.lib.util.DimensionalPosition)10 LocalizationHelper (net.silentchaos512.lib.util.LocalizationHelper)4 Entity (net.minecraft.entity.Entity)2 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 TileTeleporter (net.silentchaos512.gems.tile.TileTeleporter)2 Minecraft (net.minecraft.client.Minecraft)1 FontRenderer (net.minecraft.client.gui.FontRenderer)1 ScaledResolution (net.minecraft.client.gui.ScaledResolution)1 NBTTagCompound (net.minecraft.nbt.NBTTagCompound)1 TileEntity (net.minecraft.tileentity.TileEntity)1 ActionResult (net.minecraft.util.ActionResult)1 EnumActionResult (net.minecraft.util.EnumActionResult)1 SideOnly (net.minecraftforge.fml.relauncher.SideOnly)1 ItemTeleporterLinker (net.silentchaos512.gems.item.ItemTeleporterLinker)1 TeleporterGems (net.silentchaos512.gems.world.TeleporterGems)1 LogHelper (net.silentchaos512.lib.util.LogHelper)1