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

Allow specifying NBT matching on Research ItemStacks #2294

Merged
merged 2 commits into from
Dec 15, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
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
Original file line number Diff line number Diff line change
Expand Up @@ -155,6 +155,7 @@ public static class ResearchRecipeEntry {
private final String researchId;
private final ItemStack researchStack;
private final ItemStack dataStack;
private final boolean ignoreNBT;
private final int duration;
private final int EUt;
private final int CWUt;
Expand All @@ -166,6 +167,9 @@ public static class ResearchRecipeEntry {
* @param duration the duration of the recipe
* @param EUt the EUt of the recipe
* @param CWUt how much computation per tick this recipe needs if in Research Station
* <p>
* By default, will ignore NBT on researchStack input. If NBT matching is desired, see
* {@link #ResearchRecipeEntry(String, ItemStack, ItemStack, boolean, int, int, int)}
*/
public ResearchRecipeEntry(@NotNull String researchId, @NotNull ItemStack researchStack,
@NotNull ItemStack dataStack, int duration, int EUt, int CWUt) {
Expand All @@ -175,6 +179,26 @@ public ResearchRecipeEntry(@NotNull String researchId, @NotNull ItemStack resear
this.duration = duration;
this.EUt = EUt;
this.CWUt = CWUt;
this.ignoreNBT = true;
}

/**
* @param researchId the id of the research to store
* @param researchStack the stack to scan for research
* @param dataStack the stack to contain the data
* @param duration the duration of the recipe
* @param EUt the EUt of the recipe
* @param CWUt how much computation per tick this recipe needs if in Research Station
*/
public ResearchRecipeEntry(@NotNull String researchId, @NotNull ItemStack researchStack,
@NotNull ItemStack dataStack, boolean ignoreNBT, int duration, int EUt, int CWUt) {
this.researchId = researchId;
this.researchStack = researchStack;
this.dataStack = dataStack;
this.ignoreNBT = ignoreNBT;
this.duration = duration;
this.EUt = EUt;
this.CWUt = CWUt;
}

@NotNull
Expand All @@ -192,6 +216,10 @@ public ItemStack getDataStack() {
return dataStack;
}

public boolean getIgnoreNBT() {
return ignoreNBT;
}

public int getDuration() {
return duration;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,12 +15,22 @@ public abstract class ResearchRecipeBuilder<T extends ResearchRecipeBuilder<T>>

protected ItemStack researchStack;
protected ItemStack dataStack;
protected boolean ignoreNBT;
protected String researchId;
protected int eut;

public T researchStack(@NotNull ItemStack researchStack) {
if (!researchStack.isEmpty()) {
this.researchStack = researchStack;
this.ignoreNBT = true;
}
return (T) this;
}

public T researchStack(@NotNull ItemStack researchStack, boolean ignoreNBT) {
if (!researchStack.isEmpty()) {
this.researchStack = researchStack;
this.ignoreNBT = ignoreNBT;
}
return (T) this;
}
Expand Down Expand Up @@ -99,7 +109,8 @@ protected AssemblyLineRecipeBuilder.ResearchRecipeEntry build() {
validateResearchItem();
if (duration <= 0) duration = DEFAULT_SCANNER_DURATION;
if (eut <= 0) eut = DEFAULT_SCANNER_EUT;
return new AssemblyLineRecipeBuilder.ResearchRecipeEntry(researchId, researchStack, dataStack, duration,
return new AssemblyLineRecipeBuilder.ResearchRecipeEntry(researchId, researchStack, dataStack, ignoreNBT,
duration,
eut, 0);
}
}
Expand Down Expand Up @@ -148,7 +159,8 @@ protected AssemblyLineRecipeBuilder.ResearchRecipeEntry build() {
int duration = totalCWU;
if (eut <= 0) eut = DEFAULT_STATION_EUT;

return new AssemblyLineRecipeBuilder.ResearchRecipeEntry(researchId, researchStack, dataStack, duration,
return new AssemblyLineRecipeBuilder.ResearchRecipeEntry(researchId, researchStack, dataStack, ignoreNBT,
duration,
eut, cwut);
}
}
Expand Down
33 changes: 28 additions & 5 deletions src/main/java/gregtech/api/util/AssemblyLineManager.java
Original file line number Diff line number Diff line change
Expand Up @@ -121,33 +121,56 @@ public static void createDefaultResearchRecipe(@NotNull AssemblyLineRecipeBuilde

for (AssemblyLineRecipeBuilder.ResearchRecipeEntry entry : builder.getRecipeEntries()) {
createDefaultResearchRecipe(entry.getResearchId(), entry.getResearchStack(), entry.getDataStack(),
entry.getIgnoreNBT(),
entry.getDuration(), entry.getEUt(), entry.getCWUt());
}
}

@Deprecated
@ApiStatus.ScheduledForRemoval(inVersion = "2.9")
public static void createDefaultResearchRecipe(@NotNull String researchId, @NotNull ItemStack researchItem,
@NotNull ItemStack dataItem, int duration, int EUt, int CWUt) {
createDefaultResearchRecipe(researchId, researchItem, dataItem, true, duration, EUt, CWUt);
}

public static void createDefaultResearchRecipe(@NotNull String researchId, @NotNull ItemStack researchItem,
@NotNull ItemStack dataItem, boolean ignoreNBT, int duration,
int EUt, int CWUt) {
if (!ConfigHolder.machines.enableResearch) return;

NBTTagCompound compound = GTUtility.getOrCreateNbtCompound(dataItem);
writeResearchToNBT(compound, researchId);

if (CWUt > 0) {
RecipeMaps.RESEARCH_STATION_RECIPES.recipeBuilder()
RecipeBuilder<?> researchBuilder = RecipeMaps.RESEARCH_STATION_RECIPES.recipeBuilder()
.inputNBT(dataItem.getItem(), 1, dataItem.getMetadata(), NBTMatcher.ANY, NBTCondition.ANY)
.inputs(researchItem)
.outputs(dataItem)
.EUt(EUt)
.CWUt(CWUt)
.totalCWU(duration)
.buildAndRegister();
.totalCWU(duration);

if (ignoreNBT) {
researchBuilder.inputNBT(researchItem.getItem(), 1, researchItem.getMetadata(), NBTMatcher.ANY,
NBTCondition.ANY);
} else {
researchBuilder.inputs(researchItem);
}

researchBuilder.buildAndRegister();
} else {
RecipeBuilder<?> builder = RecipeMaps.SCANNER_RECIPES.recipeBuilder()
.inputNBT(dataItem.getItem(), 1, dataItem.getMetadata(), NBTMatcher.ANY, NBTCondition.ANY)
.inputs(researchItem)
.outputs(dataItem)
.duration(duration)
.EUt(EUt);

if (ignoreNBT) {
builder.inputNBT(researchItem.getItem(), 1, researchItem.getMetadata(), NBTMatcher.ANY,
NBTCondition.ANY);
} else {
builder.inputs(researchItem);
}

builder.applyProperty(ScanProperty.getInstance(), true);
builder.buildAndRegister();
}
Expand Down