diff --git a/build.gradle.kts b/build.gradle.kts index df6b3137..6b704617 100644 --- a/build.gradle.kts +++ b/build.gradle.kts @@ -12,7 +12,7 @@ plugins { // Project properties group = "hellfirepvp.modularmachinery" -version = "2.1.0" +version = "2.1.1" // Set the toolchain version to decouple the Java we run Gradle with from the Java used to compile and run the mod java { diff --git a/src/main/java/github/kasuminova/mmce/common/tile/MEPatternProvider.java b/src/main/java/github/kasuminova/mmce/common/tile/MEPatternProvider.java index e4950592..52850beb 100644 --- a/src/main/java/github/kasuminova/mmce/common/tile/MEPatternProvider.java +++ b/src/main/java/github/kasuminova/mmce/common/tile/MEPatternProvider.java @@ -251,8 +251,13 @@ protected void refreshPattern(final int slot) { details.set(slot, detail); } - if (workMode == WorkModeSetting.ENHANCED_BLOCKING_MODE && slot == currentPatternIdx && !currentPattern.equals(detail)) { - resetCurrentPattern(); + if (workMode == WorkModeSetting.ENHANCED_BLOCKING_MODE && slot == currentPatternIdx) { + // If it is reading NBT. + if (currentPattern == null) { + currentPattern = detail; + } else if (!currentPattern.equals(detail)) { + resetCurrentPattern(); + } } } diff --git a/src/main/java/github/kasuminova/mmce/common/util/InfItemFluidHandler.java b/src/main/java/github/kasuminova/mmce/common/util/InfItemFluidHandler.java index feac9e20..7adbd075 100644 --- a/src/main/java/github/kasuminova/mmce/common/util/InfItemFluidHandler.java +++ b/src/main/java/github/kasuminova/mmce/common/util/InfItemFluidHandler.java @@ -87,7 +87,15 @@ public synchronized int fill(final FluidStack resource, final boolean doFill) { for (int i = 0; i < fluidStackList.size(); i++) { final FluidStack stackInSlot = fluidStackList.get(i); - if (stackInSlot != null && stackInSlot.isFluidEqual(resource)) { + if (stackInSlot == null) { + fluidStackList.set(i, resource.copy()); + if (onFluidChanged != null) { + onFluidChanged.accept(i); + } + toFill = 0; + break; + } + if (stackInSlot.isFluidEqual(resource)) { int maxCanFill = Math.min(toFill, Integer.MAX_VALUE - stackInSlot.amount); stackInSlot.amount += maxCanFill; if (onFluidChanged != null) { @@ -504,7 +512,16 @@ public int receiveGas(@Nullable final EnumFacing ignored, final GasStack toRecei int toReceiveAmount = toReceive.amount; for (int i = 0; i < gasStackList.size(); i++) { final GasStack stackInSlot = gasStackList.get(i); - if (stackInSlot == null || !stackInSlot.isGasEqual(toReceive)) { + if (stackInSlot == null) { + gasStackList.set(i, toReceive.copy()); + if (onGasChanged != null) { + onGasChanged.accept(i); + } + toReceiveAmount = 0; + break; + } + + if (!stackInSlot.isGasEqual(toReceive)) { continue; } diff --git a/src/main/java/github/kasuminova/mmce/common/util/TimeRecorder.java b/src/main/java/github/kasuminova/mmce/common/util/TimeRecorder.java index 99f2c832..f696bf50 100644 --- a/src/main/java/github/kasuminova/mmce/common/util/TimeRecorder.java +++ b/src/main/java/github/kasuminova/mmce/common/util/TimeRecorder.java @@ -1,13 +1,11 @@ package github.kasuminova.mmce.common.util; import github.kasuminova.mmce.common.util.concurrent.ActionExecutor; - -import java.util.ArrayDeque; -import java.util.Deque; +import it.unimi.dsi.fastutil.ints.IntArrayFIFOQueue; public class TimeRecorder { - private final Deque usedTimeList = new ArrayDeque<>(100 + 2); - private final Deque searchUsedTimeList = new ArrayDeque<>(20 + 2); + private final IntArrayFIFOQueue usedTimeList = new IntArrayFIFOQueue(); + private final IntArrayFIFOQueue searchUsedTimeList = new IntArrayFIFOQueue(); private int usedTimeCache = 0; private int searchUsedTimeCache = 0; @@ -17,39 +15,36 @@ public void updateUsedTime(ActionExecutor executor) { public void incrementUsedTime(int add) { usedTimeCache += add; - Integer first = usedTimeList.getFirst(); - if (first != null) { - usedTimeList.removeFirst(); - usedTimeList.addFirst(first + add); + + if (!usedTimeList.isEmpty()) { + usedTimeList.enqueueFirst(usedTimeList.dequeueInt() + add); } else { - usedTimeList.addFirst(add); + usedTimeList.enqueueFirst(add); } } public void addUsedTime(int time) { usedTimeCache += time; - usedTimeList.addFirst(time); + usedTimeList.enqueueFirst(time); if (usedTimeList.size() > 100) { - usedTimeCache -= usedTimeList.pollLast(); + usedTimeCache -= usedTimeList.dequeueLastInt(); } } public void addRecipeResearchUsedTime(int time) { searchUsedTimeCache += time; - searchUsedTimeList.addFirst(time); + searchUsedTimeList.enqueueFirst(time); if (searchUsedTimeList.size() > 20) { - searchUsedTimeCache -= searchUsedTimeList.pollLast(); + searchUsedTimeCache -= searchUsedTimeList.dequeueLastInt(); } } public void incrementRecipeResearchUsedTime(int add) { searchUsedTimeCache += add; - Integer first = searchUsedTimeList.getFirst(); - if (first != null) { - searchUsedTimeList.removeFirst(); - searchUsedTimeList.addFirst(first + add); + if (!searchUsedTimeList.isEmpty()) { + searchUsedTimeList.enqueueFirst(searchUsedTimeList.dequeueInt() + add); } else { - searchUsedTimeList.addFirst(add); + searchUsedTimeList.enqueueFirst(add); } } @@ -66,4 +61,5 @@ public int recipeSearchUsedTimeAvg() { } return searchUsedTimeCache / searchUsedTimeList.size(); } + } \ No newline at end of file diff --git a/src/main/java/hellfirepvp/modularmachinery/common/crafting/helper/RecipeCraftingContext.java b/src/main/java/hellfirepvp/modularmachinery/common/crafting/helper/RecipeCraftingContext.java index 8aa605b3..652a88f7 100644 --- a/src/main/java/hellfirepvp/modularmachinery/common/crafting/helper/RecipeCraftingContext.java +++ b/src/main/java/hellfirepvp/modularmachinery/common/crafting/helper/RecipeCraftingContext.java @@ -111,7 +111,15 @@ public RecipeCraftingContext init(final ActiveMachineRecipe activeRecipe, final TileMultiblockMachineController ctrl) { this.controller = ctrl; - this.activeRecipe = activeRecipe; + if (this.activeRecipe == null || this.activeRecipe.getRecipe() != activeRecipe.getRecipe()) { + this.activeRecipe = activeRecipe; + this.requirements.clear(); + for (ComponentRequirement requirement : getParentRecipe().getCraftingRequirements()) { + this.requirements.add(this.requirements.size(), requirement.deepCopy().postDeepCopy(requirement)); + } + } else { + this.activeRecipe = activeRecipe; + } this.commandSender = new ControllerCommandSender(this.controller); reset();