Skip to content

Commit da95680

Browse files
authored
move recycling data generation up to base RecipeBuilder (GregTechCEu#2802)
1 parent f9ddde7 commit da95680

File tree

4 files changed

+29
-62
lines changed

4 files changed

+29
-62
lines changed

src/main/java/gregtech/api/recipes/RecipeBuilder.java

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,7 @@
2525
import gregtech.api.unification.OreDictUnifier;
2626
import gregtech.api.unification.material.Material;
2727
import gregtech.api.unification.ore.OrePrefix;
28+
import gregtech.api.unification.stack.ItemMaterialInfo;
2829
import gregtech.api.util.EnumValidationResult;
2930
import gregtech.api.util.GTLog;
3031
import gregtech.api.util.GTUtility;
@@ -93,6 +94,8 @@ public class RecipeBuilder<R extends RecipeBuilder<R>> {
9394
protected boolean ignoreAllBuildActions = false;
9495
protected Map<ResourceLocation, RecipeBuildAction<R>> ignoredBuildActions;
9596

97+
private boolean withItemRecycling;
98+
9699
protected RecipeBuilder() {
97100
this.inputs = new ArrayList<>();
98101
this.outputs = new ArrayList<>();
@@ -137,6 +140,7 @@ protected RecipeBuilder(RecipeBuilder<R> recipeBuilder) {
137140
if (recipeBuilder.ignoredBuildActions != null) {
138141
this.ignoredBuildActions = new Object2ObjectOpenHashMap<>(recipeBuilder.ignoredBuildActions);
139142
}
143+
this.withItemRecycling = recipeBuilder.hasItemRecycling();
140144
}
141145

142146
public R cleanroom(@Nullable CleanroomType cleanroom) {
@@ -964,6 +968,14 @@ public R ignoreBuildAction(ResourceLocation buildActionName) {
964968
return (R) this;
965969
}
966970

971+
/**
972+
* Generate Recycling Data based on this recipe's Items
973+
*/
974+
public R withRecycling() {
975+
this.withItemRecycling = true;
976+
return (R) this;
977+
}
978+
967979
public ValidationResult<Recipe> build() {
968980
EnumValidationResult result = recipePropertyStorageErrored ? EnumValidationResult.INVALID : validate();
969981
return ValidationResult.newResult(result, new Recipe(inputs, outputs,
@@ -1071,6 +1083,15 @@ public void buildAndRegister() {
10711083
buildAction.getValue().accept((R) this);
10721084
}
10731085
}
1086+
if (hasItemRecycling()) {
1087+
// ignore input fluids for item-only recycling
1088+
ItemStack outputStack = getOutputs().get(0);
1089+
ItemMaterialInfo info = RecyclingHandler.getRecyclingIngredients(getInputs(), outputStack.getCount());
1090+
if (info != null) {
1091+
OreDictUnifier.registerOre(outputStack, info);
1092+
}
1093+
}
1094+
10741095
ValidationResult<Recipe> validationResult = build();
10751096
recipeMap.addRecipe(validationResult);
10761097
}
@@ -1151,6 +1172,10 @@ public boolean ignoresAllBuildActions() {
11511172
return ignoredBuildActions;
11521173
}
11531174

1175+
public boolean hasItemRecycling() {
1176+
return withItemRecycling;
1177+
}
1178+
11541179
@Override
11551180
public String toString() {
11561181
return new ToStringBuilder(this)

src/main/java/gregtech/api/recipes/RecipeMaps.java

Lines changed: 2 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,6 @@
44
import gregtech.api.gui.GuiTextures;
55
import gregtech.api.gui.widgets.ProgressWidget;
66
import gregtech.api.gui.widgets.ProgressWidget.MoveType;
7-
import gregtech.api.recipes.builders.AssemblerRecipeBuilder;
87
import gregtech.api.recipes.builders.AssemblyLineRecipeBuilder;
98
import gregtech.api.recipes.builders.BlastRecipeBuilder;
109
import gregtech.api.recipes.builders.CircuitAssemblerRecipeBuilder;
@@ -29,15 +28,12 @@
2928
import gregtech.api.recipes.ui.impl.DistillationTowerUI;
3029
import gregtech.api.recipes.ui.impl.FormingPressUI;
3130
import gregtech.api.recipes.ui.impl.ResearchStationUI;
32-
import gregtech.api.unification.OreDictUnifier;
3331
import gregtech.api.unification.material.Materials;
34-
import gregtech.api.unification.stack.ItemMaterialInfo;
3532
import gregtech.api.util.AssemblyLineManager;
3633
import gregtech.api.util.GTUtility;
3734
import gregtech.core.sound.GTSoundEvents;
3835

3936
import net.minecraft.init.SoundEvents;
40-
import net.minecraft.item.ItemStack;
4137

4238
import crafttweaker.annotations.ZenRegister;
4339
import stanhebben.zenscript.annotations.ZenClass;
@@ -144,8 +140,8 @@ public final class RecipeMaps {
144140
* </pre>
145141
*/
146142
@ZenProperty
147-
public static final RecipeMap<AssemblerRecipeBuilder> ASSEMBLER_RECIPES = new RecipeMapBuilder<>("assembler",
148-
new AssemblerRecipeBuilder())
143+
public static final RecipeMap<SimpleRecipeBuilder> ASSEMBLER_RECIPES = new RecipeMapBuilder<>("assembler",
144+
new SimpleRecipeBuilder())
149145
.itemInputs(9)
150146
.itemOutputs(1)
151147
.fluidInputs(1)
@@ -162,17 +158,6 @@ public final class RecipeMaps {
162158
.buildAndRegister();
163159
}
164160
})
165-
.onBuild(gregtechId("assembler_recycling"), recipeBuilder -> {
166-
if (recipeBuilder.isWithRecycling()) {
167-
// ignore input fluids for recycling
168-
ItemStack outputStack = recipeBuilder.getOutputs().get(0);
169-
ItemMaterialInfo info = RecyclingHandler.getRecyclingIngredients(recipeBuilder.getInputs(),
170-
outputStack.getCount());
171-
if (info != null) {
172-
OreDictUnifier.registerOre(outputStack, info);
173-
}
174-
}
175-
})
176161
.build();
177162

178163
/**

src/main/java/gregtech/api/recipes/builders/AssemblerRecipeBuilder.java

Lines changed: 0 additions & 42 deletions
This file was deleted.

src/main/java/gregtech/loaders/recipe/handlers/WireRecipeHandler.java

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,6 @@
22

33
import gregtech.api.GTValues;
44
import gregtech.api.recipes.ModHandler;
5-
import gregtech.api.recipes.builders.AssemblerRecipeBuilder;
65
import gregtech.api.unification.OreDictUnifier;
76
import gregtech.api.unification.material.Material;
87
import gregtech.api.unification.material.properties.PropertyKey;
@@ -118,7 +117,7 @@ public static void generateCableCovering(OrePrefix wirePrefix, Material material
118117

119118
// Rubber Recipe (ULV-EV cables)
120119
if (voltageTier <= GTValues.EV) {
121-
AssemblerRecipeBuilder builder = ASSEMBLER_RECIPES.recipeBuilder().EUt(VA[ULV]).duration(100)
120+
var builder = ASSEMBLER_RECIPES.recipeBuilder().EUt(VA[ULV]).duration(100)
122121
.input(wirePrefix, material)
123122
.output(cablePrefix, material)
124123
.fluidInputs(Rubber.getFluid(GTValues.L * insulationAmount));
@@ -130,7 +129,7 @@ public static void generateCableCovering(OrePrefix wirePrefix, Material material
130129
}
131130

132131
// Silicone Rubber Recipe (all cables)
133-
AssemblerRecipeBuilder builder = ASSEMBLER_RECIPES.recipeBuilder().EUt(VA[ULV]).duration(100)
132+
var builder = ASSEMBLER_RECIPES.recipeBuilder().EUt(VA[ULV]).duration(100)
134133
.input(wirePrefix, material)
135134
.output(cablePrefix, material);
136135

0 commit comments

Comments
 (0)