Search in sources :

Example 1 with LongItemStack

use of com.cjm721.overloaded.storage.LongItemStack in project Overloaded by CJ-MC-Mods.

the class LongItemStorage method readFromNBT.

@Override
public void readFromNBT(NBTTagCompound compound) {
    ItemStack storedItem = compound.hasKey("Item") ? new ItemStack(compound.getCompoundTag("Item")) : null;
    if (storedItem != null) {
        long storedAmount = compound.hasKey("Count") ? compound.getLong("Count") : 0L;
        longItemStack = new LongItemStack(storedItem, storedAmount);
    }
}
Also used : ItemStack(net.minecraft.item.ItemStack) LongItemStack(com.cjm721.overloaded.storage.LongItemStack) LongItemStack(com.cjm721.overloaded.storage.LongItemStack)

Example 2 with LongItemStack

use of com.cjm721.overloaded.storage.LongItemStack in project Overloaded by CJ-MC-Mods.

the class LongItemStorage method take.

@Nonnull
@Override
public LongItemStack take(@Nonnull LongItemStack stack, boolean doAction) {
    if (longItemStack.getItemStack() == null)
        return LongItemStack.EMPTY_STACK;
    long result = Math.min(stack.getAmount(), longItemStack.getAmount());
    LongItemStack toReturn = new LongItemStack(longItemStack.getItemStack(), result);
    if (doAction) {
        longItemStack.removeAmount(result);
        if (longItemStack.getAmount() == 0L)
            longItemStack.setItemStack(ItemStack.EMPTY);
    }
    return toReturn;
}
Also used : LongItemStack(com.cjm721.overloaded.storage.LongItemStack) Nonnull(javax.annotation.Nonnull)

Example 3 with LongItemStack

use of com.cjm721.overloaded.storage.LongItemStack in project Overloaded by CJ-MC-Mods.

the class LongItemStorage method extractItem.

/**
     * Extracts an ItemStack from the given slot. The returned value must be null
     * if nothing is extracted, otherwise it's stack size must not be greater than amount or the
     * itemstacks getMaxStackSize().
     *
     * @param slot     Slot to extract from.
     * @param amount   Amount to extract (may be greater than the current stacks max limit)
     * @param simulate If true, the extraction is only simulated
     * @return ItemStack extracted from the slot, must be null, if nothing can be extracted
     **/
@Override
@Nonnull
public ItemStack extractItem(int slot, int amount, boolean simulate) {
    LongItemStack result = take(new LongItemStack(ItemStack.EMPTY, amount), !simulate);
    if (result.getAmount() == 0L) {
        return ItemStack.EMPTY;
    }
    ItemStack toReturn = result.getItemStack().copy();
    toReturn.setCount((int) result.getAmount());
    return toReturn;
}
Also used : ItemStack(net.minecraft.item.ItemStack) LongItemStack(com.cjm721.overloaded.storage.LongItemStack) LongItemStack(com.cjm721.overloaded.storage.LongItemStack) Nonnull(javax.annotation.Nonnull)

Example 4 with LongItemStack

use of com.cjm721.overloaded.storage.LongItemStack in project Overloaded by CJ-MC-Mods.

the class LongItemStorage method insertItem.

/**
     * Inserts an ItemStack into the given slot and return the remainder.
     * The ItemStack should not be modified in this function!
     * Note: This behaviour is subtly different from IFluidHandlers.fill()
     *
     * @param slot     Slot to insert into.
     * @param stack    ItemStack to insert.
     * @param simulate If true, the insertion is only simulated
     * @return The remaining ItemStack that was not inserted (if the entire stack is accepted, then return null).
     * May be the same as the input ItemStack if unchanged, otherwise a new ItemStack.
     **/
@Override
@Nonnull
public ItemStack insertItem(int slot, @Nonnull ItemStack stack, boolean simulate) {
    LongItemStack result = give(new LongItemStack(stack, stack.getCount()), !simulate);
    if (result.getAmount() == 0) {
        return ItemStack.EMPTY;
    }
    ItemStack toReturn = stack.copy();
    toReturn.setCount((int) result.getAmount());
    return toReturn;
}
Also used : ItemStack(net.minecraft.item.ItemStack) LongItemStack(com.cjm721.overloaded.storage.LongItemStack) LongItemStack(com.cjm721.overloaded.storage.LongItemStack) Nonnull(javax.annotation.Nonnull)

Aggregations

LongItemStack (com.cjm721.overloaded.storage.LongItemStack)4 Nonnull (javax.annotation.Nonnull)3 ItemStack (net.minecraft.item.ItemStack)3