Java Code Examples for net.minecraftforge.event.ForgeEventFactory#onPlayerDestroyItem()
The following examples show how to use
net.minecraftforge.event.ForgeEventFactory#onPlayerDestroyItem() .
You can vote up the ones you like or vote down the ones you don't like,
and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: RandomHelper.java From Electro-Magic-Tools with GNU General Public License v3.0 | 6 votes |
public static boolean placeTorch(ItemStack stack, EntityPlayer player, World world, int x, int y, int z, int side, float xOffset, float yOffset, float zOffset) { for (int i = 0; i < player.inventory.mainInventory.length; i++) { ItemStack torchStack = player.inventory.mainInventory[i]; if (torchStack == null || !torchStack.getUnlocalizedName().toLowerCase().contains("torch")) continue; Item item = torchStack.getItem(); if (!(item instanceof ItemBlock)) continue; int oldMeta = torchStack.getItemDamage(); int oldSize = torchStack.stackSize; boolean result = torchStack.tryPlaceItemIntoWorld(player, world, x, y, z, side, xOffset, yOffset, zOffset); if (player.capabilities.isCreativeMode) { torchStack.setItemDamage(oldMeta); torchStack.stackSize = oldSize; } else if (torchStack.stackSize <= 0) { ForgeEventFactory.onPlayerDestroyItem(player, torchStack); player.inventory.mainInventory[i] = null; } if (result) return true; } return false; }
Example 2
Source File: ItemOmnitoolIron.java From Electro-Magic-Tools with GNU General Public License v3.0 | 5 votes |
@Override public boolean onItemUse(ItemStack stack, EntityPlayer player, World world, int x, int y, int z, int side, float xOffset, float yOffset, float zOffset) { for (int i = 0; i < player.inventory.mainInventory.length; i++) { ItemStack torchStack = player.inventory.mainInventory[i]; if (torchStack == null || !torchStack.getUnlocalizedName().toLowerCase().contains("torch")) { continue; } Item item = torchStack.getItem(); if (!(item instanceof ItemBlock)) { continue; } int oldMeta = torchStack.getItemDamage(); int oldSize = torchStack.stackSize; boolean result = torchStack.tryPlaceItemIntoWorld(player, world, x, y, z, side, xOffset, yOffset, zOffset); if (player.capabilities.isCreativeMode) { torchStack.setItemDamage(oldMeta); torchStack.stackSize = oldSize; } else if (torchStack.stackSize <= 0) { ForgeEventFactory.onPlayerDestroyItem(player, torchStack); player.inventory.mainInventory[i] = null; } if (result) { return true; } } return super.onItemUse(stack, player, world, x, y, z, side, xOffset, yOffset, zOffset); }
Example 3
Source File: ItemDiamondChainsaw.java From Electro-Magic-Tools with GNU General Public License v3.0 | 5 votes |
@Override public boolean onItemUse(ItemStack stack, EntityPlayer player, World world, int x, int y, int z, int side, float xOffset, float yOffset, float zOffset) { for (int i = 0; i < player.inventory.mainInventory.length; i++) { ItemStack torchStack = player.inventory.mainInventory[i]; if (torchStack == null || !torchStack.getUnlocalizedName().toLowerCase().contains("torch")) { continue; } Item item = torchStack.getItem(); if (!(item instanceof ItemBlock)) { continue; } int oldMeta = torchStack.getItemDamage(); int oldSize = torchStack.stackSize; boolean result = torchStack.tryPlaceItemIntoWorld(player, world, x, y, z, side, xOffset, yOffset, zOffset); if (player.capabilities.isCreativeMode) { torchStack.setItemDamage(oldMeta); torchStack.stackSize = oldSize; } else if (torchStack.stackSize <= 0) { ForgeEventFactory.onPlayerDestroyItem(player, torchStack); player.inventory.mainInventory[i] = null; } if (result) { return true; } } return super.onItemUse(stack, player, world, x, y, z, side, xOffset, yOffset, zOffset); }
Example 4
Source File: UpgradeBreaker.java From BetterChests with GNU Lesser General Public License v3.0 | 5 votes |
/** * see PlayerInteractionManager.tryHarvestBlock */ public boolean breakBlock(EntityPlayerMP player, BlockPos pos) { World world = player.world; IBlockState state = world.getBlockState(pos); TileEntity te = world.getTileEntity(pos); if (state.getBlockHardness(world, pos) < 0 || !state.getBlock().canHarvestBlock(world, pos, player)) { return false; } else { ItemStack stack = player.getHeldItemMainhand(); if (!stack.isEmpty() && stack.getItem().onBlockStartBreak(stack, pos, player)) return false; world.playEvent(player, 2001, pos, Block.getStateId(state)); ItemStack itemHand = player.getHeldItemMainhand(); ItemStack itemHandCopy = itemHand.isEmpty() ? ItemStack.EMPTY : itemHand.copy(); boolean canHarvest = state.getBlock().canHarvestBlock(world, pos, player); if (!itemHand.isEmpty()) { itemHand.onBlockDestroyed(world, state, pos, player); if (itemHand.isEmpty()) { ForgeEventFactory.onPlayerDestroyItem(player, itemHandCopy, EnumHand.MAIN_HAND); } } boolean didRemove = removeBlock(player, pos, canHarvest); if (didRemove && canHarvest) { state.getBlock().harvestBlock(world, player, pos, state, te, itemHandCopy); } return didRemove; } }
Example 5
Source File: ItemRockbreakerDrill.java From Electro-Magic-Tools with GNU General Public License v3.0 | 4 votes |
@SuppressWarnings("unused") @Override public boolean onItemUse(ItemStack stack, EntityPlayer player, World world, int x, int y, int z, int side, float xOffset, float yOffset, float zOffset) { if (!player.isSneaking()) { for (int i = 0; i < player.inventory.mainInventory.length; i++) { ItemStack torchStack = player.inventory.mainInventory[i]; if (torchStack == null || !torchStack.getUnlocalizedName().toLowerCase().contains("torch")) { continue; } Item item = torchStack.getItem(); if (!(item instanceof ItemBlock)) { continue; } int oldMeta = torchStack.getItemDamage(); int oldSize = torchStack.stackSize; boolean result = torchStack.tryPlaceItemIntoWorld(player, world, x, y, z, side, xOffset, yOffset, zOffset); if (player.capabilities.isCreativeMode) { torchStack.setItemDamage(oldMeta); torchStack.stackSize = oldSize; } else if (torchStack.stackSize <= 0) { ForgeEventFactory.onPlayerDestroyItem(player, torchStack); player.inventory.mainInventory[i] = null; } if (result) { return true; } } } else { ElectricItem.manager.use(stack, searchCost, player); if (!world.isRemote) { world.playSoundEffect(x + 0.5D, y + 0.5D, z + 0.5D, "thaumcraft:wandfail", 0.2F, 0.2F + world.rand.nextFloat() * 0.2F); return super.onItemUse(stack, player, world, x, y, z, side, xOffset, xOffset, zOffset); } Minecraft mc = Minecraft.getMinecraft(); Thaumcraft.instance.renderEventHandler.startScan(player, x, y, z, System.currentTimeMillis() + 5000L); player.swingItem(); return super.onItemUse(stack, player, world, x, y, z, side, xOffset, yOffset, zOffset); } return super.onItemUse(stack, player, world, x, y, z, side, xOffset, yOffset, zOffset); }