use of net.minecraft.item.ItemStack in project BluePower by Qmunity.
the class SlotCircuitTableCrafting method getCraftingComponents.
private static List<ItemStack> getCraftingComponents(ItemStack gate) {
List<ItemStack> requiredItems = new ArrayList<ItemStack>();
List recipeList = CraftingManager.getInstance().getRecipeList();
for (IRecipe r : (List<IRecipe>) recipeList) {
ItemStack result = r.getRecipeOutput();
if (result != null && result.isItemEqual(gate)) {
if (r instanceof ShapedOreRecipe) {
ShapedOreRecipe recipe = (ShapedOreRecipe) r;
for (Object o : recipe.getInput()) {
if (o != null) {
ItemStack stack;
if (o instanceof ItemStack) {
stack = (ItemStack) o;
} else {
List<ItemStack> list = (List<ItemStack>) o;
stack = list.size() > 0 ? list.get(0) : null;
}
if (stack != null) {
boolean needsAdding = true;
for (ItemStack listStack : requiredItems) {
if (listStack.isItemEqual(stack)) {
listStack.stackSize++;
needsAdding = false;
break;
}
}
if (needsAdding)
requiredItems.add(stack.copy());
}
}
}
return requiredItems;
} else if (r instanceof ShapedRecipes) {
ShapedRecipes recipe = (ShapedRecipes) r;
for (ItemStack stack : recipe.recipeItems) {
if (stack != null) {
boolean needsAdding = true;
for (ItemStack listStack : requiredItems) {
if (listStack.isItemEqual(stack)) {
listStack.stackSize++;
needsAdding = false;
break;
}
}
if (needsAdding)
requiredItems.add(stack.copy());
}
}
return requiredItems;
}
}
}
return new ArrayList<ItemStack>();
}
use of net.minecraft.item.ItemStack in project BluePower by Qmunity.
the class IOHelper method extract.
public static ItemStack extract(IInventory inventory, ForgeDirection direction, boolean simulate) {
if (inventory instanceof ISidedInventory) {
ISidedInventory isidedinventory = (ISidedInventory) inventory;
int[] accessibleSlotsFromSide = isidedinventory.getAccessibleSlotsFromSide(direction.ordinal());
for (int anAccessibleSlotsFromSide : accessibleSlotsFromSide) {
ItemStack stack = extract(inventory, direction, anAccessibleSlotsFromSide, simulate);
if (stack != null)
return stack;
}
} else {
int j = inventory.getSizeInventory();
for (int k = 0; k < j; ++k) {
ItemStack stack = extract(inventory, direction, k, simulate);
if (stack != null)
return stack;
}
}
return null;
}
use of net.minecraft.item.ItemStack 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.item.ItemStack 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.item.ItemStack 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;
}
Aggregations