From 7caea6daefcbffbc102741ed09daac9d6439824d Mon Sep 17 00:00:00 2001 From: Léa Gris Date: Mon, 5 Sep 2022 17:43:09 +0200 Subject: feat(API): Implements a featured API for GT_Fluid (#1345) * feat(API): Implements a featured API for GT_Fluid *** Rationale The current implementation, which is based on the `GT_Fluid` object, does not allow for the evolution of the functionalities, or the variation of the fluid-related implementations in GregTech. *** Objectives This replacement API should free from these constraints, by providing : 1. The separation of responsibilities of the different tasks and steps: - The definition and progressive construction of an `IGT_Fluid`, - Registration of the `IGT_Fluid`, - Configuration of related equipment, such as containers, - Propagation of properties of an `IGT_Fluid` to related services such as Materials 2. The separation of interfaces exposed to the API from their internal implementations to allow: - Evolve the implementations in the most transparent way possible - To have internal GregTech implementations or outsourced implementations coexist in its extensions. *** Specificity of this new API - Provides a new interface to build and interact with fluid related records - Deprecates the old `api/objects/GT_Fluid` object and the `common/GT_Proxy.addFluid` record methods * fix(conversations): addresses @Glease review comments https://github.com/GTNewHorizons/GT5-Unofficial/pull/1345#pullrequestreview-1096261703 * ./gradlew :spotlessApply * fix(review): add review comments from @eigenraven Added missing final qualifiers on methods parameters. https://github.com/GTNewHorizons/GT5-Unofficial/pull/1345#pullrequestreview-1096318523 * fix(review) address remaining review comments from @eigenraven --- .../java/gregtech/api/fluid/GT_FluidFactory.java | 80 ++++++++++++++++++++++ 1 file changed, 80 insertions(+) create mode 100644 src/main/java/gregtech/api/fluid/GT_FluidFactory.java (limited to 'src/main/java/gregtech/api/fluid') diff --git a/src/main/java/gregtech/api/fluid/GT_FluidFactory.java b/src/main/java/gregtech/api/fluid/GT_FluidFactory.java new file mode 100644 index 0000000000..0db1aec7e6 --- /dev/null +++ b/src/main/java/gregtech/api/fluid/GT_FluidFactory.java @@ -0,0 +1,80 @@ +package gregtech.api.fluid; + +import gregtech.api.enums.FluidState; +import gregtech.api.enums.Materials; +import gregtech.api.interfaces.fluid.IGT_Fluid; +import gregtech.api.interfaces.fluid.IGT_FluidBuilder; +import gregtech.common.fluid.GT_FluidBuilder; +import net.minecraftforge.fluids.Fluid; +import net.minecraftforge.fluids.FluidContainerRegistry; +import net.minecraftforge.fluids.FluidRegistry; + +/** + *

This class contains helpers factory methods to:

+ *
    + *
  1. + *

    Build {@link IGT_Fluid} instances.

    + *
  2. + *
  3. + *

    Register the corresponding {@link Fluid}, built from an {@link IGT_Fluid}, + * to the {@link FluidRegistry}:

    + *
      + *
    • + *

      Register the optionally associated containers to the {@link FluidContainerRegistry}.

      + *
    • + *
    • + *

      Add the needed Fluid Canner recipes.

      + *
    • + *
    + *
  4. + *
+ */ +public class GT_FluidFactory { + + /** + * Helper for quick fluid creation and registration + * @param fluidName The name key of the {@link Fluid} to register in the {@link FluidRegistry} + * @param localizedName The localized name of this {@link IGT_Fluid} + * @param material The {@link Materials} of this {@link IGT_Fluid} + * @param state The {@link FluidState} of this {@link IGT_Fluid} + * @param temperature The fluid temperature in Kelvin + * @return the registered {@link IGT_Fluid} + */ + public static IGT_Fluid of( + final String fluidName, + final String localizedName, + final Materials material, + final FluidState state, + final int temperature) { + return builder(fluidName) + .withLocalizedName(localizedName) + .withStateAndTemperature(state, temperature) + .buildAndRegister() + .configureMaterials(material); + } + + /** + * Helper for quick fluid creation and registration + * @param fluidName The name key of the {@link Fluid} to register in the {@link FluidRegistry} + * @param localizedName The localized name of this {@link IGT_Fluid} + * @param state The {@link FluidState} of this {@link IGT_Fluid} + * @param temperature The fluid temperature in Kelvin + * @return the registered {@link IGT_Fluid} + */ + public static IGT_Fluid of( + final String fluidName, final String localizedName, final FluidState state, final int temperature) { + return builder(fluidName) + .withLocalizedName(localizedName) + .withStateAndTemperature(state, temperature) + .buildAndRegister(); + } + + /** + * Gets an {@link IGT_Fluid} builder instance + * @param fluidName The name key of the {@link Fluid} to register in the {@link FluidRegistry} + * @return the {@link IGT_FluidBuilder} instance + */ + public static IGT_FluidBuilder builder(final String fluidName) { + return new GT_FluidBuilder(fluidName); + } +} -- cgit