From 0cdaf8cff860ebe481a71ed53dd0e83a9b7b7d50 Mon Sep 17 00:00:00 2001 From: Richard Hendricks Date: Mon, 9 Dec 2019 22:07:26 -0600 Subject: [PATCH 1/6] Add new limiting crafting time function. --- gradle.properties | 2 +- .../forestry/factory/tiles/TileWorktable.java | 25 +++++++++++++++++++ 2 files changed, 26 insertions(+), 1 deletion(-) diff --git a/gradle.properties b/gradle.properties index 4ee121ae7..b3acca9ea 100644 --- a/gradle.properties +++ b/gradle.properties @@ -2,4 +2,4 @@ mcversion=1.7.10 forgeversion=10.13.4.1614-1.7.10 version_major=4 version_minor=2 -version_patch=20 +version_patch=21 diff --git a/src/main/java/forestry/factory/tiles/TileWorktable.java b/src/main/java/forestry/factory/tiles/TileWorktable.java index 9c9924162..6e9852c0e 100644 --- a/src/main/java/forestry/factory/tiles/TileWorktable.java +++ b/src/main/java/forestry/factory/tiles/TileWorktable.java @@ -41,6 +41,12 @@ public class TileWorktable extends TileBase implements ICrafterWorktable { private final RecipeMemory recipeMemory; private final InventoryAdapterTile craftingDisplay; private MemorizedRecipe currentRecipe; + private long savedTick = 0; + private long savedSystemTimeExpiration = 0; + private boolean isDirty=true; + + // Maximum crafting time of 750ms before ejecting out and stop hard-locking the server + static long WORKTABLE_MAX_CRAFT_TIME = 750 * 1000 * 1000; public TileWorktable() { super("worktable"); @@ -121,9 +127,28 @@ public class TileWorktable extends TileBase implements ICrafterWorktable { return false; } + long currentTick = worldObj.getTotalWorldTime(); + if (currentTick == savedTick){ + // Processing in the same tick, second call, start expiration timer + long currentTime = System.nanoTime(); + if(currentTime > savedSystemTimeExpiration) { + // Time to craft has expired, stop crafting loop + return false; + } + + } else { + // New tick has arrived, so reset data & mark as dirty so recipe is rechecked. + savedTick=currentTick; + savedSystemTimeExpiration = System.nanoTime() + WORKTABLE_MAX_CRAFT_TIME; + isDirty = true; + } + 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; } From 2af41cf68dcfa619249114e3212e86baca6c36be Mon Sep 17 00:00:00 2001 From: Richard Hendricks Date: Thu, 12 Dec 2019 20:16:58 -0600 Subject: [PATCH 2/6] not working --- .../forestry/core/recipes/RecipeUtil.java | 28 +++++++++++++++++-- .../java/forestry/core/utils/SlotUtil.java | 1 + .../forestry/factory/tiles/TileWorktable.java | 28 ++++++++++++++----- 3 files changed, 48 insertions(+), 9 deletions(-) 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; From 5615ffc5188e81bd35edac457ddb8d53432c91fd Mon Sep 17 00:00:00 2001 From: Richard Hendricks Date: Fri, 13 Dec 2019 00:12:06 -0600 Subject: [PATCH 3/6] Recipelist acceleration is working. Worktable local cache needs creating. --- .../forestry/core/recipes/RecipeUtil.java | 26 +++++++++---------- 1 file changed, 13 insertions(+), 13 deletions(-) diff --git a/src/main/java/forestry/core/recipes/RecipeUtil.java b/src/main/java/forestry/core/recipes/RecipeUtil.java index f066f2ef3..64dad5780 100644 --- a/src/main/java/forestry/core/recipes/RecipeUtil.java +++ b/src/main/java/forestry/core/recipes/RecipeUtil.java @@ -153,11 +153,9 @@ public abstract class RecipeUtil { } List matchingRecipes = new ArrayList<>(); - List matchingIndex=new ArrayList(); - List matchingRecipeMap = 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 @@ -172,22 +170,24 @@ public abstract class RecipeUtil { // 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; + matchingIndex.add(new Integer(index)); } } index++; } - - if (matchingIndex.size() > 0 ) + if (matchingRecipeMap.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++) { + if (matchingIndex.get(matchingIndex.size()-1) > 500) { + List recipeMap = CraftingManager.getInstance().getRecipeList(); + System.out.println( "Highest recipe found at " + matchingIndex.get(matchingIndex.size()-1) + ", moving " + matchingIndex.size() + " to front" ); + System.out.println("Size of recipe map " + recipeMap.size() ); + for (index = 0; index < matchingIndex.size(); index++) { // index is reused here, it goes through the matching groups. // Remove recipe and add back at the front - CraftingManager.getInstance().getRecipeList().remove(matchingIndex.get(index)); - CraftingManager.getInstance().getRecipeList().add(0,matchingRecipeMap.get(index)); + int target = matchingIndex.get(index); // remove requires int + System.out.println("Removing recipe at " + target); + recipeMap.remove(target); + recipeMap.add(0,matchingRecipeMap.get(index)); } } } From 32691c6af4ca0ae734970cab8b3e1452a7de56a1 Mon Sep 17 00:00:00 2001 From: Richard Hendricks Date: Fri, 13 Dec 2019 17:41:58 -0600 Subject: [PATCH 4/6] Add in local recipe cache --- .../forestry/core/recipes/RecipeUtil.java | 21 +++++++++++++++++-- 1 file changed, 19 insertions(+), 2 deletions(-) diff --git a/src/main/java/forestry/core/recipes/RecipeUtil.java b/src/main/java/forestry/core/recipes/RecipeUtil.java index 64dad5780..a16f8fc0f 100644 --- a/src/main/java/forestry/core/recipes/RecipeUtil.java +++ b/src/main/java/forestry/core/recipes/RecipeUtil.java @@ -36,7 +36,7 @@ import forestry.core.utils.Log; import forestry.factory.inventory.InventoryCraftingForestry; public abstract class RecipeUtil { - + static List cachedRecipes = new ArrayList(); public static void addFermenterRecipes(ItemStack resource, int fermentationValue, Fluids output) { if (RecipeManagers.fermenterManager == null) { return; @@ -158,7 +158,21 @@ public abstract class RecipeUtil { int index = 0; // Check across the whole cached recipe map // Add each recipe to the matchingRecipes list - + for (Object recipe : cachedRecipes) { + IRecipe irecipe = (IRecipe) recipe; + + if (irecipe.matches(inventory, world)) { + ItemStack result = irecipe.getCraftingResult(inventory); + if (!ItemStackUtil.containsItemStack(matchingRecipes, result)) { + matchingRecipes.add(result); + } + } + } + if( matchingRecipes.size() > 0 ) { + // If we found recipes here, we found all the potential recipes, so we can just return immediately. + return matchingRecipes; + } + // Only do this if there were no cached recipes hit for (Object recipe : CraftingManager.getInstance().getRecipeList()) { IRecipe irecipe = (IRecipe) recipe; @@ -190,6 +204,9 @@ public abstract class RecipeUtil { recipeMap.add(0,matchingRecipeMap.get(index)); } } + // However, we should always add found recipes to the front of the cached recipe map + // Location doesn't matter since we have to scan the whole cached recipe map anyways. + cachedRecipes.addAll(matchingRecipeMap); } return matchingRecipes; } From fa5c4c0218e35167c2d1ee0f31fa4dae51ced1de Mon Sep 17 00:00:00 2001 From: Richard Hendricks Date: Sat, 14 Dec 2019 02:04:02 -0600 Subject: [PATCH 5/6] Remove isDirty related stuff, it causes stack overflows because it is not properly cleared when the craft is partial. Performance now should be good enough we don't even care about a few extra calls. --- .../forestry/factory/tiles/TileWorktable.java | 32 ++++--------------- 1 file changed, 6 insertions(+), 26 deletions(-) diff --git a/src/main/java/forestry/factory/tiles/TileWorktable.java b/src/main/java/forestry/factory/tiles/TileWorktable.java index f53f2706f..ce12c3bf6 100644 --- a/src/main/java/forestry/factory/tiles/TileWorktable.java +++ b/src/main/java/forestry/factory/tiles/TileWorktable.java @@ -43,9 +43,6 @@ public class TileWorktable extends TileBase implements ICrafterWorktable { private MemorizedRecipe currentRecipe; 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; @@ -131,37 +128,23 @@ public class TileWorktable extends TileBase implements ICrafterWorktable { long currentTick = worldObj.getTotalWorldTime(); if (currentTick == savedTick){ - // Processing in the same tick, second call, start expiration timer + // Processing in the same tick, second call, check expiration timer long currentTime = System.nanoTime(); if(currentTime > savedSystemTimeExpiration) { // Time to craft has expired, stop crafting loop return false; } - } else { - // New tick has arrived, so reset data & mark as dirty so recipe is rechecked. + // New tick has arrived, so reset timer data savedTick=currentTick; savedSystemTimeExpiration = System.nanoTime() + WORKTABLE_MAX_CRAFT_TIME; - isDirty = true; - System.out.println("cleanCount " + cleanCount + " totalCount " + totalCount); - cleanCount = 0; - totalCount = 0; } - totalCount++; - - if (isDirty) { - ItemStack[] recipeItems = InventoryUtil.getStacks(currentRecipe.getCraftMatrix()); - ItemStack[] inventory = InventoryUtil.getStacks(this); - InventoryCraftingForestry crafting = RecipeUtil.getCraftRecipe(recipeItems, inventory, worldObj, currentRecipe.getRecipeOutput()); + 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; - } else { - cleanCount++; - return true; - } + return crafting != null; } @Override @@ -184,9 +167,6 @@ 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; From 93aa429cf2c98a97a32c48a8becae8e36ae646ec Mon Sep 17 00:00:00 2001 From: Richard Hendricks Date: Sat, 14 Dec 2019 13:44:27 -0600 Subject: [PATCH 6/6] Add config options, remove debug prints --- .../java/forestry/core/config/Config.java | 11 +++ .../forestry/core/recipes/RecipeUtil.java | 75 +++++++++++-------- .../forestry/factory/tiles/TileWorktable.java | 28 +++---- 3 files changed, 67 insertions(+), 47 deletions(-) diff --git a/src/main/java/forestry/core/config/Config.java b/src/main/java/forestry/core/config/Config.java index ee1b292fa..8dd6749e6 100755 --- a/src/main/java/forestry/core/config/Config.java +++ b/src/main/java/forestry/core/config/Config.java @@ -77,6 +77,12 @@ public class Config { // Performance public static boolean enableBackpackResupply = true; + // Optimization + public static boolean enableCraftingTimeout = true; + public static int craftingTimeout = 200; // Time given in ms + public static boolean cacheWorktableRecipes = true; + public static boolean promoteWorktableRecipesToFrontOfGlobalRecipemap = true; + // Customization private static boolean craftingBronzeEnabled = true; @@ -215,6 +221,11 @@ public class Config { enableBackpackResupply = configCommon.getBooleanLocalized("performance", "backpacks.resupply", enableBackpackResupply); + enableCraftingTimeout = configCommon.getBooleanLocalized("optimization","enable.crafting.timeout", enableCraftingTimeout); + craftingTimeout = configCommon.getIntLocalized("optimization","crafting.timeout",craftingTimeout, 50, 2000 ); // min 50ms, default 200ms, max 2000 ms. Integer.MAX_VALUE is ~ 2100 ms because of multiplication by 1,000,000 + cacheWorktableRecipes = configCommon.getBooleanLocalized("optimization","cache.worktable.recipes", cacheWorktableRecipes); + promoteWorktableRecipesToFrontOfGlobalRecipemap = configCommon.getBooleanLocalized("optimization","promote.worktable.recipes",promoteWorktableRecipesToFrontOfGlobalRecipemap); + // move legacy mail property configCommon.moveProperty("tweaks.gui", "mail.alert", "tweaks.gui.mail.alert"); configCommon.renameProperty("tweaks.gui.mail.alert", "mail.alert", "enabled"); diff --git a/src/main/java/forestry/core/recipes/RecipeUtil.java b/src/main/java/forestry/core/recipes/RecipeUtil.java index a16f8fc0f..11685df29 100644 --- a/src/main/java/forestry/core/recipes/RecipeUtil.java +++ b/src/main/java/forestry/core/recipes/RecipeUtil.java @@ -30,6 +30,7 @@ import cpw.mods.fml.common.registry.GameRegistry; import forestry.api.recipes.IDescriptiveRecipe; import forestry.api.recipes.RecipeManagers; +import forestry.core.config.Config; import forestry.core.fluids.Fluids; import forestry.core.utils.ItemStackUtil; import forestry.core.utils.Log; @@ -156,23 +157,25 @@ public abstract class RecipeUtil { 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 - for (Object recipe : cachedRecipes) { - IRecipe irecipe = (IRecipe) recipe; - if (irecipe.matches(inventory, world)) { - ItemStack result = irecipe.getCraftingResult(inventory); - if (!ItemStackUtil.containsItemStack(matchingRecipes, result)) { - matchingRecipes.add(result); - } - } - } - if( matchingRecipes.size() > 0 ) { - // If we found recipes here, we found all the potential recipes, so we can just return immediately. - return matchingRecipes; - } + if(Config.cacheWorktableRecipes) { + // Check across the whole cached recipe map + // Add each recipe to the matchingRecipes list + for (Object recipe : cachedRecipes) { + IRecipe irecipe = (IRecipe) recipe; + if (irecipe.matches(inventory, world)) { + ItemStack result = irecipe.getCraftingResult(inventory); + if (!ItemStackUtil.containsItemStack(matchingRecipes, result)) { + matchingRecipes.add(result); + } + } + } + if( matchingRecipes.size() > 0 ) { + // If we found recipes here, we found all the potential recipes, so we can just return immediately. + return matchingRecipes; + } + } // Only do this if there were no cached recipes hit for (Object recipe : CraftingManager.getInstance().getRecipeList()) { IRecipe irecipe = (IRecipe) recipe; @@ -181,32 +184,38 @@ 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(new Integer(index)); + if(Config.promoteWorktableRecipesToFrontOfGlobalRecipemap || Config.cacheWorktableRecipes) { + // 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(new Integer(index)); + } } } index++; } if (matchingRecipeMap.size() > 0 ) { - // Only move the recipes if the last one was beyond 500 in the recipeMap (in GTNH about 57k recipes) - if (matchingIndex.get(matchingIndex.size()-1) > 500) { - List recipeMap = CraftingManager.getInstance().getRecipeList(); - System.out.println( "Highest recipe found at " + matchingIndex.get(matchingIndex.size()-1) + ", moving " + matchingIndex.size() + " to front" ); - System.out.println("Size of recipe map " + recipeMap.size() ); - for (index = 0; index < matchingIndex.size(); index++) { // index is reused here, it goes through the matching groups. - // Remove recipe and add back at the front - int target = matchingIndex.get(index); // remove requires int - System.out.println("Removing recipe at " + target); - recipeMap.remove(target); - recipeMap.add(0,matchingRecipeMap.get(index)); + if (Config.promoteWorktableRecipesToFrontOfGlobalRecipemap) { + // Only move the recipes if the last one was beyond 500 in the recipeMap (in GTNH about 57k recipes) + if (matchingIndex.get(matchingIndex.size()-1) > 500) { + List recipeMap = CraftingManager.getInstance().getRecipeList(); + System.out.println( "Highest recipe found at " + matchingIndex.get(matchingIndex.size()-1) + ", moving " + matchingIndex.size() + " to front" ); + System.out.println( "Size of recipe map " + recipeMap.size() ); + for (index = 0; index < matchingIndex.size(); index++) { // index is reused here, it goes through the matching groups. + // Remove recipe and add back at the front + int target = matchingIndex.get(index); // remove requires int + System.out.println("Removing recipe at " + target); + recipeMap.remove(target); + recipeMap.add(0,matchingRecipeMap.get(index)); + } } } - // However, we should always add found recipes to the front of the cached recipe map - // Location doesn't matter since we have to scan the whole cached recipe map anyways. - cachedRecipes.addAll(matchingRecipeMap); + if(Config.cacheWorktableRecipes) { + // However, we should always add found recipes the cached recipe map + // Location doesn't matter since we have to scan the whole cached recipe map anyways. + cachedRecipes.addAll(matchingRecipeMap); + } } return matchingRecipes; } diff --git a/src/main/java/forestry/factory/tiles/TileWorktable.java b/src/main/java/forestry/factory/tiles/TileWorktable.java index ce12c3bf6..644e7fb90 100644 --- a/src/main/java/forestry/factory/tiles/TileWorktable.java +++ b/src/main/java/forestry/factory/tiles/TileWorktable.java @@ -21,6 +21,7 @@ import net.minecraft.nbt.NBTTagCompound; import net.minecraftforge.common.MinecraftForge; import net.minecraftforge.event.entity.player.PlayerDestroyItemEvent; +import forestry.core.config.Config; import forestry.core.inventory.InventoryAdapterTile; import forestry.core.inventory.wrappers.InventoryMapper; import forestry.core.network.DataInputStreamForestry; @@ -44,9 +45,6 @@ public class TileWorktable extends TileBase implements ICrafterWorktable { private long savedTick = 0; private long savedSystemTimeExpiration = 0; - // Maximum crafting time of 750ms before ejecting out and stop hard-locking the server - static long WORKTABLE_MAX_CRAFT_TIME = 750 * 1000 * 1000; - public TileWorktable() { super("worktable"); setInternalInventory(new InventoryWorktable(this)); @@ -126,18 +124,20 @@ public class TileWorktable extends TileBase implements ICrafterWorktable { return false; } - long currentTick = worldObj.getTotalWorldTime(); - if (currentTick == savedTick){ - // Processing in the same tick, second call, check expiration timer - long currentTime = System.nanoTime(); - if(currentTime > savedSystemTimeExpiration) { - // Time to craft has expired, stop crafting loop - return false; + if( Config.enableCraftingTimeout ) { + long currentTick = worldObj.getTotalWorldTime(); + if (currentTick == savedTick){ + // Processing in the same tick, second call, check expiration timer + long currentTime = System.nanoTime(); + if(currentTime > savedSystemTimeExpiration) { + // Time to craft has expired, stop crafting loop + return false; + } + } else { + // New tick has arrived, so reset timer data + savedTick=currentTick; + savedSystemTimeExpiration = System.nanoTime() + Config.craftingTimeout * 1000000; } - } else { - // New tick has arrived, so reset timer data - savedTick=currentTick; - savedSystemTimeExpiration = System.nanoTime() + WORKTABLE_MAX_CRAFT_TIME; } ItemStack[] recipeItems = InventoryUtil.getStacks(currentRecipe.getCraftMatrix());