use of net.mcft.copy.betterstorage.misc.ItemIdentifier in project BetterStorage by copygirl.
the class InventoryCratePlayerView method decrStackSize.
@Override
public ItemStack decrStackSize(int slot, int amount) {
ItemStack stack = getStackInSlot(slot);
if (stack == null)
return null;
amount = Math.min(amount, stack.stackSize);
ItemIdentifier item = new ItemIdentifier(stack);
getMapData(item).itemCount -= amount;
stack.stackSize -= amount;
if (stack.stackSize <= 0)
tempContents[slot] = null;
ignoreModifiedItems = true;
ItemStack result = data.removeItems(item, amount);
ignoreModifiedItems = false;
if (tempContents[slot] == null)
onSlotEmptied(slot);
return result;
}
use of net.mcft.copy.betterstorage.misc.ItemIdentifier in project BetterStorage by copygirl.
the class InventoryCratePlayerView method onSlotEmptied.
private void onSlotEmptied(int slot) {
int emptySlots = 0;
for (int s = 0; s < tempContents.length; s++) if (tempContents[s] == null)
emptySlots++;
if (emptySlots <= data.getFreeSlots())
return;
for (ItemStack stack : data.getContents().getItems()) {
ItemIdentifier item = new ItemIdentifier(stack);
MapData itemData = getMapData(item);
int count = (stack.stackSize - itemData.itemCount);
if (count <= 0)
continue;
setItemsInSlot(slot, item, itemData, count);
}
}
use of net.mcft.copy.betterstorage.misc.ItemIdentifier in project BetterStorage by copygirl.
the class CratePileData method fromCompound.
public static CratePileData fromCompound(CratePileCollection collection, int crateId, NBTTagCompound compound) {
int numCrates = compound.getShort("numCrates");
CratePileData pileData = new CratePileData(collection, crateId, numCrates);
NBTTagList stacks = compound.getTagList("stacks", NBT.TAG_COMPOUND);
for (int j = 0; j < stacks.tagCount(); j++) {
NBTTagCompound stackCompound = stacks.getCompoundTagAt(j);
Item item = Item.getItemById(stackCompound.getShort("id"));
int count = stackCompound.getInteger("Count");
int damage = stackCompound.getShort("Damage");
ItemStack stack = new ItemStack(item, count, damage);
if (stackCompound.hasKey("tag"))
stack.stackTagCompound = stackCompound.getCompoundTag("tag");
if (stack.getItem() != null)
pileData.getContents().set(new ItemIdentifier(stack), stack.stackSize);
}
if (compound.hasKey("map"))
pileData.map = CratePileMap.fromCompound(compound.getCompoundTag("map"));
return pileData;
}
use of net.mcft.copy.betterstorage.misc.ItemIdentifier in project BetterStorage by copygirl.
the class CratePileData method addItems.
// Adding items
/** Tries to add a stack to the contents. <br>
* Returns what could not be added, null if there was no overflow. */
public ItemStack addItems(ItemStack stack) {
if (stack == null)
return null;
ItemStack overflow = null;
int space = getSpaceForItem(stack);
if (space > 0) {
if (space < stack.stackSize)
overflow = stack.splitStack(stack.stackSize - space);
ItemIdentifier item = new ItemIdentifier(stack);
getContents().set(item, getContents().get(item) + stack.stackSize);
for (ICrateWatcher watcher : watchers) watcher.onCrateItemsModified(stack);
} else
overflow = stack;
markDirty();
return overflow;
}
use of net.mcft.copy.betterstorage.misc.ItemIdentifier in project BetterStorage by copygirl.
the class InventoryCrateBlockView method decrStackSize.
@Override
public ItemStack decrStackSize(int slot, int amount) {
ItemStack stack = getStackInSlot(slot);
if (stack == null)
return null;
amount = Math.min(amount, stack.stackSize);
if (stack.stackSize <= amount)
originalStacks[slot - 1] = exposedStacks[slot - 1] = null;
else
originalStacks[slot - 1].stackSize = exposedStacks[slot - 1].stackSize -= amount;
isModifying = true;
ItemStack result = data.removeItems(new ItemIdentifier(stack), amount);
isModifying = false;
return result;
}
Aggregations