use of net.minecraft.item.ItemStack in project LogisticsPipes by RS485.
the class AutoWorkbench method importRecipe.
@Override
public boolean importRecipe(TileEntity tile, ItemIdentifierInventory inventory) {
if (!(tile instanceof TileAutoWorkbench)) {
return false;
}
TileAutoWorkbench bench = (TileAutoWorkbench) tile;
ItemStack result = bench.craftMatrix.getRecipeOutput();
if (result == null) {
return false;
}
inventory.setInventorySlotContents(9, result);
// Import
for (int i = 0; i < bench.craftMatrix.getSizeInventory(); i++) {
if (i >= inventory.getSizeInventory() - 2) {
break;
}
final ItemStack newStack = bench.craftMatrix.getStackInSlot(i) == null ? null : bench.craftMatrix.getStackInSlot(i).copy();
if (newStack != null && newStack.stackSize > 1) {
newStack.stackSize = 1;
}
inventory.setInventorySlotContents(i, newStack);
}
inventory.compact_first(9);
return true;
}
use of net.minecraft.item.ItemStack in project LogisticsPipes by RS485.
the class ImmibisCraftingTableMk2 method importRecipe.
@Override
public boolean importRecipe(TileEntity tile, ItemIdentifierInventory inventory) {
try {
if (tileAutoCraftingMk2.isInstance(tile)) {
// Import recipeInputs
ItemStack[][] recipe = (ItemStack[][]) tileAutoCraftingMk2.getField("recipeInputs").get(tile);
// Not really a AutoCraftingInventory, but same content
InventoryCrafting tempCraftingInv = new InventoryCrafting(new Container() {
@Override
public boolean canInteractWith(EntityPlayer entityplayer) {
return false;
}
@Override
public void onCraftMatrixChanged(IInventory par1iInventory) {
}
}, 3, 3);
for (int i = 0; i < 9; i++) {
if (recipe[i].length > 0) {
tempCraftingInv.setInventorySlotContents(i, recipe[i][0]);
inventory.setInventorySlotContents(i, recipe[i][0]);
} else {
inventory.clearInventorySlotContents(i);
}
}
// Compact
int slotCount = 0;
for (int i = 0; i < 9; i++) {
ItemStack slotStack = inventory.getStackInSlot(i);
inventory.clearInventorySlotContents(i);
if (slotStack != null && slotStack.getItem() != null) {
int count = 1;
for (int j = i + 1; j < 9; j++) {
ItemStack tempStack = inventory.getStackInSlot(j);
if (tempStack != null && ItemIdentifier.get(slotStack).equals(ItemIdentifier.get(tempStack))) {
inventory.clearInventorySlotContents(j);
count++;
}
}
slotStack.stackSize = count;
inventory.setInventorySlotContents(slotCount, slotStack);
slotCount++;
}
}
ItemStack result = null;
for (IRecipe r : CraftingUtil.getRecipeList()) {
if (r.matches(tempCraftingInv, tile.getWorldObj())) {
result = r.getCraftingResult(tempCraftingInv);
break;
}
}
inventory.setInventorySlotContents(9, result);
return true;
}
} catch (IllegalArgumentException | NoSuchFieldException e) {
LogisticsPipes.log.fatal("Error while importing recipe from Tubestuff's AutoCraftingMk2");
e.printStackTrace();
} catch (Exception e) {
LogisticsPipes.log.error("Got a problem on ImmibisCraftingTableMk2 CraftingRecipeProvider:");
LogisticsPipes.log.error(e.getMessage());
}
return false;
}
use of net.minecraft.item.ItemStack in project LogisticsPipes by RS485.
the class SolderingStation method importRecipe.
@Override
public boolean importRecipe(TileEntity tile, ItemIdentifierInventory inventory) {
if (!(tile instanceof LogisticsSolderingTileEntity)) {
return false;
}
LogisticsSolderingTileEntity station = (LogisticsSolderingTileEntity) tile;
ItemStack result = station.getTargetForTaget();
if (result == null) {
return false;
}
inventory.setInventorySlotContents(9, result);
// Import
for (int i = 0; i < station.getRecipeForTaget().length; i++) {
if (i >= inventory.getSizeInventory() - 2) {
break;
}
final ItemStack newStack = station.getRecipeForTaget()[i] == null ? null : station.getRecipeForTaget()[i].copy();
inventory.setInventorySlotContents(i, newStack);
}
inventory.compact_first(9);
for (int i = 0; i < inventory.getSizeInventory() - 2; i++) {
if (inventory.getStackInSlot(i) != null) {
continue;
}
inventory.setInventorySlotContents(i, new ItemStack(Items.iron_ingot, 1));
break;
}
return true;
}
use of net.minecraft.item.ItemStack in project LogisticsPipes by RS485.
the class AssemblyTable method importRecipe.
@Override
public boolean importRecipe(TileEntity tile, ItemIdentifierInventory inventory) {
if (!(tile instanceof TileAssemblyTable)) {
return false;
}
TileAssemblyTable table = (TileAssemblyTable) tile;
//current pipe inputs/outputs
final ItemIdentifierInventory inputs = new ItemIdentifierInventory(inventory.getSizeInventory() - 2, "AssemblyTableDummyInv", 64, false);
for (int i = 0; i < inventory.getSizeInventory() - 2; i++) {
inputs.setInventorySlotContents(i, inventory.getIDStackInSlot(i));
}
ItemStack output = inventory.getStackInSlot(inventory.getSizeInventory() - 2);
//see if there's a recipe planned in the table that matches the current pipe settings, if yes take the next, otherwise take the first
FlexibleRecipe<ItemStack> firstRecipe = null;
FlexibleRecipe<ItemStack> nextRecipe = null;
boolean takeNext = false;
for (IFlexibleRecipe<ItemStack> r : AssemblyRecipeManager.INSTANCE.getRecipes()) {
if (!(r instanceof FlexibleRecipe)) {
continue;
}
if (!((FlexibleRecipe<ItemStack>) r).inputFluids.isEmpty()) {
continue;
}
if (table.isPlanned(r)) {
if (firstRecipe == null) {
firstRecipe = (FlexibleRecipe<ItemStack>) r;
}
if (takeNext) {
nextRecipe = (FlexibleRecipe<ItemStack>) r;
break;
}
if (output != null && ItemStack.areItemStacksEqual(output, ((FlexibleRecipe<ItemStack>) r).output)) {
if (((FlexibleRecipe<ItemStack>) r).canBeCrafted(new // Read Proxy to IInventory
IFlexibleCrafter() {
@Override
public int getCraftingItemStackSize() {
return inputs.getSizeInventory();
}
@Override
public ItemStack getCraftingItemStack(int paramInt) {
return inputs.getStackInSlot(paramInt);
}
@Override
public int getCraftingFluidStackSize() {
return 0;
}
@Override
public FluidStack getCraftingFluidStack(int paramInt) {
return null;
}
@Override
public ItemStack decrCraftingItemStack(int paramInt1, int paramInt2) {
return null;
}
@Override
public FluidStack decrCraftingFluidStack(int paramInt1, int paramInt2) {
return null;
}
})) {
takeNext = true;
}
}
}
}
if (nextRecipe == null) {
nextRecipe = firstRecipe;
}
if (nextRecipe == null) {
return false;
}
// Import
inventory.setInventorySlotContents(inventory.getSizeInventory() - 2, nextRecipe.output);
try {
for (int i = 0; i < inventory.getSizeInventory() - 2; i++) {
inventory.clearInventorySlotContents(i);
}
int i = 0;
for (Object input : nextRecipe.inputItems) {
ItemStack processed = null;
if (input instanceof String) {
List<ItemStack> ores = OreDictionary.getOres((String) input);
if (ores != null && ores.size() > 0) {
input = ores.get(0);
}
} else if (input instanceof ItemStack) {
processed = (ItemStack) input;
} else if (input instanceof Item) {
processed = new ItemStack((Item) input);
} else if (input instanceof Block) {
processed = new ItemStack((Block) input, 1, 0);
} else if (input instanceof Integer) {
processed = null;
} else {
throw new IllegalArgumentException("Unknown Object passed to recipe!");
}
if (processed != null) {
inventory.setInventorySlotContents(i, processed);
++i;
}
}
} catch (ClassCastException e) {
// TODO: make it show a nice error or
// remove this hack altogether.
}
// Compact
inventory.compact_first(9);
return true;
}
use of net.minecraft.item.ItemStack in project LogisticsPipes by RS485.
the class AssemblyAdvancedWorkbench method importRecipe.
@Override
public boolean importRecipe(TileEntity tile, ItemIdentifierInventory inventory) {
if (!(tile instanceof TileAdvancedCraftingTable)) {
return false;
}
TileAdvancedCraftingTable bench = (TileAdvancedCraftingTable) tile;
ItemStack result = bench.getOutputSlot().getStackInSlot(0);
if (result == null) {
return false;
}
inventory.setInventorySlotContents(9, result);
// Import
for (int i = 0; i < bench.getCraftingSlots().getSizeInventory(); i++) {
if (i >= inventory.getSizeInventory() - 2) {
break;
}
final ItemStack newStack = bench.getCraftingSlots().getStackInSlot(i) == null ? null : bench.getCraftingSlots().getStackInSlot(i).copy();
inventory.setInventorySlotContents(i, newStack);
}
// Compact
for (int i = 0; i < inventory.getSizeInventory() - 2; i++) {
final ItemIdentifierStack stackInSlot = inventory.getIDStackInSlot(i);
if (stackInSlot == null) {
continue;
}
final ItemIdentifier itemInSlot = stackInSlot.getItem();
for (int j = i + 1; j < inventory.getSizeInventory() - 2; j++) {
final ItemIdentifierStack stackInOtherSlot = inventory.getIDStackInSlot(j);
if (stackInOtherSlot == null) {
continue;
}
if (itemInSlot.equals(stackInOtherSlot.getItem())) {
stackInSlot.setStackSize(stackInSlot.getStackSize() + stackInOtherSlot.getStackSize());
inventory.setInventorySlotContents(i, stackInSlot);
inventory.clearInventorySlotContents(j);
}
}
}
for (int i = 0; i < inventory.getSizeInventory() - 2; i++) {
if (inventory.getStackInSlot(i) != null) {
continue;
}
for (int j = i + 1; j < inventory.getSizeInventory() - 2; j++) {
if (inventory.getStackInSlot(j) == null) {
continue;
}
inventory.setInventorySlotContents(i, inventory.getIDStackInSlot(j));
inventory.clearInventorySlotContents(j);
break;
}
}
return true;
}
Aggregations