|
40 | 40 | import net.minecraftforge.fluids.IFluidTank; |
41 | 41 | import net.minecraftforge.items.IItemHandlerModifiable; |
42 | 42 |
|
43 | | -import it.unimi.dsi.fastutil.objects.Object2IntOpenCustomHashMap; |
44 | 43 | import org.jetbrains.annotations.MustBeInvokedByOverriders; |
45 | 44 | import org.jetbrains.annotations.NotNull; |
46 | 45 | import org.jetbrains.annotations.Nullable; |
47 | 46 |
|
48 | 47 | import java.util.ArrayList; |
49 | 48 | import java.util.List; |
50 | | -import java.util.Map; |
51 | 49 |
|
52 | 50 | import static gregtech.api.GTValues.ULV; |
53 | 51 | import static gregtech.api.recipes.logic.OverclockingLogic.*; |
@@ -75,18 +73,15 @@ public abstract class AbstractRecipeLogic extends MTETrait implements IWorkable, |
75 | 73 | protected int maxProgressTime; |
76 | 74 | protected long recipeEUt; |
77 | 75 | protected List<FluidStack> fluidOutputs; |
78 | | - protected final Map<FluidStack, Integer> fluidChancesCache = new Object2IntOpenCustomHashMap<>( |
79 | | - FluidStackHashStrategy.builder() |
80 | | - .compareFluid(true) |
81 | | - .build()); |
82 | 76 | protected List<ItemStack> itemOutputs; |
83 | | - protected final Map<ItemStack, Integer> itemChancesCache = new Object2IntOpenCustomHashMap<>( |
84 | | - ItemStackHashStrategy.builder() |
85 | | - .compareItem(true) |
86 | | - .compareDamage(true) |
87 | | - .build()); |
88 | | - private final RecipeContext<ItemStack> itemContext = new RecipeContext<>(itemChancesCache); |
89 | | - private final RecipeContext<FluidStack> fluidContext = new RecipeContext<>(fluidChancesCache); |
| 77 | + |
| 78 | + private final RecipeContext<ItemStack> itemContext = new RecipeContext<>(ItemStackHashStrategy.builder() |
| 79 | + .compareItem(true) |
| 80 | + .compareDamage(true) |
| 81 | + .build()); |
| 82 | + private final RecipeContext<FluidStack> fluidContext = new RecipeContext<>(FluidStackHashStrategy.builder() |
| 83 | + .compareFluid(true) |
| 84 | + .build()); |
90 | 85 |
|
91 | 86 | protected boolean isActive; |
92 | 87 | protected boolean workingEnabled = true; |
@@ -409,8 +404,8 @@ protected void trySearchNewRecipe() { |
409 | 404 |
|
410 | 405 | // we found a new recipe, clear the cache |
411 | 406 | if (this.previousRecipe != null && !currentRecipe.equals(this.previousRecipe)) { |
412 | | - this.itemChancesCache.clear(); |
413 | | - this.fluidChancesCache.clear(); |
| 407 | + this.itemContext.getCache().clear(); |
| 408 | + this.fluidContext.getCache().clear(); |
414 | 409 | } |
415 | 410 | this.previousRecipe = currentRecipe; |
416 | 411 | } |
@@ -1237,13 +1232,13 @@ public NBTTagCompound serializeNBT() { |
1237 | 1232 | compound.setTag("FluidOutputs", fluidOutputsList); |
1238 | 1233 |
|
1239 | 1234 | NBTTagList itemCache = new NBTTagList(); |
1240 | | - for (var entry : itemChancesCache.entrySet()) { |
| 1235 | + for (var entry : itemContext.getCache().entrySet()) { |
1241 | 1236 | var tag = entry.getKey().serializeNBT(); |
1242 | 1237 | tag.setInteger("CachedChance", entry.getValue()); |
1243 | 1238 | itemCache.appendTag(tag); |
1244 | 1239 | } |
1245 | 1240 | NBTTagList fluidCache = new NBTTagList(); |
1246 | | - for (var entry : fluidChancesCache.entrySet()) { |
| 1241 | + for (var entry : fluidContext.getCache().entrySet()) { |
1247 | 1242 | var tag = entry.getKey().writeToNBT(new NBTTagCompound()); |
1248 | 1243 | tag.setInteger("CachedChance", entry.getValue()); |
1249 | 1244 | fluidCache.appendTag(tag); |
@@ -1281,14 +1276,14 @@ public void deserializeNBT(@NotNull NBTTagCompound compound) { |
1281 | 1276 | for (int i = 0; i < itemCache.tagCount(); i++) { |
1282 | 1277 | var stack = itemCache.getCompoundTagAt(i); |
1283 | 1278 | int cache = stack.getInteger("CachedChance"); |
1284 | | - this.itemChancesCache.put(new ItemStack(stack), cache); |
| 1279 | + this.itemContext.updateCachedChance(new ItemStack(stack), cache); |
1285 | 1280 | } |
1286 | 1281 |
|
1287 | 1282 | NBTTagList fluidCache = compound.getTagList("FluidChanceCache", Constants.NBT.TAG_COMPOUND); |
1288 | 1283 | for (int i = 0; i < fluidCache.tagCount(); i++) { |
1289 | 1284 | var stack = fluidCache.getCompoundTagAt(i); |
1290 | 1285 | int cache = stack.getInteger("CachedChance"); |
1291 | | - this.fluidChancesCache.put(FluidStack.loadFluidStackFromNBT(stack), cache); |
| 1286 | + this.fluidContext.updateCachedChance(FluidStack.loadFluidStackFromNBT(stack), cache); |
1292 | 1287 | } |
1293 | 1288 | } |
1294 | 1289 | } |
|
0 commit comments