diff options
author | Léa Gris <lea.gris@noiraude.net> | 2022-10-01 11:01:53 +0200 |
---|---|---|
committer | GitHub <noreply@github.com> | 2022-10-01 11:01:53 +0200 |
commit | 51a41123b0ccdf10cb7b311f8d87d250f78d1b89 (patch) | |
tree | 92b545c7768232ee09c89e39281aebff30c470f2 /src/main/java/gregtech/api/fluid | |
parent | ad7f7b95550d8a27cc5cddc8c419898d8d836713 (diff) | |
download | GT5-Unofficial-51a41123b0ccdf10cb7b311f8d87d250f78d1b89.tar.gz GT5-Unofficial-51a41123b0ccdf10cb7b311f8d87d250f78d1b89.tar.bz2 GT5-Unofficial-51a41123b0ccdf10cb7b311f8d87d250f78d1b89.zip |
refactor(fluid_api): fluent interface (#1407)
* refactor(fluid_api): fluent interface
Improves the initial construction model into a fluent interface.
See: https://java-design-patterns.com/patterns/fluentinterface/
This change provides the built and saved states of a GT_Fluid,
with their own interface, so that: object state validations are
performed at build time, rather than causing an `IllegalStateException`
to be thrown at runtime, with the previous implementation.
This also allows the IDE to display and check the applicable methods
for the GT_Fluid object's state, as it moves through the call chain.
* hotfix off-by-one in FluidState.fromValue
* minor: deduplicate buildAndRegister action
* fix(withIconsFrom): needs dependency management
Cracked fluid Icons were copied too early from non-cracked fluid
within the `IGT_FluidBuilder`'s implementation.
At this stage, the source Fluid has not registered its own icons yet,
so the Cracked fluid got null Icons (fallback to Error checkerboard).
This commit delegates the copy of the source fluid's Icons, to the
`run` Icons texture's registration task; ensuring the source Fluid
runs its own Icons textures registration before copying them,
as a light-weight dependency management.
Diffstat (limited to 'src/main/java/gregtech/api/fluid')
-rw-r--r-- | src/main/java/gregtech/api/fluid/GT_FluidFactory.java | 14 |
1 files changed, 8 insertions, 6 deletions
diff --git a/src/main/java/gregtech/api/fluid/GT_FluidFactory.java b/src/main/java/gregtech/api/fluid/GT_FluidFactory.java index 4aa39095ec..1622aa2e05 100644 --- a/src/main/java/gregtech/api/fluid/GT_FluidFactory.java +++ b/src/main/java/gregtech/api/fluid/GT_FluidFactory.java @@ -39,9 +39,9 @@ public class GT_FluidFactory { * @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} + * @return the registered {@link Fluid} */ - public static IGT_Fluid of( + public static Fluid of( final String fluidName, final String localizedName, final Materials material, @@ -51,7 +51,8 @@ public class GT_FluidFactory { .withLocalizedName(localizedName) .withStateAndTemperature(state, temperature) .buildAndRegister() - .configureMaterials(material); + .configureMaterials(material) + .asFluid(); } /** @@ -60,14 +61,15 @@ public class GT_FluidFactory { * @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} + * @return the registered {@link Fluid} */ - public static IGT_Fluid of( + public static Fluid of( final String fluidName, final String localizedName, final FluidState state, final int temperature) { return builder(fluidName) .withLocalizedName(localizedName) .withStateAndTemperature(state, temperature) - .buildAndRegister(); + .buildAndRegister() + .asFluid(); } /** |