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

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

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

Inventory.getItem介绍

[英]Returns the ItemStack found in the slot at the given index
[中]返回在给定索引的插槽中找到的ItemStack

代码示例

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

@Override
public ItemStack previous() {
  direction = -1;
  return inventory.getItem(--nextIndex);
}

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

@Override
public ItemStack next() {
  direction = 1;
  try {
    return inventory.getItem(nextIndex++);
  } catch (IndexOutOfBoundsException e) {
    throw new NoSuchElementException(e.getLocalizedMessage());
  }
}

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

private ItemStack getFirstItem(ContainerEntity container) {
  Inventory inventory = container.getInventory();
  for (int i = 0; i < inventory.getSize(); i++) {
    if (inventory.getItem(i) == null || inventory.getItem(i).getType() == null) {
      continue;
    }
    return inventory.getItem(i);
  }
  return null;
}

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

/**
 * Get a random slot index in an Inventory.
 *
 * @param random a Random instance
 * @param inventory the inventory
 * @param ignoreEmpty whether to skip empty items in the inventory
 * @return the index of a random slot in the inventory, -1 if no possible slot was found
 */
public static int getRandomSlot(Random random, Inventory inventory, boolean ignoreEmpty) {
  if (!ignoreEmpty) {
    return random.nextInt(inventory.getSize());
  }
  List<Integer> notEmpty = new ArrayList<>();
  for (int i = 0; i < inventory.getSize(); i++) {
    if (!isEmpty(inventory.getItem(i))) {
      notEmpty.add(i);
    }
  }
  if (notEmpty.isEmpty()) {
    return -1;
  }
  return notEmpty.get(random.nextInt(notEmpty.size()));
}

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

/**
 * Gets one item in this inventory view by its raw slot ID.
 *
 * @param slot The ID as returned by InventoryClickEvent.getRawSlot()
 * @return The item currently in the slot.
 */
public ItemStack getItem(int slot) {
  if (slot == OUTSIDE) {
    return null;
  }
  if (slot < getTopInventory().getSize()) {
    return getTopInventory().getItem(convertSlot(slot));
  } else {
    return getBottomInventory().getItem(convertSlot(slot));
  }
}

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

Inventory inventory = Mockito.mock(Inventory.class);
Mockito.when(inventory.getItem(Mockito.any())).thenReturn(somePresetItemStack);

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

@Override
public boolean dispense() {
  GlowBlock block = getBlock();
  int dispenseSlot = getDispenseSlot();
  if (dispenseSlot < 0) {
    block.getWorld().playEffect(block.getLocation(), Effect.CLICK1, 0);
    return false;
  }
  ItemStack origItems = getInventory().getItem(dispenseSlot);
  DispenseBehavior behavior = getDispenseBehavior(origItems.getType());
  ItemStack result = behavior.dispense(block, origItems);
  getInventory().setItem(dispenseSlot, result);
  return true;
}

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

int slot = event.getSlot();
player.getSession().send(new SetWindowSlotMessage(player.getOpenWindowId(),
    slot, event.getInventory().getItem(slot)));
player.getSession().send(new SetWindowSlotMessage(-1, -1, player.getItemOnCursor()));
return true;

代码示例来源:origin: me.lucko/helper

/**
 * Gets the item in this slot
 *
 * @return the item in this slot
 */
@Nullable
@Override
public ItemStack getItem() {
  return this.gui.getHandle().getItem(this.id);
}

代码示例来源:origin: lucko/helper

/**
 * Gets the item in this slot
 *
 * @return the item in this slot
 */
@Nullable
@Override
public ItemStack getItem() {
  return this.gui.getHandle().getItem(this.id);
}

代码示例来源:origin: eccentricdevotion/TARDIS

private boolean getBaby(Inventory i) {
  ItemStack is = i.getItem(47);
  ItemMeta im = is.getItemMeta();
  return im.getLore().get(0).equals("BABY");
}

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

@Override
  public MCItemStack getSaddle() {
    return new BukkitMCItemStack(((InventoryHolder) ah).getInventory().getItem(0));
  }
}

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

public void setToNextFree(final GuiItem item, int start) {
  for (int i = start; i < inv.getSize(); i++) {
    if (inv.getItem(i) == null) {
      this.items.put(i, item);
      this.inv.setItem(i, item.wrap());
      break;
    }
  }
}

代码示例来源:origin: eccentricdevotion/TARDIS

private Profession getProfession(Inventory i) {
  ItemStack is = i.getItem(48);
  ItemMeta im = is.getItemMeta();
  try {
    return Profession.valueOf(im.getLore().get(0));
  } catch (IllegalArgumentException e) {
    return Profession.FARMER;
  }
}

代码示例来源: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: 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));
    }
  }
}

代码示例来源: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));
  }
}

相关文章