Search in sources :

Example 1 with WildItemStack

use of com.bgsoftware.wildchests.objects.inventory.WildItemStack in project WildChests by BG-Software-LLC.

the class WRegularChest method getWildContents.

@Override
public WildItemStack<?, ?>[] getWildContents() {
    WildItemStack<?, ?>[] contents = new WildItemStack[0];
    int pagesAmount = getPagesAmount();
    if (pagesAmount == 0)
        return contents;
    for (int page = 0; page < pagesAmount; page++) {
        CraftWildInventory inventory = inventories.get(page);
        int oldLength = contents.length;
        contents = Arrays.copyOf(contents, contents.length + inventory.getSize());
        System.arraycopy(inventory.getWildContents(), 0, contents, oldLength, inventory.getSize());
    }
    return contents;
}
Also used : WildItemStack(com.bgsoftware.wildchests.objects.inventory.WildItemStack) CraftWildInventory(com.bgsoftware.wildchests.objects.inventory.CraftWildInventory)

Example 2 with WildItemStack

use of com.bgsoftware.wildchests.objects.inventory.WildItemStack in project WildChests by BG-Software-LLC.

the class WStorageChest method setItem.

@Override
public void setItem(int i, WildItemStack<?, ?> itemStack) {
    ItemStack storageItem = contents[1].getCraftItemStack();
    boolean takeItemCheckSlot = this.takeItemCheckSlot != null && this.takeItemCheckSlot == i;
    this.takeItemCheckSlot = null;
    if (itemStack == null || itemStack.getCraftItemStack().getType() == Material.AIR) {
        // If other plugins set the #1 slot to AIR, then they want to subtract the amount that they received before.
        if (i < 0 || i == 1) {
            if (amount.compareTo(BigInteger.ONE) == 0) {
                setItemStack(null);
                setAmount(BigInteger.ZERO);
            } else {
                BigInteger itemAmount = amount.min(BigInteger.valueOf(maxStackSize));
                setAmount(amount.subtract(itemAmount));
            }
        }
    } else {
        if (storageItem.getType() == Material.AIR) {
            setItemStack(itemStack.getCraftItemStack().clone());
        } else if (!takeItemCheckSlot && !canPlaceItemThroughFace(itemStack.getCraftItemStack())) {
            ItemUtils.dropItem(getLocation(), itemStack.getCraftItemStack());
            return;
        }
        int itemAmount = itemStack.getCraftItemStack().getAmount();
        int originalAmount = amount.min(BigInteger.valueOf(maxStackSize)).intValue();
        /* The slot -2 is used to pull items from the chest with hoppers.
               The slot -1 is used to push items into the chest with hoppers.
               The slot 0 is used to push items into the chest by other plugins.
               The slot 1 is used to pull items from the chest by other plugins.
             */
        if (i == 1 || i == -2 || (i != -1 && i != 2 && i != 0 && itemAmount < originalAmount && amount.intValue() < maxStackSize)) {
            setAmount(amount.subtract(BigInteger.valueOf(originalAmount - itemAmount)));
        } else {
            setAmount(amount.add(BigInteger.valueOf(itemAmount)));
        }
    }
    update();
}
Also used : BigInteger(java.math.BigInteger) ItemStack(org.bukkit.inventory.ItemStack) WildItemStack(com.bgsoftware.wildchests.objects.inventory.WildItemStack)

Aggregations

WildItemStack (com.bgsoftware.wildchests.objects.inventory.WildItemStack)2 CraftWildInventory (com.bgsoftware.wildchests.objects.inventory.CraftWildInventory)1 BigInteger (java.math.BigInteger)1 ItemStack (org.bukkit.inventory.ItemStack)1