@Override public void set(ItemStack itemStack) { if (direction == 0) { throw new IllegalStateException("Must call next or previous first"); } int i = direction > 0 ? nextIndex - 1 : nextIndex; inventory.setItem(i, itemStack); }
/** * Sets one item in this inventory view by its raw slot ID. * <p> * Note: If slot ID -999 is chosen, it may be expected that the item is * dropped on the ground. This is not required behaviour, however. * * @param slot The ID as returned by InventoryClickEvent.getRawSlot() * @param item The new item to put in the slot, or null to clear it. */ public void setItem(int slot, ItemStack item) { if (slot != OUTSIDE) { if (slot < getTopInventory().getSize()) { getTopInventory().setItem(convertSlot(slot),item); } else { getBottomInventory().setItem(convertSlot(slot),item); } } else { getPlayer().getWorld().dropItemNaturally(getPlayer().getLocation(), item); } }
/** * Populates a container with random items. * * @param random the PRNG to use * @param state the block state for a container block * @param maxStacks the maximum number of slots to fill * @return true if successful (currently always true) */ public boolean fillContainer(Random random, BlockState state, int maxStacks) { if (state.getBlock().getState() instanceof InventoryHolder) { Inventory inventory = ((InventoryHolder) state.getBlock().getState()).getInventory(); int size = inventory.getSize(); for (int i = 0; i < maxStacks; i++) { RandomAmountItem item = getRandomItem(random); if (item != null) { for (ItemStack stack : item.getItemStacks(random)) { // slot can be overriden hence maxStacks can be less than what's expected inventory.setItem(random.nextInt(size), stack); } } } } else { throw new IllegalArgumentException("Bad container type"); } return true; }
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()); } } }
@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; }
public Inventory inv; public void openGUI(Player p){ //format: null, size of inventory (must be divisible by 9), "GUI name" inv = Bukkit.createInventory(null, 9, "GUI Name"); inv.setItem(0, new ItemStack(Material.DIAMOND); p.openInventory(inv); }
public GUIMaker fillItem(ItemStack item, int[]... pos) { for (int[] nowpos : pos) { if (nowpos.length == 2) { int slot = (nowpos[1] - 1) * 9 + nowpos[0] - 1; if (slot > this.inv.getSize() - 1) { return this; } this.inv.setItem(slot, item); } } return this; }
public void fillEmpty(final ItemStack itemStack) { Validate.notNull(itemStack, "ItemStack cannot be NULL!"); for (int i = 0; i < inv.getSize(); i++) { if (inv.getItem(i) == null) { inv.setItem(i, itemStack); } } }
private void clearSlot(Integer slot) { if (slot != null) { Inventory inventory = getInventory(slot); slot = getInventorySlot(slot); inventory.setItem(slot, null); } }
public void setToNextFree(GuiItem item) { for (int i = 0; i < inv.getSize(); i++) { if (inv.getItem(i) == null) { this.items.put(i, item); this.inv.setItem(i, item.wrap()); break; } } }
public void fillEmpty(final Material material) { Validate.notNull(material, "Material cannot be NULL!"); for (int i = 0; i < inv.getSize(); i++) { if (inv.getItem(i) == null) { inv.setItem(i, new ItemStack(material, 1, (short) 15)); } } }
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; } } }
public Inventory create(MobConfig mobConfig, ServerMob mob) { Inventory inventory = Bukkit.createInventory(null, mobConfig.getInventorySize(), ChatColor.translateAlternateColorCodes('&', mob.getDisplay() + NetworkUtils.SPACE_STRING)); for (Map.Entry<Integer, MobItemLayout> mobItem : mobConfig.getDefaultItemInventory().entrySet()) inventory.setItem(mobItem.getKey() - 1, transform(mobItem.getValue())); return inventory; }
private Inventory inject(Location l, int[] slots) { int size = BlockStorage.getInventory(l).toInventory().getSize(); Inventory inv = Bukkit.createInventory(null, size); for (int i = 0; i < size; i++) { inv.setItem(i, new CustomItem(Material.COMMAND_BLOCK, " &4ALL YOUR PLACEHOLDERS ARE BELONG TO US", 0)); } for (int slot: slots) { inv.setItem(slot, BlockStorage.getInventory(l).getItemInSlot(slot)); } return inv; }
private Inventory inject(Block b) { int size = BlockStorage.getInventory(b).toInventory().getSize(); Inventory inv = Bukkit.createInventory(null, size); for (int i = 0; i < size; i++) { inv.setItem(i, new CustomItem(Material.COMMAND_BLOCK, " &4ALL YOUR PLACEHOLDERS ARE BELONG TO US", 0)); } for (int slot: getOutputSlots()) { inv.setItem(slot, BlockStorage.getInventory(b).getItemInSlot(slot)); } return inv; }
public Inventory build() { Inventory inventory = Bukkit.createInventory(new MenuBuilderHolder(lock, items), rows, name); items.forEach((key, value) -> inventory.setItem(key, value.getItemStack())); return inventory; } }
private Inventory inject(Location l) { int size = BlockStorage.getInventory(l).toInventory().getSize(); Inventory inv = Bukkit.createInventory(null, size); for (int i = 0; i < size; i++) { inv.setItem(i, new CustomItem(Material.COMMAND_BLOCK, " &4ALL YOUR PLACEHOLDERS ARE BELONG TO US", 0)); } for (int slot: getOutputSlots()) { inv.setItem(slot, BlockStorage.getInventory(l).getItemInSlot(slot)); } return inv; }
private Inventory inject(Location l) { int size = BlockStorage.getInventory(l).toInventory().getSize(); Inventory inv = Bukkit.createInventory(null, size); for (int i = 0; i < size; i++) { inv.setItem(i, new CustomItem(Material.COMMAND_BLOCK, " &4ALL YOUR PLACEHOLDERS ARE BELONG TO US", 0)); } for (int slot: getOutputSlots()) { inv.setItem(slot, BlockStorage.getInventory(l).getItemInSlot(slot)); } return inv; }
private static Inventory inject(Location l) { int size = BlockStorage.getInventory(l).toInventory().getSize(); Inventory inv = Bukkit.createInventory(null, size); for (int i = 0; i < size; i++) { inv.setItem(i, new CustomItem(Material.COMMAND_BLOCK, " &4ALL YOUR PLACEHOLDERS ARE BELONG TO US", 0)); } for (int slot: getOutputSlots()) { inv.setItem(slot, BlockStorage.getInventory(l).getItemInSlot(slot)); } return inv; }
private Inventory inject(Block b) { int size = BlockStorage.getInventory(b).toInventory().getSize(); Inventory inv = Bukkit.createInventory(null, size); for (int i = 0; i < size; i++) { inv.setItem(i, new CustomItem(Material.COMMAND_BLOCK, " &4ALL YOUR PLACEHOLDERS ARE BELONG TO US", 0)); } for (int slot: getOutputSlots()) { inv.setItem(slot, BlockStorage.getInventory(b).getItemInSlot(slot)); } return inv; }