diff options
Diffstat (limited to 'src/main/java/gregtech/api/interfaces')
-rw-r--r-- | src/main/java/gregtech/api/interfaces/IGT_RecipeMap.java | 64 | ||||
-rw-r--r-- | src/main/java/gregtech/api/interfaces/internal/IGT_RecipeAdder.java | 3 |
2 files changed, 67 insertions, 0 deletions
diff --git a/src/main/java/gregtech/api/interfaces/IGT_RecipeMap.java b/src/main/java/gregtech/api/interfaces/IGT_RecipeMap.java new file mode 100644 index 0000000000..69f87161d1 --- /dev/null +++ b/src/main/java/gregtech/api/interfaces/IGT_RecipeMap.java @@ -0,0 +1,64 @@ +package gregtech.api.interfaces; + +import java.util.ArrayList; +import java.util.Collection; +import java.util.List; +import java.util.function.Function; + +import javax.annotation.Nonnull; + +import gregtech.api.util.GT_Recipe; +import gregtech.api.util.GT_RecipeBuilder; +import gregtech.api.util.GT_Utility; + +/** + * Represents the target of a recipe adding action, usually, but not necessarily, is a recipe map itself. + */ +public interface IGT_RecipeMap { + + /** + * Add a downstream recipe map that will get to handle the original builder. + * + * @param downstream + */ + void addDownstream(IGT_RecipeMap downstream); + + /** + * Actually add the recipe represented by the builder. CAN modify the builder's internal states!!! + */ + @Nonnull + Collection<GT_Recipe> doAdd(GT_RecipeBuilder builder); + + /** + * Return a variant of this recipe map that will perform a deep copy on input recipe builder before doing anything + * to it. + * + * The returned recipe map will not have any downstreams, but can accept new downstreams. + */ + default IGT_RecipeMap deepCopyInput() { + return newRecipeMap(b -> doAdd(b.copy())); + } + + static IGT_RecipeMap newRecipeMap(Function<? super GT_RecipeBuilder, Collection<GT_Recipe>> func) { + return new IGT_RecipeMap() { + + private final Collection<IGT_RecipeMap> downstreams = new ArrayList<>(); + + @Override + public void addDownstream(IGT_RecipeMap downstream) { + downstreams.add(downstream); + } + + @Nonnull + @Override + public Collection<GT_Recipe> doAdd(GT_RecipeBuilder builder) { + List<Collection<GT_Recipe>> ret = new ArrayList<>(); + ret.add(func.apply(builder)); + for (IGT_RecipeMap downstream : downstreams) { + ret.add(downstream.doAdd(builder)); + } + return GT_Utility.concat(ret); + } + }; + } +} diff --git a/src/main/java/gregtech/api/interfaces/internal/IGT_RecipeAdder.java b/src/main/java/gregtech/api/interfaces/internal/IGT_RecipeAdder.java index bda2523811..149600b426 100644 --- a/src/main/java/gregtech/api/interfaces/internal/IGT_RecipeAdder.java +++ b/src/main/java/gregtech/api/interfaces/internal/IGT_RecipeAdder.java @@ -5,6 +5,7 @@ import net.minecraftforge.fluids.Fluid; import net.minecraftforge.fluids.FluidStack; import gregtech.api.util.GT_Recipe; +import gregtech.api.util.GT_RecipeBuilder; public interface IGT_RecipeAdder { @@ -960,4 +961,6 @@ public interface IGT_RecipeAdder { */ GT_Recipe addIC2ReactorFuelCell(ItemStack input, ItemStack output, boolean aMox, float aHeat, float aEnergy, int aCells); + + GT_RecipeBuilder stdBuilder(); } |