net.minecraft.item.ItemStack.onItemUse()方法的使用及代码示例

x33g5p2x  于2022-01-21 转载在 其他  
字(5.1k)|赞(0)|评价(0)|浏览(134)

本文整理了Java中net.minecraft.item.ItemStack.onItemUse()方法的一些代码示例,展示了ItemStack.onItemUse()的具体用法。这些代码示例主要来源于Github/Stackoverflow/Maven等平台,是从一些精选项目中提取出来的代码,具有较强的参考意义,能在一定程度帮忙到你。ItemStack.onItemUse()方法的具体详情如下:
包路径:net.minecraft.item.ItemStack
类名称:ItemStack
方法名:onItemUse

ItemStack.onItemUse介绍

暂无

代码示例

代码示例来源:origin: EngineHub/WorldEdit

@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;
}

代码示例来源:origin: OpenMods/OpenModsLib

|| (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);

代码示例来源:origin: Vazkii/Botania

@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);
}

代码示例来源:origin: Vazkii/Botania

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;
}

代码示例来源:origin: P3pp3rF1y/AncientWarfare2

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;
}

代码示例来源:origin: PrinceOfAmber/Cyclic

@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;
}

代码示例来源:origin: ForestryMC/ForestryMC

@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;
}

代码示例来源:origin: Ellpeck/ActuallyAdditions

if(toPlaceStack.onItemUse(player, world, pos, hand, side, hitX, hitY, hitZ) != EnumActionResult.FAIL){
  if(!player.capabilities.isCreativeMode){
    WorldUtil.setHandItemWithoutAnnoyingSound(player, hand, toPlaceStack.copy());

相关文章

微信公众号

最新文章

更多

ItemStack类方法