From 96fe3bee01411fa94178a120de38b5af11c1fbcb Mon Sep 17 00:00:00 2001 From: Swedz Date: Sat, 18 Oct 2025 11:55:36 -0400 Subject: [PATCH] Update MI to 2.3.15 --- gradle.properties | 4 +- .../component/SteamProductionComponent.java | 4 +- .../MultipliedCrafterComponent.java | 2 +- .../mi/helper/CrafterComponentHelper.java | 222 ++++++++++-------- 4 files changed, 125 insertions(+), 107 deletions(-) diff --git a/gradle.properties b/gradle.properties index d2841b4b..0c45a914 100644 --- a/gradle.properties +++ b/gradle.properties @@ -37,8 +37,8 @@ mod_github=https://github.com/Swedz/tesseract-neoforge # Dependencies mixinextras_version=0.3.5 emi_version=1.1.10+1.21 -modern_industrialization_version=2.3.13 -modern_industrialization_version_range=[2.3.13-, 2.4-) +modern_industrialization_version=2.3.15 +modern_industrialization_version_range=[2.3.15-, 2.4-) grandpower_version=3.0.0 cloth_config_version=15.0.127 ohthetreesyoullgrow_version_range=[5.0.7,) \ No newline at end of file diff --git a/src/main/java/net/swedz/tesseract/neoforge/compat/mi/component/SteamProductionComponent.java b/src/main/java/net/swedz/tesseract/neoforge/compat/mi/component/SteamProductionComponent.java index c317f72e..7cc1f0ae 100644 --- a/src/main/java/net/swedz/tesseract/neoforge/compat/mi/component/SteamProductionComponent.java +++ b/src/main/java/net/swedz/tesseract/neoforge/compat/mi/component/SteamProductionComponent.java @@ -69,10 +69,10 @@ public FluidVariant tryMakeSteam() } long steamToProduce = maxEuProduction.get(); - try (Transaction transaction = Transaction.openOuter()) + try (Transaction transaction = Transaction.openRoot()) { long steamProducedSimulation; - try (Transaction simulation = Transaction.openNested(transaction)) + try (Transaction simulation = Transaction.open(transaction)) { steamProducedSimulation = fluidStorage.insertAllSlot(steamKey, steamToProduce, simulation); } diff --git a/src/main/java/net/swedz/tesseract/neoforge/compat/mi/component/craft/multiplied/MultipliedCrafterComponent.java b/src/main/java/net/swedz/tesseract/neoforge/compat/mi/component/craft/multiplied/MultipliedCrafterComponent.java index 91830252..6983c357 100644 --- a/src/main/java/net/swedz/tesseract/neoforge/compat/mi/component/craft/multiplied/MultipliedCrafterComponent.java +++ b/src/main/java/net/swedz/tesseract/neoforge/compat/mi/component/craft/multiplied/MultipliedCrafterComponent.java @@ -214,7 +214,7 @@ private int calculateItemOutputRecipeMultiplier(MachineRecipe recipe) private boolean canItemOutputsAllFit(MachineRecipe recipe, int multiplier) { - try (Transaction transaction = Transaction.openOuter()) + try (Transaction transaction = Transaction.openRoot()) { MIItemStorage outputStorage = new MIItemStorage(inventory.getItemOutputs()); diff --git a/src/main/java/net/swedz/tesseract/neoforge/compat/mi/helper/CrafterComponentHelper.java b/src/main/java/net/swedz/tesseract/neoforge/compat/mi/helper/CrafterComponentHelper.java index 30571387..b598f5f0 100644 --- a/src/main/java/net/swedz/tesseract/neoforge/compat/mi/helper/CrafterComponentHelper.java +++ b/src/main/java/net/swedz/tesseract/neoforge/compat/mi/helper/CrafterComponentHelper.java @@ -1,6 +1,7 @@ package net.swedz.tesseract.neoforge.compat.mi.helper; import aztech.modern_industrialization.MI; +import aztech.modern_industrialization.compat.almostunified.AlmostUnifiedFacade; import aztech.modern_industrialization.inventory.AbstractConfigurableStack; import aztech.modern_industrialization.inventory.ConfigurableFluidStack; import aztech.modern_industrialization.inventory.ConfigurableItemStack; @@ -9,6 +10,9 @@ import aztech.modern_industrialization.stats.PlayerStatistics; import aztech.modern_industrialization.thirdparty.fabrictransfer.api.fluid.FluidVariant; import aztech.modern_industrialization.thirdparty.fabrictransfer.api.item.ItemVariant; +import aztech.modern_industrialization.thirdparty.fabrictransfer.api.storage.TransferVariant; +import com.google.common.base.Predicate; +import com.google.common.base.Supplier; import net.minecraft.core.registries.BuiltInRegistries; import net.minecraft.resources.ResourceLocation; import net.minecraft.server.level.ServerLevel; @@ -49,7 +53,7 @@ private static boolean takeItemInputs( int remainingAmount = input.amount() * (input.probability() == 0 ? 1 : multiplier); for(ConfigurableItemStack stack : stacks) { - if(stack.getAmount() > 0 && input.matches(stack.getResource().toStack())) + if(stack.getAmount() > 0 && stack.getResource().test(input.ingredient())) { int taken = Math.min((int) stack.getAmount(), remainingAmount); if(taken > 0 && !simulate) @@ -371,127 +375,140 @@ public static boolean putFluidOutputs( return putFluidOutputs(recipe, simulate, toggleLock, CommonBehavior.from(behavior), inventory, multiplier); } - public static void lockRecipe(MachineRecipe recipe, Inventory playerInventory, CrafterComponent.Inventory inventory) + private static , S extends AbstractConfigurableStack> void handleLocking( + List stacks, + Predicate matchesRecipe, + long requiredAmount, + Supplier lockTarget + ) { - // ITEM INPUTS - outer: - for(MachineRecipe.ItemInput input : recipe.itemInputs) + for(S stack : stacks) { - for(ConfigurableItemStack stack : inventory.getItemInputs()) - { - if(stack.getLockedInstance() != null && input.matches(new ItemStack(stack.getLockedInstance()))) - { - continue outer; - } - } - Item targetItem = null; - // Find the first match in the player inventory (useful for logs for example) - for(int i = 0; i < playerInventory.getContainerSize(); i++) + if(stack.getLockedInstance() != null && matchesRecipe.apply(stack.getLockedInstance())) { - ItemStack playerStack = playerInventory.getItem(i); - if(!playerStack.isEmpty() && input.matches(new ItemStack(playerStack.getItem()))) + requiredAmount -= stack.getTotalCapacityFor(stack.getLockedInstance()); + if(requiredAmount <= 0) { - targetItem = playerStack.getItem(); - break; + // We have all we need already + return; } } - if(targetItem == null) - { - // Find the first match that is an item from MI (useful for ingots for example) - for(Item item : input.getInputItems()) - { - ResourceLocation id = BuiltInRegistries.ITEM.getKey(item); - if(id.getNamespace().equals(MI.ID)) + } + var newLockedInstance = lockTarget.get(); + if(newLockedInstance == null) + { + return; + } + AbstractConfigurableStack.playerLockNoOverride(newLockedInstance, requiredAmount, stacks); + } + + public static void lockRecipe(MachineRecipe recipe, Inventory playerInventory, CrafterComponent.Inventory inventory) + { + // ITEM INPUTS + for(var input : recipe.itemInputs) + { + handleLocking( + inventory.getItemInputs(), + (item) -> input.matches(new ItemStack(item)), + input.amount(), + () -> { - targetItem = item; - break; + // Find the first match in the player inventory (useful for logs for example) + for(int i = 0; i < playerInventory.getContainerSize(); i++) + { + ItemStack playerStack = playerInventory.getItem(i); + if(!playerStack.isEmpty() && input.matches(new ItemStack(playerStack.getItem()))) + { + return playerStack.getItem(); + } + } + List inputItems = input.getInputItems(); + // Find the preferred item with Almost Unified if possible + if(!inputItems.isEmpty()) + { + var targetItem = AlmostUnifiedFacade.INSTANCE.getTargetItem(inputItems.getFirst()); + if(targetItem != null) + { + return targetItem; + } + } + // Find the first match that is an item from MI (useful for ingots for example) + for(Item item : inputItems) + { + ResourceLocation id = BuiltInRegistries.ITEM.getKey(item); + if(id.getNamespace().equals(MI.ID)) + { + return item; + } + } + // If there is only one value in the tag, pick that one + if(inputItems.size() == 1) + { + return inputItems.getFirst(); + } + return null; } - } - } - if(targetItem == null) - { - // If there is only one value in the tag, pick that one - if(input.getInputItems().size() == 1) - { - targetItem = input.getInputItems().getFirst(); - } - } - - if(targetItem != null) - { - AbstractConfigurableStack.playerLockNoOverride(targetItem, inventory.getItemInputs()); - } + ); } + // ITEM OUTPUTS - outer: - for(MachineRecipe.ItemOutput output : recipe.itemOutputs) + for(var output : recipe.itemOutputs) { - for(ConfigurableItemStack stack : inventory.getItemOutputs()) - { - if(stack.getLockedInstance() == output.variant().getItem()) - continue outer; - } - AbstractConfigurableStack.playerLockNoOverride(output.variant().getItem(), inventory.getItemOutputs()); + handleLocking( + inventory.getItemOutputs(), + (item) -> output.variant().isOf(item), + output.amount(), + output.variant()::getItem + ); } // FLUID INPUTS - outer: - for(MachineRecipe.FluidInput input : recipe.fluidInputs) + for(var input : recipe.fluidInputs) { - for(ConfigurableFluidStack stack : inventory.getFluidInputs()) - { - if(stack.getLockedInstance() != null && input.fluid().test(new FluidStack(stack.getLockedInstance(), 1))) - { - continue outer; - } - } - Fluid targetFluid = null; - // Find the first match in the player inventory - for(int i = 0; i < playerInventory.getContainerSize(); i++) - { - var playerStack = FluidUtil.getFluidContained(playerInventory.getItem(i)).orElse(FluidStack.EMPTY); - if(!playerStack.isEmpty() && input.fluid().test(new FluidStack(playerStack.getFluid(), 1))) - { - targetFluid = playerStack.getFluid(); - break; - } - } - if(targetFluid == null) - { - // Find the first match that is an item from MI - for(Fluid fluid : input.getInputFluids()) - { - ResourceLocation id = BuiltInRegistries.FLUID.getKey(fluid); - if(id.getNamespace().equals(MI.ID)) + handleLocking( + inventory.getFluidInputs(), + (fluid) -> input.fluid().test(new FluidStack(fluid, 1)), + input.amount(), + () -> { - targetFluid = fluid; - break; + // Find the first match in the player inventory + for(int i = 0; i < playerInventory.getContainerSize(); i++) + { + var playerStack = FluidUtil.getFluidContained(playerInventory.getItem(i)).orElse(FluidStack.EMPTY); + if(!playerStack.isEmpty() && input.fluid().test(new FluidStack(playerStack.getFluid(), 1))) + { + return playerStack.getFluid(); + } + } + List inputFluids = input.getInputFluids(); + // Find the first match that is an item from MI + for(Fluid fluid : inputFluids) + { + ResourceLocation id = BuiltInRegistries.FLUID.getKey(fluid); + if(id.getNamespace().equals(MI.ID)) + { + return fluid; + } + } + // If there is only one value in the tag, pick that one + if(inputFluids.size() == 1) + { + return inputFluids.getFirst(); + } + return null; } - } - } - if(targetFluid == null) - { - // If there is only one value in the tag, pick that one - if(input.getInputFluids().size() == 1) - { - targetFluid = input.getInputFluids().getFirst(); - } - } - if(targetFluid != null) - { - AbstractConfigurableStack.playerLockNoOverride(targetFluid, inventory.getFluidInputs()); - } + ); } + // FLUID OUTPUTS - outer: - for(MachineRecipe.FluidOutput output : recipe.fluidOutputs) + for(var output : recipe.fluidOutputs) { - for(ConfigurableFluidStack stack : inventory.getFluidOutputs()) - { - if(stack.isLockedTo(output.fluid())) - continue outer; - } - AbstractConfigurableStack.playerLockNoOverride(output.fluid(), inventory.getFluidOutputs()); + handleLocking( + inventory.getFluidOutputs(), + (fluid) -> output.fluid() == fluid, + output.amount(), + output::fluid + ); } // LOCK ITEMS @@ -500,6 +517,7 @@ public static void lockRecipe(MachineRecipe recipe, Inventory playerInventory, C lockAll(inventory.getItemInputs()); lockAll(inventory.getItemOutputs()); } + // LOCK FLUIDS if(!recipe.fluidInputs.isEmpty() || !recipe.fluidOutputs.isEmpty()) {