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