From cd750287da464714667f619909483f2d8b5ea127 Mon Sep 17 00:00:00 2001 From: alongstringofnumbers Date: Wed, 13 Dec 2023 12:50:19 -0700 Subject: [PATCH 1/2] Allow specifying NBT matching on Research ItemStacks --- .../builders/AssemblyLineRecipeBuilder.java | 28 ++++++++++++++++ .../api/util/AssemblyLineManager.java | 33 ++++++++++++++++--- 2 files changed, 56 insertions(+), 5 deletions(-) diff --git a/src/main/java/gregtech/api/recipes/builders/AssemblyLineRecipeBuilder.java b/src/main/java/gregtech/api/recipes/builders/AssemblyLineRecipeBuilder.java index 2d9d5006c1b..9ddc9d6851b 100644 --- a/src/main/java/gregtech/api/recipes/builders/AssemblyLineRecipeBuilder.java +++ b/src/main/java/gregtech/api/recipes/builders/AssemblyLineRecipeBuilder.java @@ -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; @@ -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 + *

+ * 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) { @@ -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 @@ -192,6 +216,10 @@ public ItemStack getDataStack() { return dataStack; } + public boolean getIgnoreNBT() { + return ignoreNBT; + } + public int getDuration() { return duration; } diff --git a/src/main/java/gregtech/api/util/AssemblyLineManager.java b/src/main/java/gregtech/api/util/AssemblyLineManager.java index f4f577996b2..a2652acfa84 100644 --- a/src/main/java/gregtech/api/util/AssemblyLineManager.java +++ b/src/main/java/gregtech/api/util/AssemblyLineManager.java @@ -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(); } From 8d229f273292b6e1856e4a782f815d90470ea76f Mon Sep 17 00:00:00 2001 From: alongstringofnumbers Date: Thu, 14 Dec 2023 20:22:05 -0700 Subject: [PATCH 2/2] Add ignoreNBT to the builder --- .../recipes/builders/ResearchRecipeBuilder.java | 16 ++++++++++++++-- 1 file changed, 14 insertions(+), 2 deletions(-) diff --git a/src/main/java/gregtech/api/recipes/builders/ResearchRecipeBuilder.java b/src/main/java/gregtech/api/recipes/builders/ResearchRecipeBuilder.java index bbbda50d520..b20da993e70 100644 --- a/src/main/java/gregtech/api/recipes/builders/ResearchRecipeBuilder.java +++ b/src/main/java/gregtech/api/recipes/builders/ResearchRecipeBuilder.java @@ -15,12 +15,22 @@ public abstract class ResearchRecipeBuilder> 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; } @@ -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); } } @@ -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); } }