diff --git a/src/main/java/forestry/core/recipes/RecipeUtil.java b/src/main/java/forestry/core/recipes/RecipeUtil.java index d842d639b..f066f2ef3 100644 --- a/src/main/java/forestry/core/recipes/RecipeUtil.java +++ b/src/main/java/forestry/core/recipes/RecipeUtil.java @@ -99,7 +99,6 @@ public abstract class RecipeUtil { if (ItemStackUtil.containsSets(recipeItems, availableItems, true, true) == 0) { return null; } - // Check that it doesn't make a different recipe. // For example: // Wood Logs are all ore dictionary equivalent with each other, @@ -140,7 +139,6 @@ public abstract class RecipeUtil { } } } - List outputs = findMatchingRecipes(crafting, world); if (!ItemStackUtil.containsItemStack(outputs, recipeOutput)) { return null; @@ -155,7 +153,15 @@ public abstract class RecipeUtil { } List matchingRecipes = new ArrayList<>(); + List matchingIndex=new ArrayList(); + List matchingRecipeMap = new ArrayList(); + int index = 0; + + // Check across the whole cached recipe map + // Add each recipe to the matchingRecipes list + + // Only do this if there were no cached recipes hit for (Object recipe : CraftingManager.getInstance().getRecipeList()) { IRecipe irecipe = (IRecipe) recipe; @@ -163,10 +169,28 @@ public abstract class RecipeUtil { ItemStack result = irecipe.getCraftingResult(inventory); if (!ItemStackUtil.containsItemStack(matchingRecipes, result)) { matchingRecipes.add(result); + // Add to the back of the list. That way when we cycle through the list + // moving items to the front, the index locations for the following items doesn't change + matchingRecipeMap.add(recipe); + matchingIndex.add(index); + break; } } + index++; } + if (matchingIndex.size() > 0 ) + { + // Only move the recipes if the last one was beyond 500 in the recipeMap (in GTNH about 57k recipes) + if (index > 500) { + System.out.println( "Highest recipe found at " + index + ", moving " + matchingIndex.size() + " to front" ); + for (index = 0; index < matchingIndex.size(); index++) { + // Remove recipe and add back at the front + CraftingManager.getInstance().getRecipeList().remove(matchingIndex.get(index)); + CraftingManager.getInstance().getRecipeList().add(0,matchingRecipeMap.get(index)); + } + } + } return matchingRecipes; } diff --git a/src/main/java/forestry/core/utils/SlotUtil.java b/src/main/java/forestry/core/utils/SlotUtil.java index cdc9ea3f4..c3cce6774 100644 --- a/src/main/java/forestry/core/utils/SlotUtil.java +++ b/src/main/java/forestry/core/utils/SlotUtil.java @@ -265,6 +265,7 @@ public abstract class SlotUtil { // if mergeOnly = true, don't shift into empty slots. private static boolean shiftToMachineInventory(List inventorySlots, ItemStack stackToShift, int numSlots, boolean mergeOnly) { for (int machineIndex = playerInventorySize; machineIndex < numSlots; machineIndex++) { +// System.out.println("SlotUtil::shiftToMachineinventory"); Slot slot = (Slot) inventorySlots.get(machineIndex); if (mergeOnly && slot.getStack() == null) { continue; diff --git a/src/main/java/forestry/factory/tiles/TileWorktable.java b/src/main/java/forestry/factory/tiles/TileWorktable.java index 6e9852c0e..f53f2706f 100644 --- a/src/main/java/forestry/factory/tiles/TileWorktable.java +++ b/src/main/java/forestry/factory/tiles/TileWorktable.java @@ -44,6 +44,8 @@ public class TileWorktable extends TileBase implements ICrafterWorktable { private long savedTick = 0; private long savedSystemTimeExpiration = 0; private boolean isDirty=true; + private long cleanCount = 0; + private long totalCount = 0; // Maximum crafting time of 750ms before ejecting out and stop hard-locking the server static long WORKTABLE_MAX_CRAFT_TIME = 750 * 1000 * 1000; @@ -141,15 +143,25 @@ public class TileWorktable extends TileBase implements ICrafterWorktable { savedTick=currentTick; savedSystemTimeExpiration = System.nanoTime() + WORKTABLE_MAX_CRAFT_TIME; isDirty = true; + System.out.println("cleanCount " + cleanCount + " totalCount " + totalCount); + cleanCount = 0; + totalCount = 0; } - ItemStack[] recipeItems = InventoryUtil.getStacks(currentRecipe.getCraftMatrix()); - ItemStack[] inventory = InventoryUtil.getStacks(this); - InventoryCraftingForestry crafting = RecipeUtil.getCraftRecipe(recipeItems, inventory, worldObj, currentRecipe.getRecipeOutput()); + totalCount++; + + if (isDirty) { + ItemStack[] recipeItems = InventoryUtil.getStacks(currentRecipe.getCraftMatrix()); + ItemStack[] inventory = InventoryUtil.getStacks(this); + InventoryCraftingForestry crafting = RecipeUtil.getCraftRecipe(recipeItems, inventory, worldObj, currentRecipe.getRecipeOutput()); - // Craft is validated, mark as clean - isDirty = false; - return crafting != null; + // Craft is validated, mark as clean + isDirty = false; + return crafting != null; + } else { + cleanCount++; + return true; + } } @Override @@ -172,7 +184,9 @@ public class TileWorktable extends TileBase implements ICrafterWorktable { if (removed == null) { return false; } - + + // Contents have changed, have to revalidate recipe + isDirty = true; // update crafting display to match the ingredients that were actually used setCraftingDisplay(crafting); return true;