use of org.bukkit.inventory.ItemStack in project Glowstone by GlowstoneMC.
the class GlowDispenser method placeInDispenser.
public ItemStack placeInDispenser(ItemStack toPlace) {
Inventory inv = getInventory();
Map<Integer, ItemStack> map = inv.addItem(toPlace);
return map.isEmpty() ? null : map.get(0);
}
use of org.bukkit.inventory.ItemStack in project Glowstone by GlowstoneMC.
the class GlowJukebox method setPlaying.
@Override
public void setPlaying(Material record) {
int id = 0;
if (record == null || record == Material.AIR) {
playing = null;
} else {
playing = new ItemStack(record);
id = record.getId();
}
Collection<GlowPlayer> players = getWorld().getRawPlayers();
for (GlowPlayer player : players) {
player.playEffect(getLocation(), Effect.RECORD_PLAY, id);
}
setRawData((byte) (id > 0 ? 1 : 0));
}
use of org.bukkit.inventory.ItemStack in project SpaciousLib by anhcraft.
the class InteractItem method interact.
@EventHandler(priority = EventPriority.MONITOR)
public void interact(InventoryClickEvent event) {
Player player = (Player) event.getWhoClicked();
Inventory inventory = _InventoryClickEvent.getInventory(event);
ClickType type = event.getClick();
if (inventory != null && data.containsKey(inventory)) {
event.setCancelled(true);
event.setResult(Event.Result.DENY);
ItemStack item = event.getCurrentItem();
if (item != null && !item.getType().equals(Material.AIR) && data.get(inventory).containsKey(item)) {
HashMap<ItemStack, InteractItemRunnable> items = data.get(inventory);
items.get(item).run(player, item, type, event.getSlot());
data.put(inventory, items);
}
}
}
use of org.bukkit.inventory.ItemStack in project Glowstone by GlowstoneMC.
the class GlowHumanEntity method dropUnusedInputs.
// Drop items left in crafting area.
private void dropUnusedInputs() {
for (int i = 0; i < getTopInventory().getSlots().size(); i++) {
ItemStack itemStack = getOpenInventory().getItem(i);
if (InventoryUtil.isEmpty(itemStack)) {
continue;
}
if (isDroppableCraftingSlot(i)) {
drop(itemStack);
getOpenInventory().setItem(i, InventoryUtil.createEmptyStack());
}
}
}
use of org.bukkit.inventory.ItemStack in project Glowstone by GlowstoneMC.
the class RandomItemsContent method fillContainer.
public boolean fillContainer(Random random, DirectionalContainer container, 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;
}
Aggregations