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

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

Introduction

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

Prototype

@Nonnull
public Hand getHand() 

Source Link

Usage

From source file:com.lothrazar.cyclicmagic.item.core.BaseItemChargeScepter.java

License:Open Source License

@SubscribeEvent
public void onHit(PlayerInteractEvent.LeftClickBlock event) {
    EntityPlayer player = event.getEntityPlayer();
    ItemStack held = player.getHeldItem(event.getHand());
    if (held.getItem() == this) {
        //did we turn it off? is the visible timer still going?
        if (ActionType.getTimeout(held) > 0) {
            return;
        }//  w  ww  . j a  v a  2s  .  c  om
        ActionType.setTimeout(held);
        event.setCanceled(true);
        UtilSound.playSound(player, player.getPosition(), SoundRegistry.tool_mode, SoundCategory.PLAYERS, 0.1F);
        if (!player.getEntityWorld().isRemote) { // server side
            ActionType.toggle(held);
            UtilChat.sendStatusMessage(player, UtilChat.lang(ActionType.getName(held)));
        }
    }
}

From source file:com.lothrazar.cyclicmagic.item.exchangebuild.ItemBuildSwapper.java

License:Open Source License

@SubscribeEvent
public void onHit(PlayerInteractEvent.LeftClickBlock event) {
    EntityPlayer player = event.getEntityPlayer();
    ItemStack held = player.getHeldItem(event.getHand());
    if (!held.isEmpty() && held.getItem() == this) {
        //      if (event.getFace() != null && player.isSneaking()) {
        //        //hita block
        //        IBlockState hit = player.world.getBlockState(event.getPos());
        //        ModCyclic.logger.log("HIT" + hit.getBlock());
        //        return;
        //      }
        if (ActionType.getTimeout(held) > 0) {
            //without a timeout, this fires every tick. so you 'hit once' and get this happening 6 times
            return;
        }//from   w w  w . ja v  a 2s. c om
        ActionType.setTimeout(held);
        event.setCanceled(true);
        UtilSound.playSound(player, player.getPosition(), SoundRegistry.tool_mode, SoundCategory.PLAYERS);
        if (!player.getEntityWorld().isRemote) { // server side
            ActionType.toggle(held);
            UtilChat.sendStatusMessage(player, UtilChat.lang(ActionType.getName(held)));
        }
    }
}

From source file:com.lothrazar.cyclicmagic.item.ItemPistonWand.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) {
        if (ActionType.getTimeout(held) > 0) {
            //without a timeout, this fires every tick. so you 'hit once' and get this happening 6 times
            return;
        }//w w w  .  j a v a 2  s. c  o  m
        ActionType.setTimeout(held);
        event.setCanceled(true);
        UtilSound.playSound(player, player.getPosition(), SoundRegistry.tool_mode, SoundCategory.PLAYERS);
        if (!player.getEntityWorld().isRemote) { // server side
            ActionType.toggle(held);
            UtilChat.sendStatusMessage(player, UtilChat.lang(ActionType.getName(held)));
        }
    }
}

From source file:com.lothrazar.cyclicmagic.item.ItemPlayerLauncher.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) {
        //did we turn it off? is the visible timer still going?
        if (ActionType.getTimeout(held) > 0) {
            return;
        }//from  w w w  .j a v a 2  s .c  o  m
        ActionType.setTimeout(held);
        event.setCanceled(true);
        UtilSound.playSound(player, player.getPosition(), SoundRegistry.tool_mode, SoundCategory.PLAYERS, 0.3F);
        if (!player.getEntityWorld().isRemote) { // server side
            ActionType.toggle(held);
            UtilChat.sendStatusMessage(player, UtilChat.lang(ActionType.getName(held)));
        }
    }
}

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   w w w  .j  av a2  s  . 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();/*from   w ww .  ja v  a 2s.com*/
    World worldObj = event.getWorld();
    //    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());
        }
    }
}