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

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

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

ItemStack.setCount介绍

暂无

代码示例

代码示例来源:origin: AppliedEnergistics/Applied-Energistics-2

public FacadePart( final ItemStack facade, final AEPartLocation side )
{
  if( facade == null )
  {
    throw new IllegalArgumentException( "Facade Part constructed on null item." );
  }
  this.facade = facade.copy();
  this.facade.setCount( 1 );
  this.side = side;
}

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

public OrechidRecipeWrapper(Map.Entry<String, Integer> entry) {
  this.weight = entry.getValue();
  final int amount = Math.max(1, Math.round((float) weight * 64 / getTotalOreWeight()));
  // Shouldn't ever return an empty list since the ore weight
  // list is filtered to only have ores with ItemBlocks
  List<ItemStack> stackList = OreDictionary.getOres(entry.getKey()).stream()
      .filter(s -> s.getItem() instanceof ItemBlock)
      .map(ItemStack::copy)
      .collect(Collectors.toList());
  stackList.forEach(s -> s.setCount(amount));
  outputStacks = Collections.singletonList(stackList);
}

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

private void addItem(ItemStack stack) {
  int size = stack.getCount();
  stack.setCount(1);
  for(int i = 0; i < size; i++)
    stacksIn.add(stack.copy());
}

代码示例来源:origin: AppliedEnergistics/Applied-Energistics-2

@Override
public boolean isSameType( final ItemStack otherStack )
{
  if( otherStack.isEmpty() )
  {
    return false;
  }
  int oldSize = otherStack.getCount();
  otherStack.setCount( 1 );
  boolean ret = ItemStack.areItemStacksEqual( this.getDefinition(), otherStack );
  otherStack.setCount( oldSize );
  return ret;
}

代码示例来源:origin: AppliedEnergistics/Applied-Energistics-2

@Override
@Nonnull
public ItemStack getStack()
{
  ItemStack orgStack = this.delegate.getStack();
  if( !orgStack.isEmpty() )
  {
    ItemStack modifiedStack = orgStack.copy();
    modifiedStack.setCount( 1 );
    return modifiedStack;
  }
  return ItemStack.EMPTY;
}

代码示例来源:origin: AppliedEnergistics/Applied-Energistics-2

@Override
  public void putStack( ItemStack is )
  {
    if( !is.isEmpty() )
    {
      is = is.copy();
      if( is.getCount() > 1 )
      {
        is.setCount( 1 );
      }
      else if( is.getCount() < -1 )
      {
        is.setCount( -1 );
      }
    }

    super.putStack( is );
  }
}

代码示例来源:origin: AppliedEnergistics/Applied-Energistics-2

@Override
  public void putStack( ItemStack is )
  {
    if( !is.isEmpty() )
    {
      is = is.copy();
      if( is.getCount() > 1 )
      {
        is.setCount( 1 );
      }
      else if( is.getCount() < -1 )
      {
        is.setCount( -1 );
      }
    }

    super.putStack( is );
  }
}

代码示例来源:origin: AppliedEnergistics/Applied-Energistics-2

private void fixCraftingRecipes()
{
  if( this.craftingMode )
  {
    for( int x = 0; x < this.crafting.getSlots(); x++ )
    {
      final ItemStack is = this.crafting.getStackInSlot( x );
      if( !is.isEmpty() )
      {
        is.setCount( 1 );
      }
    }
  }
}

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

protected Collection<? extends ItemStack> breakDownBigStack(ItemStack stack) {
    List<ItemStack> stacks = new ArrayList<ItemStack>();
    int additionalStacks = stack.getCount() / stack.getMaxStackSize();
    int lastStackSize = stack.getCount() % stack.getMaxStackSize();
    if(additionalStacks > 0) {
      ItemStack fullStack = stack.copy();
      fullStack.setCount(stack.getMaxStackSize());
      for (int i = 0; i < additionalStacks; i++) {
        stacks.add(fullStack.copy());
      }
    }
    ItemStack lastStack = stack.copy();
    lastStack.setCount(lastStackSize);
    stacks.add(lastStack);

    return stacks;
  }
}

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

@Nonnull
@Override
public ItemStack getCraftingResult(@Nonnull InventoryCrafting var1) {
  ItemStack item = ItemStack.EMPTY;
  for(int i = 0; i < var1.getSizeInventory(); i++) {
    ItemStack stack = var1.getStackInSlot(i);
    if(!stack.isEmpty() && stack.getItem() != ModItems.keepIvy)
      item = stack;
  }
  ItemStack copy = item.copy();
  ItemNBTHelper.setBoolean(copy, ItemKeepIvy.TAG_KEEP, true);
  copy.setCount(1);
  return copy;
}

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

public void setRequestTarget(ItemStack stack) {
  if(!stack.isEmpty()) {
    ItemStack copy = stack.copy();
    copy.setCount(1);
    requestTarget = copy;
    updateCount();
    if(!world.isRemote)
      VanillaPacketDispatcher.dispatchTEToNearbyPlayers(this);
  }
}

代码示例来源:origin: AppliedEnergistics/Applied-Energistics-2

@Override
public void securityBreak()
{
  if( this.getItemStack().getCount() > 0 && this.getGridNode() != null )
  {
    final List<ItemStack> items = new ArrayList<>();
    items.add( this.is.copy() );
    this.host.removePart( this.side, false );
    Platform.spawnDrops( this.tile.getWorld(), this.tile.getPos(), items );
    this.is.setCount( 0 );
  }
}

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

@Nonnull
@Override
public ActionResult<ItemStack> onItemRightClick(World world, EntityPlayer player, @Nonnull EnumHand hand)  {
  ItemStack stack = player.getHeldItem(hand);
  if(!world.isRemote) {
    ItemStack copy = stack.copy();
    copy.setCount(1);
    EntityThornChakram c = new EntityThornChakram(world, player, copy);
    c.shoot(player, player.rotationPitch, player.rotationYaw, 0.0F, 1.5F, 1.0F);
    c.setFire(stack.getItemDamage() != 0);
    world.spawnEntity(c);
    world.playSound(null, player.posX, player.posY, player.posZ, SoundEvents.ENTITY_ARROW_SHOOT, SoundCategory.PLAYERS, 0.5F, 0.4F / (itemRand.nextFloat() * 0.4F + 0.8F));
    stack.shrink(1);
  }
  return ActionResult.newResult(EnumActionResult.SUCCESS, stack);
}

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

@Nonnull
@Override
public ItemStack getCraftingResult(@Nonnull InventoryCrafting var1) {
  ItemStack stackToDisenchant = ItemStack.EMPTY;
  for(int i = 0; i < var1.getSizeInventory(); i++) {
    ItemStack stack = var1.getStackInSlot(i);
    if(!stack.isEmpty() && stack.isItemEnchanted()) {
      stackToDisenchant = stack.copy();
      stackToDisenchant.setCount(1);
      break;
    }
  }
  if(stackToDisenchant.isEmpty())
    return ItemStack.EMPTY;
  stackToDisenchant.getTagCompound().removeTag("ench"); // Remove enchantments
  return stackToDisenchant;
}

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

public List<ItemStack> getFilter() {
  List<ItemStack> filter = new ArrayList<>();
  final int[] rotationToStackSize = new int[] {
      1, 2, 4, 8, 16, 32, 48, 64
  };
  for(EnumFacing dir : EnumFacing.HORIZONTALS) {
    List<EntityItemFrame> frames = world.getEntitiesWithinAABB(EntityItemFrame.class, new AxisAlignedBB(pos.offset(dir), pos.offset(dir).add(1, 1, 1)));
    for(EntityItemFrame frame : frames) {
      EnumFacing orientation = frame.facingDirection;
      if(orientation == dir) {
        ItemStack stack = frame.getDisplayedItem();
        if(!stack.isEmpty()) {
          ItemStack copy = stack.copy();
          copy.setCount(rotationToStackSize[frame.getRotation()]);
          filter.add(copy);
        }
      }
    }
  }
  return filter;
}

代码示例来源:origin: AppliedEnergistics/Applied-Energistics-2

/**
 * Handles a possible overflow or none at all.
 * It will update the entity to match the leftover stack size as well as mark it as dead without any leftover
 * amount.
 *
 * @param entityItem the entity to update or destroy
 * @param overflow the leftover {@link IAEItemStack}
 *
 * @return true, if the entity was changed otherwise false.
 */
private boolean handleOverflow( final EntityItem entityItem, final IAEItemStack overflow )
{
  if( overflow == null || overflow.getStackSize() == 0 )
  {
    entityItem.setDead();
    return true;
  }
  final int oldStackSize = entityItem.getItem().getCount();
  final int newStackSize = (int) overflow.getStackSize();
  final boolean changed = oldStackSize != newStackSize;
  entityItem.getItem().setCount( newStackSize );
  return changed;
}

代码示例来源:origin: AppliedEnergistics/Applied-Energistics-2

public static ItemStack getContainerItem( final ItemStack stackInSlot )
{
  if( stackInSlot == null )
  {
    return ItemStack.EMPTY;
  }
  final Item i = stackInSlot.getItem();
  if( i == null || !i.hasContainerItem( stackInSlot ) )
  {
    if( stackInSlot.getCount() > 1 )
    {
      stackInSlot.setCount( stackInSlot.getCount() - 1 );
      return stackInSlot;
    }
    return ItemStack.EMPTY;
  }
  ItemStack ci = i.getContainerItem( stackInSlot.copy() );
  if( !ci.isEmpty() && ci.isItemStackDamageable() && ci.getItemDamage() == ci.getMaxDamage() )
  {
    ci = ItemStack.EMPTY;
  }
  return ci;
}

代码示例来源:origin: AppliedEnergistics/Applied-Energistics-2

@Nullable
private ItemStack getOutput( final IInventory inv, final boolean createFacade )
{
  if( inv.getStackInSlot( 0 ).isEmpty() && inv.getStackInSlot( 2 ).isEmpty() && inv.getStackInSlot( 6 ).isEmpty() && inv.getStackInSlot( 8 ).isEmpty() )
  {
    if( this.anchor.isSameAs( inv.getStackInSlot( 1 ) ) && this.anchor.isSameAs( inv.getStackInSlot( 3 ) ) && this.anchor
        .isSameAs( inv.getStackInSlot( 5 ) ) && this.anchor.isSameAs( inv.getStackInSlot( 7 ) ) )
    {
      final ItemStack facades = this.facade.createFacadeForItem( inv.getStackInSlot( 4 ), !createFacade );
      if( !facades.isEmpty() && createFacade )
      {
        facades.setCount( 4 );
      }
      return facades;
    }
  }
  return ItemStack.EMPTY;
}

代码示例来源:origin: AppliedEnergistics/Applied-Energistics-2

@Override
  protected ItemStack dispenseStack( final IBlockSource dispenser, final ItemStack dispensedItem )
  {
    final EnumFacing enumfacing = dispenser.getBlockState().getValue( BlockDispenser.FACING );
    final World world = dispenser.getWorld();
    final int i = dispenser.getBlockPos().getX() + enumfacing.getFrontOffsetX();
    final int j = dispenser.getBlockPos().getY() + enumfacing.getFrontOffsetY();
    final int k = dispenser.getBlockPos().getZ() + enumfacing.getFrontOffsetZ();
    final EntityTinyTNTPrimed primedTinyTNTEntity = new EntityTinyTNTPrimed( world, i + 0.5F, j + 0.5F, k + 0.5F, null );
    world.spawnEntity( primedTinyTNTEntity );
    dispensedItem.setCount( dispensedItem.getCount() - 1 );
    return dispensedItem;
  }
}

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

private void saveRecipeToStack(ItemCraftedEvent event, ItemStack stack) {
  NBTTagCompound cmp = new NBTTagCompound();
  NBTTagCompound cmp1 = new NBTTagCompound();
  ItemStack result = CraftingManager.findMatchingResult((InventoryCrafting) event.craftMatrix, event.player.world);
  if(!result.isEmpty()) {
    cmp1 = result.writeToNBT(cmp1);
    cmp.setTag(TAG_ITEM_PREFIX + 9, cmp1);
    for(int i = 0; i < 9; i++) {
      cmp1 = new NBTTagCompound();
      ItemStack stackSlot = event.craftMatrix.getStackInSlot(i);
      if(!stackSlot.isEmpty()) {
        ItemStack writeStack = stackSlot.copy();
        writeStack.setCount(1);
        cmp1 = writeStack.writeToNBT(cmp1);
      }
      cmp.setTag(TAG_ITEM_PREFIX + i, cmp1);
    }
  }
  ItemNBTHelper.setCompound(stack, TAG_LAST_CRAFTING, cmp);
}

相关文章

微信公众号

最新文章

更多

ItemStack类方法