Example usage for net.minecraftforge.event.entity.player PlayerInteractEvent.LeftClickBlock getPos

List of usage examples for net.minecraftforge.event.entity.player PlayerInteractEvent.LeftClickBlock getPos

Introduction

In this page you can find the example usage for net.minecraftforge.event.entity.player PlayerInteractEvent.LeftClickBlock getPos.

Prototype

@Nonnull
public BlockPos getPos() 

Source Link

Document

If the interaction was on an entity, will be a BlockPos centered on the entity.

Usage

From source file:com.lothrazar.cyclicmagic.block.vector.BlockVectorPlate.java

License:Open Source License

@SubscribeEvent
public void onLeftClickBlock(PlayerInteractEvent.LeftClickBlock event) {
    BlockPos pos = event.getPos();
    World world = event.getWorld();//  ww w. j  a va2  s.  com
    EntityPlayer player = event.getEntityPlayer();
    ItemStack stack = event.getItemStack();//    ItemStack stack = player.getHeldItem(event.getHand());
    if (player.isSneaking() == false && world.getTileEntity(pos) instanceof TileEntityVector && stack != null
            && Block.getBlockFromItem(stack.getItem()) instanceof BlockVectorPlate) {
        IBlockState iblockstate = world.getBlockState(pos);
        Block block = iblockstate.getBlock();
        TileEntityVector tile = (TileEntityVector) world.getTileEntity(pos);
        if (stack.hasTagCompound()) {
            ((BlockVectorPlate) block).saveStackDataTotile(stack, tile);
            if (world.isRemote)
                UtilChat.addChatMessage(player, "tile.plate_vector.copied");
        }
    }
}

From source file:com.lothrazar.cyclicmagic.block.wireless.BlockRedstoneWireless.java

License:Open Source License

@SubscribeEvent
public static void onLeftClickBlock(PlayerInteractEvent.LeftClickBlock event) {
    BlockPos pos = event.getPos();
    World world = event.getWorld();/* w ww  . j  av a2 s  . c  o  m*/
    ItemStack stack = event.getItemStack();//player held item
    if (world.getTileEntity(pos) instanceof TileEntityWirelessRec
            && stack.getItem() == Item.getByNameOrId("cyclicmagic:wireless_transmitter")) {
        UtilNBT.setItemStackBlockPos(stack, pos);
        UtilChat.sendStatusMessage(event.getEntityPlayer(),
                UtilChat.lang("tile.wireless_transmitter.saved") + UtilChat.blockPosToString(pos));
    }
}

From source file:com.lothrazar.cyclicmagic.item.storagesack.ItemStorageBag.java

License:Open Source License

@SubscribeEvent
public void onHit(PlayerInteractEvent.LeftClickBlock event) {
    EntityPlayer player = event.getEntityPlayer();
    ItemStack held = player.getHeldItem(event.getHand());
    if (held != null && held.getItem() == this) {
        World world = event.getWorld();/*from  ww w. jav a2s . c o m*/
        TileEntity tile = world.getTileEntity(event.getPos());
        if (tile != null && tile instanceof IInventory) {
            int depositType = StorageActionType.get(held);
            if (depositType == StorageActionType.NOTHING.ordinal()) {
                if (world.isRemote) {
                    UtilChat.addChatMessage(player, UtilChat.lang("item.storage_bag.disabled"));
                }
                return;
            } else {
                if (world.isRemote == false) {
                    NonNullList<ItemStack> inv = InventoryStorage.readFromNBT(held);
                    BagDepositReturn ret = null;
                    if (depositType == StorageActionType.DEPOSIT.ordinal()) {
                        ret = UtilInventoryTransfer.dumpFromListToIInventory(world, (IInventory) tile, inv,
                                false);
                    } else if (depositType == StorageActionType.MERGE.ordinal()) {
                        ret = UtilInventoryTransfer.dumpFromListToIInventory(world, (IInventory) tile, inv,
                                true);
                    }
                    if (ret != null && ret.moved > 0) {
                        InventoryStorage.writeToNBT(held, ret.stacks);
                        UtilChat.addChatMessage(player, UtilChat.lang("item.storage_bag.success") + ret.moved);
                    }
                }
                UtilSound.playSound(player, SoundRegistry.sack_holding);
            }
        }
    }
}

From source file:com.lothrazar.cyclicmagic.playerupgrade.PlayerAbilitiesModule.java

License:Open Source License

@SubscribeEvent
public void onLeftClickBlock(PlayerInteractEvent.LeftClickBlock event) {
    EntityPlayer entityPlayer = event.getEntityPlayer();
    BlockPos pos = event.getPos();
    World worldObj = event.getWorld();//w ww  .  ja  v a 2 s  . c  o  m
    //    ItemStack held = entityPlayer.getHeldItem(event.getHand());
    ItemStack held = event.getItemStack();
    if (stardewFurnace) {
        // ignore in creative// left clicking just breaks it anyway
        if (entityPlayer.capabilities.isCreativeMode || pos == null || held.getItem() instanceof ItemPickaxe) {
            return;
        }
        int playerSlot = 0;// entityPlayer.inventory.currentItem;
        boolean wasMain = event.getHand() == EnumHand.MAIN_HAND;
        if (wasMain) {
            playerSlot = entityPlayer.inventory.currentItem;
        } else {
            //just dont use offhand, ignore it for now. is easier
            playerSlot = 40;
        }
        TileEntity tile = worldObj.getTileEntity(pos);
        if (tile instanceof TileEntityFurnace) {
            TileEntityFurnace furnace = (TileEntityFurnace) tile;
            if (held.isEmpty()) {
                UtilFurnace.extractFurnaceOutput(furnace, entityPlayer);
            } else {
                //holding a non null stack for sure
                //ALSO tools are smeltable now in new 1.11, but we skip that eh
                if (UtilFurnace.canBeSmelted(held) && (held.getItem() instanceof ItemTool) == false) {
                    UtilFurnace.tryMergeStackIntoSlot(furnace, entityPlayer, playerSlot,
                            UtilFurnace.SLOT_INPUT);
                } else if (UtilFurnace.isFuel(held)) {
                    UtilFurnace.tryMergeStackIntoSlot(furnace, entityPlayer, playerSlot, UtilFurnace.SLOT_FUEL);
                }
            }
        }
    }
    if (easyEnderChest) {
        if (!held.isEmpty() && held.getItem() == Item.getItemFromBlock(Blocks.ENDER_CHEST)) {
            entityPlayer.displayGUIChest(entityPlayer.getInventoryEnderChest());
        }
    }
}

From source file:vazkii.quark.tweaks.feature.KnockOnDoors.java

License:Creative Commons License

@SubscribeEvent
public void leftClick(PlayerInteractEvent.LeftClickBlock event) {
    if (event.getEntityPlayer().getHeldItemMainhand().isEmpty()) {
        IBlockState state = event.getWorld().getBlockState(event.getPos());
        Block block = state.getBlock();//from www. j  a va2  s  .  c  o  m
        if (block instanceof BlockDoor && state.getMaterial() == Material.WOOD)
            event.getWorld().playSound(null, event.getPos().getX(), event.getPos().getY(),
                    event.getPos().getZ(), block.getSoundType().getPlaceSound(), SoundCategory.PLAYERS, 1F, 1F);
    }
}