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 20 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
29 changes: 29 additions & 0 deletions src/main/java/gregtech/api/logic/ProcessingLogic.java
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,8 @@ public class ProcessingLogic extends AbstractProcessingLogic<ProcessingLogic> {
protected ItemStack[] inputItems;
protected FluidStack[] inputFluids;
protected boolean isRecipeLocked;
protected GTRecipe cribsRecipe;
protected int cribsRecipeMapHash;

public ProcessingLogic() {}

Expand Down Expand Up @@ -63,6 +65,14 @@ public ProcessingLogic setSpecialSlotItem(ItemStack specialSlotItem) {
return getThis();
}

public void setCribsRecipe(GTRecipe recipe) {
this.cribsRecipe = recipe;
}

public int getCribsRecipeMapHash() {
return cribsRecipeMapHash;
}
Dream-Master marked this conversation as resolved.
Show resolved Hide resolved

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

Expand All @@ -95,6 +106,7 @@ public ProcessingLogic clear() {
/**
* Executes the recipe check: Find recipe from recipemap, Calculate parallel, overclock and outputs.
*/

@Nonnull
public CheckRecipeResult process() {
RecipeMap<?> recipeMap = preProcess();
Expand All @@ -106,6 +118,13 @@ public CheckRecipeResult process() {
inputFluids = new FluidStack[0];
}

if (cribsRecipe != null) {
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();
Expand Down Expand Up @@ -136,6 +155,16 @@ public CheckRecipeResult process() {
return checkRecipeResult;
}

public GTRecipe getRecipeByInputs(ItemStack[] inItems, FluidStack[] inFluids) {
RecipeMap<?> map = preProcess();
cribsRecipeMapHash = map.hashCode();
return map.findRecipeQuery()
.items(inItems)
.fluids(inFluids)
.specialSlot(specialSlotItem)
.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 @@ -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<MTEHatchInput> mInputHatches = new ArrayList<>();
Expand Down Expand Up @@ -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;
}
Dream-Master marked this conversation as resolved.
Show resolved Hide resolved

@Override
public boolean isSimpleMachine() {
return false;
Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -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)) {
Expand Down Expand Up @@ -875,6 +892,91 @@ 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) {
return false;
} else if (maps != null) {
for (RecipeMap<?> tempMap : maps) {
if (tempMap.hashCode() == hash) {
return false;
}
}
}
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.
Expand All @@ -884,21 +986,34 @@ 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);
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;
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;
}
}
}
}
Expand Down Expand Up @@ -2409,6 +2524,7 @@ public UITexture getMachineModeIcon(int index) {
@Override
public void setMachineMode(int index) {
machineMode = index;
resetCribsRecipes();
}

@Override
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,4 +18,10 @@ public interface IDualInputHatch {
Optional<IDualInputInventory> getFirstNonEmptyInventory();

boolean supportsFluids();

ItemStack[] getSharedItems();

void resetRecipes();

void setSuperCribsRecipeCheck(boolean state);
}
Original file line number Diff line number Diff line change
Expand Up @@ -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(ItemStack[] sharedItems);
Dream-Master marked this conversation as resolved.
Show resolved Hide resolved

void setPatternRecipe(GTRecipe recipe, int hash);

GTRecipe getPatternRecipe();

int getPatternRecipeMapHash();
}
Loading
Loading