org.bukkit.inventory.Inventory.addItem()方法的使用及代码示例

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

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

Inventory.addItem介绍

[英]Stores the given ItemStacks in the inventory. This will try to fill existing stacks and empty slots as well as it can.

The returned HashMap contains what it couldn't store, where the key is the index of the parameter, and the value is the ItemStack at that index of the varargs parameter. If all items are stored, it will return an empty HashMap.

If you pass in ItemStacks which exceed the maximum stack size for the Material, first they will be added to partial stacks where Material.getMaxStackSize() is not exceeded, up to Material.getMaxStackSize(). When there are no partial stacks left stacks will be split on Inventory.getMaxStackSize() allowing you to exceed the maximum stack size for that material.
[中]将给定的ItemStacks存储在库存中。这将尽可能地填充现有堆栈和空插槽。
返回的HashMap包含它无法存储的内容,其中键是参数的索引,值是varargs参数索引处的ItemStack。如果存储了所有项,它将返回一个空HashMap。
如果传入的ItemStacks超过了材质的最大堆栈大小,则首先会将它们添加到材质所在的部分堆栈中。不超过getMaxStackSize(),直到材质。getMaxStackSize()。当没有部分堆栈时,剩余堆栈将在库存上拆分。getMaxStackSize()允许您超过该材质的最大堆栈大小。

代码示例

代码示例来源:origin: GlowstoneMC/Glowstone

/**
 * Puts as much as possible of an {@link ItemStack} in the dispenser, and returns the rest.
 *
 * @param toPlace the item stack
 * @return the portion of the item stack that didn't fit in the dispenser, or null if it all
 *         fit
 */
public ItemStack placeInDispenser(ItemStack toPlace) {
  Inventory inv = getInventory();
  Map<Integer, ItemStack> map = inv.addItem(toPlace);
  return map.isEmpty() ? null : map.get(0);
}

代码示例来源:origin: GlowstoneMC/Glowstone

private void handleUnusedInputs() {
  for (int i = 0; i < getTopInventory().getSlots().size(); i++) {
    ItemStack itemStack = getOpenInventory().getItem(i);
    if (InventoryUtil.isEmpty(itemStack)) {
      continue;
    }
    if (isDroppableCraftingSlot(i)) {
      getOpenInventory().getBottomInventory().addItem(itemStack);
      getOpenInventory().getTopInventory().setItem(i, InventoryUtil.createEmptyStack());
    }
  }
}

代码示例来源:origin: bergerkiller/BKCommonLib

@Override
public HashMap<Integer, ItemStack> addItem(ItemStack... items) {
  return base.addItem(items);
}

代码示例来源:origin: bergerkiller/BKCommonLib

@Override
public HashMap<Integer, ItemStack> addItem(ItemStack... items) {
  return base.addItem(items);
}

代码示例来源:origin: elBukkit/MagicPlugin

public boolean addToStoredInventory(ItemStack item) {
  if (storedInventory == null) {
    return false;
  }
  HashMap<Integer, ItemStack> remainder = storedInventory.addItem(item);
  return remainder.size() == 0;
}

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

@Override
public Map<Integer, MCItemStack> addItem(MCItemStack stack) {
  Map<Integer, ItemStack> h = i.addItem(stack == null ? null : ((BukkitMCItemStack) stack).is);
  Map<Integer, MCItemStack> m = new HashMap<>();
  for(Map.Entry<Integer, ItemStack> entry : h.entrySet()) {
    Integer key = entry.getKey();
    ItemStack value = entry.getValue();
    m.put(key, new BukkitMCItemStack(value));
  }
  return m;
}

代码示例来源:origin: stackoverflow.com

public class Room {

  private Inventory inventory = new Inventory();

  public void addItem(Item item) {
    inventory.addItem(item);
  }

  public void removeItem(Item item) {
    inventory.removeItem(item);
  }
}

代码示例来源:origin: zDevelopers/ImageOnMap

static public int giveCache(Player player)
{
  Queue<ItemStack> cache = getCache(player);
  Inventory inventory = player.getInventory();
  int givenItemsCount = 0;
  
  while(inventory.firstEmpty() >= 0 && !cache.isEmpty())
  {
    inventory.addItem(cache.poll());
    givenItemsCount++;
  }
  
  return givenItemsCount;
}

代码示例来源:origin: TheBusyBiscuit/Slimefun4

public ItemStack pushItems(Location l, ItemStack item, int[] slots) {
  Inventory inv = inject(l, slots);
  Map<Integer, ItemStack> map = inv.addItem(item);
  for (int slot: slots) {
    BlockStorage.getInventory(l).replaceExistingItem(slot, inv.getItem(slot));
  }
  for (Map.Entry<Integer, ItemStack> entry: map.entrySet()) {
    return entry.getValue();
  }
  return null;
}

代码示例来源:origin: echurchill/CityWorld

@Override
  public void setLoot(CityWorldGenerator generator, Odds odds, String worldPrefix, LootLocation lootLocation,
      Block block) {
    Chest chest = (Chest) block.getState();
    Inventory inv = chest.getInventory();
//        inv.clear();
    ItemStack[] items = getLoot(generator, odds, lootLocation, block);
    if (items != null)
      inv.addItem(items);
  }

代码示例来源:origin: TheBusyBiscuit/Slimefun4

public static ItemStack pushItems(Location l, ItemStack item) {
    Inventory inv = inject(l);
    Map<Integer, ItemStack> map = inv.addItem(item);
    
    for (int slot: getOutputSlots()) {
      BlockStorage.getInventory(l).replaceExistingItem(slot, inv.getItem(slot));
    }
    
    for (Map.Entry<Integer, ItemStack> entry: map.entrySet()) {
      return entry.getValue();
    }
    return null;
  }
}

代码示例来源:origin: TotalFreedom/TotalFreedomMod

private static void setDispenserContents(final Block targetBlock, final ItemStack[] items)
  {
    if (targetBlock.getType() == Material.DISPENSER)
    {
      final Inventory dispenserInv = ((Dispenser) targetBlock.getState()).getInventory();
      dispenserInv.clear();
      dispenserInv.addItem(items);
    }
  }
}

代码示例来源:origin: TheBusyBiscuit/Slimefun4

protected void pushItems(Block b, ItemStack[] items) {
  Inventory inv = inject(b);
  inv.addItem(items);
  
  for (int slot: getOutputSlots()) {
    BlockStorage.getInventory(b).replaceExistingItem(slot, inv.getItem(slot));
  }
}

代码示例来源:origin: TheBusyBiscuit/Slimefun4

protected void pushItems(Block b, ItemStack... items) {
  Inventory inv = inject(b);
  inv.addItem(items);
  
  for (int slot: getOutputSlots()) {
    BlockStorage.getInventory(b).replaceExistingItem(slot, inv.getItem(slot));
  }
}

代码示例来源:origin: TheBusyBiscuit/Slimefun4

protected void pushItems(Block b, ItemStack... items) {
  Inventory inv = inject(b);
  inv.addItem(items);
  for (int slot: getOutputSlots()) {
    BlockStorage.getInventory(b).replaceExistingItem(slot, inv.getItem(slot));
  }
}

代码示例来源:origin: TheBusyBiscuit/Slimefun4

protected void pushItems(Block b, ItemStack[] items) {
  Inventory inv = inject(b);
  inv.addItem(items);
  
  for (int slot: getOutputSlots()) {
    BlockStorage.getInventory(b).replaceExistingItem(slot, inv.getItem(slot));
  }
}

代码示例来源:origin: TheBusyBiscuit/Slimefun4

protected void pushItems(Block b, ItemStack[] items) {
  Inventory inv = inject(b);
  inv.addItem(items);
  
  for (int slot: getOutputSlots()) {
    BlockStorage.getInventory(b).replaceExistingItem(slot, inv.getItem(slot));
  }
}

代码示例来源:origin: TheBusyBiscuit/Slimefun4

protected void pushItems(Block b, ItemStack[] items) {
  Inventory inv = inject(b);
  inv.addItem(items);
  
  for (int slot: getOutputSlots()) {
    BlockStorage.getInventory(b).replaceExistingItem(slot, inv.getItem(slot));
  }
}

代码示例来源:origin: TheBusyBiscuit/Slimefun4

public void pushItems(Location l, ItemStack item) {
  Inventory inv = inject(l);
  inv.addItem(item);
  for (int slot: getOutputSlots()) {
    BlockStorage.getInventory(l).replaceExistingItem(slot, inv.getItem(slot));
  }
}

代码示例来源:origin: TheBusyBiscuit/Slimefun4

protected void pushItems(Location l, ItemStack[] items) {
    Inventory inv = inject(l);
    inv.addItem(items);
    
    for (int slot: getOutputSlots()) {
      BlockStorage.getInventory(l).replaceExistingItem(slot, inv.getItem(slot));
    }
  }
}

相关文章