Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Cribs super recipe check #3608

Open
wants to merge 32 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
32 commits
Select commit Hold shift + click to select a range
3fb4b52
ft
lordIcocain Nov 23, 2024
479381d
save
lordIcocain Nov 27, 2024
40242c4
save
lordIcocain Dec 5, 2024
337f1d9
seems works
lordIcocain Dec 6, 2024
094c88e
smol imrvmnt
lordIcocain Dec 6, 2024
fa6f276
less var
lordIcocain Dec 6, 2024
2d8f1fa
fix
lordIcocain Dec 6, 2024
ac7ada0
Merge branch 'master' into cribs_super_recipe_check
Dream-Master Dec 6, 2024
51d237c
indicate if pattern not have recipe.
lordIcocain Dec 10, 2024
8992bcc
Merge remote-tracking branch 'origin/cribs_super_recipe_check' into c…
lordIcocain Dec 10, 2024
7c788e8
Merge branch 'master' into cribs_super_recipe_check
lordIcocain Dec 10, 2024
3359634
recipe indicator using FakeSyncWidget
lordIcocain Dec 10, 2024
297dcf2
Merge remote-tracking branch 'origin/cribs_super_recipe_check' into c…
lordIcocain Dec 10, 2024
59ff738
spotless
lordIcocain Dec 10, 2024
81d4423
as mode
lordIcocain Dec 11, 2024
140fa5b
Merge branch 'master' into cribs_super_recipe_check
Dream-Master Dec 11, 2024
c27a227
get out sharedItems from PatternSlot.
lordIcocain Dec 12, 2024
6d25fd1
get out sharedItems from PatternSlot.
lordIcocain Dec 12, 2024
a4ec36a
Merge remote-tracking branch 'origin/cribs_super_recipe_check' into c…
lordIcocain Dec 12, 2024
f98f98f
Merge branch 'master' into cribs_super_recipe_check
Dream-Master Dec 12, 2024
12e9d76
Merge branch 'master' into cribs_super_recipe_check
Dream-Master Dec 13, 2024
ad5a450
re
lordIcocain Dec 14, 2024
4560720
Merge remote-tracking branch 'origin/cribs_super_recipe_check' into c…
lordIcocain Dec 14, 2024
837ad2f
cleanup
lordIcocain Dec 14, 2024
b3246c6
even more cleanup
lordIcocain Dec 14, 2024
ac8b451
a bit
lordIcocain Dec 14, 2024
4a4af59
Merge branch 'master' into cribs_super_recipe_check
Dream-Master Dec 14, 2024
89cca94
Merge branch 'master' into cribs_super_recipe_check
lordIcocain Dec 21, 2024
7f00989
Merge branch 'master' into cribs_super_recipe_check
Dream-Master Dec 21, 2024
fce62d9
Merge branch 'master' into cribs_super_recipe_check
serenibyss Dec 21, 2024
560b268
Merge branch 'master' into cribs_super_recipe_check
Dream-Master Dec 21, 2024
7796601
Merge branch 'master' into cribs_super_recipe_check
Dream-Master Dec 26, 2024
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
44 changes: 44 additions & 0 deletions src/main/java/gregtech/api/logic/ProcessingLogic.java
Original file line number Diff line number Diff line change
@@ -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;
Expand All @@ -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;
Expand All @@ -29,6 +32,8 @@ public class ProcessingLogic extends AbstractProcessingLogic<ProcessingLogic> {
protected ItemStack[] inputItems;
protected FluidStack[] inputFluids;
protected boolean isRecipeLocked;
protected int cribsSlotHash;
protected Map<Integer, GTRecipe> cribsRecipeMap = new HashMap<>();

public ProcessingLogic() {}

Expand Down Expand Up @@ -63,6 +68,27 @@ 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;
}
return false;
}

public void resetCribsRecipeMap() {
cribsRecipeMap.clear();
}

/**
* Enables single recipe locking mode.
*/
Expand All @@ -85,6 +111,7 @@ public ProcessingLogic clear() {
this.calculatedEut = 0;
this.duration = 0;
this.calculatedParallels = 0;
this.cribsSlotHash = 0;
return getThis();
}

Expand All @@ -106,6 +133,14 @@ 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;
}
return CheckRecipeResultRegistry.NO_RECIPE;
}

if (isRecipeLocked && recipeLockableMachine != null && recipeLockableMachine.getSingleRecipeCheck() != null) {
// Recipe checker is already built, we'll use it
SingleRecipeCheck singleRecipeCheck = recipeLockableMachine.getSingleRecipeCheck();
Expand Down Expand Up @@ -136,6 +171,15 @@ 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.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -883,16 +883,23 @@ protected boolean supportsCraftingMEBuffer() {
@Nonnull
protected CheckRecipeResult doCheckRecipe() {
CheckRecipeResult result = CheckRecipeResultRegistry.NO_RECIPE;

// check crafting input hatches first
if (supportsCraftingMEBuffer()) {
for (IDualInputHatch dualInputHatch : mDualInputHatches) {
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 = slot.getItemInputs();
ArrayUtils.reverse(inputItems);
processingLogic.setInputItems(inputItems);
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;

processingLogic.setInputItems(ArrayUtils.addAll(sharedItems, slot.getItemInputs()));
processingLogic.setInputFluids(slot.getFluidInputs());
processingLogic.setCribsSlotHash(slotHash);

CheckRecipeResult foundResult = processingLogic.process();
if (foundResult.wasSuccessful()) {
return foundResult;
Expand Down Expand Up @@ -2421,6 +2428,7 @@ public UITexture getMachineModeIcon(int index) {
@Override
public void setMachineMode(int index) {
machineMode = index;
processingLogic.resetCribsRecipeMap();
}

@Override
Expand Down
10 changes: 10 additions & 0 deletions src/main/java/gregtech/api/objects/GTDualInputs.java
Original file line number Diff line number Diff line change
@@ -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;
}
Original file line number Diff line number Diff line change
Expand Up @@ -18,4 +18,8 @@ public interface IDualInputHatch {
Optional<IDualInputInventory> getFirstNonEmptyInventory();

boolean supportsFluids();

ItemStack[] getSharedItems();

boolean needClearRecipeMap();
}
Original file line number Diff line number Diff line change
Expand Up @@ -3,9 +3,16 @@
import net.minecraft.item.ItemStack;
import net.minecraftforge.fluids.FluidStack;

import gregtech.api.objects.GTDualInputs;

public interface IDualInputInventory {

boolean isEmpty();

ItemStack[] getItemInputs();

FluidStack[] getFluidInputs();

GTDualInputs getPatternInputs();

}
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,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;
Expand Down Expand Up @@ -93,6 +94,7 @@
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.GTUtility;
import gregtech.api.util.extensions.ArrayExt;
Expand Down Expand Up @@ -198,14 +200,15 @@ public boolean isFluidEmpty() {
return fluidInventory.isEmpty();
}

@Override
public boolean isEmpty() {
return isItemEmpty() && isFluidEmpty();
}

@Override
public ItemStack[] getItemInputs() {
if (isEmpty()) return new ItemStack[0];
return ArrayUtils.addAll(itemInventory.toArray(new ItemStack[0]), sharedItemGetter.getSharedItem());
if (isItemEmpty()) return new ItemStack[0];
return itemInventory.toArray(new ItemStack[0]);
}

@Override
Expand All @@ -218,6 +221,29 @@ public ICraftingPatternDetails getPatternDetails() {
return patternDetails;
}

public GTDualInputs getPatternInputs() {
GTDualInputs dualInputs = new GTDualInputs();

ItemStack[] inputItems = this.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);
}
}

dualInputs.inputItems = inputItems;
dualInputs.inputFluid = inputFluids;
return dualInputs;
}

public void refund(AENetworkProxy proxy, BaseActionSource src) throws GridAccessException {
IMEMonitor<IAEItemStack> sg = proxy.getStorage()
.getItemInventory();
Expand Down Expand Up @@ -324,6 +350,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];
Expand Down Expand Up @@ -784,6 +811,7 @@ 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;
Expand All @@ -802,6 +830,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];
Expand Down Expand Up @@ -1068,6 +1097,11 @@ public List<ItemStack> getItemsForHoloGlasses() {
return list;
}

@Override
public boolean needClearRecipeMap() {
return needClearRecipeMap;
}

public void doublePatterns(int val) {
boolean fast = (val & 1) != 0;
boolean backwards = (val & 2) != 0;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -163,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();
Expand Down Expand Up @@ -291,4 +296,9 @@ public void getWailaNBTData(EntityPlayerMP player, TileEntity tile, NBTTagCompou
public List<ItemStack> getItemsForHoloGlasses() {
return getMaster() != null ? getMaster().getItemsForHoloGlasses() : null;
}

@Override
public boolean needClearRecipeMap() {
return getMaster() != null && getMaster().needClearRecipeMap();
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -435,12 +436,21 @@ protected CheckRecipeResult doCheckRecipe() {
CheckRecipeResult result = CheckRecipeResultRegistry.NO_RECIPE;

// check crafting input hatches first
if (supportsCraftingMEBuffer()) {
for (IDualInputHatch dualInputHatch : mDualInputHatches) {
for (var it = dualInputHatch.inventories(); it.hasNext();) {
IDualInputInventory slot = it.next();
processingLogic.setInputItems(slot.getItemInputs());
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;

processingLogic.setInputItems(ArrayUtils.addAll(sharedItems, slot.getItemInputs()));
processingLogic.setInputFluids(slot.getFluidInputs());
processingLogic.setCribsSlotHash(slotHash);

CheckRecipeResult foundResult = processingLogic.process();
if (foundResult.wasSuccessful()) {
return foundResult;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -534,6 +534,26 @@ protected Stream<GTRecipe> findRecipeMatches(@Nullable RecipeMap<?> map) {
}
}

@Override
public GTRecipe getRecipeByInputs(ItemStack[] inItems, FluidStack[] inFluids) {
serenibyss marked this conversation as resolved.
Show resolved Hide resolved
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) {
Expand Down
Loading