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);
}
}
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;
}
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);
}
}
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;
}
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;
}
Aggregations