@Override public boolean useItem(BlockVector3 position, BaseItem item, Direction face) { Item nativeItem = Item.getByNameOrId(item.getType().getId()); ItemStack stack = null; if (item.getNbtData() == null) { stack = new ItemStack(nativeItem, 1, 0); } else { stack = new ItemStack(nativeItem, 1, 0, NBTConverter.toNative(item.getNbtData())); } World world = getWorld(); EnumActionResult used = stack.onItemUse(new WorldEditFakePlayer((WorldServer) world), world, ForgeAdapter.toBlockPos(position), EnumHand.MAIN_HAND, ForgeAdapter.adapt(face), 0, 0, 0); return used != EnumActionResult.FAIL; }
|| (result == EnumActionResult.SUCCESS && event.getUseItem() == Event.Result.ALLOW)) { try { return itemStack.onItemUse(this, world, pos, hand, facing, hitX, hitY, hitZ); } catch (Throwable t) { Log.warn(t, "Invalid use of fake player with item %s @ (%s), aborting. Don't do it again", usedItem, pos);
@Nonnull @Override public ActionResult<ItemStack> onItemRightClick(World world, EntityPlayer player, @Nonnull EnumHand hand) { ItemStack stack = player.getHeldItem(hand); if(!world.isRemote && ManaItemHandler.requestManaExactForTool(stack, player, COST * 2, false)) { Vector3 playerVec = Vector3.fromEntityCenter(player); Vector3 lookVec = new Vector3(player.getLookVec()).multiply(3); Vector3 placeVec = playerVec.add(lookVec); int x = MathHelper.floor(placeVec.x); int y = MathHelper.floor(placeVec.y) + 1; int z = MathHelper.floor(placeVec.z); int entities = world.getEntitiesWithinAABB(EntityLivingBase.class, new AxisAlignedBB(x, y, z, x + 1, y + 1, z + 1)).size(); if(entities == 0) { ItemStack stackToPlace = new ItemStack(Blocks.DIRT); player.setHeldItem(hand, stackToPlace); stackToPlace.onItemUse(player, world, new BlockPos(x, y, z), hand, EnumFacing.DOWN, 0F, 0F, 0F); player.setHeldItem(hand, stack); if(stackToPlace.isEmpty()) { ManaItemHandler.requestManaExactForTool(stack, player, COST * 2, true); for(int i = 0; i < 6; i++) Botania.proxy.sparkleFX(x + Math.random(), y + Math.random(), z + Math.random(), 0.35F, 0.2F, 0.05F, 1F, 5); } } } if(world.isRemote) player.swingArm(hand); return ActionResult.newResult(EnumActionResult.SUCCESS, stack); }
public static EnumActionResult place(EntityPlayer player, World world, BlockPos pos, EnumHand hand, EnumFacing side, float hitX, float hitY, float hitZ, Block block, int cost, float r, float g, float b) { ItemStack stack = player.getHeldItem(hand); if(ManaItemHandler.requestManaExactForTool(stack, player, cost, false)) { int entities = world.getEntitiesWithinAABB(EntityLivingBase.class, new AxisAlignedBB(pos.offset(side), pos.offset(side).add(1, 1, 1))).size(); if(entities == 0) { ItemStack stackToPlace = new ItemStack(block); player.setHeldItem(hand, stackToPlace); stackToPlace.onItemUse(player, world, pos, hand, side, hitX, hitY, hitZ); player.setHeldItem(hand, stack); if(stackToPlace.isEmpty()) { ManaItemHandler.requestManaExactForTool(stack, player, cost, true); for(int i = 0; i < 6; i++) Botania.proxy.sparkleFX(pos.getX() + side.getXOffset() + Math.random(), pos.getY() + side.getYOffset() + Math.random(), pos.getZ() + side.getZOffset() + Math.random(), r, g, b, 1F, 5); return EnumActionResult.SUCCESS; } } return EnumActionResult.FAIL; } return EnumActionResult.PASS; }
public static boolean placeItemBlock(ItemStack stack, World world, BlockPos pos, EnumFacing face) { EnumFacing direction = face.getOpposite(); EntityPlayer owner = AWFakePlayer.get(world); owner.setHeldItem(EnumHand.MAIN_HAND, stack); return stack.onItemUse(owner, world, pos.offset(direction), EnumHand.MAIN_HAND, face, 0.25F, 0.25F, 0.25F) == EnumActionResult.SUCCESS; }
@Override public boolean onBlockActivated(World worldIn, BlockPos pos, IBlockState state, EntityPlayer playerIn, EnumHand hand, EnumFacing side, float hitX, float hitY, float hitZ) { ItemStack heldItem = playerIn.getHeldItem(hand); if (heldItem.isEmpty()) { return false; } Block b = Block.getBlockFromItem(heldItem.getItem()); if (b != null && b != Blocks.AIR && !(b instanceof BlockScaffolding)) { worldIn.destroyBlock(pos, dropBlock); heldItem.onItemUse(playerIn, worldIn, pos, hand, side, hitX, hitY, hitZ); return true;//to cancel event chains } return false; }
@Override public boolean plantSaplingAt(EntityPlayer player, ItemStack germling, World world, BlockPos pos) { ItemStack copy = germling.copy(); player.setHeldItem(EnumHand.MAIN_HAND, copy); EnumActionResult actionResult = copy.onItemUse(player, world, pos.down(), EnumHand.MAIN_HAND, EnumFacing.UP, 0, 0, 0); player.setHeldItem(EnumHand.MAIN_HAND, ItemStack.EMPTY); if (actionResult == EnumActionResult.SUCCESS) { PacketFXSignal packet = new PacketFXSignal(PacketFXSignal.SoundFXType.BLOCK_PLACE, pos, Blocks.SAPLING.getDefaultState()); NetworkUtil.sendNetworkPacket(packet, pos, world); return true; } return false; }
if(toPlaceStack.onItemUse(player, world, pos, hand, side, hitX, hitY, hitZ) != EnumActionResult.FAIL){ if(!player.capabilities.isCreativeMode){ WorldUtil.setHandItemWithoutAnnoyingSound(player, hand, toPlaceStack.copy());