From 51a41123b0ccdf10cb7b311f8d87d250f78d1b89 Mon Sep 17 00:00:00 2001 From: Léa Gris Date: Sat, 1 Oct 2022 11:01:53 +0200 Subject: 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. --- src/main/java/gregtech/api/enums/FluidState.java | 9 ++++++++- 1 file changed, 8 insertions(+), 1 deletion(-) (limited to 'src/main/java/gregtech/api/enums') diff --git a/src/main/java/gregtech/api/enums/FluidState.java b/src/main/java/gregtech/api/enums/FluidState.java index ad27047a1c..a6e81ab43d 100644 --- a/src/main/java/gregtech/api/enums/FluidState.java +++ b/src/main/java/gregtech/api/enums/FluidState.java @@ -6,5 +6,12 @@ public enum FluidState { MOLTEN, PLASMA, SLURRY; - public static final FluidState[] VALUES = new FluidState[] {SLURRY, LIQUID, GAS, PLASMA, MOLTEN}; + + public static final FluidState[] VALID_STATES = new FluidState[] {SLURRY, LIQUID, GAS, PLASMA, MOLTEN}; + + public static FluidState fromValue(int stateValue) { + return stateValue >= 0 && stateValue < FluidState.VALID_STATES.length + ? FluidState.VALID_STATES[stateValue] + : FluidState.LIQUID; + } } -- cgit