From 3fb4b5215ce6a4c4abd5b55e9e0b5c39e7cff419 Mon Sep 17 00:00:00 2001 From: lordIcocain Date: Sat, 23 Nov 2024 18:11:09 +0200 Subject: [PATCH 01/18] ft --- .../gregtech/api/logic/ProcessingLogic.java | 35 +++++++++++- .../implementations/MTEMultiBlockBase.java | 53 +++++++++++++++---- .../machines/IDualInputHatch.java | 3 ++ .../machines/MTEHatchCraftingInputME.java | 29 ++++++++++ .../machines/MTEHatchCraftingInputSlave.java | 5 ++ 5 files changed, 114 insertions(+), 11 deletions(-) diff --git a/src/main/java/gregtech/api/logic/ProcessingLogic.java b/src/main/java/gregtech/api/logic/ProcessingLogic.java index 63c8f6494e4..f68020ff5c4 100644 --- a/src/main/java/gregtech/api/logic/ProcessingLogic.java +++ b/src/main/java/gregtech/api/logic/ProcessingLogic.java @@ -1,5 +1,6 @@ package gregtech.api.logic; +import java.util.ArrayList; import java.util.List; import java.util.stream.Stream; @@ -29,6 +30,7 @@ public class ProcessingLogic extends AbstractProcessingLogic { protected ItemStack[] inputItems; protected FluidStack[] inputFluids; protected boolean isRecipeLocked; + protected ArrayList cribsCustomRecipeMap; public ProcessingLogic() {} @@ -63,6 +65,11 @@ public ProcessingLogic setSpecialSlotItem(ItemStack specialSlotItem) { return getThis(); } + public ProcessingLogic setCribsCustomRecipeMap(ArrayList cribsCustomRecipeMap) { + this.cribsCustomRecipeMap = cribsCustomRecipeMap; + return getThis(); + } + /** * Enables single recipe locking mode. */ @@ -95,6 +102,12 @@ public ProcessingLogic clear() { /** * Executes the recipe check: Find recipe from recipemap, Calculate parallel, overclock and outputs. */ + + @Nonnull + public CheckRecipeResult processCribs(GTRecipe recipe) { + return validateAndCalculateRecipe(recipe).checkRecipeResult; + } + @Nonnull public CheckRecipeResult process() { RecipeMap recipeMap = preProcess(); @@ -136,6 +149,26 @@ public CheckRecipeResult process() { return checkRecipeResult; } + public GTRecipe getCribsMatch(ItemStack[] iI, FluidStack[] iF) { + RecipeMap recipeMap = preProcess(); + inputItems = iI; + inputFluids = iF; + if (inputItems == null) { + inputItems = new ItemStack[0]; + } + if (inputFluids == null) { + inputFluids = new FluidStack[0]; + } + + Stream matchedRecipes = findRecipeMatches(recipeMap); + Iterable recipeIterable = matchedRecipes::iterator; + CheckRecipeResult checkRecipeResult = CheckRecipeResultRegistry.NO_RECIPE; + for (GTRecipe matchedRecipe : recipeIterable) { + return matchedRecipe; + } + return null; + } + /** * Checks if supplied recipe is valid for process. This involves voltage check, output full check. If successful, * additionally performs input consumption, output calculation with parallel, and overclock calculation. @@ -143,7 +176,7 @@ public CheckRecipeResult process() { * @param recipe The recipe which will be checked and processed */ @Nonnull - private CalculationResult validateAndCalculateRecipe(@Nonnull GTRecipe recipe) { + public CalculationResult validateAndCalculateRecipe(@Nonnull GTRecipe recipe) { CheckRecipeResult result = validateRecipe(recipe); if (!result.wasSuccessful()) { return CalculationResult.ofFailure(result); diff --git a/src/main/java/gregtech/api/metatileentity/implementations/MTEMultiBlockBase.java b/src/main/java/gregtech/api/metatileentity/implementations/MTEMultiBlockBase.java index 1e29d797a49..32add2b1f3e 100644 --- a/src/main/java/gregtech/api/metatileentity/implementations/MTEMultiBlockBase.java +++ b/src/main/java/gregtech/api/metatileentity/implementations/MTEMultiBlockBase.java @@ -42,6 +42,7 @@ import org.jetbrains.annotations.ApiStatus; import org.jetbrains.annotations.TestOnly; +import com.glodblock.github.common.item.ItemFluidDrop; import com.google.common.collect.Iterables; import com.google.common.collect.Lists; import com.gtnewhorizons.modularui.api.NumberFormatMUI; @@ -140,6 +141,7 @@ public abstract class MTEMultiBlockBase extends MetaTileEntity protected VoidingMode voidingMode = getDefaultVoidingMode(); protected boolean batchMode = getDefaultBatchMode(); protected @Nonnull CheckRecipeResult checkRecipeResult = CheckRecipeResultRegistry.NONE; + protected ArrayList cribsCustomRecipeMap = null; protected static final String INPUT_SEPARATION_NBT_KEY = "inputSeparation"; protected static final String VOID_EXCESS_NBT_KEY = "voidExcess"; @@ -872,6 +874,35 @@ protected boolean supportsCraftingMEBuffer() { return true; } + public ArrayList getCribsCustomRecipeMap() { + ArrayList recipeList = new ArrayList<>(); + for (IDualInputHatch dualInputHatch : mDualInputHatches) { + List temp = dualInputHatch.getPatternsInputs(); + for (ItemStack[] t : temp) { + if (t == null) { + recipeList.add(null); + continue; + } + ArrayList inputF = new ArrayList<>(); + ArrayList inputI = new ArrayList<>(); + for (ItemStack tt : t) { + if (tt.getItem() instanceof ItemFluidDrop) { + FluidStack fluidStack = ItemFluidDrop.getFluidStack(tt); + if (fluidStack != null) { + inputF.add(fluidStack); + } + } else { + inputI.add(tt); + } + } + GTRecipe recipe = processingLogic + .getCribsMatch(inputI.toArray(new ItemStack[0]), inputF.toArray(new FluidStack[0])); + recipeList.add(recipe); + } + } + return recipeList; + } + /** * Iterates over hatches and tries to find recipe. Assume {@link #processingLogic} is already set up for use. * If return value is successful, inputs are consumed. @@ -881,21 +912,23 @@ protected CheckRecipeResult doCheckRecipe() { CheckRecipeResult result = CheckRecipeResultRegistry.NO_RECIPE; // check crafting input hatches first if (supportsCraftingMEBuffer()) { + if (cribsCustomRecipeMap == null) { + cribsCustomRecipeMap = getCribsCustomRecipeMap(); + } + int n = 0; for (IDualInputHatch dualInputHatch : mDualInputHatches) { for (var it = dualInputHatch.inventories(); it.hasNext();) { - IDualInputInventory slot = it.next(); - processingLogic.setInputItems(slot.getItemInputs()); - processingLogic.setInputFluids(slot.getFluidInputs()); - CheckRecipeResult foundResult = processingLogic.process(); - if (foundResult.wasSuccessful()) { - return foundResult; - } - if (foundResult != CheckRecipeResultRegistry.NO_RECIPE) { - // Recipe failed in interesting way, so remember that and continue searching - result = foundResult; + GTRecipe recipe = cribsCustomRecipeMap.get(n); + n++; + if (recipe != null) { + IDualInputInventory slot = it.next(); + processingLogic.setInputItems(slot.getItemInputs()); + processingLogic.setInputFluids(slot.getFluidInputs()); + return processingLogic.processCribs(recipe); } } } + return result; } processingLogic.setInputFluids(getStoredFluids()); diff --git a/src/main/java/gregtech/common/tileentities/machines/IDualInputHatch.java b/src/main/java/gregtech/common/tileentities/machines/IDualInputHatch.java index 0660f6b1a1b..fb5fc306380 100644 --- a/src/main/java/gregtech/common/tileentities/machines/IDualInputHatch.java +++ b/src/main/java/gregtech/common/tileentities/machines/IDualInputHatch.java @@ -1,6 +1,7 @@ package gregtech.common.tileentities.machines; import java.util.Iterator; +import java.util.List; import java.util.Optional; import net.minecraft.item.ItemStack; @@ -18,4 +19,6 @@ public interface IDualInputHatch { Optional getFirstNonEmptyInventory(); boolean supportsFluids(); + + List getPatternsInputs(); } diff --git a/src/main/java/gregtech/common/tileentities/machines/MTEHatchCraftingInputME.java b/src/main/java/gregtech/common/tileentities/machines/MTEHatchCraftingInputME.java index d1bc27310a1..dd715ce6b04 100644 --- a/src/main/java/gregtech/common/tileentities/machines/MTEHatchCraftingInputME.java +++ b/src/main/java/gregtech/common/tileentities/machines/MTEHatchCraftingInputME.java @@ -1054,4 +1054,33 @@ public List getItemsForHoloGlasses() { } return list; } + + @Override + public List getPatternsInputs() { + List list = new ArrayList<>(); + for (PatternSlot slot : internalInventory) { + if (slot == null) { + list.add(null); + continue; + } + IAEItemStack[] inputs = slot.getPatternDetails() + .getInputs(); + list.add(inputs); + } + List itemList = new ArrayList<>(); + ItemStack[] sharedItems = getSharedItems(); + for (IAEItemStack[] t : list) { + if (t == null) { + itemList.add(null); + continue; + } + ItemStack[] inputI = sharedItems; + for (IAEItemStack y : t) { + if (y == null) continue; + inputI = ArrayUtils.addAll(inputI, y.getItemStack()); + } + itemList.add(inputI); + } + return itemList; + } } diff --git a/src/main/java/gregtech/common/tileentities/machines/MTEHatchCraftingInputSlave.java b/src/main/java/gregtech/common/tileentities/machines/MTEHatchCraftingInputSlave.java index 35db434a32a..e84df0b756a 100644 --- a/src/main/java/gregtech/common/tileentities/machines/MTEHatchCraftingInputSlave.java +++ b/src/main/java/gregtech/common/tileentities/machines/MTEHatchCraftingInputSlave.java @@ -291,4 +291,9 @@ public void getWailaNBTData(EntityPlayerMP player, TileEntity tile, NBTTagCompou public List getItemsForHoloGlasses() { return getMaster() != null ? getMaster().getItemsForHoloGlasses() : null; } + + @Override + public List getPatternsInputs() { + return getMaster() != null ? getMaster().getPatternsInputs() : null; + } } From 479381ddc38e876bc8461bd38d0d0416fa20fb4a Mon Sep 17 00:00:00 2001 From: lordIcocain Date: Wed, 27 Nov 2024 21:00:14 +0200 Subject: [PATCH 02/18] save --- .../implementations/MTEMultiBlockBase.java | 50 ++++++-------- .../machines/IDualInputHatch.java | 9 ++- .../machines/MTEHatchCraftingInputME.java | 68 +++++++++++++------ .../machines/MTEHatchCraftingInputSlave.java | 13 +++- 4 files changed, 88 insertions(+), 52 deletions(-) diff --git a/src/main/java/gregtech/api/metatileentity/implementations/MTEMultiBlockBase.java b/src/main/java/gregtech/api/metatileentity/implementations/MTEMultiBlockBase.java index 32add2b1f3e..2d5d39934a7 100644 --- a/src/main/java/gregtech/api/metatileentity/implementations/MTEMultiBlockBase.java +++ b/src/main/java/gregtech/api/metatileentity/implementations/MTEMultiBlockBase.java @@ -39,10 +39,10 @@ import net.minecraftforge.fluids.Fluid; import net.minecraftforge.fluids.FluidStack; +import org.apache.commons.lang3.ArrayUtils; import org.jetbrains.annotations.ApiStatus; import org.jetbrains.annotations.TestOnly; -import com.glodblock.github.common.item.ItemFluidDrop; import com.google.common.collect.Iterables; import com.google.common.collect.Lists; import com.gtnewhorizons.modularui.api.NumberFormatMUI; @@ -141,7 +141,6 @@ public abstract class MTEMultiBlockBase extends MetaTileEntity protected VoidingMode voidingMode = getDefaultVoidingMode(); protected boolean batchMode = getDefaultBatchMode(); protected @Nonnull CheckRecipeResult checkRecipeResult = CheckRecipeResultRegistry.NONE; - protected ArrayList cribsCustomRecipeMap = null; protected static final String INPUT_SEPARATION_NBT_KEY = "inputSeparation"; protected static final String VOID_EXCESS_NBT_KEY = "voidExcess"; @@ -874,33 +873,21 @@ protected boolean supportsCraftingMEBuffer() { return true; } - public ArrayList getCribsCustomRecipeMap() { - ArrayList recipeList = new ArrayList<>(); + public void setSuperCribsRecipeList() { for (IDualInputHatch dualInputHatch : mDualInputHatches) { - List temp = dualInputHatch.getPatternsInputs(); - for (ItemStack[] t : temp) { + ArrayList recipeList = new ArrayList<>(); + List temp = dualInputHatch.getPatternsInputs(); + if (temp == null) return; + for (MTEHatchCraftingInputME.recipeInputs t : temp) { if (t == null) { recipeList.add(null); continue; } - ArrayList inputF = new ArrayList<>(); - ArrayList inputI = new ArrayList<>(); - for (ItemStack tt : t) { - if (tt.getItem() instanceof ItemFluidDrop) { - FluidStack fluidStack = ItemFluidDrop.getFluidStack(tt); - if (fluidStack != null) { - inputF.add(fluidStack); - } - } else { - inputI.add(tt); - } - } - GTRecipe recipe = processingLogic - .getCribsMatch(inputI.toArray(new ItemStack[0]), inputF.toArray(new FluidStack[0])); + GTRecipe recipe = processingLogic.getCribsMatch(t.inputItems, t.inputFluid); recipeList.add(recipe); } + dualInputHatch.setSuperCribsRecipeList(recipeList); } - return recipeList; } /** @@ -912,23 +899,28 @@ protected CheckRecipeResult doCheckRecipe() { CheckRecipeResult result = CheckRecipeResultRegistry.NO_RECIPE; // check crafting input hatches first if (supportsCraftingMEBuffer()) { - if (cribsCustomRecipeMap == null) { - cribsCustomRecipeMap = getCribsCustomRecipeMap(); - } - int n = 0; for (IDualInputHatch dualInputHatch : mDualInputHatches) { + ArrayList cribsCustomRecipeMap = dualInputHatch.getSuperCribsRecipeList(); + if (cribsCustomRecipeMap == null) { + setSuperCribsRecipeList(); + continue; + } + int n = 0; for (var it = dualInputHatch.inventories(); it.hasNext();) { GTRecipe recipe = cribsCustomRecipeMap.get(n); + IDualInputInventory slot = it.next(); n++; if (recipe != null) { - IDualInputInventory slot = it.next(); - processingLogic.setInputItems(slot.getItemInputs()); - processingLogic.setInputFluids(slot.getFluidInputs()); + ItemStack[] items = slot.getItemInputs(); + FluidStack[] fluids = slot.getFluidInputs(); + if (items == null && fluids == null) continue; + if (items.length == 0 && fluids.length == 0) continue; + processingLogic.setInputItems(items); + processingLogic.setInputFluids(fluids); return processingLogic.processCribs(recipe); } } } - return result; } processingLogic.setInputFluids(getStoredFluids()); diff --git a/src/main/java/gregtech/common/tileentities/machines/IDualInputHatch.java b/src/main/java/gregtech/common/tileentities/machines/IDualInputHatch.java index fb5fc306380..7b104d36c38 100644 --- a/src/main/java/gregtech/common/tileentities/machines/IDualInputHatch.java +++ b/src/main/java/gregtech/common/tileentities/machines/IDualInputHatch.java @@ -1,11 +1,14 @@ package gregtech.common.tileentities.machines; +import java.util.ArrayList; import java.util.Iterator; import java.util.List; import java.util.Optional; import net.minecraft.item.ItemStack; +import gregtech.api.util.GTRecipe; + public interface IDualInputHatch { boolean justUpdated(); @@ -20,5 +23,9 @@ public interface IDualInputHatch { boolean supportsFluids(); - List getPatternsInputs(); + List getPatternsInputs(); + + void setSuperCribsRecipeList(ArrayList rList); + + ArrayList getSuperCribsRecipeList(); } diff --git a/src/main/java/gregtech/common/tileentities/machines/MTEHatchCraftingInputME.java b/src/main/java/gregtech/common/tileentities/machines/MTEHatchCraftingInputME.java index dd715ce6b04..8b9fea9c701 100644 --- a/src/main/java/gregtech/common/tileentities/machines/MTEHatchCraftingInputME.java +++ b/src/main/java/gregtech/common/tileentities/machines/MTEHatchCraftingInputME.java @@ -40,6 +40,7 @@ import org.apache.commons.lang3.ArrayUtils; import org.jetbrains.annotations.NotNull; +import com.glodblock.github.common.item.ItemFluidDrop; import com.glodblock.github.common.item.ItemFluidPacket; import com.google.common.collect.ImmutableList; import com.gtnewhorizons.modularui.api.math.Alignment; @@ -91,6 +92,7 @@ import gregtech.api.metatileentity.MetaTileEntity; import gregtech.api.metatileentity.implementations.MTEHatchInputBus; import gregtech.api.render.TextureFactory; +import gregtech.api.util.GTRecipe; import gregtech.api.util.GTUtility; import gregtech.api.util.extensions.ArrayExt; import mcp.mobius.waila.api.IWailaConfigHandler; @@ -187,7 +189,7 @@ public void updateSlotFluids() { public boolean isItemEmpty() { updateSlotItems(); - return itemInventory.isEmpty() && sharedItemGetter.getSharedItem().length == 0; + return itemInventory.isEmpty() && isFluidEmpty(); } public boolean isFluidEmpty() { @@ -977,6 +979,7 @@ private boolean postMEPatternChange() { } catch (GridAccessException ignored) { return false; } + superCribsRecipeList = null; return true; } @@ -1055,32 +1058,55 @@ public List getItemsForHoloGlasses() { return list; } + public static class recipeInputs { + + public ItemStack[] inputItems; + public FluidStack[] inputFluid; + } + + ArrayList superCribsRecipeList = new ArrayList<>(); + @Override - public List getPatternsInputs() { - List list = new ArrayList<>(); + public List getPatternsInputs() { + ItemStack[] sharedItems = getSharedItems(); + List recipeInputsList = new ArrayList<>(); for (PatternSlot slot : internalInventory) { if (slot == null) { - list.add(null); + recipeInputsList.add(null); continue; } - IAEItemStack[] inputs = slot.getPatternDetails() - .getInputs(); - list.add(inputs); - } - List itemList = new ArrayList<>(); - ItemStack[] sharedItems = getSharedItems(); - for (IAEItemStack[] t : list) { - if (t == null) { - itemList.add(null); - continue; - } - ItemStack[] inputI = sharedItems; - for (IAEItemStack y : t) { - if (y == null) continue; - inputI = ArrayUtils.addAll(inputI, y.getItemStack()); + + recipeInputs inputsSuper = new recipeInputs(); + + ItemStack[] inputItems = sharedItems; + FluidStack[] inputFluids = new FluidStack[0]; + + for (IAEItemStack singleInput : slot.getPatternDetails() + .getInputs()) { + if (singleInput == null) continue; + ItemStack singleInputItemStack = singleInput.getItemStack(); + if (singleInputItemStack.getItem() instanceof ItemFluidDrop) { + FluidStack fluidStack = ItemFluidDrop.getFluidStack(singleInputItemStack); + if (fluidStack != null) inputFluids = ArrayUtils.addAll(inputFluids, fluidStack); + } else { + inputItems = ArrayUtils.addAll(inputItems, singleInputItemStack); + } } - itemList.add(inputI); + + inputsSuper.inputItems = inputItems; + inputsSuper.inputFluid = inputFluids; + recipeInputsList.add(inputsSuper); } - return itemList; + return recipeInputsList; + } + + @Override + public void setSuperCribsRecipeList(ArrayList rList) { + superCribsRecipeList = rList; + } + + @Override + public ArrayList getSuperCribsRecipeList() { + return superCribsRecipeList; } } diff --git a/src/main/java/gregtech/common/tileentities/machines/MTEHatchCraftingInputSlave.java b/src/main/java/gregtech/common/tileentities/machines/MTEHatchCraftingInputSlave.java index e84df0b756a..cabfcd0b1a6 100644 --- a/src/main/java/gregtech/common/tileentities/machines/MTEHatchCraftingInputSlave.java +++ b/src/main/java/gregtech/common/tileentities/machines/MTEHatchCraftingInputSlave.java @@ -26,6 +26,7 @@ import gregtech.api.metatileentity.MetaTileEntity; import gregtech.api.metatileentity.implementations.MTEHatchInputBus; import gregtech.api.render.TextureFactory; +import gregtech.api.util.GTRecipe; import mcp.mobius.waila.api.IWailaConfigHandler; import mcp.mobius.waila.api.IWailaDataAccessor; @@ -293,7 +294,17 @@ public List getItemsForHoloGlasses() { } @Override - public List getPatternsInputs() { + public List getPatternsInputs() { return getMaster() != null ? getMaster().getPatternsInputs() : null; } + + @Override + public void setSuperCribsRecipeList(ArrayList rList) { + + } + + @Override + public ArrayList getSuperCribsRecipeList() { + return getMaster() != null ? getMaster().superCribsRecipeList : null; + } } From 40242c41c5e847ae8d75ba356913d72092503e94 Mon Sep 17 00:00:00 2001 From: lordIcocain Date: Thu, 5 Dec 2024 08:25:57 +0200 Subject: [PATCH 03/18] save --- .../gregtech/api/logic/ProcessingLogic.java | 52 +++++---- .../implementations/MTEMultiBlockBase.java | 62 ++++++----- .../machines/IDualInputHatch.java | 10 +- .../machines/IDualInputInventory.java | 10 ++ .../machines/MTEHatchCraftingInputME.java | 103 +++++++++--------- .../machines/MTEHatchCraftingInputSlave.java | 20 ++-- .../machines/multi/MTEMultiSolidifier.java | 27 ++++- .../processing/MTEIndustrialMultiMachine.java | 27 ++++- 8 files changed, 181 insertions(+), 130 deletions(-) diff --git a/src/main/java/gregtech/api/logic/ProcessingLogic.java b/src/main/java/gregtech/api/logic/ProcessingLogic.java index f68020ff5c4..69eb3dd1031 100644 --- a/src/main/java/gregtech/api/logic/ProcessingLogic.java +++ b/src/main/java/gregtech/api/logic/ProcessingLogic.java @@ -31,6 +31,8 @@ public class ProcessingLogic extends AbstractProcessingLogic { protected FluidStack[] inputFluids; protected boolean isRecipeLocked; protected ArrayList cribsCustomRecipeMap; + protected boolean processCribs; + protected GTRecipe cribsRecipe; public ProcessingLogic() {} @@ -65,9 +67,12 @@ public ProcessingLogic setSpecialSlotItem(ItemStack specialSlotItem) { return getThis(); } - public ProcessingLogic setCribsCustomRecipeMap(ArrayList cribsCustomRecipeMap) { - this.cribsCustomRecipeMap = cribsCustomRecipeMap; - return getThis(); + public void setProcessCribs(boolean bool) { + this.processCribs = bool; + } + + public void setCribsRecipe(GTRecipe recipe) { + this.cribsRecipe = recipe; } /** @@ -92,6 +97,8 @@ public ProcessingLogic clear() { this.calculatedEut = 0; this.duration = 0; this.calculatedParallels = 0; + this.processCribs = false; + this.cribsRecipe = null; return getThis(); } @@ -103,11 +110,6 @@ public ProcessingLogic clear() { * Executes the recipe check: Find recipe from recipemap, Calculate parallel, overclock and outputs. */ - @Nonnull - public CheckRecipeResult processCribs(GTRecipe recipe) { - return validateAndCalculateRecipe(recipe).checkRecipeResult; - } - @Nonnull public CheckRecipeResult process() { RecipeMap recipeMap = preProcess(); @@ -119,6 +121,13 @@ public CheckRecipeResult process() { inputFluids = new FluidStack[0]; } + if (processCribs) { + if (cribsRecipe.maxParallelCalculatedByInputs(1, inputFluids, inputItems) == 1) { + return validateAndCalculateRecipe(cribsRecipe).checkRecipeResult; + } + return CheckRecipeResultRegistry.NO_RECIPE; + } + if (isRecipeLocked && recipeLockableMachine != null && recipeLockableMachine.getSingleRecipeCheck() != null) { // Recipe checker is already built, we'll use it SingleRecipeCheck singleRecipeCheck = recipeLockableMachine.getSingleRecipeCheck(); @@ -149,24 +158,13 @@ public CheckRecipeResult process() { return checkRecipeResult; } - public GTRecipe getCribsMatch(ItemStack[] iI, FluidStack[] iF) { - RecipeMap recipeMap = preProcess(); - inputItems = iI; - inputFluids = iF; - if (inputItems == null) { - inputItems = new ItemStack[0]; - } - if (inputFluids == null) { - inputFluids = new FluidStack[0]; - } - - Stream matchedRecipes = findRecipeMatches(recipeMap); - Iterable recipeIterable = matchedRecipes::iterator; - CheckRecipeResult checkRecipeResult = CheckRecipeResultRegistry.NO_RECIPE; - for (GTRecipe matchedRecipe : recipeIterable) { - return matchedRecipe; - } - return null; + public GTRecipe getRecipeByInputs(ItemStack[] iI, FluidStack[] iF) { + return preProcess().findRecipeQuery() + .items(iI) + .fluids(iF) + .specialSlot(specialSlotItem) + .cachedRecipe(lastRecipe) + .find(); } /** @@ -176,7 +174,7 @@ public GTRecipe getCribsMatch(ItemStack[] iI, FluidStack[] iF) { * @param recipe The recipe which will be checked and processed */ @Nonnull - public CalculationResult validateAndCalculateRecipe(@Nonnull GTRecipe recipe) { + private CalculationResult validateAndCalculateRecipe(@Nonnull GTRecipe recipe) { CheckRecipeResult result = validateRecipe(recipe); if (!result.wasSuccessful()) { return CalculationResult.ofFailure(result); diff --git a/src/main/java/gregtech/api/metatileentity/implementations/MTEMultiBlockBase.java b/src/main/java/gregtech/api/metatileentity/implementations/MTEMultiBlockBase.java index 2d5d39934a7..52782c3899e 100644 --- a/src/main/java/gregtech/api/metatileentity/implementations/MTEMultiBlockBase.java +++ b/src/main/java/gregtech/api/metatileentity/implementations/MTEMultiBlockBase.java @@ -873,20 +873,9 @@ protected boolean supportsCraftingMEBuffer() { return true; } - public void setSuperCribsRecipeList() { + public void resetCribsRecipes() { for (IDualInputHatch dualInputHatch : mDualInputHatches) { - ArrayList recipeList = new ArrayList<>(); - List temp = dualInputHatch.getPatternsInputs(); - if (temp == null) return; - for (MTEHatchCraftingInputME.recipeInputs t : temp) { - if (t == null) { - recipeList.add(null); - continue; - } - GTRecipe recipe = processingLogic.getCribsMatch(t.inputItems, t.inputFluid); - recipeList.add(recipe); - } - dualInputHatch.setSuperCribsRecipeList(recipeList); + dualInputHatch.resetRecipes(); } } @@ -899,25 +888,40 @@ protected CheckRecipeResult doCheckRecipe() { CheckRecipeResult result = CheckRecipeResultRegistry.NO_RECIPE; // check crafting input hatches first if (supportsCraftingMEBuffer()) { + RecipeMap recipeMap = getRecipeMap(); + if (recipeMap == null) return result; + int recipeMapHash = recipeMap.hashCode(); for (IDualInputHatch dualInputHatch : mDualInputHatches) { - ArrayList cribsCustomRecipeMap = dualInputHatch.getSuperCribsRecipeList(); - if (cribsCustomRecipeMap == null) { - setSuperCribsRecipeList(); - continue; - } - int n = 0; + ItemStack[] sharedItems = dualInputHatch.getSharedItems(); for (var it = dualInputHatch.inventories(); it.hasNext();) { - GTRecipe recipe = cribsCustomRecipeMap.get(n); IDualInputInventory slot = it.next(); - n++; - if (recipe != null) { - ItemStack[] items = slot.getItemInputs(); - FluidStack[] fluids = slot.getFluidInputs(); - if (items == null && fluids == null) continue; - if (items.length == 0 && fluids.length == 0) continue; - processingLogic.setInputItems(items); - processingLogic.setInputFluids(fluids); - return processingLogic.processCribs(recipe); + GTRecipe recipe = slot.getPatternRecipe(); + if (recipe == null) { + MTEHatchCraftingInputME.PatternSlot.recipeInputs t = slot.getPatternInputs(); + GTRecipe slotRecipe = processingLogic.getRecipeByInputs(t.inputItems, t.inputFluid); + if (slotRecipe != null) slot.setPatternRecipe(slotRecipe, recipeMapHash); + continue; + } + + if (slot.getPatternRecipeMapHash() != recipeMapHash) continue; + + ItemStack[] items = slot.getItemInputs(); + FluidStack[] fluids = slot.getFluidInputs(); + + if (items.length == 0 && fluids.length == 0) continue; + + processingLogic.setInputItems(ArrayUtils.addAll(sharedItems, items)); + processingLogic.setInputFluids(fluids); + processingLogic.setProcessCribs(true); + processingLogic.setCribsRecipe(recipe); + + CheckRecipeResult foundResult = processingLogic.process(); + if (foundResult.wasSuccessful()) { + return foundResult; + } + if (foundResult != CheckRecipeResultRegistry.NO_RECIPE) { + // Recipe failed in interesting way, so remember that and continue searching + result = foundResult; } } } diff --git a/src/main/java/gregtech/common/tileentities/machines/IDualInputHatch.java b/src/main/java/gregtech/common/tileentities/machines/IDualInputHatch.java index 7b104d36c38..da561a2ccdb 100644 --- a/src/main/java/gregtech/common/tileentities/machines/IDualInputHatch.java +++ b/src/main/java/gregtech/common/tileentities/machines/IDualInputHatch.java @@ -1,14 +1,10 @@ package gregtech.common.tileentities.machines; -import java.util.ArrayList; import java.util.Iterator; -import java.util.List; import java.util.Optional; import net.minecraft.item.ItemStack; -import gregtech.api.util.GTRecipe; - public interface IDualInputHatch { boolean justUpdated(); @@ -23,9 +19,7 @@ public interface IDualInputHatch { boolean supportsFluids(); - List getPatternsInputs(); - - void setSuperCribsRecipeList(ArrayList rList); + ItemStack[] getSharedItems(); - ArrayList getSuperCribsRecipeList(); + void resetRecipes(); } diff --git a/src/main/java/gregtech/common/tileentities/machines/IDualInputInventory.java b/src/main/java/gregtech/common/tileentities/machines/IDualInputInventory.java index 01649fe1817..9eaab8d323d 100644 --- a/src/main/java/gregtech/common/tileentities/machines/IDualInputInventory.java +++ b/src/main/java/gregtech/common/tileentities/machines/IDualInputInventory.java @@ -3,9 +3,19 @@ import net.minecraft.item.ItemStack; import net.minecraftforge.fluids.FluidStack; +import gregtech.api.util.GTRecipe; + public interface IDualInputInventory { ItemStack[] getItemInputs(); FluidStack[] getFluidInputs(); + + MTEHatchCraftingInputME.PatternSlot.recipeInputs getPatternInputs(); + + void setPatternRecipe(GTRecipe recipe, int hash); + + GTRecipe getPatternRecipe(); + + int getPatternRecipeMapHash(); } diff --git a/src/main/java/gregtech/common/tileentities/machines/MTEHatchCraftingInputME.java b/src/main/java/gregtech/common/tileentities/machines/MTEHatchCraftingInputME.java index 8b9fea9c701..e41d4049d93 100644 --- a/src/main/java/gregtech/common/tileentities/machines/MTEHatchCraftingInputME.java +++ b/src/main/java/gregtech/common/tileentities/machines/MTEHatchCraftingInputME.java @@ -110,11 +110,19 @@ public interface SharedItemGetter { ItemStack[] getSharedItem(); } + public static class recipeInputs { + + public ItemStack[] inputItems; + public FluidStack[] inputFluid; + } + private final ItemStack pattern; private final ICraftingPatternDetails patternDetails; private final List itemInventory; private final List fluidInventory; private final SharedItemGetter sharedItemGetter; + private GTRecipe patternRecipe; + private int patternRecipeMapHash; public PatternSlot(ItemStack pattern, World world, SharedItemGetter getter) { this.pattern = pattern; @@ -123,6 +131,8 @@ public PatternSlot(ItemStack pattern, World world, SharedItemGetter getter) { this.itemInventory = new ArrayList<>(); this.fluidInventory = new ArrayList<>(); this.sharedItemGetter = getter; + this.patternRecipe = null; + this.patternRecipeMapHash = 0; } public PatternSlot(ItemStack pattern, NBTTagCompound nbt, World world, SharedItemGetter getter) { @@ -132,6 +142,8 @@ public PatternSlot(ItemStack pattern, NBTTagCompound nbt, World world, SharedIte this.itemInventory = new ArrayList<>(); this.fluidInventory = new ArrayList<>(); this.sharedItemGetter = getter; + this.patternRecipe = null; + this.patternRecipeMapHash = 0; NBTTagList inv = nbt.getTagList("inventory", Constants.NBT.TAG_COMPOUND); for (int i = 0; i < inv.tagCount(); i++) { NBTTagCompound tagItemStack = inv.getCompoundTagAt(i); @@ -204,7 +216,7 @@ public boolean isEmpty() { @Override public ItemStack[] getItemInputs() { if (isItemEmpty()) return new ItemStack[0]; - return ArrayUtils.addAll(itemInventory.toArray(new ItemStack[0]), sharedItemGetter.getSharedItem()); + return itemInventory.toArray(new ItemStack[0]); } @Override @@ -217,6 +229,42 @@ public ICraftingPatternDetails getPatternDetails() { return patternDetails; } + public recipeInputs getPatternInputs() { + recipeInputs inputsSuper = new recipeInputs(); + + ItemStack[] inputItems = sharedItemGetter.getSharedItem(); + FluidStack[] inputFluids = new FluidStack[0]; + + for (IAEItemStack singleInput : this.getPatternDetails() + .getInputs()) { + if (singleInput == null) continue; + ItemStack singleInputItemStack = singleInput.getItemStack(); + if (singleInputItemStack.getItem() instanceof ItemFluidDrop) { + FluidStack fluidStack = ItemFluidDrop.getFluidStack(singleInputItemStack); + if (fluidStack != null) inputFluids = ArrayUtils.addAll(inputFluids, fluidStack); + } else { + inputItems = ArrayUtils.addAll(inputItems, singleInputItemStack); + } + } + + inputsSuper.inputItems = inputItems; + inputsSuper.inputFluid = inputFluids; + return inputsSuper; + } + + public void setPatternRecipe(GTRecipe recipe, int hash) { + patternRecipe = recipe; + patternRecipeMapHash = hash; + } + + public GTRecipe getPatternRecipe() { + return patternRecipe; + } + + public int getPatternRecipeMapHash() { + return patternRecipeMapHash; + } + public void refund(AENetworkProxy proxy, BaseActionSource src) throws GridAccessException { IMEMonitor sg = proxy.getStorage() .getItemInventory(); @@ -773,6 +821,7 @@ private void onPatternChange(int index, ItemStack newItem) { if (originalPattern.hasChanged(newItem, world)) { try { originalPattern.refund(getProxy(), getRequest()); + originalPattern.setPatternRecipe(null, 0); } catch (GridAccessException ignored) {} internalInventory[index] = null; needPatternSync = true; @@ -791,6 +840,7 @@ private void onPatternChange(int index, ItemStack newItem) { needPatternSync = true; } + @Override public ItemStack[] getSharedItems() { ItemStack[] sharedItems = new ItemStack[SLOT_MANUAL_SIZE + 1]; sharedItems[0] = mInventory[SLOT_CIRCUIT]; @@ -979,7 +1029,6 @@ private boolean postMEPatternChange() { } catch (GridAccessException ignored) { return false; } - superCribsRecipeList = null; return true; } @@ -1058,55 +1107,11 @@ public List getItemsForHoloGlasses() { return list; } - public static class recipeInputs { - - public ItemStack[] inputItems; - public FluidStack[] inputFluid; - } - - ArrayList superCribsRecipeList = new ArrayList<>(); - @Override - public List getPatternsInputs() { - ItemStack[] sharedItems = getSharedItems(); - List recipeInputsList = new ArrayList<>(); + public void resetRecipes() { for (PatternSlot slot : internalInventory) { - if (slot == null) { - recipeInputsList.add(null); - continue; - } - - recipeInputs inputsSuper = new recipeInputs(); - - ItemStack[] inputItems = sharedItems; - FluidStack[] inputFluids = new FluidStack[0]; - - for (IAEItemStack singleInput : slot.getPatternDetails() - .getInputs()) { - if (singleInput == null) continue; - ItemStack singleInputItemStack = singleInput.getItemStack(); - if (singleInputItemStack.getItem() instanceof ItemFluidDrop) { - FluidStack fluidStack = ItemFluidDrop.getFluidStack(singleInputItemStack); - if (fluidStack != null) inputFluids = ArrayUtils.addAll(inputFluids, fluidStack); - } else { - inputItems = ArrayUtils.addAll(inputItems, singleInputItemStack); - } - } - - inputsSuper.inputItems = inputItems; - inputsSuper.inputFluid = inputFluids; - recipeInputsList.add(inputsSuper); + if (slot == null) continue; + slot.setPatternRecipe(null, 0); } - return recipeInputsList; - } - - @Override - public void setSuperCribsRecipeList(ArrayList rList) { - superCribsRecipeList = rList; - } - - @Override - public ArrayList getSuperCribsRecipeList() { - return superCribsRecipeList; } } diff --git a/src/main/java/gregtech/common/tileentities/machines/MTEHatchCraftingInputSlave.java b/src/main/java/gregtech/common/tileentities/machines/MTEHatchCraftingInputSlave.java index cabfcd0b1a6..6d71d0efa7c 100644 --- a/src/main/java/gregtech/common/tileentities/machines/MTEHatchCraftingInputSlave.java +++ b/src/main/java/gregtech/common/tileentities/machines/MTEHatchCraftingInputSlave.java @@ -26,7 +26,6 @@ import gregtech.api.metatileentity.MetaTileEntity; import gregtech.api.metatileentity.implementations.MTEHatchInputBus; import gregtech.api.render.TextureFactory; -import gregtech.api.util.GTRecipe; import mcp.mobius.waila.api.IWailaConfigHandler; import mcp.mobius.waila.api.IWailaDataAccessor; @@ -164,6 +163,11 @@ public boolean supportsFluids() { return getMaster() != null && getMaster().supportsFluids(); } + @Override + public ItemStack[] getSharedItems() { + return getMaster() != null ? getMaster().getSharedItems() : new ItemStack[0]; + } + @Override public boolean justUpdated() { return getMaster() != null && getMaster().justUpdated(); @@ -294,17 +298,7 @@ public List getItemsForHoloGlasses() { } @Override - public List getPatternsInputs() { - return getMaster() != null ? getMaster().getPatternsInputs() : null; - } - - @Override - public void setSuperCribsRecipeList(ArrayList rList) { - - } - - @Override - public ArrayList getSuperCribsRecipeList() { - return getMaster() != null ? getMaster().superCribsRecipeList : null; + public void resetRecipes() { + if (getMaster() != null) getMaster().resetRecipes(); } } diff --git a/src/main/java/gregtech/common/tileentities/machines/multi/MTEMultiSolidifier.java b/src/main/java/gregtech/common/tileentities/machines/multi/MTEMultiSolidifier.java index d6c32a2185c..84b496f5ce7 100644 --- a/src/main/java/gregtech/common/tileentities/machines/multi/MTEMultiSolidifier.java +++ b/src/main/java/gregtech/common/tileentities/machines/multi/MTEMultiSolidifier.java @@ -32,6 +32,7 @@ import net.minecraftforge.common.util.ForgeDirection; import net.minecraftforge.fluids.FluidStack; +import org.apache.commons.lang3.ArrayUtils; import org.jetbrains.annotations.NotNull; import com.gtnewhorizon.structurelib.alignment.constructable.ISurvivalConstructable; @@ -429,11 +430,33 @@ protected CheckRecipeResult doCheckRecipe() { // check crafting input hatches first if (supportsCraftingMEBuffer()) { + RecipeMap recipeMap = getRecipeMap(); + if (recipeMap == null) return result; + int recipeMapHash = recipeMap.hashCode(); for (IDualInputHatch dualInputHatch : mDualInputHatches) { + ItemStack[] sharedItems = dualInputHatch.getSharedItems(); for (var it = dualInputHatch.inventories(); it.hasNext();) { IDualInputInventory slot = it.next(); - processingLogic.setInputItems(slot.getItemInputs()); - processingLogic.setInputFluids(slot.getFluidInputs()); + GTRecipe recipe = slot.getPatternRecipe(); + if (recipe == null) { + MTEHatchCraftingInputME.PatternSlot.recipeInputs t = slot.getPatternInputs(); + GTRecipe slotRecipe = processingLogic.getRecipeByInputs(t.inputItems, t.inputFluid); + if (slotRecipe != null) slot.setPatternRecipe(slotRecipe, recipeMapHash); + continue; + } + + if (slot.getPatternRecipeMapHash() != recipeMapHash) continue; + + ItemStack[] items = slot.getItemInputs(); + FluidStack[] fluids = slot.getFluidInputs(); + + if (items.length == 0 && fluids.length == 0) continue; + + processingLogic.setInputItems(ArrayUtils.addAll(sharedItems, items)); + processingLogic.setInputFluids(fluids); + processingLogic.setProcessCribs(true); + processingLogic.setCribsRecipe(recipe); + CheckRecipeResult foundResult = processingLogic.process(); if (foundResult.wasSuccessful()) { return foundResult; diff --git a/src/main/java/gtPlusPlus/xmod/gregtech/common/tileentities/machines/multi/processing/MTEIndustrialMultiMachine.java b/src/main/java/gtPlusPlus/xmod/gregtech/common/tileentities/machines/multi/processing/MTEIndustrialMultiMachine.java index f8117df4802..948b8fc1abb 100644 --- a/src/main/java/gtPlusPlus/xmod/gregtech/common/tileentities/machines/multi/processing/MTEIndustrialMultiMachine.java +++ b/src/main/java/gtPlusPlus/xmod/gregtech/common/tileentities/machines/multi/processing/MTEIndustrialMultiMachine.java @@ -33,6 +33,7 @@ import net.minecraftforge.common.util.ForgeDirection; import net.minecraftforge.fluids.FluidStack; +import org.apache.commons.lang3.ArrayUtils; import org.jetbrains.annotations.NotNull; import com.gtnewhorizon.structurelib.alignment.constructable.ISurvivalConstructable; @@ -392,11 +393,33 @@ protected CheckRecipeResult doCheckRecipe() { // check crafting input hatches first if (supportsCraftingMEBuffer()) { + RecipeMap recipeMap = getRecipeMap(); + if (recipeMap == null) return result; + int recipeMapHash = recipeMap.hashCode(); for (IDualInputHatch dualInputHatch : mDualInputHatches) { + ItemStack[] sharedItems = dualInputHatch.getSharedItems(); for (var it = dualInputHatch.inventories(); it.hasNext();) { IDualInputInventory slot = it.next(); - processingLogic.setInputItems(slot.getItemInputs()); - processingLogic.setInputFluids(slot.getFluidInputs()); + GTRecipe recipe = slot.getPatternRecipe(); + if (recipe == null) { + MTEHatchCraftingInputME.PatternSlot.recipeInputs t = slot.getPatternInputs(); + GTRecipe slotRecipe = processingLogic.getRecipeByInputs(t.inputItems, t.inputFluid); + if (slotRecipe != null) slot.setPatternRecipe(slotRecipe, recipeMapHash); + continue; + } + + if (slot.getPatternRecipeMapHash() != recipeMapHash) continue; + + ItemStack[] items = slot.getItemInputs(); + FluidStack[] fluids = slot.getFluidInputs(); + + if (items.length == 0 && fluids.length == 0) continue; + + processingLogic.setInputItems(ArrayUtils.addAll(sharedItems, items)); + processingLogic.setInputFluids(fluids); + processingLogic.setProcessCribs(true); + processingLogic.setCribsRecipe(recipe); + CheckRecipeResult foundResult = processingLogic.process(); if (foundResult.wasSuccessful()) { return foundResult; From 337f1d98273010ad9df959920e5320c9b3b799ab Mon Sep 17 00:00:00 2001 From: lordIcocain Date: Fri, 6 Dec 2024 07:53:26 +0200 Subject: [PATCH 04/18] seems works --- .../gregtech/api/logic/ProcessingLogic.java | 11 +++-- .../implementations/MTEMultiBlockBase.java | 47 +++++++++++++++---- .../compressor/MTEBlackHoleCompressor.java | 28 +++++++++++ .../processing/MTEIndustrialMultiMachine.java | 27 +---------- 4 files changed, 77 insertions(+), 36 deletions(-) diff --git a/src/main/java/gregtech/api/logic/ProcessingLogic.java b/src/main/java/gregtech/api/logic/ProcessingLogic.java index 69eb3dd1031..e5aebad5755 100644 --- a/src/main/java/gregtech/api/logic/ProcessingLogic.java +++ b/src/main/java/gregtech/api/logic/ProcessingLogic.java @@ -1,6 +1,5 @@ package gregtech.api.logic; -import java.util.ArrayList; import java.util.List; import java.util.stream.Stream; @@ -30,9 +29,9 @@ public class ProcessingLogic extends AbstractProcessingLogic { protected ItemStack[] inputItems; protected FluidStack[] inputFluids; protected boolean isRecipeLocked; - protected ArrayList cribsCustomRecipeMap; protected boolean processCribs; protected GTRecipe cribsRecipe; + protected int cribsRecipeMapHash; public ProcessingLogic() {} @@ -75,6 +74,10 @@ public void setCribsRecipe(GTRecipe recipe) { this.cribsRecipe = recipe; } + public int getCribsRecipeMapHash() { + return cribsRecipeMapHash; + } + /** * Enables single recipe locking mode. */ @@ -159,7 +162,9 @@ public CheckRecipeResult process() { } public GTRecipe getRecipeByInputs(ItemStack[] iI, FluidStack[] iF) { - return preProcess().findRecipeQuery() + RecipeMap map = preProcess(); + cribsRecipeMapHash = map.hashCode(); + return map.findRecipeQuery() .items(iI) .fluids(iF) .specialSlot(specialSlotItem) diff --git a/src/main/java/gregtech/api/metatileentity/implementations/MTEMultiBlockBase.java b/src/main/java/gregtech/api/metatileentity/implementations/MTEMultiBlockBase.java index 52782c3899e..507fd5c0588 100644 --- a/src/main/java/gregtech/api/metatileentity/implementations/MTEMultiBlockBase.java +++ b/src/main/java/gregtech/api/metatileentity/implementations/MTEMultiBlockBase.java @@ -879,6 +879,23 @@ public void resetCribsRecipes() { } } + public RecipeMap[] getRecipeMaps() { + return null; + } + + public boolean checkRecipeHash(RecipeMap map, RecipeMap[] maps, int hash) { + if (map != null && map.hashCode() == hash) { + return false; + } else if (maps != null) { + for (RecipeMap tempMap : maps) { + if (tempMap.hashCode() == hash) { + return false; + } + } + } + return true; + } + /** * Iterates over hatches and tries to find recipe. Assume {@link #processingLogic} is already set up for use. * If return value is successful, inputs are consumed. @@ -888,22 +905,35 @@ protected CheckRecipeResult doCheckRecipe() { CheckRecipeResult result = CheckRecipeResultRegistry.NO_RECIPE; // check crafting input hatches first if (supportsCraftingMEBuffer()) { - RecipeMap recipeMap = getRecipeMap(); - if (recipeMap == null) return result; - int recipeMapHash = recipeMap.hashCode(); + + RecipeMap map = getRecipeMap(); + RecipeMap[] maps = getRecipeMaps(); + for (IDualInputHatch dualInputHatch : mDualInputHatches) { ItemStack[] sharedItems = dualInputHatch.getSharedItems(); + for (var it = dualInputHatch.inventories(); it.hasNext();) { IDualInputInventory slot = it.next(); GTRecipe recipe = slot.getPatternRecipe(); + int recipeMapHash = slot.getPatternRecipeMapHash(); + if (recipe == null) { - MTEHatchCraftingInputME.PatternSlot.recipeInputs t = slot.getPatternInputs(); - GTRecipe slotRecipe = processingLogic.getRecipeByInputs(t.inputItems, t.inputFluid); - if (slotRecipe != null) slot.setPatternRecipe(slotRecipe, recipeMapHash); - continue; + MTEHatchCraftingInputME.PatternSlot.recipeInputs tempRecipeInputs = slot.getPatternInputs(); + GTRecipe slotRecipe = processingLogic + .getRecipeByInputs(tempRecipeInputs.inputItems, tempRecipeInputs.inputFluid); + int tempRecipeMapHash = processingLogic.getCribsRecipeMapHash(); + + if (slotRecipe != null) { + slot.setPatternRecipe(slotRecipe, tempRecipeMapHash); + } else { + continue; + } + + recipe = slotRecipe; + recipeMapHash = tempRecipeMapHash; } - if (slot.getPatternRecipeMapHash() != recipeMapHash) continue; + if (checkRecipeHash(map, maps, recipeMapHash)) continue; ItemStack[] items = slot.getItemInputs(); FluidStack[] fluids = slot.getFluidInputs(); @@ -2384,6 +2414,7 @@ public UITexture getMachineModeIcon(int index) { @Override public void setMachineMode(int index) { machineMode = index; + resetCribsRecipes(); } @Override diff --git a/src/main/java/gregtech/common/tileentities/machines/multi/compressor/MTEBlackHoleCompressor.java b/src/main/java/gregtech/common/tileentities/machines/multi/compressor/MTEBlackHoleCompressor.java index 35aad1292ad..acd91abafaa 100644 --- a/src/main/java/gregtech/common/tileentities/machines/multi/compressor/MTEBlackHoleCompressor.java +++ b/src/main/java/gregtech/common/tileentities/machines/multi/compressor/MTEBlackHoleCompressor.java @@ -514,6 +514,11 @@ protected void setupProcessingLogic(ProcessingLogic logic) { searchAndDecrementCatalysts(); } + @Override + public RecipeMap[] getRecipeMaps() { + return new RecipeMap[] { RecipeMaps.compressorRecipes, RecipeMaps.neutroniumCompressorRecipes }; + } + @Override protected ProcessingLogic createProcessingLogic() { return new ProcessingLogic() { @@ -534,6 +539,29 @@ protected Stream findRecipeMatches(@Nullable RecipeMap map) { } } + @Override + public GTRecipe getRecipeByInputs(ItemStack[] iI, FluidStack[] iF) { + RecipeMap map; + switch (getModeFromCircuit(iI)) { + case MACHINEMODE_COMPRESSOR -> { + map = RecipeMaps.compressorRecipes; + } + case MACHINEMODE_BLACKHOLE -> { + map = RecipeMaps.neutroniumCompressorRecipes; + } + default -> { + return null; + } + } + cribsRecipeMapHash = map.hashCode(); + return map.findRecipeQuery() + .items(iI) + .fluids(iF) + .specialSlot(specialSlotItem) + .cachedRecipe(lastRecipe) + .find(); + } + @NotNull @Override protected OverclockCalculator createOverclockCalculator(@NotNull GTRecipe recipe) { diff --git a/src/main/java/gtPlusPlus/xmod/gregtech/common/tileentities/machines/multi/processing/MTEIndustrialMultiMachine.java b/src/main/java/gtPlusPlus/xmod/gregtech/common/tileentities/machines/multi/processing/MTEIndustrialMultiMachine.java index 948b8fc1abb..f8117df4802 100644 --- a/src/main/java/gtPlusPlus/xmod/gregtech/common/tileentities/machines/multi/processing/MTEIndustrialMultiMachine.java +++ b/src/main/java/gtPlusPlus/xmod/gregtech/common/tileentities/machines/multi/processing/MTEIndustrialMultiMachine.java @@ -33,7 +33,6 @@ import net.minecraftforge.common.util.ForgeDirection; import net.minecraftforge.fluids.FluidStack; -import org.apache.commons.lang3.ArrayUtils; import org.jetbrains.annotations.NotNull; import com.gtnewhorizon.structurelib.alignment.constructable.ISurvivalConstructable; @@ -393,33 +392,11 @@ protected CheckRecipeResult doCheckRecipe() { // check crafting input hatches first if (supportsCraftingMEBuffer()) { - RecipeMap recipeMap = getRecipeMap(); - if (recipeMap == null) return result; - int recipeMapHash = recipeMap.hashCode(); for (IDualInputHatch dualInputHatch : mDualInputHatches) { - ItemStack[] sharedItems = dualInputHatch.getSharedItems(); for (var it = dualInputHatch.inventories(); it.hasNext();) { IDualInputInventory slot = it.next(); - GTRecipe recipe = slot.getPatternRecipe(); - if (recipe == null) { - MTEHatchCraftingInputME.PatternSlot.recipeInputs t = slot.getPatternInputs(); - GTRecipe slotRecipe = processingLogic.getRecipeByInputs(t.inputItems, t.inputFluid); - if (slotRecipe != null) slot.setPatternRecipe(slotRecipe, recipeMapHash); - continue; - } - - if (slot.getPatternRecipeMapHash() != recipeMapHash) continue; - - ItemStack[] items = slot.getItemInputs(); - FluidStack[] fluids = slot.getFluidInputs(); - - if (items.length == 0 && fluids.length == 0) continue; - - processingLogic.setInputItems(ArrayUtils.addAll(sharedItems, items)); - processingLogic.setInputFluids(fluids); - processingLogic.setProcessCribs(true); - processingLogic.setCribsRecipe(recipe); - + processingLogic.setInputItems(slot.getItemInputs()); + processingLogic.setInputFluids(slot.getFluidInputs()); CheckRecipeResult foundResult = processingLogic.process(); if (foundResult.wasSuccessful()) { return foundResult; From 094c88ee7cbcb678b43db339c3969af33626d19f Mon Sep 17 00:00:00 2001 From: lordIcocain Date: Fri, 6 Dec 2024 08:02:32 +0200 Subject: [PATCH 05/18] smol imrvmnt --- src/main/java/gregtech/api/logic/ProcessingLogic.java | 6 +++--- .../metatileentity/implementations/MTEMultiBlockBase.java | 6 +++--- .../machines/multi/compressor/MTEBlackHoleCompressor.java | 8 ++++---- 3 files changed, 10 insertions(+), 10 deletions(-) diff --git a/src/main/java/gregtech/api/logic/ProcessingLogic.java b/src/main/java/gregtech/api/logic/ProcessingLogic.java index e5aebad5755..ea523f73691 100644 --- a/src/main/java/gregtech/api/logic/ProcessingLogic.java +++ b/src/main/java/gregtech/api/logic/ProcessingLogic.java @@ -161,12 +161,12 @@ public CheckRecipeResult process() { return checkRecipeResult; } - public GTRecipe getRecipeByInputs(ItemStack[] iI, FluidStack[] iF) { + public GTRecipe getRecipeByInputs(ItemStack[] inItems, FluidStack[] inFluids) { RecipeMap map = preProcess(); cribsRecipeMapHash = map.hashCode(); return map.findRecipeQuery() - .items(iI) - .fluids(iF) + .items(inItems) + .fluids(inFluids) .specialSlot(specialSlotItem) .cachedRecipe(lastRecipe) .find(); diff --git a/src/main/java/gregtech/api/metatileentity/implementations/MTEMultiBlockBase.java b/src/main/java/gregtech/api/metatileentity/implementations/MTEMultiBlockBase.java index 507fd5c0588..96bd0b4e24d 100644 --- a/src/main/java/gregtech/api/metatileentity/implementations/MTEMultiBlockBase.java +++ b/src/main/java/gregtech/api/metatileentity/implementations/MTEMultiBlockBase.java @@ -882,7 +882,7 @@ public void resetCribsRecipes() { public RecipeMap[] getRecipeMaps() { return null; } - + //check if this machine working in same recipe map/maps public boolean checkRecipeHash(RecipeMap map, RecipeMap[] maps, int hash) { if (map != null && map.hashCode() == hash) { return false; @@ -917,7 +917,7 @@ protected CheckRecipeResult doCheckRecipe() { GTRecipe recipe = slot.getPatternRecipe(); int recipeMapHash = slot.getPatternRecipeMapHash(); - if (recipe == null) { + if (recipe == null) { //set recipe MTEHatchCraftingInputME.PatternSlot.recipeInputs tempRecipeInputs = slot.getPatternInputs(); GTRecipe slotRecipe = processingLogic .getRecipeByInputs(tempRecipeInputs.inputItems, tempRecipeInputs.inputFluid); @@ -933,7 +933,7 @@ protected CheckRecipeResult doCheckRecipe() { recipeMapHash = tempRecipeMapHash; } - if (checkRecipeHash(map, maps, recipeMapHash)) continue; + if (checkRecipeHash(map, maps, recipeMapHash)) continue; //make sure that this machine able to process recipe ItemStack[] items = slot.getItemInputs(); FluidStack[] fluids = slot.getFluidInputs(); diff --git a/src/main/java/gregtech/common/tileentities/machines/multi/compressor/MTEBlackHoleCompressor.java b/src/main/java/gregtech/common/tileentities/machines/multi/compressor/MTEBlackHoleCompressor.java index acd91abafaa..5a0d87a2cfe 100644 --- a/src/main/java/gregtech/common/tileentities/machines/multi/compressor/MTEBlackHoleCompressor.java +++ b/src/main/java/gregtech/common/tileentities/machines/multi/compressor/MTEBlackHoleCompressor.java @@ -540,9 +540,9 @@ protected Stream findRecipeMatches(@Nullable RecipeMap map) { } @Override - public GTRecipe getRecipeByInputs(ItemStack[] iI, FluidStack[] iF) { + public GTRecipe getRecipeByInputs(ItemStack[] inItems, FluidStack[] inFluids) { RecipeMap map; - switch (getModeFromCircuit(iI)) { + switch (getModeFromCircuit(inItems)) { case MACHINEMODE_COMPRESSOR -> { map = RecipeMaps.compressorRecipes; } @@ -555,8 +555,8 @@ public GTRecipe getRecipeByInputs(ItemStack[] iI, FluidStack[] iF) { } cribsRecipeMapHash = map.hashCode(); return map.findRecipeQuery() - .items(iI) - .fluids(iF) + .items(inItems) + .fluids(inFluids) .specialSlot(specialSlotItem) .cachedRecipe(lastRecipe) .find(); From fa6f276c13b6c1f9c2f5388fa98ac8e5add6018d Mon Sep 17 00:00:00 2001 From: lordIcocain Date: Fri, 6 Dec 2024 08:06:46 +0200 Subject: [PATCH 06/18] less var --- .../gregtech/api/logic/ProcessingLogic.java | 8 +---- .../implementations/MTEMultiBlockBase.java | 9 ++--- .../machines/multi/MTEMultiSolidifier.java | 33 +++++++++++++------ 3 files changed, 29 insertions(+), 21 deletions(-) diff --git a/src/main/java/gregtech/api/logic/ProcessingLogic.java b/src/main/java/gregtech/api/logic/ProcessingLogic.java index ea523f73691..41ddd018b08 100644 --- a/src/main/java/gregtech/api/logic/ProcessingLogic.java +++ b/src/main/java/gregtech/api/logic/ProcessingLogic.java @@ -29,7 +29,6 @@ public class ProcessingLogic extends AbstractProcessingLogic { protected ItemStack[] inputItems; protected FluidStack[] inputFluids; protected boolean isRecipeLocked; - protected boolean processCribs; protected GTRecipe cribsRecipe; protected int cribsRecipeMapHash; @@ -66,10 +65,6 @@ public ProcessingLogic setSpecialSlotItem(ItemStack specialSlotItem) { return getThis(); } - public void setProcessCribs(boolean bool) { - this.processCribs = bool; - } - public void setCribsRecipe(GTRecipe recipe) { this.cribsRecipe = recipe; } @@ -100,7 +95,6 @@ public ProcessingLogic clear() { this.calculatedEut = 0; this.duration = 0; this.calculatedParallels = 0; - this.processCribs = false; this.cribsRecipe = null; return getThis(); } @@ -124,7 +118,7 @@ public CheckRecipeResult process() { inputFluids = new FluidStack[0]; } - if (processCribs) { + if (cribsRecipe != null) { if (cribsRecipe.maxParallelCalculatedByInputs(1, inputFluids, inputItems) == 1) { return validateAndCalculateRecipe(cribsRecipe).checkRecipeResult; } diff --git a/src/main/java/gregtech/api/metatileentity/implementations/MTEMultiBlockBase.java b/src/main/java/gregtech/api/metatileentity/implementations/MTEMultiBlockBase.java index 96bd0b4e24d..cffc8358221 100644 --- a/src/main/java/gregtech/api/metatileentity/implementations/MTEMultiBlockBase.java +++ b/src/main/java/gregtech/api/metatileentity/implementations/MTEMultiBlockBase.java @@ -882,7 +882,8 @@ public void resetCribsRecipes() { public RecipeMap[] getRecipeMaps() { return null; } - //check if this machine working in same recipe map/maps + + // check if this machine working in same recipe map/maps public boolean checkRecipeHash(RecipeMap map, RecipeMap[] maps, int hash) { if (map != null && map.hashCode() == hash) { return false; @@ -917,7 +918,7 @@ protected CheckRecipeResult doCheckRecipe() { GTRecipe recipe = slot.getPatternRecipe(); int recipeMapHash = slot.getPatternRecipeMapHash(); - if (recipe == null) { //set recipe + if (recipe == null) { // set recipe MTEHatchCraftingInputME.PatternSlot.recipeInputs tempRecipeInputs = slot.getPatternInputs(); GTRecipe slotRecipe = processingLogic .getRecipeByInputs(tempRecipeInputs.inputItems, tempRecipeInputs.inputFluid); @@ -933,7 +934,8 @@ protected CheckRecipeResult doCheckRecipe() { recipeMapHash = tempRecipeMapHash; } - if (checkRecipeHash(map, maps, recipeMapHash)) continue; //make sure that this machine able to process recipe + if (checkRecipeHash(map, maps, recipeMapHash)) continue; // make sure that this machine able to + // process recipe ItemStack[] items = slot.getItemInputs(); FluidStack[] fluids = slot.getFluidInputs(); @@ -942,7 +944,6 @@ protected CheckRecipeResult doCheckRecipe() { processingLogic.setInputItems(ArrayUtils.addAll(sharedItems, items)); processingLogic.setInputFluids(fluids); - processingLogic.setProcessCribs(true); processingLogic.setCribsRecipe(recipe); CheckRecipeResult foundResult = processingLogic.process(); diff --git a/src/main/java/gregtech/common/tileentities/machines/multi/MTEMultiSolidifier.java b/src/main/java/gregtech/common/tileentities/machines/multi/MTEMultiSolidifier.java index 84b496f5ce7..b979f1e036a 100644 --- a/src/main/java/gregtech/common/tileentities/machines/multi/MTEMultiSolidifier.java +++ b/src/main/java/gregtech/common/tileentities/machines/multi/MTEMultiSolidifier.java @@ -430,22 +430,36 @@ protected CheckRecipeResult doCheckRecipe() { // check crafting input hatches first if (supportsCraftingMEBuffer()) { - RecipeMap recipeMap = getRecipeMap(); - if (recipeMap == null) return result; - int recipeMapHash = recipeMap.hashCode(); + + RecipeMap map = getRecipeMap(); + RecipeMap[] maps = getRecipeMaps(); + for (IDualInputHatch dualInputHatch : mDualInputHatches) { ItemStack[] sharedItems = dualInputHatch.getSharedItems(); + for (var it = dualInputHatch.inventories(); it.hasNext();) { IDualInputInventory slot = it.next(); GTRecipe recipe = slot.getPatternRecipe(); - if (recipe == null) { - MTEHatchCraftingInputME.PatternSlot.recipeInputs t = slot.getPatternInputs(); - GTRecipe slotRecipe = processingLogic.getRecipeByInputs(t.inputItems, t.inputFluid); - if (slotRecipe != null) slot.setPatternRecipe(slotRecipe, recipeMapHash); - continue; + int recipeMapHash = slot.getPatternRecipeMapHash(); + + if (recipe == null) { // set recipe + MTEHatchCraftingInputME.PatternSlot.recipeInputs tempRecipeInputs = slot.getPatternInputs(); + GTRecipe slotRecipe = processingLogic + .getRecipeByInputs(tempRecipeInputs.inputItems, tempRecipeInputs.inputFluid); + int tempRecipeMapHash = processingLogic.getCribsRecipeMapHash(); + + if (slotRecipe != null) { + slot.setPatternRecipe(slotRecipe, tempRecipeMapHash); + } else { + continue; + } + + recipe = slotRecipe; + recipeMapHash = tempRecipeMapHash; } - if (slot.getPatternRecipeMapHash() != recipeMapHash) continue; + if (checkRecipeHash(map, maps, recipeMapHash)) continue; // make sure that this machine able to + // process recipe ItemStack[] items = slot.getItemInputs(); FluidStack[] fluids = slot.getFluidInputs(); @@ -454,7 +468,6 @@ protected CheckRecipeResult doCheckRecipe() { processingLogic.setInputItems(ArrayUtils.addAll(sharedItems, items)); processingLogic.setInputFluids(fluids); - processingLogic.setProcessCribs(true); processingLogic.setCribsRecipe(recipe); CheckRecipeResult foundResult = processingLogic.process(); From 2d8f1fafa52f13e4ffc5103c972f0b45986e5c19 Mon Sep 17 00:00:00 2001 From: lordIcocain Date: Fri, 6 Dec 2024 08:29:38 +0200 Subject: [PATCH 07/18] fix --- .../common/tileentities/machines/MTEHatchCraftingInputME.java | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/main/java/gregtech/common/tileentities/machines/MTEHatchCraftingInputME.java b/src/main/java/gregtech/common/tileentities/machines/MTEHatchCraftingInputME.java index e41d4049d93..29d6058a19e 100644 --- a/src/main/java/gregtech/common/tileentities/machines/MTEHatchCraftingInputME.java +++ b/src/main/java/gregtech/common/tileentities/machines/MTEHatchCraftingInputME.java @@ -201,7 +201,7 @@ public void updateSlotFluids() { public boolean isItemEmpty() { updateSlotItems(); - return itemInventory.isEmpty() && isFluidEmpty(); + return itemInventory.isEmpty(); } public boolean isFluidEmpty() { From 51d237cbe0df765623f4b995435ed85ef46ea0c3 Mon Sep 17 00:00:00 2001 From: lordIcocain Date: Tue, 10 Dec 2024 11:47:31 +0200 Subject: [PATCH 08/18] indicate if pattern not have recipe. --- .../tileentities/machines/MTEHatchCraftingInputME.java | 8 +++++++- 1 file changed, 7 insertions(+), 1 deletion(-) diff --git a/src/main/java/gregtech/common/tileentities/machines/MTEHatchCraftingInputME.java b/src/main/java/gregtech/common/tileentities/machines/MTEHatchCraftingInputME.java index 29d6058a19e..e639909e7fc 100644 --- a/src/main/java/gregtech/common/tileentities/machines/MTEHatchCraftingInputME.java +++ b/src/main/java/gregtech/common/tileentities/machines/MTEHatchCraftingInputME.java @@ -253,6 +253,11 @@ public recipeInputs getPatternInputs() { } public void setPatternRecipe(GTRecipe recipe, int hash) { + if (recipe != null) { + Objects.requireNonNull(pattern.getItem()).setMaxStackSize(63); //trick for indicate "have recipe" in gui + } else { + Objects.requireNonNull(pattern.getItem()).setMaxStackSize(64); + } patternRecipe = recipe; patternRecipeMapHash = hash; } @@ -756,7 +761,7 @@ public void addUIWidgets(ModularWindow.@NotNull Builder builder, UIBuildContext @Override protected ItemStack getItemStackForRendering(Slot slotIn) { ItemStack stack = slot.getStack(); - if (stack == null || !(stack.getItem() instanceof ItemEncodedPattern patternItem)) { + if (stack == null || !(stack.getItem() instanceof ItemEncodedPattern patternItem) || stack.getItem().getItemStackLimit() == 64) { return stack; } ItemStack output = patternItem.getOutput(stack); @@ -822,6 +827,7 @@ private void onPatternChange(int index, ItemStack newItem) { try { originalPattern.refund(getProxy(), getRequest()); originalPattern.setPatternRecipe(null, 0); + Objects.requireNonNull(originalPattern.pattern.getItem()).setMaxStackSize(64); } catch (GridAccessException ignored) {} internalInventory[index] = null; needPatternSync = true; From 335963416efe541074c22ac863d2c58206204745 Mon Sep 17 00:00:00 2001 From: lordIcocain Date: Tue, 10 Dec 2024 14:04:09 +0200 Subject: [PATCH 09/18] recipe indicator using FakeSyncWidget --- .../machines/MTEHatchCraftingInputME.java | 28 ++++++++++++++----- 1 file changed, 21 insertions(+), 7 deletions(-) diff --git a/src/main/java/gregtech/common/tileentities/machines/MTEHatchCraftingInputME.java b/src/main/java/gregtech/common/tileentities/machines/MTEHatchCraftingInputME.java index e639909e7fc..29acd788244 100644 --- a/src/main/java/gregtech/common/tileentities/machines/MTEHatchCraftingInputME.java +++ b/src/main/java/gregtech/common/tileentities/machines/MTEHatchCraftingInputME.java @@ -18,6 +18,7 @@ import javax.annotation.Nullable; +import com.gtnewhorizons.modularui.common.widget.FakeSyncWidget; import net.minecraft.entity.player.EntityPlayer; import net.minecraft.entity.player.EntityPlayerMP; import net.minecraft.inventory.IInventory; @@ -253,11 +254,6 @@ public recipeInputs getPatternInputs() { } public void setPatternRecipe(GTRecipe recipe, int hash) { - if (recipe != null) { - Objects.requireNonNull(pattern.getItem()).setMaxStackSize(63); //trick for indicate "have recipe" in gui - } else { - Objects.requireNonNull(pattern.getItem()).setMaxStackSize(64); - } patternRecipe = recipe; patternRecipeMapHash = hash; } @@ -747,6 +743,24 @@ public int getGUIWidth() { return super.getGUIWidth() + 16; } + private String getPatternHasRecipeList() { + StringBuilder sl = new StringBuilder(); + for (PatternSlot slot : internalInventory) { + if (slot == null) { + sl.append(0); + } else { + if (slot.patternRecipe != null) { + sl.append(1); + } else { + sl.append(0); + } + } + } + return sl.toString(); + } + + private String patternHasRecipeListCache = "000000000000000000000000000000000000"; + @Override public void addUIWidgets(ModularWindow.@NotNull Builder builder, UIBuildContext buildContext) { buildContext.addSyncedWindow(MANUAL_SLOT_WINDOW, this::createSlotManualWindow); @@ -761,7 +775,7 @@ public void addUIWidgets(ModularWindow.@NotNull Builder builder, UIBuildContext @Override protected ItemStack getItemStackForRendering(Slot slotIn) { ItemStack stack = slot.getStack(); - if (stack == null || !(stack.getItem() instanceof ItemEncodedPattern patternItem) || stack.getItem().getItemStackLimit() == 64) { + if (stack == null || !(stack.getItem() instanceof ItemEncodedPattern patternItem) || patternHasRecipeListCache.charAt(slot.getSlotIndex()) == '0') { return stack; } ItemStack output = patternItem.getOutput(stack); @@ -771,6 +785,7 @@ protected ItemStack getItemStackForRendering(Slot slotIn) { .setChangeListener(() -> onPatternChange(slot.getSlotIndex(), slot.getStack()))) .build() .setPos(7, 9)) + .widget(new FakeSyncWidget.StringSyncer(this::getPatternHasRecipeList, val -> patternHasRecipeListCache = val)) .widget(new ButtonWidget().setOnClick((clickData, widget) -> { if (clickData.mouseButton == 0) { widget.getContext() @@ -827,7 +842,6 @@ private void onPatternChange(int index, ItemStack newItem) { try { originalPattern.refund(getProxy(), getRequest()); originalPattern.setPatternRecipe(null, 0); - Objects.requireNonNull(originalPattern.pattern.getItem()).setMaxStackSize(64); } catch (GridAccessException ignored) {} internalInventory[index] = null; needPatternSync = true; From 59ff738876f175e427758e352f0f7b0cdb6ab3cd Mon Sep 17 00:00:00 2001 From: lordIcocain Date: Tue, 10 Dec 2024 17:52:38 +0200 Subject: [PATCH 10/18] spotless --- .../tileentities/machines/MTEHatchCraftingInputME.java | 8 +++++--- 1 file changed, 5 insertions(+), 3 deletions(-) diff --git a/src/main/java/gregtech/common/tileentities/machines/MTEHatchCraftingInputME.java b/src/main/java/gregtech/common/tileentities/machines/MTEHatchCraftingInputME.java index 29acd788244..ebbc2fd7802 100644 --- a/src/main/java/gregtech/common/tileentities/machines/MTEHatchCraftingInputME.java +++ b/src/main/java/gregtech/common/tileentities/machines/MTEHatchCraftingInputME.java @@ -18,7 +18,6 @@ import javax.annotation.Nullable; -import com.gtnewhorizons.modularui.common.widget.FakeSyncWidget; import net.minecraft.entity.player.EntityPlayer; import net.minecraft.entity.player.EntityPlayerMP; import net.minecraft.inventory.IInventory; @@ -50,6 +49,7 @@ import com.gtnewhorizons.modularui.api.screen.UIBuildContext; import com.gtnewhorizons.modularui.common.widget.ButtonWidget; import com.gtnewhorizons.modularui.common.widget.CycleButtonWidget; +import com.gtnewhorizons.modularui.common.widget.FakeSyncWidget; import com.gtnewhorizons.modularui.common.widget.SlotGroup; import com.gtnewhorizons.modularui.common.widget.SlotWidget; @@ -775,7 +775,8 @@ public void addUIWidgets(ModularWindow.@NotNull Builder builder, UIBuildContext @Override protected ItemStack getItemStackForRendering(Slot slotIn) { ItemStack stack = slot.getStack(); - if (stack == null || !(stack.getItem() instanceof ItemEncodedPattern patternItem) || patternHasRecipeListCache.charAt(slot.getSlotIndex()) == '0') { + if (stack == null || !(stack.getItem() instanceof ItemEncodedPattern patternItem) + || patternHasRecipeListCache.charAt(slot.getSlotIndex()) == '0') { return stack; } ItemStack output = patternItem.getOutput(stack); @@ -785,7 +786,8 @@ protected ItemStack getItemStackForRendering(Slot slotIn) { .setChangeListener(() -> onPatternChange(slot.getSlotIndex(), slot.getStack()))) .build() .setPos(7, 9)) - .widget(new FakeSyncWidget.StringSyncer(this::getPatternHasRecipeList, val -> patternHasRecipeListCache = val)) + .widget( + new FakeSyncWidget.StringSyncer(this::getPatternHasRecipeList, val -> patternHasRecipeListCache = val)) .widget(new ButtonWidget().setOnClick((clickData, widget) -> { if (clickData.mouseButton == 0) { widget.getContext() From 81d4423db92cc2c9bc1e6f7a7ad1f9e7591f3413 Mon Sep 17 00:00:00 2001 From: lordIcocain Date: Wed, 11 Dec 2024 13:00:36 +0200 Subject: [PATCH 11/18] as mode --- .../gregtech/api/logic/ProcessingLogic.java | 1 - .../implementations/MTEMultiBlockBase.java | 147 ++++++++++++------ .../machines/IDualInputHatch.java | 2 + .../machines/MTEHatchCraftingInputME.java | 31 ++-- .../machines/MTEHatchCraftingInputSlave.java | 7 +- .../machines/multi/MTEMultiSolidifier.java | 70 +++------ .../resources/assets/gregtech/lang/en_US.lang | 2 + 7 files changed, 154 insertions(+), 106 deletions(-) diff --git a/src/main/java/gregtech/api/logic/ProcessingLogic.java b/src/main/java/gregtech/api/logic/ProcessingLogic.java index 41ddd018b08..fe8d1623697 100644 --- a/src/main/java/gregtech/api/logic/ProcessingLogic.java +++ b/src/main/java/gregtech/api/logic/ProcessingLogic.java @@ -162,7 +162,6 @@ public GTRecipe getRecipeByInputs(ItemStack[] inItems, FluidStack[] inFluids) { .items(inItems) .fluids(inFluids) .specialSlot(specialSlotItem) - .cachedRecipe(lastRecipe) .find(); } diff --git a/src/main/java/gregtech/api/metatileentity/implementations/MTEMultiBlockBase.java b/src/main/java/gregtech/api/metatileentity/implementations/MTEMultiBlockBase.java index baf89938030..863c2ded84c 100644 --- a/src/main/java/gregtech/api/metatileentity/implementations/MTEMultiBlockBase.java +++ b/src/main/java/gregtech/api/metatileentity/implementations/MTEMultiBlockBase.java @@ -143,11 +143,13 @@ public abstract class MTEMultiBlockBase extends MetaTileEntity protected VoidingMode voidingMode = getDefaultVoidingMode(); protected boolean batchMode = getDefaultBatchMode(); protected @Nonnull CheckRecipeResult checkRecipeResult = CheckRecipeResultRegistry.NONE; + protected boolean superCribsRecipeCheck = false; protected static final String INPUT_SEPARATION_NBT_KEY = "inputSeparation"; protected static final String VOID_EXCESS_NBT_KEY = "voidExcess"; protected static final String VOIDING_MODE_NBT_KEY = "voidingMode"; protected static final String BATCH_MODE_NBT_KEY = "batchMode"; + protected static final String SUPER_CRIBS_MODE_NBT_KEY = "superCribsMode"; protected SingleRecipeCheck mSingleRecipeCheck = null; public ArrayList mInputHatches = new ArrayList<>(); @@ -211,6 +213,19 @@ public void onScrewdriverRightClick(ForgeDirection side, EntityPlayer aPlayer, f } } + @Override + public boolean onSolderingToolRightClick(ForgeDirection side, ForgeDirection wrenchingSide, EntityPlayer aPlayer, + float aX, float aY, float aZ, ItemStack aTool) { + if (side == getBaseMetaTileEntity().getFrontFacing()) { + superCribsRecipeCheck ^= true; + resetCribsRecipes(); + setSuperCribsRecipeCheck(superCribsRecipeCheck); + aPlayer.addChatMessage(new ChatComponentTranslation("GT5U.multiblock.superCribs." + superCribsRecipeCheck)); + return true; + } + return false; + } + @Override public boolean isSimpleMachine() { return false; @@ -297,6 +312,7 @@ public void saveNBTData(NBTTagCompound aNBT) { aNBT.setBoolean(BATCH_MODE_NBT_KEY, batchMode); aNBT.setBoolean(INPUT_SEPARATION_NBT_KEY, inputSeparation); aNBT.setString(VOIDING_MODE_NBT_KEY, voidingMode.name); + aNBT.setBoolean(SUPER_CRIBS_MODE_NBT_KEY, superCribsRecipeCheck); } @Override @@ -335,6 +351,7 @@ public void loadNBTData(NBTTagCompound aNBT) { } batchMode = aNBT.getBoolean(BATCH_MODE_NBT_KEY); inputSeparation = aNBT.getBoolean(INPUT_SEPARATION_NBT_KEY); + superCribsRecipeCheck = aNBT.getBoolean(SUPER_CRIBS_MODE_NBT_KEY); if (aNBT.hasKey(VOIDING_MODE_NBT_KEY, Constants.NBT.TAG_STRING)) { voidingMode = VoidingMode.fromName(aNBT.getString(VOIDING_MODE_NBT_KEY)); } else if (aNBT.hasKey(VOID_EXCESS_NBT_KEY)) { @@ -881,6 +898,12 @@ public void resetCribsRecipes() { } } + public void setSuperCribsRecipeCheck(boolean state) { + for (IDualInputHatch dualInputHatch : mDualInputHatches) { + dualInputHatch.setSuperCribsRecipeCheck(state); + } + } + public RecipeMap[] getRecipeMaps() { return null; } @@ -899,62 +922,94 @@ public boolean checkRecipeHash(RecipeMap map, RecipeMap[] maps, int hash) return true; } - /** - * Iterates over hatches and tries to find recipe. Assume {@link #processingLogic} is already set up for use. - * If return value is successful, inputs are consumed. - */ - @Nonnull - protected CheckRecipeResult doCheckRecipe() { + public CheckRecipeResult doSuperCribsCheckRecipe() { CheckRecipeResult result = CheckRecipeResultRegistry.NO_RECIPE; - // check crafting input hatches first - if (supportsCraftingMEBuffer()) { + RecipeMap map = getRecipeMap(); + RecipeMap[] maps = getRecipeMaps(); + + for (IDualInputHatch dualInputHatch : mDualInputHatches) { + ItemStack[] sharedItems = dualInputHatch.getSharedItems(); - RecipeMap map = getRecipeMap(); - RecipeMap[] maps = getRecipeMaps(); + for (var it = dualInputHatch.inventories(); it.hasNext();) { + IDualInputInventory slot = it.next(); + GTRecipe recipe = slot.getPatternRecipe(); + int recipeMapHash = slot.getPatternRecipeMapHash(); - for (IDualInputHatch dualInputHatch : mDualInputHatches) { - ItemStack[] sharedItems = dualInputHatch.getSharedItems(); - - for (var it = dualInputHatch.inventories(); it.hasNext();) { - IDualInputInventory slot = it.next(); - GTRecipe recipe = slot.getPatternRecipe(); - int recipeMapHash = slot.getPatternRecipeMapHash(); - - if (recipe == null) { // set recipe - MTEHatchCraftingInputME.PatternSlot.recipeInputs tempRecipeInputs = slot.getPatternInputs(); - GTRecipe slotRecipe = processingLogic - .getRecipeByInputs(tempRecipeInputs.inputItems, tempRecipeInputs.inputFluid); - int tempRecipeMapHash = processingLogic.getCribsRecipeMapHash(); - - if (slotRecipe != null) { - slot.setPatternRecipe(slotRecipe, tempRecipeMapHash); - } else { - continue; - } + if (recipe == null) { // set recipe + MTEHatchCraftingInputME.PatternSlot.recipeInputs tempRecipeInputs = slot.getPatternInputs(); + GTRecipe slotRecipe = processingLogic + .getRecipeByInputs(tempRecipeInputs.inputItems, tempRecipeInputs.inputFluid); + int tempRecipeMapHash = processingLogic.getCribsRecipeMapHash(); - recipe = slotRecipe; - recipeMapHash = tempRecipeMapHash; + if (slotRecipe != null) { + slot.setPatternRecipe(slotRecipe, tempRecipeMapHash); + } else { + continue; } - if (checkRecipeHash(map, maps, recipeMapHash)) continue; // make sure that this machine able to - // process recipe + recipe = slotRecipe; + recipeMapHash = tempRecipeMapHash; + } - ItemStack[] items = slot.getItemInputs(); - FluidStack[] fluids = slot.getFluidInputs(); + if (checkRecipeHash(map, maps, recipeMapHash)) continue; // make sure that this machine able to + // process recipe - if (items.length == 0 && fluids.length == 0) continue; + ItemStack[] items = slot.getItemInputs(); + FluidStack[] fluids = slot.getFluidInputs(); - processingLogic.setInputItems(ArrayUtils.addAll(sharedItems, items)); - processingLogic.setInputFluids(fluids); - processingLogic.setCribsRecipe(recipe); + if (items.length == 0 && fluids.length == 0) continue; - CheckRecipeResult foundResult = processingLogic.process(); - if (foundResult.wasSuccessful()) { - return foundResult; - } - if (foundResult != CheckRecipeResultRegistry.NO_RECIPE) { - // Recipe failed in interesting way, so remember that and continue searching - result = foundResult; + processingLogic.setInputItems(ArrayUtils.addAll(sharedItems, items)); + processingLogic.setInputFluids(fluids); + processingLogic.setCribsRecipe(recipe); + + CheckRecipeResult foundResult = processingLogic.process(); + if (foundResult.wasSuccessful()) { + return foundResult; + } + if (foundResult != CheckRecipeResultRegistry.NO_RECIPE) { + // Recipe failed in interesting way, so remember that and continue searching + result = foundResult; + } + } + } + return result; + } + + /** + * Iterates over hatches and tries to find recipe. Assume {@link #processingLogic} is already set up for use. + * If return value is successful, inputs are consumed. + */ + @Nonnull + protected CheckRecipeResult doCheckRecipe() { + CheckRecipeResult result = CheckRecipeResultRegistry.NO_RECIPE; + // check crafting input hatches first + if (supportsCraftingMEBuffer()) { + if (superCribsRecipeCheck) { + CheckRecipeResult superCribsRecipeCheckResult = doSuperCribsCheckRecipe(); + if (superCribsRecipeCheckResult == CheckRecipeResultRegistry.SUCCESSFUL) { + return superCribsRecipeCheckResult; + } else { + result = superCribsRecipeCheckResult; + } + } else { + for (IDualInputHatch dualInputHatch : mDualInputHatches) { + ItemStack[] sharedItems = dualInputHatch.getSharedItems(); + for (var it = dualInputHatch.inventories(); it.hasNext();) { + IDualInputInventory slot = it.next(); + // Reverse order of input items for consistent behavior with standard input buses. + ItemStack[] inputItems = ArrayUtils.addAll(slot.getItemInputs(), sharedItems); + ArrayUtils.reverse(inputItems); + processingLogic.setInputItems(inputItems); + processingLogic.setInputFluids(slot.getFluidInputs()); + CheckRecipeResult foundResult = processingLogic.process(); + if (foundResult.wasSuccessful()) { + return foundResult; + } + if (foundResult != CheckRecipeResultRegistry.NO_RECIPE) { + // Recipe failed in interesting way, so remember that and continue searching + result = foundResult; + } } } } diff --git a/src/main/java/gregtech/common/tileentities/machines/IDualInputHatch.java b/src/main/java/gregtech/common/tileentities/machines/IDualInputHatch.java index da561a2ccdb..54e57a41cc0 100644 --- a/src/main/java/gregtech/common/tileentities/machines/IDualInputHatch.java +++ b/src/main/java/gregtech/common/tileentities/machines/IDualInputHatch.java @@ -22,4 +22,6 @@ public interface IDualInputHatch { ItemStack[] getSharedItems(); void resetRecipes(); + + void setSuperCribsRecipeCheck(boolean state); } diff --git a/src/main/java/gregtech/common/tileentities/machines/MTEHatchCraftingInputME.java b/src/main/java/gregtech/common/tileentities/machines/MTEHatchCraftingInputME.java index ebbc2fd7802..7b4ba73f120 100644 --- a/src/main/java/gregtech/common/tileentities/machines/MTEHatchCraftingInputME.java +++ b/src/main/java/gregtech/common/tileentities/machines/MTEHatchCraftingInputME.java @@ -387,6 +387,7 @@ public NBTTagCompound writeToNBT(NBTTagCompound nbt) { private final boolean supportFluids; private boolean additionalConnection = false; private boolean disablePatternOptimization = false; + public boolean superCribsRecipeCheck = false; public MTEHatchCraftingInputME(int aID, String aName, String aNameRegional, boolean supportFluids) { super( @@ -594,6 +595,7 @@ public void saveNBTData(NBTTagCompound aNBT) { if (customName != null) aNBT.setString("customName", customName); aNBT.setBoolean("additionalConnection", additionalConnection); aNBT.setBoolean("disablePatternOptimization", disablePatternOptimization); + aNBT.setBoolean("superCribsRecipeCheck", superCribsRecipeCheck); getProxy().writeToNBT(aNBT); } @@ -644,6 +646,7 @@ public void loadNBTData(NBTTagCompound aNBT) { if (aNBT.hasKey("customName")) customName = aNBT.getString("customName"); additionalConnection = aNBT.getBoolean("additionalConnection"); disablePatternOptimization = aNBT.getBoolean("disablePatternOptimization"); + superCribsRecipeCheck = aNBT.getBoolean("superCribsRecipeCheck"); getProxy().readFromNBT(aNBT); } @@ -744,22 +747,30 @@ public int getGUIWidth() { } private String getPatternHasRecipeList() { - StringBuilder sl = new StringBuilder(); - for (PatternSlot slot : internalInventory) { - if (slot == null) { - sl.append(0); - } else { - if (slot.patternRecipe != null) { - sl.append(1); - } else { + if (superCribsRecipeCheck) { + StringBuilder sl = new StringBuilder(); + for (PatternSlot slot : internalInventory) { + if (slot == null) { sl.append(0); + } else { + if (slot.patternRecipe != null) { + sl.append(1); + } else { + sl.append(0); + } } } + return sl.toString(); } - return sl.toString(); + return patternHasRecipeListCache; + } + + @Override + public void setSuperCribsRecipeCheck(boolean state) { + superCribsRecipeCheck = state; } - private String patternHasRecipeListCache = "000000000000000000000000000000000000"; + private String patternHasRecipeListCache = "111111111111111111111111111111111111"; @Override public void addUIWidgets(ModularWindow.@NotNull Builder builder, UIBuildContext buildContext) { diff --git a/src/main/java/gregtech/common/tileentities/machines/MTEHatchCraftingInputSlave.java b/src/main/java/gregtech/common/tileentities/machines/MTEHatchCraftingInputSlave.java index 6d71d0efa7c..663258751bf 100644 --- a/src/main/java/gregtech/common/tileentities/machines/MTEHatchCraftingInputSlave.java +++ b/src/main/java/gregtech/common/tileentities/machines/MTEHatchCraftingInputSlave.java @@ -298,7 +298,8 @@ public List getItemsForHoloGlasses() { } @Override - public void resetRecipes() { - if (getMaster() != null) getMaster().resetRecipes(); - } + public void resetRecipes() {} + + @Override + public void setSuperCribsRecipeCheck(boolean state) {} } diff --git a/src/main/java/gregtech/common/tileentities/machines/multi/MTEMultiSolidifier.java b/src/main/java/gregtech/common/tileentities/machines/multi/MTEMultiSolidifier.java index b19ce3a6ef3..f49b7019ab1 100644 --- a/src/main/java/gregtech/common/tileentities/machines/multi/MTEMultiSolidifier.java +++ b/src/main/java/gregtech/common/tileentities/machines/multi/MTEMultiSolidifier.java @@ -431,53 +431,31 @@ protected CheckRecipeResult doCheckRecipe() { // check crafting input hatches first if (supportsCraftingMEBuffer()) { - - RecipeMap map = getRecipeMap(); - RecipeMap[] maps = getRecipeMaps(); - - for (IDualInputHatch dualInputHatch : mDualInputHatches) { - ItemStack[] sharedItems = dualInputHatch.getSharedItems(); - - for (var it = dualInputHatch.inventories(); it.hasNext();) { - IDualInputInventory slot = it.next(); - GTRecipe recipe = slot.getPatternRecipe(); - int recipeMapHash = slot.getPatternRecipeMapHash(); - - if (recipe == null) { // set recipe - MTEHatchCraftingInputME.PatternSlot.recipeInputs tempRecipeInputs = slot.getPatternInputs(); - GTRecipe slotRecipe = processingLogic - .getRecipeByInputs(tempRecipeInputs.inputItems, tempRecipeInputs.inputFluid); - int tempRecipeMapHash = processingLogic.getCribsRecipeMapHash(); - - if (slotRecipe != null) { - slot.setPatternRecipe(slotRecipe, tempRecipeMapHash); - } else { - continue; + if (superCribsRecipeCheck) { + CheckRecipeResult superCribsRecipeCheckResult = doSuperCribsCheckRecipe(); + if (superCribsRecipeCheckResult == CheckRecipeResultRegistry.SUCCESSFUL) { + return superCribsRecipeCheckResult; + } else { + result = superCribsRecipeCheckResult; + } + } else { + for (IDualInputHatch dualInputHatch : mDualInputHatches) { + ItemStack[] sharedItems = dualInputHatch.getSharedItems(); + for (var it = dualInputHatch.inventories(); it.hasNext();) { + IDualInputInventory slot = it.next(); + // Reverse order of input items for consistent behavior with standard input buses. + ItemStack[] inputItems = ArrayUtils.addAll(slot.getItemInputs(), sharedItems); + ArrayUtils.reverse(inputItems); + processingLogic.setInputItems(inputItems); + processingLogic.setInputFluids(slot.getFluidInputs()); + CheckRecipeResult foundResult = processingLogic.process(); + if (foundResult.wasSuccessful()) { + return foundResult; + } + if (foundResult != CheckRecipeResultRegistry.NO_RECIPE) { + // Recipe failed in interesting way, so remember that and continue searching + result = foundResult; } - - recipe = slotRecipe; - recipeMapHash = tempRecipeMapHash; - } - - if (checkRecipeHash(map, maps, recipeMapHash)) continue; // make sure that this machine able to - // process recipe - - ItemStack[] items = slot.getItemInputs(); - FluidStack[] fluids = slot.getFluidInputs(); - - if (items.length == 0 && fluids.length == 0) continue; - - processingLogic.setInputItems(ArrayUtils.addAll(sharedItems, items)); - processingLogic.setInputFluids(fluids); - processingLogic.setCribsRecipe(recipe); - - CheckRecipeResult foundResult = processingLogic.process(); - if (foundResult.wasSuccessful()) { - return foundResult; - } - if (foundResult != CheckRecipeResultRegistry.NO_RECIPE) { - // Recipe failed in interesting way, so remember that and continue searching - result = foundResult; } } } diff --git a/src/main/resources/assets/gregtech/lang/en_US.lang b/src/main/resources/assets/gregtech/lang/en_US.lang index 78ea8d1d537..ac50fc98a43 100644 --- a/src/main/resources/assets/gregtech/lang/en_US.lang +++ b/src/main/resources/assets/gregtech/lang/en_US.lang @@ -683,6 +683,8 @@ GT5U.multiblock.speed=Speed GT5U.multiblock.fluidPipeTier=Fluid Pipe Tier GT5U.multiblock.itemPipeTier=Item Pipe Tier GT5U.multiblock.coilLevel=Heating Coil Level +GT5U.multiblock.superCribs.true=SuperCribs recipe check mode is §aEnabled +GT5U.multiblock.superCribs.false=SuperCribs recipe check mode is §cDisabled # NEI recipe handlers GT5U.nei.heat_capacity=Heat Capacity: %s K (%s) From c27a227dec8339b35b1b1ca56cff0d63409ae405 Mon Sep 17 00:00:00 2001 From: lordIcocain Date: Thu, 12 Dec 2024 12:31:06 +0200 Subject: [PATCH 12/18] get out sharedItems from PatternSlot. --- .../implementations/MTEMultiBlockBase.java | 2 +- .../machines/IDualInputInventory.java | 2 +- .../machines/MTEHatchCraftingInputME.java | 16 ++++++---------- 3 files changed, 8 insertions(+), 12 deletions(-) diff --git a/src/main/java/gregtech/api/metatileentity/implementations/MTEMultiBlockBase.java b/src/main/java/gregtech/api/metatileentity/implementations/MTEMultiBlockBase.java index 863c2ded84c..a1a72560fac 100644 --- a/src/main/java/gregtech/api/metatileentity/implementations/MTEMultiBlockBase.java +++ b/src/main/java/gregtech/api/metatileentity/implementations/MTEMultiBlockBase.java @@ -936,7 +936,7 @@ public CheckRecipeResult doSuperCribsCheckRecipe() { int recipeMapHash = slot.getPatternRecipeMapHash(); if (recipe == null) { // set recipe - MTEHatchCraftingInputME.PatternSlot.recipeInputs tempRecipeInputs = slot.getPatternInputs(); + MTEHatchCraftingInputME.PatternSlot.recipeInputs tempRecipeInputs = slot.getPatternInputs(sharedItems); GTRecipe slotRecipe = processingLogic .getRecipeByInputs(tempRecipeInputs.inputItems, tempRecipeInputs.inputFluid); int tempRecipeMapHash = processingLogic.getCribsRecipeMapHash(); diff --git a/src/main/java/gregtech/common/tileentities/machines/IDualInputInventory.java b/src/main/java/gregtech/common/tileentities/machines/IDualInputInventory.java index 9eaab8d323d..3b8b5609813 100644 --- a/src/main/java/gregtech/common/tileentities/machines/IDualInputInventory.java +++ b/src/main/java/gregtech/common/tileentities/machines/IDualInputInventory.java @@ -11,7 +11,7 @@ public interface IDualInputInventory { FluidStack[] getFluidInputs(); - MTEHatchCraftingInputME.PatternSlot.recipeInputs getPatternInputs(); + MTEHatchCraftingInputME.PatternSlot.recipeInputs getPatternInputs(ItemStack[] sharedItems); void setPatternRecipe(GTRecipe recipe, int hash); diff --git a/src/main/java/gregtech/common/tileentities/machines/MTEHatchCraftingInputME.java b/src/main/java/gregtech/common/tileentities/machines/MTEHatchCraftingInputME.java index 7b4ba73f120..2b328a2da3e 100644 --- a/src/main/java/gregtech/common/tileentities/machines/MTEHatchCraftingInputME.java +++ b/src/main/java/gregtech/common/tileentities/machines/MTEHatchCraftingInputME.java @@ -121,28 +121,25 @@ public static class recipeInputs { private final ICraftingPatternDetails patternDetails; private final List itemInventory; private final List fluidInventory; - private final SharedItemGetter sharedItemGetter; private GTRecipe patternRecipe; private int patternRecipeMapHash; - public PatternSlot(ItemStack pattern, World world, SharedItemGetter getter) { + public PatternSlot(ItemStack pattern, World world) { this.pattern = pattern; this.patternDetails = ((ICraftingPatternItem) Objects.requireNonNull(pattern.getItem())) .getPatternForItem(pattern, world); this.itemInventory = new ArrayList<>(); this.fluidInventory = new ArrayList<>(); - this.sharedItemGetter = getter; this.patternRecipe = null; this.patternRecipeMapHash = 0; } - public PatternSlot(ItemStack pattern, NBTTagCompound nbt, World world, SharedItemGetter getter) { + public PatternSlot(ItemStack pattern, NBTTagCompound nbt, World world) { this.pattern = pattern; this.patternDetails = ((ICraftingPatternItem) Objects.requireNonNull(pattern.getItem())) .getPatternForItem(pattern, world); this.itemInventory = new ArrayList<>(); this.fluidInventory = new ArrayList<>(); - this.sharedItemGetter = getter; this.patternRecipe = null; this.patternRecipeMapHash = 0; NBTTagList inv = nbt.getTagList("inventory", Constants.NBT.TAG_COMPOUND); @@ -230,10 +227,10 @@ public ICraftingPatternDetails getPatternDetails() { return patternDetails; } - public recipeInputs getPatternInputs() { + public recipeInputs getPatternInputs(ItemStack[] sharedItems) { recipeInputs inputsSuper = new recipeInputs(); - ItemStack[] inputItems = sharedItemGetter.getSharedItem(); + ItemStack[] inputItems = sharedItems; FluidStack[] inputFluids = new FluidStack[0]; for (IAEItemStack singleInput : this.getPatternDetails() @@ -613,8 +610,7 @@ public void loadNBTData(NBTTagCompound aNBT) { internalInventory[patternSlot] = new PatternSlot( pattern, patternSlotNBT, - getBaseMetaTileEntity().getWorld(), - this::getSharedItems); + getBaseMetaTileEntity().getWorld()); } else { GTMod.GT_FML_LOGGER.warn( "An error occurred while loading contents of ME Crafting Input Bus. This pattern has been voided: " @@ -866,7 +862,7 @@ private void onPatternChange(int index, ItemStack newItem) { // original does not exist or has changed if (newItem == null || !(newItem.getItem() instanceof ICraftingPatternItem)) return; - PatternSlot patternSlot = new PatternSlot(newItem, world, this::getSharedItems); + PatternSlot patternSlot = new PatternSlot(newItem, world); internalInventory[index] = patternSlot; patternDetailsPatternSlotMap.put(patternSlot.getPatternDetails(), patternSlot); From 6d25fd1fb462abd816eef23f696d9232afbf788c Mon Sep 17 00:00:00 2001 From: lordIcocain Date: Thu, 12 Dec 2024 12:43:35 +0200 Subject: [PATCH 13/18] get out sharedItems from PatternSlot. --- .../implementations/MTEMultiBlockBase.java | 8 ++++++-- .../machines/multi/MTEMultiSolidifier.java | 5 ++++- .../multi/processing/MTEIndustrialMultiMachine.java | 10 +++++++++- 3 files changed, 19 insertions(+), 4 deletions(-) diff --git a/src/main/java/gregtech/api/metatileentity/implementations/MTEMultiBlockBase.java b/src/main/java/gregtech/api/metatileentity/implementations/MTEMultiBlockBase.java index a1a72560fac..dc820e20429 100644 --- a/src/main/java/gregtech/api/metatileentity/implementations/MTEMultiBlockBase.java +++ b/src/main/java/gregtech/api/metatileentity/implementations/MTEMultiBlockBase.java @@ -936,7 +936,8 @@ public CheckRecipeResult doSuperCribsCheckRecipe() { int recipeMapHash = slot.getPatternRecipeMapHash(); if (recipe == null) { // set recipe - MTEHatchCraftingInputME.PatternSlot.recipeInputs tempRecipeInputs = slot.getPatternInputs(sharedItems); + MTEHatchCraftingInputME.PatternSlot.recipeInputs tempRecipeInputs = slot + .getPatternInputs(sharedItems); GTRecipe slotRecipe = processingLogic .getRecipeByInputs(tempRecipeInputs.inputItems, tempRecipeInputs.inputFluid); int tempRecipeMapHash = processingLogic.getCribsRecipeMapHash(); @@ -997,8 +998,11 @@ protected CheckRecipeResult doCheckRecipe() { ItemStack[] sharedItems = dualInputHatch.getSharedItems(); for (var it = dualInputHatch.inventories(); it.hasNext();) { IDualInputInventory slot = it.next(); + ItemStack[] inputItems = slot.getItemInputs(); + FluidStack[] inputFluids = slot.getFluidInputs(); + if (inputItems.length == 0 && inputFluids.length == 0) continue; + inputItems = ArrayUtils.addAll(inputItems, sharedItems); // Reverse order of input items for consistent behavior with standard input buses. - ItemStack[] inputItems = ArrayUtils.addAll(slot.getItemInputs(), sharedItems); ArrayUtils.reverse(inputItems); processingLogic.setInputItems(inputItems); processingLogic.setInputFluids(slot.getFluidInputs()); diff --git a/src/main/java/gregtech/common/tileentities/machines/multi/MTEMultiSolidifier.java b/src/main/java/gregtech/common/tileentities/machines/multi/MTEMultiSolidifier.java index f49b7019ab1..027c7d4caa3 100644 --- a/src/main/java/gregtech/common/tileentities/machines/multi/MTEMultiSolidifier.java +++ b/src/main/java/gregtech/common/tileentities/machines/multi/MTEMultiSolidifier.java @@ -443,8 +443,11 @@ protected CheckRecipeResult doCheckRecipe() { ItemStack[] sharedItems = dualInputHatch.getSharedItems(); for (var it = dualInputHatch.inventories(); it.hasNext();) { IDualInputInventory slot = it.next(); + ItemStack[] inputItems = slot.getItemInputs(); + FluidStack[] inputFluids = slot.getFluidInputs(); + if (inputItems.length == 0 && inputFluids.length == 0) continue; + inputItems = ArrayUtils.addAll(inputItems, sharedItems); // Reverse order of input items for consistent behavior with standard input buses. - ItemStack[] inputItems = ArrayUtils.addAll(slot.getItemInputs(), sharedItems); ArrayUtils.reverse(inputItems); processingLogic.setInputItems(inputItems); processingLogic.setInputFluids(slot.getFluidInputs()); diff --git a/src/main/java/gtPlusPlus/xmod/gregtech/common/tileentities/machines/multi/processing/MTEIndustrialMultiMachine.java b/src/main/java/gtPlusPlus/xmod/gregtech/common/tileentities/machines/multi/processing/MTEIndustrialMultiMachine.java index f8117df4802..968d9e1638c 100644 --- a/src/main/java/gtPlusPlus/xmod/gregtech/common/tileentities/machines/multi/processing/MTEIndustrialMultiMachine.java +++ b/src/main/java/gtPlusPlus/xmod/gregtech/common/tileentities/machines/multi/processing/MTEIndustrialMultiMachine.java @@ -33,6 +33,7 @@ import net.minecraftforge.common.util.ForgeDirection; import net.minecraftforge.fluids.FluidStack; +import org.apache.commons.lang3.ArrayUtils; import org.jetbrains.annotations.NotNull; import com.gtnewhorizon.structurelib.alignment.constructable.ISurvivalConstructable; @@ -393,9 +394,16 @@ protected CheckRecipeResult doCheckRecipe() { // check crafting input hatches first if (supportsCraftingMEBuffer()) { for (IDualInputHatch dualInputHatch : mDualInputHatches) { + ItemStack[] sharedItems = dualInputHatch.getSharedItems(); for (var it = dualInputHatch.inventories(); it.hasNext();) { IDualInputInventory slot = it.next(); - processingLogic.setInputItems(slot.getItemInputs()); + ItemStack[] inputItems = slot.getItemInputs(); + FluidStack[] inputFluids = slot.getFluidInputs(); + if (inputItems.length == 0 && inputFluids.length == 0) continue; + inputItems = ArrayUtils.addAll(inputItems, sharedItems); + // Reverse order of input items for consistent behavior with standard input buses. + ArrayUtils.reverse(inputItems); + processingLogic.setInputItems(inputItems); processingLogic.setInputFluids(slot.getFluidInputs()); CheckRecipeResult foundResult = processingLogic.process(); if (foundResult.wasSuccessful()) { From ad5a4504b150b95a10707f9cee830bc9fa60195e Mon Sep 17 00:00:00 2001 From: lordIcocain Date: Sat, 14 Dec 2024 14:35:13 +0200 Subject: [PATCH 14/18] re --- .../gregtech/api/logic/ProcessingLogic.java | 39 +++-- .../implementations/MTEMultiBlockBase.java | 137 +++--------------- .../gregtech/api/objects/GTDualInputs.java | 10 ++ .../machines/IDualInputHatch.java | 4 +- .../machines/IDualInputInventory.java | 11 +- .../machines/MTEHatchCraftingInputME.java | 85 ++--------- .../machines/MTEHatchCraftingInputSlave.java | 7 +- .../machines/multi/MTEMultiSolidifier.java | 51 +++---- .../compressor/MTEBlackHoleCompressor.java | 7 - 9 files changed, 103 insertions(+), 248 deletions(-) create mode 100644 src/main/java/gregtech/api/objects/GTDualInputs.java diff --git a/src/main/java/gregtech/api/logic/ProcessingLogic.java b/src/main/java/gregtech/api/logic/ProcessingLogic.java index fe8d1623697..226a58a2948 100644 --- a/src/main/java/gregtech/api/logic/ProcessingLogic.java +++ b/src/main/java/gregtech/api/logic/ProcessingLogic.java @@ -1,6 +1,8 @@ package gregtech.api.logic; +import java.util.HashMap; import java.util.List; +import java.util.Map; import java.util.stream.Stream; import javax.annotation.Nonnull; @@ -10,6 +12,7 @@ import net.minecraftforge.fluids.FluidStack; import gregtech.api.interfaces.tileentity.IRecipeLockable; +import gregtech.api.objects.GTDualInputs; import gregtech.api.recipe.RecipeMap; import gregtech.api.recipe.check.CheckRecipeResult; import gregtech.api.recipe.check.CheckRecipeResultRegistry; @@ -29,8 +32,8 @@ public class ProcessingLogic extends AbstractProcessingLogic { protected ItemStack[] inputItems; protected FluidStack[] inputFluids; protected boolean isRecipeLocked; - protected GTRecipe cribsRecipe; - protected int cribsRecipeMapHash; + protected int cribsSlotHash; + protected Map cribsRecipeMap = new HashMap<>(); public ProcessingLogic() {} @@ -65,12 +68,25 @@ public ProcessingLogic setSpecialSlotItem(ItemStack specialSlotItem) { return getThis(); } - public void setCribsRecipe(GTRecipe recipe) { - this.cribsRecipe = recipe; + public void setCribsSlotHash(int hash) { + this.cribsSlotHash = hash; } - public int getCribsRecipeMapHash() { - return cribsRecipeMapHash; + public boolean cribsHasRecipe(int hash) { + return cribsRecipeMap.containsKey(hash); + } + + public boolean setCribsSlotRecipe(GTDualInputs inputs, int hash) { + GTRecipe tempRecipe = getRecipeByInputs(inputs.inputItems, inputs.inputFluid); + if (tempRecipe != null) { + cribsRecipeMap.put(hash, tempRecipe); + return true; + } + return false; + } + + public void resetCribsRecipeMap() { + cribsRecipeMap.clear(); } /** @@ -95,7 +111,7 @@ public ProcessingLogic clear() { this.calculatedEut = 0; this.duration = 0; this.calculatedParallels = 0; - this.cribsRecipe = null; + this.cribsSlotHash = 0; return getThis(); } @@ -118,9 +134,10 @@ public CheckRecipeResult process() { inputFluids = new FluidStack[0]; } - if (cribsRecipe != null) { - if (cribsRecipe.maxParallelCalculatedByInputs(1, inputFluids, inputItems) == 1) { - return validateAndCalculateRecipe(cribsRecipe).checkRecipeResult; + if (cribsSlotHash != 0 && cribsRecipeMap.containsKey(cribsSlotHash)) { + if (cribsRecipeMap.get(cribsSlotHash) + .maxParallelCalculatedByInputs(1, inputFluids, inputItems) == 1) { + return validateAndCalculateRecipe(cribsRecipeMap.get(cribsSlotHash)).checkRecipeResult; } return CheckRecipeResultRegistry.NO_RECIPE; } @@ -157,7 +174,7 @@ public CheckRecipeResult process() { public GTRecipe getRecipeByInputs(ItemStack[] inItems, FluidStack[] inFluids) { RecipeMap map = preProcess(); - cribsRecipeMapHash = map.hashCode(); + if (map == null) return null; return map.findRecipeQuery() .items(inItems) .fluids(inFluids) diff --git a/src/main/java/gregtech/api/metatileentity/implementations/MTEMultiBlockBase.java b/src/main/java/gregtech/api/metatileentity/implementations/MTEMultiBlockBase.java index dc820e20429..ab22b087705 100644 --- a/src/main/java/gregtech/api/metatileentity/implementations/MTEMultiBlockBase.java +++ b/src/main/java/gregtech/api/metatileentity/implementations/MTEMultiBlockBase.java @@ -213,19 +213,6 @@ public void onScrewdriverRightClick(ForgeDirection side, EntityPlayer aPlayer, f } } - @Override - public boolean onSolderingToolRightClick(ForgeDirection side, ForgeDirection wrenchingSide, EntityPlayer aPlayer, - float aX, float aY, float aZ, ItemStack aTool) { - if (side == getBaseMetaTileEntity().getFrontFacing()) { - superCribsRecipeCheck ^= true; - resetCribsRecipes(); - setSuperCribsRecipeCheck(superCribsRecipeCheck); - aPlayer.addChatMessage(new ChatComponentTranslation("GT5U.multiblock.superCribs." + superCribsRecipeCheck)); - return true; - } - return false; - } - @Override public boolean isSimpleMachine() { return false; @@ -892,22 +879,6 @@ protected boolean supportsCraftingMEBuffer() { return true; } - public void resetCribsRecipes() { - for (IDualInputHatch dualInputHatch : mDualInputHatches) { - dualInputHatch.resetRecipes(); - } - } - - public void setSuperCribsRecipeCheck(boolean state) { - for (IDualInputHatch dualInputHatch : mDualInputHatches) { - dualInputHatch.setSuperCribsRecipeCheck(state); - } - } - - public RecipeMap[] getRecipeMaps() { - return null; - } - // check if this machine working in same recipe map/maps public boolean checkRecipeHash(RecipeMap map, RecipeMap[] maps, int hash) { if (map != null && map.hashCode() == hash) { @@ -922,61 +893,6 @@ public boolean checkRecipeHash(RecipeMap map, RecipeMap[] maps, int hash) return true; } - public CheckRecipeResult doSuperCribsCheckRecipe() { - CheckRecipeResult result = CheckRecipeResultRegistry.NO_RECIPE; - RecipeMap map = getRecipeMap(); - RecipeMap[] maps = getRecipeMaps(); - - for (IDualInputHatch dualInputHatch : mDualInputHatches) { - ItemStack[] sharedItems = dualInputHatch.getSharedItems(); - - for (var it = dualInputHatch.inventories(); it.hasNext();) { - IDualInputInventory slot = it.next(); - GTRecipe recipe = slot.getPatternRecipe(); - int recipeMapHash = slot.getPatternRecipeMapHash(); - - if (recipe == null) { // set recipe - MTEHatchCraftingInputME.PatternSlot.recipeInputs tempRecipeInputs = slot - .getPatternInputs(sharedItems); - GTRecipe slotRecipe = processingLogic - .getRecipeByInputs(tempRecipeInputs.inputItems, tempRecipeInputs.inputFluid); - int tempRecipeMapHash = processingLogic.getCribsRecipeMapHash(); - - if (slotRecipe != null) { - slot.setPatternRecipe(slotRecipe, tempRecipeMapHash); - } else { - continue; - } - - recipe = slotRecipe; - recipeMapHash = tempRecipeMapHash; - } - - if (checkRecipeHash(map, maps, recipeMapHash)) continue; // make sure that this machine able to - // process recipe - - ItemStack[] items = slot.getItemInputs(); - FluidStack[] fluids = slot.getFluidInputs(); - - if (items.length == 0 && fluids.length == 0) continue; - - processingLogic.setInputItems(ArrayUtils.addAll(sharedItems, items)); - processingLogic.setInputFluids(fluids); - processingLogic.setCribsRecipe(recipe); - - CheckRecipeResult foundResult = processingLogic.process(); - if (foundResult.wasSuccessful()) { - return foundResult; - } - if (foundResult != CheckRecipeResultRegistry.NO_RECIPE) { - // Recipe failed in interesting way, so remember that and continue searching - result = foundResult; - } - } - } - return result; - } - /** * Iterates over hatches and tries to find recipe. Assume {@link #processingLogic} is already set up for use. * If return value is successful, inputs are consumed. @@ -985,35 +901,28 @@ public CheckRecipeResult doSuperCribsCheckRecipe() { protected CheckRecipeResult doCheckRecipe() { CheckRecipeResult result = CheckRecipeResultRegistry.NO_RECIPE; // check crafting input hatches first - if (supportsCraftingMEBuffer()) { - if (superCribsRecipeCheck) { - CheckRecipeResult superCribsRecipeCheckResult = doSuperCribsCheckRecipe(); - if (superCribsRecipeCheckResult == CheckRecipeResultRegistry.SUCCESSFUL) { - return superCribsRecipeCheckResult; - } else { - result = superCribsRecipeCheckResult; - } - } else { - for (IDualInputHatch dualInputHatch : mDualInputHatches) { - ItemStack[] sharedItems = dualInputHatch.getSharedItems(); - for (var it = dualInputHatch.inventories(); it.hasNext();) { - IDualInputInventory slot = it.next(); - ItemStack[] inputItems = slot.getItemInputs(); - FluidStack[] inputFluids = slot.getFluidInputs(); - if (inputItems.length == 0 && inputFluids.length == 0) continue; - inputItems = ArrayUtils.addAll(inputItems, sharedItems); - // Reverse order of input items for consistent behavior with standard input buses. - ArrayUtils.reverse(inputItems); - processingLogic.setInputItems(inputItems); - processingLogic.setInputFluids(slot.getFluidInputs()); - CheckRecipeResult foundResult = processingLogic.process(); - if (foundResult.wasSuccessful()) { - return foundResult; - } - if (foundResult != CheckRecipeResultRegistry.NO_RECIPE) { - // Recipe failed in interesting way, so remember that and continue searching - result = foundResult; - } + for (IDualInputHatch dualInputHatch : mDualInputHatches) { + ItemStack[] sharedItems = dualInputHatch.getSharedItems(); + if (dualInputHatch.needClearRecipeMap()) processingLogic.resetCribsRecipeMap(); + for (var it = dualInputHatch.inventories(); it.hasNext();) { + IDualInputInventory slot = it.next(); + int slotHash = slot.hashCode(); + + if (!slot.isEmpty()) { + if (!processingLogic.cribsHasRecipe(slotHash) + && !processingLogic.setCribsSlotRecipe(slot.getPatternInputs(sharedItems), slotHash)) continue; + + processingLogic.setInputItems(ArrayUtils.addAll(sharedItems, slot.getItemInputs())); + processingLogic.setInputFluids(slot.getFluidInputs()); + processingLogic.setCribsSlotHash(slotHash); + + CheckRecipeResult foundResult = processingLogic.process(); + if (foundResult.wasSuccessful()) { + return foundResult; + } + if (foundResult != CheckRecipeResultRegistry.NO_RECIPE) { + // Recipe failed in interesting way, so remember that and continue searching + result = foundResult; } } } @@ -2524,7 +2433,7 @@ public UITexture getMachineModeIcon(int index) { @Override public void setMachineMode(int index) { machineMode = index; - resetCribsRecipes(); + processingLogic.resetCribsRecipeMap(); } @Override diff --git a/src/main/java/gregtech/api/objects/GTDualInputs.java b/src/main/java/gregtech/api/objects/GTDualInputs.java new file mode 100644 index 00000000000..368892fb8a9 --- /dev/null +++ b/src/main/java/gregtech/api/objects/GTDualInputs.java @@ -0,0 +1,10 @@ +package gregtech.api.objects; + +import net.minecraft.item.ItemStack; +import net.minecraftforge.fluids.FluidStack; + +public class GTDualInputs { + + public ItemStack[] inputItems; + public FluidStack[] inputFluid; +} diff --git a/src/main/java/gregtech/common/tileentities/machines/IDualInputHatch.java b/src/main/java/gregtech/common/tileentities/machines/IDualInputHatch.java index 54e57a41cc0..97c289f8ed8 100644 --- a/src/main/java/gregtech/common/tileentities/machines/IDualInputHatch.java +++ b/src/main/java/gregtech/common/tileentities/machines/IDualInputHatch.java @@ -21,7 +21,5 @@ public interface IDualInputHatch { ItemStack[] getSharedItems(); - void resetRecipes(); - - void setSuperCribsRecipeCheck(boolean state); + boolean needClearRecipeMap(); } diff --git a/src/main/java/gregtech/common/tileentities/machines/IDualInputInventory.java b/src/main/java/gregtech/common/tileentities/machines/IDualInputInventory.java index 3b8b5609813..ca6053edca6 100644 --- a/src/main/java/gregtech/common/tileentities/machines/IDualInputInventory.java +++ b/src/main/java/gregtech/common/tileentities/machines/IDualInputInventory.java @@ -3,19 +3,16 @@ import net.minecraft.item.ItemStack; import net.minecraftforge.fluids.FluidStack; -import gregtech.api.util.GTRecipe; +import gregtech.api.objects.GTDualInputs; public interface IDualInputInventory { + boolean isEmpty(); + ItemStack[] getItemInputs(); FluidStack[] getFluidInputs(); - MTEHatchCraftingInputME.PatternSlot.recipeInputs getPatternInputs(ItemStack[] sharedItems); - - void setPatternRecipe(GTRecipe recipe, int hash); - - GTRecipe getPatternRecipe(); + GTDualInputs getPatternInputs(ItemStack[] sharedItems); - int getPatternRecipeMapHash(); } diff --git a/src/main/java/gregtech/common/tileentities/machines/MTEHatchCraftingInputME.java b/src/main/java/gregtech/common/tileentities/machines/MTEHatchCraftingInputME.java index 2b328a2da3e..78c92f3086c 100644 --- a/src/main/java/gregtech/common/tileentities/machines/MTEHatchCraftingInputME.java +++ b/src/main/java/gregtech/common/tileentities/machines/MTEHatchCraftingInputME.java @@ -49,7 +49,6 @@ import com.gtnewhorizons.modularui.api.screen.UIBuildContext; import com.gtnewhorizons.modularui.common.widget.ButtonWidget; import com.gtnewhorizons.modularui.common.widget.CycleButtonWidget; -import com.gtnewhorizons.modularui.common.widget.FakeSyncWidget; import com.gtnewhorizons.modularui.common.widget.SlotGroup; import com.gtnewhorizons.modularui.common.widget.SlotWidget; @@ -92,8 +91,8 @@ import gregtech.api.interfaces.tileentity.IGregTechTileEntity; import gregtech.api.metatileentity.MetaTileEntity; import gregtech.api.metatileentity.implementations.MTEHatchInputBus; +import gregtech.api.objects.GTDualInputs; import gregtech.api.render.TextureFactory; -import gregtech.api.util.GTRecipe; import gregtech.api.util.GTUtility; import gregtech.api.util.extensions.ArrayExt; import mcp.mobius.waila.api.IWailaConfigHandler; @@ -106,23 +105,10 @@ public class MTEHatchCraftingInputME extends MTEHatchInputBus // Each pattern slot in the crafting input hatch has its own internal inventory public static class PatternSlot implements IDualInputInventory { - public interface SharedItemGetter { - - ItemStack[] getSharedItem(); - } - - public static class recipeInputs { - - public ItemStack[] inputItems; - public FluidStack[] inputFluid; - } - private final ItemStack pattern; private final ICraftingPatternDetails patternDetails; private final List itemInventory; private final List fluidInventory; - private GTRecipe patternRecipe; - private int patternRecipeMapHash; public PatternSlot(ItemStack pattern, World world) { this.pattern = pattern; @@ -130,8 +116,6 @@ public PatternSlot(ItemStack pattern, World world) { .getPatternForItem(pattern, world); this.itemInventory = new ArrayList<>(); this.fluidInventory = new ArrayList<>(); - this.patternRecipe = null; - this.patternRecipeMapHash = 0; } public PatternSlot(ItemStack pattern, NBTTagCompound nbt, World world) { @@ -140,8 +124,6 @@ public PatternSlot(ItemStack pattern, NBTTagCompound nbt, World world) { .getPatternForItem(pattern, world); this.itemInventory = new ArrayList<>(); this.fluidInventory = new ArrayList<>(); - this.patternRecipe = null; - this.patternRecipeMapHash = 0; NBTTagList inv = nbt.getTagList("inventory", Constants.NBT.TAG_COMPOUND); for (int i = 0; i < inv.tagCount(); i++) { NBTTagCompound tagItemStack = inv.getCompoundTagAt(i); @@ -207,6 +189,7 @@ public boolean isFluidEmpty() { return fluidInventory.isEmpty(); } + @Override public boolean isEmpty() { return isItemEmpty() && isFluidEmpty(); } @@ -227,8 +210,8 @@ public ICraftingPatternDetails getPatternDetails() { return patternDetails; } - public recipeInputs getPatternInputs(ItemStack[] sharedItems) { - recipeInputs inputsSuper = new recipeInputs(); + public GTDualInputs getPatternInputs(ItemStack[] sharedItems) { + GTDualInputs dualInputs = new GTDualInputs(); ItemStack[] inputItems = sharedItems; FluidStack[] inputFluids = new FluidStack[0]; @@ -245,22 +228,9 @@ public recipeInputs getPatternInputs(ItemStack[] sharedItems) { } } - inputsSuper.inputItems = inputItems; - inputsSuper.inputFluid = inputFluids; - return inputsSuper; - } - - public void setPatternRecipe(GTRecipe recipe, int hash) { - patternRecipe = recipe; - patternRecipeMapHash = hash; - } - - public GTRecipe getPatternRecipe() { - return patternRecipe; - } - - public int getPatternRecipeMapHash() { - return patternRecipeMapHash; + dualInputs.inputItems = inputItems; + dualInputs.inputFluid = inputFluids; + return dualInputs; } public void refund(AENetworkProxy proxy, BaseActionSource src) throws GridAccessException { @@ -369,6 +339,7 @@ public NBTTagCompound writeToNBT(NBTTagCompound nbt) { private static final int MANUAL_SLOT_WINDOW = 10; private BaseActionSource requestSource = null; private @Nullable AENetworkProxy gridProxy = null; + public boolean needClearRecipeMap; // holds all internal inventories private final PatternSlot[] internalInventory = new PatternSlot[MAX_PATTERN_COUNT]; @@ -742,32 +713,6 @@ public int getGUIWidth() { return super.getGUIWidth() + 16; } - private String getPatternHasRecipeList() { - if (superCribsRecipeCheck) { - StringBuilder sl = new StringBuilder(); - for (PatternSlot slot : internalInventory) { - if (slot == null) { - sl.append(0); - } else { - if (slot.patternRecipe != null) { - sl.append(1); - } else { - sl.append(0); - } - } - } - return sl.toString(); - } - return patternHasRecipeListCache; - } - - @Override - public void setSuperCribsRecipeCheck(boolean state) { - superCribsRecipeCheck = state; - } - - private String patternHasRecipeListCache = "111111111111111111111111111111111111"; - @Override public void addUIWidgets(ModularWindow.@NotNull Builder builder, UIBuildContext buildContext) { buildContext.addSyncedWindow(MANUAL_SLOT_WINDOW, this::createSlotManualWindow); @@ -782,8 +727,7 @@ public void addUIWidgets(ModularWindow.@NotNull Builder builder, UIBuildContext @Override protected ItemStack getItemStackForRendering(Slot slotIn) { ItemStack stack = slot.getStack(); - if (stack == null || !(stack.getItem() instanceof ItemEncodedPattern patternItem) - || patternHasRecipeListCache.charAt(slot.getSlotIndex()) == '0') { + if (stack == null || !(stack.getItem() instanceof ItemEncodedPattern patternItem)) { return stack; } ItemStack output = patternItem.getOutput(stack); @@ -793,8 +737,6 @@ protected ItemStack getItemStackForRendering(Slot slotIn) { .setChangeListener(() -> onPatternChange(slot.getSlotIndex(), slot.getStack()))) .build() .setPos(7, 9)) - .widget( - new FakeSyncWidget.StringSyncer(this::getPatternHasRecipeList, val -> patternHasRecipeListCache = val)) .widget(new ButtonWidget().setOnClick((clickData, widget) -> { if (clickData.mouseButton == 0) { widget.getContext() @@ -850,7 +792,7 @@ private void onPatternChange(int index, ItemStack newItem) { if (originalPattern.hasChanged(newItem, world)) { try { originalPattern.refund(getProxy(), getRequest()); - originalPattern.setPatternRecipe(null, 0); + needClearRecipeMap = true; } catch (GridAccessException ignored) {} internalInventory[index] = null; needPatternSync = true; @@ -1137,10 +1079,7 @@ public List getItemsForHoloGlasses() { } @Override - public void resetRecipes() { - for (PatternSlot slot : internalInventory) { - if (slot == null) continue; - slot.setPatternRecipe(null, 0); - } + public boolean needClearRecipeMap() { + return needClearRecipeMap; } } diff --git a/src/main/java/gregtech/common/tileentities/machines/MTEHatchCraftingInputSlave.java b/src/main/java/gregtech/common/tileentities/machines/MTEHatchCraftingInputSlave.java index 663258751bf..16c60dcdbe3 100644 --- a/src/main/java/gregtech/common/tileentities/machines/MTEHatchCraftingInputSlave.java +++ b/src/main/java/gregtech/common/tileentities/machines/MTEHatchCraftingInputSlave.java @@ -298,8 +298,7 @@ public List getItemsForHoloGlasses() { } @Override - public void resetRecipes() {} - - @Override - public void setSuperCribsRecipeCheck(boolean state) {} + public boolean needClearRecipeMap() { + return getMaster() != null && getMaster().needClearRecipeMap(); + } } diff --git a/src/main/java/gregtech/common/tileentities/machines/multi/MTEMultiSolidifier.java b/src/main/java/gregtech/common/tileentities/machines/multi/MTEMultiSolidifier.java index 027c7d4caa3..76334d9ebf3 100644 --- a/src/main/java/gregtech/common/tileentities/machines/multi/MTEMultiSolidifier.java +++ b/src/main/java/gregtech/common/tileentities/machines/multi/MTEMultiSolidifier.java @@ -430,35 +430,28 @@ protected CheckRecipeResult doCheckRecipe() { CheckRecipeResult result = CheckRecipeResultRegistry.NO_RECIPE; // check crafting input hatches first - if (supportsCraftingMEBuffer()) { - if (superCribsRecipeCheck) { - CheckRecipeResult superCribsRecipeCheckResult = doSuperCribsCheckRecipe(); - if (superCribsRecipeCheckResult == CheckRecipeResultRegistry.SUCCESSFUL) { - return superCribsRecipeCheckResult; - } else { - result = superCribsRecipeCheckResult; - } - } else { - for (IDualInputHatch dualInputHatch : mDualInputHatches) { - ItemStack[] sharedItems = dualInputHatch.getSharedItems(); - for (var it = dualInputHatch.inventories(); it.hasNext();) { - IDualInputInventory slot = it.next(); - ItemStack[] inputItems = slot.getItemInputs(); - FluidStack[] inputFluids = slot.getFluidInputs(); - if (inputItems.length == 0 && inputFluids.length == 0) continue; - inputItems = ArrayUtils.addAll(inputItems, sharedItems); - // Reverse order of input items for consistent behavior with standard input buses. - ArrayUtils.reverse(inputItems); - processingLogic.setInputItems(inputItems); - processingLogic.setInputFluids(slot.getFluidInputs()); - CheckRecipeResult foundResult = processingLogic.process(); - if (foundResult.wasSuccessful()) { - return foundResult; - } - if (foundResult != CheckRecipeResultRegistry.NO_RECIPE) { - // Recipe failed in interesting way, so remember that and continue searching - result = foundResult; - } + for (IDualInputHatch dualInputHatch : mDualInputHatches) { + ItemStack[] sharedItems = dualInputHatch.getSharedItems(); + if (dualInputHatch.needClearRecipeMap()) processingLogic.resetCribsRecipeMap(); + for (var it = dualInputHatch.inventories(); it.hasNext();) { + IDualInputInventory slot = it.next(); + int slotHash = slot.hashCode(); + + if (!slot.isEmpty()) { + if (!processingLogic.cribsHasRecipe(slotHash) + && !processingLogic.setCribsSlotRecipe(slot.getPatternInputs(sharedItems), slotHash)) continue; + + processingLogic.setInputItems(ArrayUtils.addAll(sharedItems, slot.getItemInputs())); + processingLogic.setInputFluids(slot.getFluidInputs()); + processingLogic.setCribsSlotHash(slotHash); + + CheckRecipeResult foundResult = processingLogic.process(); + if (foundResult.wasSuccessful()) { + return foundResult; + } + if (foundResult != CheckRecipeResultRegistry.NO_RECIPE) { + // Recipe failed in interesting way, so remember that and continue searching + result = foundResult; } } } diff --git a/src/main/java/gregtech/common/tileentities/machines/multi/compressor/MTEBlackHoleCompressor.java b/src/main/java/gregtech/common/tileentities/machines/multi/compressor/MTEBlackHoleCompressor.java index 7e86d5d6599..439540b88d8 100644 --- a/src/main/java/gregtech/common/tileentities/machines/multi/compressor/MTEBlackHoleCompressor.java +++ b/src/main/java/gregtech/common/tileentities/machines/multi/compressor/MTEBlackHoleCompressor.java @@ -514,11 +514,6 @@ protected void setupProcessingLogic(ProcessingLogic logic) { searchAndDecrementCatalysts(); } - @Override - public RecipeMap[] getRecipeMaps() { - return new RecipeMap[] { RecipeMaps.compressorRecipes, RecipeMaps.neutroniumCompressorRecipes }; - } - @Override protected ProcessingLogic createProcessingLogic() { return new ProcessingLogic() { @@ -553,12 +548,10 @@ public GTRecipe getRecipeByInputs(ItemStack[] inItems, FluidStack[] inFluids) { return null; } } - cribsRecipeMapHash = map.hashCode(); return map.findRecipeQuery() .items(inItems) .fluids(inFluids) .specialSlot(specialSlotItem) - .cachedRecipe(lastRecipe) .find(); } From 837ad2f1cbbef3dcb600aa5688e9268a9d1a1fd6 Mon Sep 17 00:00:00 2001 From: lordIcocain Date: Sat, 14 Dec 2024 14:45:54 +0200 Subject: [PATCH 15/18] cleanup --- .../implementations/MTEMultiBlockBase.java | 17 ----------------- .../machines/MTEHatchCraftingInputME.java | 3 --- .../processing/MTEIndustrialMultiMachine.java | 10 +--------- .../resources/assets/gregtech/lang/en_US.lang | 2 -- 4 files changed, 1 insertion(+), 31 deletions(-) diff --git a/src/main/java/gregtech/api/metatileentity/implementations/MTEMultiBlockBase.java b/src/main/java/gregtech/api/metatileentity/implementations/MTEMultiBlockBase.java index 254c37f4deb..3c0775eaaab 100644 --- a/src/main/java/gregtech/api/metatileentity/implementations/MTEMultiBlockBase.java +++ b/src/main/java/gregtech/api/metatileentity/implementations/MTEMultiBlockBase.java @@ -144,7 +144,6 @@ public abstract class MTEMultiBlockBase extends MetaTileEntity protected VoidingMode voidingMode = getDefaultVoidingMode(); protected boolean batchMode = getDefaultBatchMode(); protected @Nonnull CheckRecipeResult checkRecipeResult = CheckRecipeResultRegistry.NONE; - protected boolean superCribsRecipeCheck = false; protected static final String INPUT_SEPARATION_NBT_KEY = "inputSeparation"; protected static final String VOID_EXCESS_NBT_KEY = "voidExcess"; @@ -300,7 +299,6 @@ public void saveNBTData(NBTTagCompound aNBT) { aNBT.setBoolean(BATCH_MODE_NBT_KEY, batchMode); aNBT.setBoolean(INPUT_SEPARATION_NBT_KEY, inputSeparation); aNBT.setString(VOIDING_MODE_NBT_KEY, voidingMode.name); - aNBT.setBoolean(SUPER_CRIBS_MODE_NBT_KEY, superCribsRecipeCheck); } @Override @@ -339,7 +337,6 @@ public void loadNBTData(NBTTagCompound aNBT) { } batchMode = aNBT.getBoolean(BATCH_MODE_NBT_KEY); inputSeparation = aNBT.getBoolean(INPUT_SEPARATION_NBT_KEY); - superCribsRecipeCheck = aNBT.getBoolean(SUPER_CRIBS_MODE_NBT_KEY); if (aNBT.hasKey(VOIDING_MODE_NBT_KEY, Constants.NBT.TAG_STRING)) { voidingMode = VoidingMode.fromName(aNBT.getString(VOIDING_MODE_NBT_KEY)); } else if (aNBT.hasKey(VOID_EXCESS_NBT_KEY)) { @@ -880,20 +877,6 @@ protected boolean supportsCraftingMEBuffer() { return true; } - // check if this machine working in same recipe map/maps - public boolean checkRecipeHash(RecipeMap map, RecipeMap[] maps, int hash) { - if (map != null && map.hashCode() == hash) { - return false; - } else if (maps != null) { - for (RecipeMap tempMap : maps) { - if (tempMap.hashCode() == hash) { - return false; - } - } - } - return true; - } - /** * Iterates over hatches and tries to find recipe. Assume {@link #processingLogic} is already set up for use. * If return value is successful, inputs are consumed. diff --git a/src/main/java/gregtech/common/tileentities/machines/MTEHatchCraftingInputME.java b/src/main/java/gregtech/common/tileentities/machines/MTEHatchCraftingInputME.java index 78c92f3086c..a5a10850e1b 100644 --- a/src/main/java/gregtech/common/tileentities/machines/MTEHatchCraftingInputME.java +++ b/src/main/java/gregtech/common/tileentities/machines/MTEHatchCraftingInputME.java @@ -355,7 +355,6 @@ public NBTTagCompound writeToNBT(NBTTagCompound nbt) { private final boolean supportFluids; private boolean additionalConnection = false; private boolean disablePatternOptimization = false; - public boolean superCribsRecipeCheck = false; public MTEHatchCraftingInputME(int aID, String aName, String aNameRegional, boolean supportFluids) { super( @@ -563,7 +562,6 @@ public void saveNBTData(NBTTagCompound aNBT) { if (customName != null) aNBT.setString("customName", customName); aNBT.setBoolean("additionalConnection", additionalConnection); aNBT.setBoolean("disablePatternOptimization", disablePatternOptimization); - aNBT.setBoolean("superCribsRecipeCheck", superCribsRecipeCheck); getProxy().writeToNBT(aNBT); } @@ -613,7 +611,6 @@ public void loadNBTData(NBTTagCompound aNBT) { if (aNBT.hasKey("customName")) customName = aNBT.getString("customName"); additionalConnection = aNBT.getBoolean("additionalConnection"); disablePatternOptimization = aNBT.getBoolean("disablePatternOptimization"); - superCribsRecipeCheck = aNBT.getBoolean("superCribsRecipeCheck"); getProxy().readFromNBT(aNBT); } diff --git a/src/main/java/gtPlusPlus/xmod/gregtech/common/tileentities/machines/multi/processing/MTEIndustrialMultiMachine.java b/src/main/java/gtPlusPlus/xmod/gregtech/common/tileentities/machines/multi/processing/MTEIndustrialMultiMachine.java index 968d9e1638c..f8117df4802 100644 --- a/src/main/java/gtPlusPlus/xmod/gregtech/common/tileentities/machines/multi/processing/MTEIndustrialMultiMachine.java +++ b/src/main/java/gtPlusPlus/xmod/gregtech/common/tileentities/machines/multi/processing/MTEIndustrialMultiMachine.java @@ -33,7 +33,6 @@ import net.minecraftforge.common.util.ForgeDirection; import net.minecraftforge.fluids.FluidStack; -import org.apache.commons.lang3.ArrayUtils; import org.jetbrains.annotations.NotNull; import com.gtnewhorizon.structurelib.alignment.constructable.ISurvivalConstructable; @@ -394,16 +393,9 @@ protected CheckRecipeResult doCheckRecipe() { // check crafting input hatches first if (supportsCraftingMEBuffer()) { for (IDualInputHatch dualInputHatch : mDualInputHatches) { - ItemStack[] sharedItems = dualInputHatch.getSharedItems(); for (var it = dualInputHatch.inventories(); it.hasNext();) { IDualInputInventory slot = it.next(); - ItemStack[] inputItems = slot.getItemInputs(); - FluidStack[] inputFluids = slot.getFluidInputs(); - if (inputItems.length == 0 && inputFluids.length == 0) continue; - inputItems = ArrayUtils.addAll(inputItems, sharedItems); - // Reverse order of input items for consistent behavior with standard input buses. - ArrayUtils.reverse(inputItems); - processingLogic.setInputItems(inputItems); + processingLogic.setInputItems(slot.getItemInputs()); processingLogic.setInputFluids(slot.getFluidInputs()); CheckRecipeResult foundResult = processingLogic.process(); if (foundResult.wasSuccessful()) { diff --git a/src/main/resources/assets/gregtech/lang/en_US.lang b/src/main/resources/assets/gregtech/lang/en_US.lang index 950b165e3f9..850e013a73c 100644 --- a/src/main/resources/assets/gregtech/lang/en_US.lang +++ b/src/main/resources/assets/gregtech/lang/en_US.lang @@ -683,8 +683,6 @@ GT5U.multiblock.speed=Speed GT5U.multiblock.fluidPipeTier=Fluid Pipe Tier GT5U.multiblock.itemPipeTier=Item Pipe Tier GT5U.multiblock.coilLevel=Heating Coil Level -GT5U.multiblock.superCribs.true=SuperCribs recipe check mode is §aEnabled -GT5U.multiblock.superCribs.false=SuperCribs recipe check mode is §cDisabled # NEI recipe handlers GT5U.nei.heat_capacity=Heat Capacity: %s K (%s) From b3246c6d3d40cbb9dc4cea8a7fdd5122068fcd05 Mon Sep 17 00:00:00 2001 From: lordIcocain Date: Sat, 14 Dec 2024 15:01:18 +0200 Subject: [PATCH 16/18] even more cleanup --- .../gregtech/api/logic/ProcessingLogic.java | 1 - .../implementations/MTEMultiBlockBase.java | 3 +-- .../machines/IDualInputInventory.java | 2 +- .../machines/MTEHatchCraftingInputME.java | 21 +++++++++++++------ .../machines/multi/MTEMultiSolidifier.java | 2 +- .../compressor/MTEBlackHoleCompressor.java | 1 - 6 files changed, 18 insertions(+), 12 deletions(-) diff --git a/src/main/java/gregtech/api/logic/ProcessingLogic.java b/src/main/java/gregtech/api/logic/ProcessingLogic.java index 226a58a2948..07d5c5c2695 100644 --- a/src/main/java/gregtech/api/logic/ProcessingLogic.java +++ b/src/main/java/gregtech/api/logic/ProcessingLogic.java @@ -178,7 +178,6 @@ public GTRecipe getRecipeByInputs(ItemStack[] inItems, FluidStack[] inFluids) { return map.findRecipeQuery() .items(inItems) .fluids(inFluids) - .specialSlot(specialSlotItem) .find(); } diff --git a/src/main/java/gregtech/api/metatileentity/implementations/MTEMultiBlockBase.java b/src/main/java/gregtech/api/metatileentity/implementations/MTEMultiBlockBase.java index 3c0775eaaab..7d362878c90 100644 --- a/src/main/java/gregtech/api/metatileentity/implementations/MTEMultiBlockBase.java +++ b/src/main/java/gregtech/api/metatileentity/implementations/MTEMultiBlockBase.java @@ -149,7 +149,6 @@ public abstract class MTEMultiBlockBase extends MetaTileEntity protected static final String VOID_EXCESS_NBT_KEY = "voidExcess"; protected static final String VOIDING_MODE_NBT_KEY = "voidingMode"; protected static final String BATCH_MODE_NBT_KEY = "batchMode"; - protected static final String SUPER_CRIBS_MODE_NBT_KEY = "superCribsMode"; protected SingleRecipeCheck mSingleRecipeCheck = null; public ArrayList mInputHatches = new ArrayList<>(); @@ -894,7 +893,7 @@ protected CheckRecipeResult doCheckRecipe() { if (!slot.isEmpty()) { if (!processingLogic.cribsHasRecipe(slotHash) - && !processingLogic.setCribsSlotRecipe(slot.getPatternInputs(sharedItems), slotHash)) continue; + && !processingLogic.setCribsSlotRecipe(slot.getPatternInputs(), slotHash)) continue; processingLogic.setInputItems(ArrayUtils.addAll(sharedItems, slot.getItemInputs())); processingLogic.setInputFluids(slot.getFluidInputs()); diff --git a/src/main/java/gregtech/common/tileentities/machines/IDualInputInventory.java b/src/main/java/gregtech/common/tileentities/machines/IDualInputInventory.java index ca6053edca6..56fedf5e41e 100644 --- a/src/main/java/gregtech/common/tileentities/machines/IDualInputInventory.java +++ b/src/main/java/gregtech/common/tileentities/machines/IDualInputInventory.java @@ -13,6 +13,6 @@ public interface IDualInputInventory { FluidStack[] getFluidInputs(); - GTDualInputs getPatternInputs(ItemStack[] sharedItems); + GTDualInputs getPatternInputs(); } diff --git a/src/main/java/gregtech/common/tileentities/machines/MTEHatchCraftingInputME.java b/src/main/java/gregtech/common/tileentities/machines/MTEHatchCraftingInputME.java index a5a10850e1b..4aa9c257f6e 100644 --- a/src/main/java/gregtech/common/tileentities/machines/MTEHatchCraftingInputME.java +++ b/src/main/java/gregtech/common/tileentities/machines/MTEHatchCraftingInputME.java @@ -105,25 +105,33 @@ public class MTEHatchCraftingInputME extends MTEHatchInputBus // Each pattern slot in the crafting input hatch has its own internal inventory public static class PatternSlot implements IDualInputInventory { + public interface SharedItemGetter { + + ItemStack[] getSharedItem(); + } + private final ItemStack pattern; private final ICraftingPatternDetails patternDetails; private final List itemInventory; private final List fluidInventory; + private final SharedItemGetter sharedItemGetter; - public PatternSlot(ItemStack pattern, World world) { + public PatternSlot(ItemStack pattern, World world, SharedItemGetter getter) { this.pattern = pattern; this.patternDetails = ((ICraftingPatternItem) Objects.requireNonNull(pattern.getItem())) .getPatternForItem(pattern, world); this.itemInventory = new ArrayList<>(); this.fluidInventory = new ArrayList<>(); + this.sharedItemGetter = getter; } - public PatternSlot(ItemStack pattern, NBTTagCompound nbt, World world) { + public PatternSlot(ItemStack pattern, NBTTagCompound nbt, World world, SharedItemGetter getter) { this.pattern = pattern; this.patternDetails = ((ICraftingPatternItem) Objects.requireNonNull(pattern.getItem())) .getPatternForItem(pattern, world); this.itemInventory = new ArrayList<>(); this.fluidInventory = new ArrayList<>(); + this.sharedItemGetter = getter; NBTTagList inv = nbt.getTagList("inventory", Constants.NBT.TAG_COMPOUND); for (int i = 0; i < inv.tagCount(); i++) { NBTTagCompound tagItemStack = inv.getCompoundTagAt(i); @@ -210,10 +218,10 @@ public ICraftingPatternDetails getPatternDetails() { return patternDetails; } - public GTDualInputs getPatternInputs(ItemStack[] sharedItems) { + public GTDualInputs getPatternInputs() { GTDualInputs dualInputs = new GTDualInputs(); - ItemStack[] inputItems = sharedItems; + ItemStack[] inputItems = this.sharedItemGetter.getSharedItem(); FluidStack[] inputFluids = new FluidStack[0]; for (IAEItemStack singleInput : this.getPatternDetails() @@ -579,7 +587,8 @@ public void loadNBTData(NBTTagCompound aNBT) { internalInventory[patternSlot] = new PatternSlot( pattern, patternSlotNBT, - getBaseMetaTileEntity().getWorld()); + getBaseMetaTileEntity().getWorld(), + this::getSharedItems); } else { GTMod.GT_FML_LOGGER.warn( "An error occurred while loading contents of ME Crafting Input Bus. This pattern has been voided: " @@ -801,7 +810,7 @@ private void onPatternChange(int index, ItemStack newItem) { // original does not exist or has changed if (newItem == null || !(newItem.getItem() instanceof ICraftingPatternItem)) return; - PatternSlot patternSlot = new PatternSlot(newItem, world); + PatternSlot patternSlot = new PatternSlot(newItem, world, this::getSharedItems); internalInventory[index] = patternSlot; patternDetailsPatternSlotMap.put(patternSlot.getPatternDetails(), patternSlot); diff --git a/src/main/java/gregtech/common/tileentities/machines/multi/MTEMultiSolidifier.java b/src/main/java/gregtech/common/tileentities/machines/multi/MTEMultiSolidifier.java index 76334d9ebf3..654ba2e4434 100644 --- a/src/main/java/gregtech/common/tileentities/machines/multi/MTEMultiSolidifier.java +++ b/src/main/java/gregtech/common/tileentities/machines/multi/MTEMultiSolidifier.java @@ -439,7 +439,7 @@ protected CheckRecipeResult doCheckRecipe() { if (!slot.isEmpty()) { if (!processingLogic.cribsHasRecipe(slotHash) - && !processingLogic.setCribsSlotRecipe(slot.getPatternInputs(sharedItems), slotHash)) continue; + && !processingLogic.setCribsSlotRecipe(slot.getPatternInputs(), slotHash)) continue; processingLogic.setInputItems(ArrayUtils.addAll(sharedItems, slot.getItemInputs())); processingLogic.setInputFluids(slot.getFluidInputs()); diff --git a/src/main/java/gregtech/common/tileentities/machines/multi/compressor/MTEBlackHoleCompressor.java b/src/main/java/gregtech/common/tileentities/machines/multi/compressor/MTEBlackHoleCompressor.java index 439540b88d8..00da4b53688 100644 --- a/src/main/java/gregtech/common/tileentities/machines/multi/compressor/MTEBlackHoleCompressor.java +++ b/src/main/java/gregtech/common/tileentities/machines/multi/compressor/MTEBlackHoleCompressor.java @@ -551,7 +551,6 @@ public GTRecipe getRecipeByInputs(ItemStack[] inItems, FluidStack[] inFluids) { return map.findRecipeQuery() .items(inItems) .fluids(inFluids) - .specialSlot(specialSlotItem) .find(); } From ac8b451b2a81ed0b52fe3a39f805e2ac5922a78f Mon Sep 17 00:00:00 2001 From: lordIcocain Date: Sat, 14 Dec 2024 15:05:18 +0200 Subject: [PATCH 17/18] a bit --- src/main/java/gregtech/api/logic/ProcessingLogic.java | 1 - .../api/metatileentity/implementations/MTEMultiBlockBase.java | 1 + 2 files changed, 1 insertion(+), 1 deletion(-) diff --git a/src/main/java/gregtech/api/logic/ProcessingLogic.java b/src/main/java/gregtech/api/logic/ProcessingLogic.java index 07d5c5c2695..c274a695daf 100644 --- a/src/main/java/gregtech/api/logic/ProcessingLogic.java +++ b/src/main/java/gregtech/api/logic/ProcessingLogic.java @@ -122,7 +122,6 @@ public ProcessingLogic clear() { /** * Executes the recipe check: Find recipe from recipemap, Calculate parallel, overclock and outputs. */ - @Nonnull public CheckRecipeResult process() { RecipeMap recipeMap = preProcess(); diff --git a/src/main/java/gregtech/api/metatileentity/implementations/MTEMultiBlockBase.java b/src/main/java/gregtech/api/metatileentity/implementations/MTEMultiBlockBase.java index 7d362878c90..0c6645fb961 100644 --- a/src/main/java/gregtech/api/metatileentity/implementations/MTEMultiBlockBase.java +++ b/src/main/java/gregtech/api/metatileentity/implementations/MTEMultiBlockBase.java @@ -883,6 +883,7 @@ protected boolean supportsCraftingMEBuffer() { @Nonnull protected CheckRecipeResult doCheckRecipe() { CheckRecipeResult result = CheckRecipeResultRegistry.NO_RECIPE; + // check crafting input hatches first for (IDualInputHatch dualInputHatch : mDualInputHatches) { ItemStack[] sharedItems = dualInputHatch.getSharedItems(); From 92e376e4f4cacb5930e2581c80e3a66066546706 Mon Sep 17 00:00:00 2001 From: lordIcocain Date: Sat, 11 Jan 2025 12:53:19 +0200 Subject: [PATCH 18/18] rework --- .../api/logic/AbstractProcessingLogic.java | 2 + .../gregtech/api/logic/ProcessingLogic.java | 73 +++++++++++-------- .../implementations/MTEMultiBlockBase.java | 18 +---- .../machines/IDualInputHatch.java | 4 +- .../machines/MTEHatchCraftingInputME.java | 38 ++++++++-- .../machines/MTEHatchCraftingInputSlave.java | 5 +- .../machines/multi/MTEMultiSolidifier.java | 7 +- .../compressor/MTEBlackHoleCompressor.java | 20 ----- 8 files changed, 85 insertions(+), 82 deletions(-) diff --git a/src/main/java/gregtech/api/logic/AbstractProcessingLogic.java b/src/main/java/gregtech/api/logic/AbstractProcessingLogic.java index 57fbf227006..d4f0e96a36b 100644 --- a/src/main/java/gregtech/api/logic/AbstractProcessingLogic.java +++ b/src/main/java/gregtech/api/logic/AbstractProcessingLogic.java @@ -43,6 +43,7 @@ public abstract class AbstractProcessingLogic

preProcess() { recipeMap = recipeMapSupplier.get(); } if (lastRecipeMap != recipeMap) { + if (lastRecipeMap != null) needWipeCraftingPatternRecipeCache = true; lastRecipe = null; lastRecipeMap = recipeMap; } diff --git a/src/main/java/gregtech/api/logic/ProcessingLogic.java b/src/main/java/gregtech/api/logic/ProcessingLogic.java index c274a695daf..6e5cf5ae56d 100644 --- a/src/main/java/gregtech/api/logic/ProcessingLogic.java +++ b/src/main/java/gregtech/api/logic/ProcessingLogic.java @@ -1,5 +1,8 @@ package gregtech.api.logic; +import static java.util.stream.Collectors.toList; + +import java.util.ArrayList; import java.util.HashMap; import java.util.List; import java.util.Map; @@ -20,6 +23,7 @@ import gregtech.api.util.GTRecipe; import gregtech.api.util.OverclockCalculator; import gregtech.api.util.ParallelHelper; +import gregtech.common.tileentities.machines.IDualInputInventory; /** * Logic class to calculate result of recipe check from inputs, based on recipemap. @@ -32,8 +36,8 @@ public class ProcessingLogic extends AbstractProcessingLogic { protected ItemStack[] inputItems; protected FluidStack[] inputFluids; protected boolean isRecipeLocked; - protected int cribsSlotHash; - protected Map cribsRecipeMap = new HashMap<>(); + protected int craftingPatternHash; + protected Map> craftingPatternRecipeCache = new HashMap<>(); public ProcessingLogic() {} @@ -68,25 +72,35 @@ public ProcessingLogic setSpecialSlotItem(ItemStack specialSlotItem) { return getThis(); } - public void setCribsSlotHash(int hash) { - this.cribsSlotHash = hash; - } - - public boolean cribsHasRecipe(int hash) { - return cribsRecipeMap.containsKey(hash); - } - - public boolean setCribsSlotRecipe(GTDualInputs inputs, int hash) { - GTRecipe tempRecipe = getRecipeByInputs(inputs.inputItems, inputs.inputFluid); - if (tempRecipe != null) { - cribsRecipeMap.put(hash, tempRecipe); - return true; + public boolean craftingPatternHandler(IDualInputInventory slot) { + int hash = slot.hashCode(); + if (needWipeCraftingPatternRecipeCache) { + craftingPatternRecipeCache.clear(); + needWipeCraftingPatternRecipeCache = false; } - return false; + if (!craftingPatternRecipeCache.containsKey(hash)) { + GTDualInputs inputs = slot.getPatternInputs(); + setInputItems(inputs.inputItems); + setInputFluids(inputs.inputFluid); + List recipes = new ArrayList<>(); + for (GTRecipe recipe : findRecipeMatches(preProcess()).collect(toList())) { + if (!recipes.contains(recipe)) { + recipes.add(recipe); + } + } + if (!recipes.isEmpty()) { + craftingPatternRecipeCache.put(hash, recipes); + craftingPatternHash = hash; + return true; + } + return false; + } + craftingPatternHash = hash; + return true; } - public void resetCribsRecipeMap() { - cribsRecipeMap.clear(); + public void removeEntryCraftingPatternRecipeCache(int hash) { + craftingPatternRecipeCache.remove(hash); } /** @@ -111,7 +125,7 @@ public ProcessingLogic clear() { this.calculatedEut = 0; this.duration = 0; this.calculatedParallels = 0; - this.cribsSlotHash = 0; + this.craftingPatternHash = 0; return getThis(); } @@ -133,11 +147,15 @@ public CheckRecipeResult process() { inputFluids = new FluidStack[0]; } - if (cribsSlotHash != 0 && cribsRecipeMap.containsKey(cribsSlotHash)) { - if (cribsRecipeMap.get(cribsSlotHash) - .maxParallelCalculatedByInputs(1, inputFluids, inputItems) == 1) { - return validateAndCalculateRecipe(cribsRecipeMap.get(cribsSlotHash)).checkRecipeResult; + if (craftingPatternHash != 0) { + List matchedRecipes = craftingPatternRecipeCache.get(craftingPatternHash); + for (GTRecipe matchedRecipe : matchedRecipes) { + if (matchedRecipe.maxParallelCalculatedByInputs(1, inputFluids, inputItems) == 1) { + CalculationResult foundResult = validateAndCalculateRecipe(matchedRecipe); + return foundResult.checkRecipeResult; + } } + craftingPatternHash = 0; return CheckRecipeResultRegistry.NO_RECIPE; } @@ -171,15 +189,6 @@ public CheckRecipeResult process() { return checkRecipeResult; } - public GTRecipe getRecipeByInputs(ItemStack[] inItems, FluidStack[] inFluids) { - RecipeMap map = preProcess(); - if (map == null) return null; - return map.findRecipeQuery() - .items(inItems) - .fluids(inFluids) - .find(); - } - /** * Checks if supplied recipe is valid for process. This involves voltage check, output full check. If successful, * additionally performs input consumption, output calculation with parallel, and overclock calculation. diff --git a/src/main/java/gregtech/api/metatileentity/implementations/MTEMultiBlockBase.java b/src/main/java/gregtech/api/metatileentity/implementations/MTEMultiBlockBase.java index ebc91ed59f4..38df2158f5f 100644 --- a/src/main/java/gregtech/api/metatileentity/implementations/MTEMultiBlockBase.java +++ b/src/main/java/gregtech/api/metatileentity/implementations/MTEMultiBlockBase.java @@ -887,18 +887,13 @@ protected CheckRecipeResult doCheckRecipe() { // check crafting input hatches first for (IDualInputHatch dualInputHatch : mDualInputHatches) { ItemStack[] sharedItems = dualInputHatch.getSharedItems(); - if (dualInputHatch.needClearRecipeMap()) processingLogic.resetCribsRecipeMap(); for (var it = dualInputHatch.inventories(); it.hasNext();) { IDualInputInventory slot = it.next(); - int slotHash = slot.hashCode(); - if (!slot.isEmpty()) { - if (!processingLogic.cribsHasRecipe(slotHash) - && !processingLogic.setCribsSlotRecipe(slot.getPatternInputs(), slotHash)) continue; + if (!slot.isEmpty() && processingLogic.craftingPatternHandler(slot)) { processingLogic.setInputItems(ArrayUtils.addAll(sharedItems, slot.getItemInputs())); processingLogic.setInputFluids(slot.getFluidInputs()); - processingLogic.setCribsSlotHash(slotHash); CheckRecipeResult foundResult = processingLogic.process(); if (foundResult.wasSuccessful()) { @@ -1727,6 +1722,7 @@ public boolean addToMachineList(IGregTechTileEntity aTileEntity, int aBaseCasing } if (aMetaTileEntity instanceof IDualInputHatch hatch) { hatch.updateCraftingIcon(this.getMachineCraftingIcon()); + hatch.setProcessingLogic(processingLogic); return mDualInputHatches.add(hatch); } if (aMetaTileEntity instanceof ISmartInputHatch hatch) { @@ -2056,12 +2052,8 @@ public void getWailaBody(ItemStack itemStack, List currentTip, IWailaDat } } } - currentTip.add( - GTWaila.getMachineProgressString( - isActive, - tag.getBoolean("isAllowedToWork"), - tag.getInteger("maxProgress"), - tag.getInteger("progress"))); + currentTip + .add(GTWaila.getMachineProgressString(isActive, tag.getInteger("maxProgress"), tag.getInteger("progress"))); // Show ns on the tooltip if (GTMod.gregtechproxy.wailaAverageNS && tag.hasKey("averageNS")) { int tAverageTime = tag.getInteger("averageNS"); @@ -2110,7 +2102,6 @@ public void getWailaNBTData(EntityPlayerMP player, TileEntity tile, NBTTagCompou final IGregTechTileEntity tileEntity = getBaseMetaTileEntity(); if (tileEntity != null) { tag.setBoolean("isActive", tileEntity.isActive()); - tag.setBoolean("isAllowedToWork", tileEntity.isAllowedToWork()); if (tileEntity.isActive()) { if (mEUt < 0) tag.setLong("energyUsage", getActualEnergyUsage()); else tag.setLong("energyUsage", (long) -mEUt * mEfficiency / 10000); @@ -2433,7 +2424,6 @@ public UITexture getMachineModeIcon(int index) { @Override public void setMachineMode(int index) { machineMode = index; - processingLogic.resetCribsRecipeMap(); } @Override diff --git a/src/main/java/gregtech/common/tileentities/machines/IDualInputHatch.java b/src/main/java/gregtech/common/tileentities/machines/IDualInputHatch.java index 97c289f8ed8..31e09d8f461 100644 --- a/src/main/java/gregtech/common/tileentities/machines/IDualInputHatch.java +++ b/src/main/java/gregtech/common/tileentities/machines/IDualInputHatch.java @@ -5,6 +5,8 @@ import net.minecraft.item.ItemStack; +import gregtech.api.logic.ProcessingLogic; + public interface IDualInputHatch { boolean justUpdated(); @@ -21,5 +23,5 @@ public interface IDualInputHatch { ItemStack[] getSharedItems(); - boolean needClearRecipeMap(); + void setProcessingLogic(ProcessingLogic pl); } diff --git a/src/main/java/gregtech/common/tileentities/machines/MTEHatchCraftingInputME.java b/src/main/java/gregtech/common/tileentities/machines/MTEHatchCraftingInputME.java index 06be11d37af..ee415771f90 100644 --- a/src/main/java/gregtech/common/tileentities/machines/MTEHatchCraftingInputME.java +++ b/src/main/java/gregtech/common/tileentities/machines/MTEHatchCraftingInputME.java @@ -92,6 +92,7 @@ import gregtech.api.interfaces.modularui.IAddGregtechLogo; import gregtech.api.interfaces.modularui.IAddUIWidgets; import gregtech.api.interfaces.tileentity.IGregTechTileEntity; +import gregtech.api.logic.ProcessingLogic; import gregtech.api.metatileentity.MetaTileEntity; import gregtech.api.metatileentity.implementations.MTEHatchInputBus; import gregtech.api.objects.GTDualInputs; @@ -221,6 +222,11 @@ public ICraftingPatternDetails getPatternDetails() { return patternDetails; } + @Override + public int hashCode() { + return Objects.hashCode(patternDetails); + } + public GTDualInputs getPatternInputs() { GTDualInputs dualInputs = new GTDualInputs(); @@ -350,7 +356,7 @@ public NBTTagCompound writeToNBT(NBTTagCompound nbt) { private static final int MANUAL_SLOT_WINDOW = 10; private BaseActionSource requestSource = null; private @Nullable AENetworkProxy gridProxy = null; - public boolean needClearRecipeMap; + public ArrayList processingLogics = new ArrayList<>(); // holds all internal inventories private final PatternSlot[] internalInventory = new PatternSlot[MAX_PATTERN_COUNT]; @@ -812,7 +818,6 @@ private void onPatternChange(int index, ItemStack newItem) { if (originalPattern.hasChanged(newItem, world)) { try { originalPattern.refund(getProxy(), getRequest()); - needClearRecipeMap = true; } catch (GridAccessException ignored) {} internalInventory[index] = null; needPatternSync = true; @@ -839,6 +844,23 @@ public ItemStack[] getSharedItems() { return ArrayExt.withoutNulls(sharedItems, ItemStack[]::new); } + @Override + public void setProcessingLogic(ProcessingLogic pl) { + if (!processingLogics.contains(pl)) { + processingLogics.add(pl); + } + } + + private void resetCraftingInputRecipeMap() { + for (ProcessingLogic pl : processingLogics) { + if (pl == null) continue; + for (PatternSlot slot : internalInventory) { + if (slot == null) continue; + pl.removeEntryCraftingPatternRecipeCache(slot.hashCode()); + } + } + } + @Override public void getWailaBody(ItemStack itemStack, List currenttip, IWailaDataAccessor accessor, IWailaConfigHandler config) { @@ -1011,6 +1033,12 @@ public ItemStack getCrafterIcon() { return getMachineCraftingIcon(); } + @Override + public void markDirty() { + super.markDirty(); + resetCraftingInputRecipeMap(); + } + private boolean postMEPatternChange() { // don't post until it's active if (!getProxy().isActive()) return false; @@ -1044,6 +1072,7 @@ protected ModularWindow createSlotManualWindow(final EntityPlayer player) { .endAtSlot(SLOT_MANUAL_START + SLOT_MANUAL_SIZE - 1) .phantom(false) .background(getGUITextureSet().getItemSlot()) + .widgetCreator(slot -> new SlotWidget(slot).setChangeListener(this::resetCraftingInputRecipeMap)) .build() .setPos(7, 7)); return builder.build(); @@ -1098,11 +1127,6 @@ public List getItemsForHoloGlasses() { return list; } - @Override - public boolean needClearRecipeMap() { - return needClearRecipeMap; - } - public void doublePatterns(int val) { boolean fast = (val & 1) != 0; boolean backwards = (val & 2) != 0; diff --git a/src/main/java/gregtech/common/tileentities/machines/MTEHatchCraftingInputSlave.java b/src/main/java/gregtech/common/tileentities/machines/MTEHatchCraftingInputSlave.java index 16c60dcdbe3..73216f46743 100644 --- a/src/main/java/gregtech/common/tileentities/machines/MTEHatchCraftingInputSlave.java +++ b/src/main/java/gregtech/common/tileentities/machines/MTEHatchCraftingInputSlave.java @@ -23,6 +23,7 @@ import gregtech.api.interfaces.IDataCopyable; import gregtech.api.interfaces.ITexture; import gregtech.api.interfaces.tileentity.IGregTechTileEntity; +import gregtech.api.logic.ProcessingLogic; import gregtech.api.metatileentity.MetaTileEntity; import gregtech.api.metatileentity.implementations.MTEHatchInputBus; import gregtech.api.render.TextureFactory; @@ -298,7 +299,7 @@ public List getItemsForHoloGlasses() { } @Override - public boolean needClearRecipeMap() { - return getMaster() != null && getMaster().needClearRecipeMap(); + public void setProcessingLogic(ProcessingLogic pl) { + if (getMaster() != null) getMaster().setProcessingLogic(pl); } } diff --git a/src/main/java/gregtech/common/tileentities/machines/multi/MTEMultiSolidifier.java b/src/main/java/gregtech/common/tileentities/machines/multi/MTEMultiSolidifier.java index d02b591337a..ef409934211 100644 --- a/src/main/java/gregtech/common/tileentities/machines/multi/MTEMultiSolidifier.java +++ b/src/main/java/gregtech/common/tileentities/machines/multi/MTEMultiSolidifier.java @@ -438,18 +438,13 @@ protected CheckRecipeResult doCheckRecipe() { // check crafting input hatches first for (IDualInputHatch dualInputHatch : mDualInputHatches) { ItemStack[] sharedItems = dualInputHatch.getSharedItems(); - if (dualInputHatch.needClearRecipeMap()) processingLogic.resetCribsRecipeMap(); for (var it = dualInputHatch.inventories(); it.hasNext();) { IDualInputInventory slot = it.next(); - int slotHash = slot.hashCode(); - if (!slot.isEmpty()) { - if (!processingLogic.cribsHasRecipe(slotHash) - && !processingLogic.setCribsSlotRecipe(slot.getPatternInputs(), slotHash)) continue; + if (!slot.isEmpty() && processingLogic.craftingPatternHandler(slot)) { processingLogic.setInputItems(ArrayUtils.addAll(sharedItems, slot.getItemInputs())); processingLogic.setInputFluids(slot.getFluidInputs()); - processingLogic.setCribsSlotHash(slotHash); CheckRecipeResult foundResult = processingLogic.process(); if (foundResult.wasSuccessful()) { diff --git a/src/main/java/gregtech/common/tileentities/machines/multi/compressor/MTEBlackHoleCompressor.java b/src/main/java/gregtech/common/tileentities/machines/multi/compressor/MTEBlackHoleCompressor.java index 00da4b53688..4fc4ecc99f2 100644 --- a/src/main/java/gregtech/common/tileentities/machines/multi/compressor/MTEBlackHoleCompressor.java +++ b/src/main/java/gregtech/common/tileentities/machines/multi/compressor/MTEBlackHoleCompressor.java @@ -534,26 +534,6 @@ protected Stream findRecipeMatches(@Nullable RecipeMap map) { } } - @Override - public GTRecipe getRecipeByInputs(ItemStack[] inItems, FluidStack[] inFluids) { - RecipeMap map; - switch (getModeFromCircuit(inItems)) { - case MACHINEMODE_COMPRESSOR -> { - map = RecipeMaps.compressorRecipes; - } - case MACHINEMODE_BLACKHOLE -> { - map = RecipeMaps.neutroniumCompressorRecipes; - } - default -> { - return null; - } - } - return map.findRecipeQuery() - .items(inItems) - .fluids(inFluids) - .find(); - } - @NotNull @Override protected OverclockCalculator createOverclockCalculator(@NotNull GTRecipe recipe) {