Search in sources :

Example 1 with ItemIdentifier

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;
}
Also used : ItemIdentifier(net.mcft.copy.betterstorage.misc.ItemIdentifier) ItemStack(net.minecraft.item.ItemStack)

Example 2 with ItemIdentifier

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);
    }
}
Also used : ItemIdentifier(net.mcft.copy.betterstorage.misc.ItemIdentifier) ItemStack(net.minecraft.item.ItemStack)

Example 3 with ItemIdentifier

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;
}
Also used : NBTTagList(net.minecraft.nbt.NBTTagList) Item(net.minecraft.item.Item) ItemIdentifier(net.mcft.copy.betterstorage.misc.ItemIdentifier) NBTTagCompound(net.minecraft.nbt.NBTTagCompound) ItemStack(net.minecraft.item.ItemStack)

Example 4 with ItemIdentifier

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;
}
Also used : ItemIdentifier(net.mcft.copy.betterstorage.misc.ItemIdentifier) ICrateWatcher(net.mcft.copy.betterstorage.api.crate.ICrateWatcher) ItemStack(net.minecraft.item.ItemStack)

Example 5 with ItemIdentifier

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;
}
Also used : ItemIdentifier(net.mcft.copy.betterstorage.misc.ItemIdentifier) ItemStack(net.minecraft.item.ItemStack)

Aggregations

ItemIdentifier (net.mcft.copy.betterstorage.misc.ItemIdentifier)7 ItemStack (net.minecraft.item.ItemStack)7 LinkedList (java.util.LinkedList)1 ICrateWatcher (net.mcft.copy.betterstorage.api.crate.ICrateWatcher)1 Item (net.minecraft.item.Item)1 NBTTagCompound (net.minecraft.nbt.NBTTagCompound)1 NBTTagList (net.minecraft.nbt.NBTTagList)1