Updated to ForestryMC/master

This commit is contained in:
Parker Young committed 2014-09-20 16:29:10 -04:00
commit c95c527fb4
22 files changed
+132 -94

No files matched your search

@@ -434,7 +434,9 @@ public class MachineCarpenter extends TilePowered implements ISidedInventory, IL
return false;
// Need at least one matched set
return StackUtils.containsSets(craftingInventory.getStacks(SLOT_CRAFTING_1, 9), accessibleInventory.getStacks(SLOT_INVENTORY_1, SLOT_INVENTORY_COUNT), null, true, false) > 0;
ItemStack[] set = craftingInventory.getStacks(SLOT_CRAFTING_1, 9);
ItemStack[] stock = accessibleInventory.getStacks(SLOT_INVENTORY_1, SLOT_INVENTORY_COUNT);
return StackUtils.containsSets(set, stock, true, false) > 0;
}
private boolean removeResources(Recipe recipe) {
@@ -84,7 +84,7 @@ public class MachineSqueezer extends TilePowered implements ISpecialInventory, I
}
public boolean matches(ItemStack[] res) {
return StackUtils.containsSets(resources, res, null, true, true) > 0;
return StackUtils.containsSets(resources, res, true, true) > 0;
}
}
@@ -461,10 +461,61 @@ public class TileWorktable extends TileBase implements ICrafter {
craftingInventory.setInventorySlotContents(SLOT_CRAFTING_RESULT, null);
}
private boolean validateResources() {
private boolean canCraftCurrentRecipe() {
if (currentRecipe == null)
return false;
// Need at least one matched set
ItemStack[] set = craftingInventory.getStacks(SLOT_CRAFTING_1, 9);
ItemStack[] stock = accessibleInventory.getStacks(SLOT_INVENTORY_1, SLOT_INVENTORY_COUNT);
return StackUtils.containsSets(set, stock, currentRecipe.getRecipeOutput(), true, true) > 0;
if (StackUtils.containsSets(set, stock, true, true) == 0)
return false;
// Check that it doesn't make a different recipe.
// For example:
// Wood Logs are all ore dictionary equivalent with each other,
// but an Oak Log shouldn't be able to make Ebony Wood Planks
// because it makes Oak Wood Planks using the same recipe.
// Strategy:
// Create a fake crafting inventory using items we have in stock
// in place of the ones in the saved crafting inventory.
// Check that the recipe it makes is the same as the currentRecipe.
InventoryCrafting crafting = new InventoryCrafting(DUMMY_CONTAINER, 3, 3);
InventoryAdapter recipeMatrix = currentRecipe.getMatrix();
ItemStack[] stockCopy = StackUtils.condenseStacks(stock);
for (int slot = 0; slot < recipeMatrix.getSizeInventory(); slot++) {
ItemStack recipeStack = recipeMatrix.getStackInSlot(slot);
if (recipeStack == null)
continue;
// Use crafting equivalent (not oredict) items first
for (ItemStack stockStack : stockCopy) {
if (stockStack.stackSize > 0 && StackUtils.isCraftingEquivalent(recipeStack, stockStack, false, false)) {
ItemStack stack = new ItemStack(stockStack.getItem(), 1, stockStack.getItemDamage());
stockStack.stackSize--;
crafting.setInventorySlotContents(slot, stack);
break;
}
}
// Use oredict items if crafting equivalent items aren't available
if (crafting.getStackInSlot(slot) == null) {
for (ItemStack stockStack : stockCopy) {
if (stockStack.stackSize > 0 && StackUtils.isCraftingEquivalent(recipeStack, stockStack, true, true)) {
ItemStack stack = new ItemStack(stockStack.getItem(), 1, stockStack.getItemDamage());
stockStack.stackSize--;
crafting.setInventorySlotContents(slot, stack);
break;
}
}
}
}
IRecipe recipe = RECIPE_BRIDGE.getRecipe(crafting, worldObj);
if (recipe == null)
return false;
return recipe.getRecipeOutput().isItemEqual(currentRecipe.getRecipeOutput());
}
private boolean removeResources(EntityPlayer player) {
@@ -474,7 +525,9 @@ public class TileWorktable extends TileBase implements ICrafter {
@Override
public boolean canTakeStack(int slotIndex) {
return validateResources();
if (slotIndex == SLOT_CRAFTING_RESULT)
return canCraftCurrentRecipe();
return true;
}
@Override