Skip to content
This repository has been archived by the owner on Mar 8, 2024. It is now read-only.

Commit

Permalink
Migrate findRecipe method (#338)
Browse files Browse the repository at this point in the history
* Migrate findRecipe method

* Update dependencies.gradle

* Update deps

* update deps

---------

Co-authored-by: Martin Robertz <[email protected]>
Former-commit-id: 228994f28e6e967ec2cfb9f082ea265022316587
  • Loading branch information
miozune and Dream-Master authored Jul 10, 2023
1 parent 17c20f0 commit 6cacdb9
Show file tree
Hide file tree
Showing 6 changed files with 14 additions and 626 deletions.
14 changes: 8 additions & 6 deletions build.gradle
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
//version: 1684218858
//version: 1685785062
/*
DO NOT CHANGE THIS FILE!
Also, you may replace this file at any time if there is an update available.
Expand Down Expand Up @@ -1276,12 +1276,14 @@ tasks.register('faq') {
description = 'Prints frequently asked questions about building a project'

doLast {
print("If your build fails to fetch dependencies, they might have been deleted and replaced by newer " +
"versions.\nCheck if the versions you try to fetch are still on the distributing sites.\n" +
"The links can be found in repositories.gradle and build.gradle:repositories, " +
"not build.gradle:buildscript.repositories - this one is for gradle plugin metadata.\n\n" +
print("If your build fails to fetch dependencies, run './gradlew updateDependencies'. " +
"Or you can manually check if the versions are still on the distributing sites - " +
"the links can be found in repositories.gradle and build.gradle:repositories, " +
"but not build.gradle:buildscript.repositories - those ones are for gradle plugin metadata.\n\n" +
"If your build fails to recognize the syntax of new Java versions, enable Jabel in your " +
"gradle.properties. See how it's done in GTNH ExampleMod/gradle.properties.")
"gradle.properties. See how it's done in GTNH ExampleMod/gradle.properties. " +
"However, keep in mind that Jabel enables only syntax features, but not APIs that were introduced in " +
"Java 9 or later.")
}
}

Expand Down
10 changes: 5 additions & 5 deletions dependencies.gradle
Original file line number Diff line number Diff line change
@@ -1,14 +1,14 @@
// Add your dependencies here

dependencies {
api('com.github.GTNewHorizons:GT5-Unofficial:5.09.43.57-pre:dev')
api("com.github.GTNewHorizons:TecTech:5.2.18:dev")
api('com.github.GTNewHorizons:GT5-Unofficial:5.09.43.122:dev')
api("com.github.GTNewHorizons:TecTech:5.2.34:dev")
api("com.github.GTNewHorizons:GalacticGregGT5:1.0.9:dev") {
exclude group:"com.github.GTNewHorizons", module:"bartworks"
}
api("com.github.GTNewHorizons:Avaritia:1.42:dev")
implementation("com.github.GTNewHorizons:TinkersConstruct:1.9.35-GTNH:dev")
api("com.github.GTNewHorizons:Avaritia:1.45:dev")
implementation("com.github.GTNewHorizons:TinkersConstruct:1.9.38-GTNH:dev")

compileOnly("TGregworks:TGregworks:1.7.10-GTNH-1.0.24:deobf") {transitive = false}
compileOnly("com.github.GTNewHorizons:OpenComputers:1.9.5-GTNH:api") {transitive = false}
compileOnly("com.github.GTNewHorizons:OpenComputers:1.9.12-GTNH:api") {transitive = false}
}
Original file line number Diff line number Diff line change
Expand Up @@ -45,13 +45,10 @@
import com.gtnewhorizons.modularui.api.screen.ModularWindow;
import com.gtnewhorizons.modularui.common.widget.DrawableWidget;

import gregtech.api.GregTech_API;
import gregtech.api.enums.GT_Values;
import gregtech.api.enums.Materials;
import gregtech.api.enums.OrePrefixes;
import gregtech.api.gui.modularui.GT_UITextures;
import gregtech.api.interfaces.tileentity.IHasWorldObjectAndCoords;
import gregtech.api.objects.GT_ItemStack;
import gregtech.api.util.GT_OreDictUnificator;
import gregtech.api.util.GT_Recipe;
import gregtech.api.util.GT_Utility;
Expand Down Expand Up @@ -812,85 +809,7 @@ public SpecialObjectSensitiveMap(Collection<GT_Recipe> aRecipeList, String aUnlo
aNEISpecialValuePost,
aShowVoltageAmperageInNEI,
aNEIAllowed);
}

/**
* finds a Recipe matching the aFluid, aSpecial and ItemStack Inputs.
*
* @param aTileEntity an Object representing the current coordinates of the executing
* Block/Entity/Whatever. This may be null, especially during Startup.
* @param aRecipe in case this is != null it will try to use this Recipe first when looking things
* up.
* @param aNotUnificated if this is T the Recipe searcher will unificate the ItemStack Inputs
* @param aDontCheckStackSizes if set to false will only return recipes that can be executed at least once with
* the provided input
* @param aVoltage Voltage of the Machine or Long.MAX_VALUE if it has no Voltage
* @param aFluids the Fluid Inputs
* @param aSpecialSlot the content of the Special Slot, the regular Manager doesn't do anything with
* this, but some custom ones do. Like this one.
* @param aInputs the Item Inputs
* @return the Recipe it has found or null for no matching Recipe
*/
public GT_Recipe findRecipe(IHasWorldObjectAndCoords aTileEntity, GT_Recipe aRecipe, boolean aNotUnificated,
boolean aDontCheckStackSizes, long aVoltage, FluidStack[] aFluids, ItemStack aSpecialSlot,
ItemStack... aInputs) {
// No Recipes? Well, nothing to be found then.
if (mRecipeList.isEmpty()) return null;

// Some Recipe Classes require a certain amount of Inputs of certain kinds. Like "at least 1 Fluid + 1
// Stack" or "at least 2 Stacks" before they start searching for Recipes.
// This improves Performance massively, especially if people leave things like Circuits, Molds or Shapes in
// their Machines to select Sub Recipes.
if (GregTech_API.sPostloadFinished) {
if (mMinimalInputFluids > 0) {
if (aFluids == null) return null;
int tAmount = 0;
for (FluidStack aFluid : aFluids) if (aFluid != null) tAmount++;
if (tAmount < mMinimalInputFluids) return null;
}
if (mMinimalInputItems > 0) {
if (aInputs == null) return null;
int tAmount = 0;
for (ItemStack aInput : aInputs) if (aInput != null) tAmount++;
if (tAmount < mMinimalInputItems) return null;
}
}

// Unification happens here in case the Input isn't already unificated.
if (aNotUnificated) aInputs = GT_OreDictUnificator.getStackArray(true, (Object) aInputs);

// Check the Recipe which has been used last time in order to not have to search for it again, if possible.
if (aRecipe != null) if (!aRecipe.mFakeRecipe && aRecipe.mCanBeBuffered
&& aRecipe.isRecipeInputEqual(false, aDontCheckStackSizes, aFluids, aInputs)
&& BW_Util.areStacksEqualOrNull((ItemStack) aRecipe.mSpecialItems, aSpecialSlot))
return aRecipe.mEnabled && aVoltage * mAmperage >= aRecipe.mEUt ? aRecipe : null;

// Now look for the Recipes inside the Item HashMaps, but only when the Recipes usually have Items.
if (mUsualInputCount > 0 && aInputs != null) for (ItemStack tStack : aInputs) if (tStack != null) {
Collection<GT_Recipe> tRecipes = mRecipeItemMap.get(new GT_ItemStack(tStack));
if (tRecipes != null) for (GT_Recipe tRecipe : tRecipes) if (!tRecipe.mFakeRecipe
&& tRecipe.isRecipeInputEqual(false, aDontCheckStackSizes, aFluids, aInputs)
&& BW_Util.areStacksEqualOrNull((ItemStack) tRecipe.mSpecialItems, aSpecialSlot))
return tRecipe.mEnabled && aVoltage * mAmperage >= tRecipe.mEUt ? tRecipe : null;
tRecipes = mRecipeItemMap.get(new GT_ItemStack(GT_Utility.copyMetaData(GT_Values.W, tStack)));
if (tRecipes != null) for (GT_Recipe tRecipe : tRecipes) if (!tRecipe.mFakeRecipe
&& tRecipe.isRecipeInputEqual(false, aDontCheckStackSizes, aFluids, aInputs)
&& BW_Util.areStacksEqualOrNull((ItemStack) tRecipe.mSpecialItems, aSpecialSlot))
return tRecipe.mEnabled && aVoltage * mAmperage >= tRecipe.mEUt ? tRecipe : null;
}

// If the minimal Amount of Items for the Recipe is 0, then it could be a Fluid-Only Recipe, so check that
// Map too.
if (mMinimalInputItems == 0 && aFluids != null) for (FluidStack aFluid : aFluids) if (aFluid != null) {
Collection<GT_Recipe> tRecipes = mRecipeFluidMap.get(aFluid.getFluid());
if (tRecipes != null) for (GT_Recipe tRecipe : tRecipes) if (!tRecipe.mFakeRecipe
&& tRecipe.isRecipeInputEqual(false, aDontCheckStackSizes, aFluids, aInputs)
&& BW_Util.areStacksEqualOrNull((ItemStack) tRecipe.mSpecialItems, aSpecialSlot))
return tRecipe.mEnabled && aVoltage * mAmperage >= tRecipe.mEUt ? tRecipe : null;
}

// And nothing has been found.
return null;
setSpecialSlotSensitive(true);
}
}

Expand Down
Loading

0 comments on commit 6cacdb9

Please sign in to comment.