use of net.minecraft.inventory.IInventory in project BluePower by Qmunity.
the class ItemSeedBag method getItemDamageForDisplay.
public int getItemDamageForDisplay(ItemStack stack) {
int items = 0;
IInventory seedBagInventory = InventoryItem.getItemInventory(stack, "Seed Bag", 9);
seedBagInventory.openInventory();
for (int i = 0; i < seedBagInventory.getSizeInventory(); i++) {
ItemStack is = seedBagInventory.getStackInSlot(i);
if (is != null) {
items += is.stackSize;
}
}
return items;
}
use of net.minecraft.inventory.IInventory in project BluePower by Qmunity.
the class IOHelper method extract.
/**
* Retrieves an item from the specified inventory. This item can be specified.
*
* @param tile
* @param direction
* @param requestedStack
* @param useItemCount
* if true, it'll only retrieve the stack of the exact item count given. it'll look in multiple slots of the inventory. if false, the
* first matching stack, ignoring item count, will be returned.
* @param simulate
* @param fuzzySetting
* ,
* @return
*/
public static ItemStack extract(TileEntity tile, ForgeDirection direction, ItemStack requestedStack, boolean useItemCount, boolean simulate, int fuzzySetting) {
if (requestedStack == null)
return requestedStack;
IInventory inv = getInventoryForTE(tile);
if (inv != null) {
int[] accessibleSlots;
if (inv instanceof ISidedInventory) {
accessibleSlots = ((ISidedInventory) inv).getAccessibleSlotsFromSide(direction.ordinal());
} else {
accessibleSlots = new int[inv.getSizeInventory()];
for (int i = 0; i < accessibleSlots.length; i++) accessibleSlots[i] = i;
}
int itemsFound = 0;
for (int slot : accessibleSlots) {
ItemStack stack = inv.getStackInSlot(slot);
if (stack != null && ItemStackHelper.areStacksEqual(stack, requestedStack, fuzzySetting) && IOHelper.canExtractItemFromInventory(inv, requestedStack, slot, direction.ordinal())) {
if (!useItemCount) {
if (!simulate) {
inv.setInventorySlotContents(slot, null);
}
return stack;
}
itemsFound += stack.stackSize;
}
}
if (itemsFound >= requestedStack.stackSize) {
ItemStack exportedStack = null;
int itemsNeeded = requestedStack.stackSize;
for (int slot : accessibleSlots) {
ItemStack stack = inv.getStackInSlot(slot);
if (stack != null && ItemStackHelper.areStacksEqual(stack, requestedStack, fuzzySetting) && IOHelper.canExtractItemFromInventory(inv, requestedStack, slot, direction.ordinal())) {
int itemsSubstracted = Math.min(itemsNeeded, stack.stackSize);
if (itemsSubstracted > 0)
exportedStack = stack;
itemsNeeded -= itemsSubstracted;
if (!simulate) {
stack.stackSize -= itemsSubstracted;
if (stack.stackSize == 0)
inv.setInventorySlotContents(slot, null);
tile.markDirty();
}
}
}
exportedStack = exportedStack.copy();
exportedStack.stackSize = requestedStack.stackSize;
return exportedStack;
}
}
return null;
}
use of net.minecraft.inventory.IInventory in project BluePower by Qmunity.
the class IOHelper method extractOneItem.
public static ItemStack extractOneItem(TileEntity tile, ForgeDirection dir) {
IInventory inv = getInventoryForTE(tile);
if (inv != null) {
int[] accessibleSlots;
if (inv instanceof ISidedInventory) {
accessibleSlots = ((ISidedInventory) inv).getAccessibleSlotsFromSide(dir.ordinal());
} else {
accessibleSlots = new int[inv.getSizeInventory()];
for (int i = 0; i < accessibleSlots.length; i++) accessibleSlots[i] = i;
}
for (int slot : accessibleSlots) {
ItemStack stack = inv.getStackInSlot(slot);
ItemStack retrievingStack = stack == null ? null : stack.copy().splitStack(1);
if (stack != null && IOHelper.canExtractItemFromInventory(inv, retrievingStack, slot, dir.ordinal())) {
ItemStack ret = stack.splitStack(1);
if (stack.stackSize == 0)
inv.setInventorySlotContents(slot, null);
tile.markDirty();
return ret;
}
}
}
return null;
}
use of net.minecraft.inventory.IInventory in project BluePower by Qmunity.
the class IOHelper method getItemCount.
public static int getItemCount(ItemStack type, TileEntity inv, ForgeDirection side, int fuzzySetting) {
IInventory inventory = getInventoryForTE(inv);
int[] slots = getAccessibleSlotsForInventory(inventory, side);
int count = 0;
for (int slot : slots) {
ItemStack invStack = inventory.getStackInSlot(slot);
if (invStack != null) {
if (ItemStackHelper.areStacksEqual(invStack, type, fuzzySetting)) {
count += invStack.stackSize;
}
}
}
return count;
}
use of net.minecraft.inventory.IInventory in project BluePower by Qmunity.
the class IOHelper method dropInventory.
public static void dropInventory(World world, int x, int y, int z) {
TileEntity tileEntity = world.getTileEntity(x, y, z);
if (!(tileEntity instanceof IInventory)) {
return;
}
IInventory inventory = (IInventory) tileEntity;
for (int i = 0; i < inventory.getSizeInventory(); i++) {
ItemStack itemStack = inventory.getStackInSlot(i);
if (itemStack != null && itemStack.stackSize > 0) {
spawnItemInWorld(world, itemStack, x, y, z);
}
}
}
Aggregations