aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--src/main/java/com/github/bartimaeusnek/ASM/BWCoreStaticReplacementMethodes.java15
-rw-r--r--src/main/java/com/github/bartimaeusnek/bartworks/common/commands/ClearCraftingCache.java4
-rw-r--r--src/main/java/com/github/bartimaeusnek/bartworks/system/material/CircuitGeneration/CircuitImprintLoader.java2
3 files changed, 13 insertions, 8 deletions
diff --git a/src/main/java/com/github/bartimaeusnek/ASM/BWCoreStaticReplacementMethodes.java b/src/main/java/com/github/bartimaeusnek/ASM/BWCoreStaticReplacementMethodes.java
index 6399a5119b..47705042a9 100644
--- a/src/main/java/com/github/bartimaeusnek/ASM/BWCoreStaticReplacementMethodes.java
+++ b/src/main/java/com/github/bartimaeusnek/ASM/BWCoreStaticReplacementMethodes.java
@@ -32,14 +32,18 @@ import net.minecraft.item.crafting.CraftingManager;
import net.minecraft.item.crafting.IRecipe;
import net.minecraft.world.World;
-import java.util.ArrayList;
import java.util.HashSet;
import java.util.Iterator;
import java.util.List;
public class BWCoreStaticReplacementMethodes {
+ private static ThreadLocal<AccessPriorityList<IRecipe>> RECENTLYUSEDRECIPES = ThreadLocal.withInitial(AccessPriorityList::new);
- public static final AccessPriorityList<IRecipe> RECENTLYUSEDRECIPES = new AccessPriorityList<>();
+ public static void clearRecentlyUsedRecipes() {
+ // the easiest way to ensure the cache is flushed without causing synchronization overhead
+ // is to just replace the whole ThreadLocal instance.
+ RECENTLYUSEDRECIPES = ThreadLocal.withInitial(AccessPriorityList::new);
+ }
@SuppressWarnings("ALL")
public static ItemStack findCachedMatchingRecipe(InventoryCrafting inventoryCrafting, World world) {
@@ -79,7 +83,8 @@ public class BWCoreStaticReplacementMethodes {
} else {
IRecipe iPossibleRecipe = null;
- Iterator<AccessPriorityListNode<IRecipe>> it = RECENTLYUSEDRECIPES.nodeIterator();
+ AccessPriorityList<IRecipe> cache = RECENTLYUSEDRECIPES.get();
+ Iterator<AccessPriorityListNode<IRecipe>> it = cache.nodeIterator();
while (it.hasNext()) {
AccessPriorityListNode<IRecipe> recipeNode = it.next();
@@ -88,7 +93,7 @@ public class BWCoreStaticReplacementMethodes {
if (!iPossibleRecipe.matches(inventoryCrafting, world))
continue;
- RECENTLYUSEDRECIPES.addPrioToNode(recipeNode);
+ cache.addPrioToNode(recipeNode);
return iPossibleRecipe.getCraftingResult(inventoryCrafting);
}
@@ -115,7 +120,7 @@ public class BWCoreStaticReplacementMethodes {
return stack;
if (stack != null)
- RECENTLYUSEDRECIPES.addLast(recipe);
+ cache.addLast(recipe);
return stack;
}
diff --git a/src/main/java/com/github/bartimaeusnek/bartworks/common/commands/ClearCraftingCache.java b/src/main/java/com/github/bartimaeusnek/bartworks/common/commands/ClearCraftingCache.java
index 42385c60f1..f9aba701a6 100644
--- a/src/main/java/com/github/bartimaeusnek/bartworks/common/commands/ClearCraftingCache.java
+++ b/src/main/java/com/github/bartimaeusnek/bartworks/common/commands/ClearCraftingCache.java
@@ -40,7 +40,7 @@ public class ClearCraftingCache extends CommandBase {
@Override
public void processCommand(ICommandSender p_71515_1_, String[] p_71515_2_) {
- BWCoreStaticReplacementMethodes.RECENTLYUSEDRECIPES.clear();
- p_71515_1_.addChatMessage(new ChatComponentText("Recipe Cache cleared? "+(BWCoreStaticReplacementMethodes.RECENTLYUSEDRECIPES.size() == 0)));
+ BWCoreStaticReplacementMethodes.clearRecentlyUsedRecipes();
+ p_71515_1_.addChatMessage(new ChatComponentText("Recipe Cache cleared "));
}
}
diff --git a/src/main/java/com/github/bartimaeusnek/bartworks/system/material/CircuitGeneration/CircuitImprintLoader.java b/src/main/java/com/github/bartimaeusnek/bartworks/system/material/CircuitGeneration/CircuitImprintLoader.java
index bad997cb1e..3c4cb02013 100644
--- a/src/main/java/com/github/bartimaeusnek/bartworks/system/material/CircuitGeneration/CircuitImprintLoader.java
+++ b/src/main/java/com/github/bartimaeusnek/bartworks/system/material/CircuitGeneration/CircuitImprintLoader.java
@@ -219,7 +219,7 @@ public class CircuitImprintLoader {
private static void removeOldRecipesFromRegistries() {
recipeWorldCache.forEach(CraftingManager.getInstance().getRecipeList()::remove);
- BWCoreStaticReplacementMethodes.RECENTLYUSEDRECIPES.clear();
+ BWCoreStaticReplacementMethodes.clearRecentlyUsedRecipes();
gtrecipeWorldCache.forEach(GT_Recipe.GT_Recipe_Map.sSlicerRecipes.mRecipeList::remove);
recipeWorldCache.forEach( r ->
{