Search in sources :

Example 1 with LongItemStack

use of com.cjm721.overloaded.storage.stacks.intint.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.stacks.intint.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().isEmpty())
        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);
        dataUpdate.dataUpdated();
    }
    return toReturn;
}
Also used : LongItemStack(com.cjm721.overloaded.storage.stacks.intint.LongItemStack) Nonnull(javax.annotation.Nonnull)

Example 3 with LongItemStack

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

the class LongItemStorage method deserializeNBT.

@Override
public void deserializeNBT(CompoundNBT compound) {
    ItemStack storedItem = compound.contains("Item") ? ItemStack.of((CompoundNBT) compound.get("Item")) : null;
    if (storedItem != null) {
        long storedAmount = compound.contains("Count") ? compound.getLong("Count") : 0L;
        longItemStack = new LongItemStack(storedItem, storedAmount);
    }
}
Also used : CompoundNBT(net.minecraft.nbt.CompoundNBT) LongItemStack(com.cjm721.overloaded.storage.stacks.intint.LongItemStack) ItemStack(net.minecraft.item.ItemStack) LongItemStack(com.cjm721.overloaded.storage.stacks.intint.LongItemStack)

Example 4 with LongItemStack

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

the class BigIntItemStorage method take.

@Nonnull
@Override
public LongItemStack take(@Nonnull LongItemStack stack, boolean doAction) {
    if (storedItem.itemStack.isEmpty())
        return LongItemStack.EMPTY_STACK;
    long result = storedItem.amount.min(BigInteger.valueOf(stack.getAmount())).longValueExact();
    LongItemStack toReturn = new LongItemStack(storedItem.itemStack, result);
    if (doAction) {
        storedItem.amount = storedItem.amount.subtract(BigInteger.valueOf(result));
        if (storedItem.amount.equals(BigInteger.ZERO))
            storedItem.itemStack = ItemStack.EMPTY;
        dataUpdate.dataUpdated();
    }
    return toReturn;
}
Also used : LongItemStack(com.cjm721.overloaded.storage.stacks.intint.LongItemStack) Nonnull(javax.annotation.Nonnull)

Example 5 with LongItemStack

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

the class BigIntItemStorage method give.

@Nonnull
@Override
public LongItemStack give(@Nonnull LongItemStack stack, boolean doAction) {
    if (storedItem.itemStack.isEmpty()) {
        if (doAction) {
            storedItem = new BigIntItemStack(stack.getItemStack(), BigInteger.valueOf(stack.getAmount()));
            dataUpdate.dataUpdated();
        }
        return LongItemStack.EMPTY_STACK;
    }
    if (ItemHandlerHelper.canItemStacksStack(storedItem.itemStack, stack.getItemStack())) {
        if (doAction) {
            storedItem.amount = storedItem.amount.add(BigInteger.valueOf(stack.getAmount()));
            dataUpdate.dataUpdated();
        }
        return LongItemStack.EMPTY_STACK;
    }
    return stack;
}
Also used : BigIntItemStack(com.cjm721.overloaded.storage.stacks.bigint.BigIntItemStack) Nonnull(javax.annotation.Nonnull)

Aggregations

LongItemStack (com.cjm721.overloaded.storage.stacks.intint.LongItemStack)6 Nonnull (javax.annotation.Nonnull)6 ItemStack (net.minecraft.item.ItemStack)4 LongItemStack (com.cjm721.overloaded.storage.LongItemStack)1 BigIntItemStack (com.cjm721.overloaded.storage.stacks.bigint.BigIntItemStack)1 NumberUtil (com.cjm721.overloaded.util.NumberUtil)1 CompoundNBT (net.minecraft.nbt.CompoundNBT)1