Search in sources :

Example 41 with ItemStack

use of net.minecraft.item.ItemStack in project compactsolars by cpw.

the class TileEntityCompactSolar method getStackInSlotOnClosing.

@Override
public ItemStack getStackInSlotOnClosing(int var1) {
    if (this.inventory[var1] != null) {
        ItemStack var2 = this.inventory[var1];
        this.inventory[var1] = null;
        return var2;
    } else {
        return null;
    }
}
Also used : ItemStack(net.minecraft.item.ItemStack)

Example 42 with ItemStack

use of net.minecraft.item.ItemStack in project BetterStorage by copygirl.

the class CrateItems method set.

/** Sets the amount of items of this type. <br>
	 *  If amount > 0 and item was previously not present, adds the item. <br>
	 *  If amount <= 0 and item was previously present, removes the item.
	 *  Automatically updates the number of total stacks
	 *  and marks the weighted map as dirty if necessary. */
public void set(ItemIdentifier item, int amount) {
    ItemStack stack = itemsMap.get(item);
    int stacksBefore, stacksAfter;
    if (stack != null) {
        if (amount == stack.stackSize)
            return;
        stacksBefore = StackUtils.calcNumStacks(stack);
        if (amount > 0) {
            stack.stackSize = amount;
            stacksAfter = StackUtils.calcNumStacks(stack);
        } else {
            stacksAfter = 0;
            itemsMap.remove(item);
        }
    } else if (amount > 0) {
        stack = item.createStack(amount);
        stacksBefore = 0;
        stacksAfter = StackUtils.calcNumStacks(stack);
        itemsMap.put(item, stack);
    } else
        return;
    if (stacksBefore != stacksAfter) {
        totalStacks += (stacksAfter - stacksBefore);
        weightedMapDirty = true;
    }
}
Also used : ItemStack(net.minecraft.item.ItemStack)

Example 43 with ItemStack

use of net.minecraft.item.ItemStack in project BetterStorage by copygirl.

the class StackUtils method getStackContents.

public static ItemStack[] getStackContents(ItemStack stack, int size) {
    ItemStack[] contents = new ItemStack[size];
    NBTTagCompound compound = stack.getTagCompound();
    if (compound != null && compound.hasKey("Items"))
        NbtUtils.readItems(contents, compound.getTagList("Items", NBT.TAG_COMPOUND));
    return contents;
}
Also used : NBTTagCompound(net.minecraft.nbt.NBTTagCompound) ItemStack(net.minecraft.item.ItemStack)

Example 44 with ItemStack

use of net.minecraft.item.ItemStack in project BetterStorage by copygirl.

the class CrateItems method getWeightedMap.

private NavigableMap<Integer, ItemStack> getWeightedMap() {
    if (weightedMapDirty) {
        weightedMap.clear();
        int stacks = 0;
        for (ItemStack stack : getItems()) weightedMap.put((stacks += StackUtils.calcNumStacks(stack)), stack);
    }
    return weightedMap;
}
Also used : ItemStack(net.minecraft.item.ItemStack)

Example 45 with ItemStack

use of net.minecraft.item.ItemStack in project BetterStorage by copygirl.

the class CratePileData method removeItems.

// Removing items
/** Removes and returns a specific amount of items. <br>
	 *  Returns less than the requested amount when there's
	 *  not enough, or null if there's none at all. */
public ItemStack removeItems(ItemIdentifier item, int amount) {
    int currentAmount = getContents().get(item);
    amount = Math.min(amount, currentAmount);
    if (amount <= 0)
        return null;
    getContents().set(item, currentAmount - amount);
    ItemStack removedStack = item.createStack(-amount);
    for (ICrateWatcher watcher : watchers) watcher.onCrateItemsModified(removedStack);
    markDirty();
    return item.createStack(amount);
}
Also used : ICrateWatcher(net.mcft.copy.betterstorage.api.crate.ICrateWatcher) ItemStack(net.minecraft.item.ItemStack)

Aggregations

ItemStack (net.minecraft.item.ItemStack)2512 NBTTagCompound (net.minecraft.nbt.NBTTagCompound)250 ArrayList (java.util.ArrayList)244 EntityItem (net.minecraft.entity.item.EntityItem)170 Slot (net.minecraft.inventory.Slot)164 TileEntity (net.minecraft.tileentity.TileEntity)155 EntityPlayer (net.minecraft.entity.player.EntityPlayer)153 Block (net.minecraft.block.Block)148 Item (net.minecraft.item.Item)118 BlockPos (net.minecraft.util.math.BlockPos)83 NBTTagList (net.minecraft.nbt.NBTTagList)74 IInventory (net.minecraft.inventory.IInventory)73 IBlockState (net.minecraft.block.state.IBlockState)70 SubscribeEvent (net.minecraftforge.fml.common.eventhandler.SubscribeEvent)67 FluidStack (net.minecraftforge.fluids.FluidStack)63 ShapedOreRecipe (net.minecraftforge.oredict.ShapedOreRecipe)63 World (net.minecraft.world.World)56 List (java.util.List)55 ResourceLocation (net.minecraft.util.ResourceLocation)50 Entity (net.minecraft.entity.Entity)47