Java Code Examples for net.minecraft.entity.player.EntityPlayerMP#getHeldItem()
The following examples show how to use
net.minecraft.entity.player.EntityPlayerMP#getHeldItem() .
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: CraftEventFactory.java From Thermos with GNU General Public License v3.0 | 6 votes |
public static BlockBreakEvent callBlockBreakEvent(net.minecraft.world.World world, int x, int y, int z, net.minecraft.block.Block block, int blockMetadata, net.minecraft.entity.player.EntityPlayerMP player) { org.bukkit.block.Block bukkitBlock = world.getWorld().getBlockAt(x, y, z); org.bukkit.event.block.BlockBreakEvent blockBreakEvent = new org.bukkit.event.block.BlockBreakEvent(bukkitBlock, ((EntityPlayerMP)player).getBukkitEntity()); EntityPlayerMP playermp = (EntityPlayerMP)player; if (!(playermp instanceof FakePlayer)) { if (!(playermp.theItemInWorldManager.getGameType().isAdventure() && !playermp.isCurrentToolAdventureModeExempt(x, y, z)) && !(playermp.theItemInWorldManager.getGameType().isCreative() && playermp.getHeldItem() != null && playermp.getHeldItem().getItem() instanceof ItemSword)) { int exp = 0; if (!(block == null || !player.canHarvestBlock(block) || // Handle empty block or player unable to break block scenario block.canSilkHarvest(world, player, x, y, z, blockMetadata) && EnchantmentHelper.getSilkTouchModifier(player))) // If the block is being silk harvested, the exp dropped is 0 { int meta = block.getDamageValue(world, x, y, z); int bonusLevel = EnchantmentHelper.getFortuneModifier(player); exp = block.getExpDrop(world, meta, bonusLevel); } blockBreakEvent.setExpToDrop(exp); } else blockBreakEvent.setCancelled(true); } world.getServer().getPluginManager().callEvent(blockBreakEvent); return blockBreakEvent; }
Example 2
Source File: PacketToggleMode.java From YouTubeModdingTutorial with MIT License | 5 votes |
private void handle(PacketToggleMode message, MessageContext ctx) { EntityPlayerMP playerEntity = ctx.getServerHandler().player; ItemStack heldItem = playerEntity.getHeldItem(EnumHand.MAIN_HAND); if (!heldItem.isEmpty() && heldItem.getItem() instanceof ItemWand) { ItemWand wand = (ItemWand) (heldItem.getItem()); wand.toggleMode(playerEntity, heldItem); } }
Example 3
Source File: UpgradePlacer.java From BetterChests with GNU Lesser General Public License v3.0 | 5 votes |
public boolean placeBlock(EntityPlayerMP player, BlockPos tatgetPos, EnumFacing side) { World world = player.world; ItemStack stack = player.getHeldItem(EnumHand.MAIN_HAND); EnumActionResult result = player.interactionManager.processRightClickBlock(player, world, stack, EnumHand.MAIN_HAND, tatgetPos, side.getOpposite(), .5F, .5F, .5F); if (result == EnumActionResult.PASS) { result = player.interactionManager.processRightClick(player, world, stack, EnumHand.MAIN_HAND); } return result != EnumActionResult.PASS; }