Fixed duping bug with imprinter again...
Well again i have fixed a few duping bugs with the imprinter. This time though i have made it a bit harder for it to break down. However, the issue could happen again with the current crafting system.
This commit is contained in:
parent
cac5f0d12a
commit
b0574b7f58
2 changed files with 45 additions and 32 deletions
|
@ -10,7 +10,6 @@ import net.minecraft.item.crafting.CraftingManager;
|
|||
import net.minecraft.item.crafting.IRecipe;
|
||||
import net.minecraft.item.crafting.ShapedRecipes;
|
||||
import net.minecraft.item.crafting.ShapelessRecipes;
|
||||
import net.minecraft.nbt.NBTTagCompound;
|
||||
import net.minecraft.tileentity.TileEntity;
|
||||
import net.minecraftforge.common.MinecraftForge;
|
||||
import net.minecraftforge.event.entity.player.PlayerDestroyItemEvent;
|
||||
|
@ -27,7 +26,7 @@ import dark.library.helpers.Pair;
|
|||
*/
|
||||
public class AutoCraftingManager
|
||||
{
|
||||
boolean doDebug = true;
|
||||
final static boolean doDebug = true;
|
||||
TileEntity craftingEntity;
|
||||
IInventory craftingInv;
|
||||
|
||||
|
@ -144,7 +143,10 @@ public class AutoCraftingManager
|
|||
|
||||
for (int slot = 0; slot < slots.length; slot++)
|
||||
{
|
||||
containingItems[slot] = inv.getStackInSlot(slots[slot]);
|
||||
if (inv.getStackInSlot(slots[slot]) != null)
|
||||
{
|
||||
containingItems[slot] = inv.getStackInSlot(slots[slot]).copy();
|
||||
}
|
||||
}
|
||||
|
||||
return containingItems;
|
||||
|
@ -164,14 +166,16 @@ public class AutoCraftingManager
|
|||
this.printDebug("ResourceChecker", "Looking for items");
|
||||
for (int i = 0; i < recipeItems.length && this.doDebug; i++)
|
||||
{
|
||||
this.printDebug("ResourceChecker", "ResourceChecker: Looking for " + recipeItems.toString());
|
||||
this.printDebug("ResourceChecker", "Looking for " + recipeItems.toString());
|
||||
}
|
||||
/**
|
||||
* The actual amount of resource required. Each ItemStack will only have stacksize of 1.
|
||||
*/
|
||||
ArrayList<ItemStack> actualResources = new ArrayList<ItemStack>();
|
||||
|
||||
int itemMatch = 0;
|
||||
int itemInList = 0;
|
||||
|
||||
for (Object obj : recipeItems)
|
||||
{
|
||||
itemInList++;
|
||||
|
@ -179,11 +183,12 @@ public class AutoCraftingManager
|
|||
{
|
||||
ItemStack recipeItem = (ItemStack) obj;
|
||||
actualResources.add(recipeItem.copy());
|
||||
|
||||
if (recipeItem != null)
|
||||
{
|
||||
this.printDebug("ResourceChecker", "Item0" + itemInList + " = " + recipeItem.toString());
|
||||
int match = this.doesItemExist(recipeItem, containingItems);
|
||||
if (match != -2)
|
||||
if (match >= 0)
|
||||
{
|
||||
containingItems[match] = this.decrStackSize(containingItems[match], recipeItem.stackSize);
|
||||
this.printDebug("ResourceChecker", "Match found @" + match);
|
||||
|
@ -211,8 +216,7 @@ public class AutoCraftingManager
|
|||
if (recipeItem != null)
|
||||
{
|
||||
int match = this.doesItemExist(recipeItem, containingItems);
|
||||
this.printDebug("ResourceChecker", "Item0" + itemInList + " = " + recipeItem.toString());
|
||||
if (match != -2)
|
||||
if (match >= 0)
|
||||
{
|
||||
containingItems[match] = this.decrStackSize(containingItems[match], recipeItem.stackSize);
|
||||
this.printDebug("ResourceChecker", "Match found @" + match);
|
||||
|
@ -226,11 +230,10 @@ public class AutoCraftingManager
|
|||
else
|
||||
{
|
||||
this.printDebug("ResourceChecker", "Item0" + itemInList + " = null");
|
||||
itemMatch++;
|
||||
}
|
||||
}
|
||||
boolean resourcesFound = itemMatch >= actualResources.size();
|
||||
this.printDebug("ResourceChecker", "Found " + actualResources.size() + " Items and " + itemMatch + " slot matches");
|
||||
this.printDebug("ResourceChecker", actualResources.size() + " items needed and " + itemMatch + " valid matches found");
|
||||
this.printDebug("ResourceChecker", "has all resources been found? /n A: " + resourcesFound);
|
||||
return resourcesFound ? actualResources : null;
|
||||
}
|
||||
|
@ -254,19 +257,20 @@ public class AutoCraftingManager
|
|||
{
|
||||
if (stack != null)
|
||||
{
|
||||
if (stack.stackSize <= amount)
|
||||
ItemStack itemStack = stack.copy();
|
||||
if (itemStack.stackSize <= amount)
|
||||
{
|
||||
return null;
|
||||
}
|
||||
else
|
||||
{
|
||||
stack = stack.splitStack(amount);
|
||||
itemStack.stackSize -= amount;
|
||||
|
||||
if (stack.stackSize == 0)
|
||||
if (itemStack.stackSize <= 0)
|
||||
{
|
||||
return null;
|
||||
}
|
||||
return stack;
|
||||
return itemStack;
|
||||
}
|
||||
}
|
||||
else
|
||||
|
@ -297,7 +301,7 @@ public class AutoCraftingManager
|
|||
if (checkStack != null)
|
||||
{
|
||||
this.printDebug("ResourceChecker", " -----Item in slot0" + i + " = " + checkStack.toString());
|
||||
if (areStacksEqual(recipeItem, checkStack))
|
||||
if (this.areStacksEqual(recipeItem, checkStack))
|
||||
{
|
||||
this.printDebug("ResourceChecker", "Found matching item " + checkStack.toString());
|
||||
return i;
|
||||
|
@ -328,7 +332,11 @@ public class AutoCraftingManager
|
|||
{
|
||||
return recipeItem.itemID == checkStack.itemID;
|
||||
}
|
||||
return recipeItem.isItemEqual(checkStack) || (recipeItem.itemID == checkStack.itemID && recipeItem.isItemStackDamageable() && !recipeItem.isItemDamaged());
|
||||
if (recipeItem.isItemStackDamageable())
|
||||
{
|
||||
return !recipeItem.isItemDamaged() && recipeItem.itemID == checkStack.itemID;
|
||||
}
|
||||
return recipeItem.isItemEqual(checkStack);
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -338,12 +346,13 @@ public class AutoCraftingManager
|
|||
* @param ammount - amount to consume
|
||||
* @return what is left of the itemStack if any
|
||||
*/
|
||||
public ItemStack consumeItem(ItemStack stack, int amount)
|
||||
public ItemStack consumeItem(ItemStack itemStack, int amount)
|
||||
{
|
||||
if (stack == null)
|
||||
if (itemStack == null)
|
||||
{
|
||||
return null;
|
||||
}
|
||||
ItemStack stack = itemStack.copy();
|
||||
if (stack.getItem().hasContainerItem())
|
||||
{
|
||||
ItemStack containerStack = stack.getItem().getContainerItemStack(stack);
|
||||
|
|
|
@ -51,6 +51,9 @@ public class TileEntityImprinter extends TileEntityAdvanced implements net.minec
|
|||
|
||||
public ItemStack[] imprinterMatrix = new ItemStack[3];
|
||||
public static final int[] imprinterSlots = { IMPRINTER_MATRIX_START, IMPRINTER_MATRIX_START + 1, IMPRINTER_MATRIX_START + 2 };
|
||||
int imprintInputSlot = 0;
|
||||
int imprintOutputSlot = 1;
|
||||
int craftingOutputSlot = 2;
|
||||
|
||||
/**
|
||||
* The Imprinter inventory containing slots.
|
||||
|
@ -260,18 +263,18 @@ public class TileEntityImprinter extends TileEntityAdvanced implements net.minec
|
|||
*/
|
||||
this.isImprinting = false;
|
||||
|
||||
if (this.isMatrixEmpty() && this.imprinterMatrix[0] != null && this.imprinterMatrix[1] != null)
|
||||
if (this.isMatrixEmpty() && this.imprinterMatrix[imprintInputSlot] != null && this.imprinterMatrix[1] != null)
|
||||
{
|
||||
if (this.imprinterMatrix[0].getItem() instanceof ItemImprinter)
|
||||
if (this.imprinterMatrix[imprintInputSlot].getItem() instanceof ItemImprinter)
|
||||
{
|
||||
ItemStack outputStack = this.imprinterMatrix[0].copy();
|
||||
ItemStack outputStack = this.imprinterMatrix[imprintInputSlot].copy();
|
||||
outputStack.stackSize = 1;
|
||||
ArrayList<ItemStack> filters = ItemImprinter.getFilters(outputStack);
|
||||
boolean filteringItemExists = false;
|
||||
|
||||
for (ItemStack filteredStack : filters)
|
||||
{
|
||||
if (filteredStack.isItemEqual(this.imprinterMatrix[1]))
|
||||
if (filteredStack.isItemEqual(this.imprinterMatrix[imprintOutputSlot]))
|
||||
{
|
||||
filters.remove(filteredStack);
|
||||
filteringItemExists = true;
|
||||
|
@ -281,18 +284,18 @@ public class TileEntityImprinter extends TileEntityAdvanced implements net.minec
|
|||
|
||||
if (!filteringItemExists)
|
||||
{
|
||||
filters.add(this.imprinterMatrix[1]);
|
||||
filters.add(this.imprinterMatrix[imprintOutputSlot]);
|
||||
}
|
||||
|
||||
ItemImprinter.setFilters(outputStack, filters);
|
||||
this.imprinterMatrix[2] = outputStack;
|
||||
this.imprinterMatrix[craftingOutputSlot] = outputStack;
|
||||
this.isImprinting = true;
|
||||
}
|
||||
}
|
||||
|
||||
if (!this.isImprinting)
|
||||
{
|
||||
this.imprinterMatrix[2] = null;
|
||||
this.imprinterMatrix[craftingOutputSlot] = null;
|
||||
|
||||
/**
|
||||
* Try to craft from crafting grid. If not possible, then craft from imprint.
|
||||
|
@ -310,15 +313,16 @@ public class TileEntityImprinter extends TileEntityAdvanced implements net.minec
|
|||
|
||||
if (matrixOutput != null && this.craftingManager.getIdealRecipe(matrixOutput) != null)
|
||||
{
|
||||
this.imprinterMatrix[2] = matrixOutput;
|
||||
System.out.println("Using crafting grid");
|
||||
this.imprinterMatrix[craftingOutputSlot] = matrixOutput;
|
||||
didCraft = true;
|
||||
}
|
||||
}
|
||||
|
||||
if (this.imprinterMatrix[0] != null && !didCraft)
|
||||
if (this.imprinterMatrix[imprintInputSlot] != null && !didCraft)
|
||||
{
|
||||
// System.out.println("Using imprint as grid");
|
||||
if (this.imprinterMatrix[0].getItem() instanceof ItemImprinter)
|
||||
System.out.println("Using imprint as grid");
|
||||
if (this.imprinterMatrix[imprintInputSlot].getItem() instanceof ItemImprinter)
|
||||
{
|
||||
|
||||
ArrayList<ItemStack> filters = ItemImprinter.getFilters(this.imprinterMatrix[0]);
|
||||
|
@ -338,7 +342,7 @@ public class TileEntityImprinter extends TileEntityAdvanced implements net.minec
|
|||
ItemStack recipeOutput = idealRecipe.getKey();
|
||||
if (recipeOutput != null & recipeOutput.stackSize > 0)
|
||||
{
|
||||
this.imprinterMatrix[2] = recipeOutput;
|
||||
this.imprinterMatrix[craftingOutputSlot] = recipeOutput;
|
||||
didCraft = true;
|
||||
break;
|
||||
}
|
||||
|
@ -350,7 +354,7 @@ public class TileEntityImprinter extends TileEntityAdvanced implements net.minec
|
|||
|
||||
if (!didCraft)
|
||||
{
|
||||
this.imprinterMatrix[2] = null;
|
||||
this.imprinterMatrix[craftingOutputSlot] = null;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -633,6 +637,6 @@ public class TileEntityImprinter extends TileEntityAdvanced implements net.minec
|
|||
@Override
|
||||
public int[] getCraftingInv()
|
||||
{
|
||||
return this.invSlots;
|
||||
return TileEntityImprinter.invSlots;
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Reference in a new issue