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. --- .../preload/GT_Loader_Item_Block_And_Fluid.java | 28 +++++++++++----------- 1 file changed, 14 insertions(+), 14 deletions(-) (limited to 'src/main/java/gregtech/loaders') diff --git a/src/main/java/gregtech/loaders/preload/GT_Loader_Item_Block_And_Fluid.java b/src/main/java/gregtech/loaders/preload/GT_Loader_Item_Block_And_Fluid.java index 633a8d77ae..ad85963075 100644 --- a/src/main/java/gregtech/loaders/preload/GT_Loader_Item_Block_And_Fluid.java +++ b/src/main/java/gregtech/loaders/preload/GT_Loader_Item_Block_And_Fluid.java @@ -915,8 +915,7 @@ public class GT_Loader_Item_Block_And_Fluid implements Runnable { Materials.Ice.mGas = Materials.Water.mGas; Materials.Water.mGas.setTemperature(375).setGaseous(true); - ItemList.sOilExtraHeavy = GT_FluidFactory.of("liquid_extra_heavy_oil", "Very Heavy Oil", LIQUID, 295) - .asFluid(); + ItemList.sOilExtraHeavy = GT_FluidFactory.of("liquid_extra_heavy_oil", "Very Heavy Oil", LIQUID, 295); ItemList.sEpichlorhydrin = GT_FluidFactory.builder("liquid_epichlorhydrin") .withLocalizedName("Epichlorohydrin") .withStateAndTemperature(LIQUID, 295) @@ -924,8 +923,7 @@ public class GT_Loader_Item_Block_And_Fluid implements Runnable { .configureMaterials(Materials.Epichlorohydrin) .registerBContainers(Materials.Epichlorohydrin.getCells(1), Materials.Empty.getCells(1)) .asFluid(); - ItemList.sDrillingFluid = GT_FluidFactory.of("liquid_drillingfluid", "Drilling Fluid", LIQUID, 295) - .asFluid(); + ItemList.sDrillingFluid = GT_FluidFactory.of("liquid_drillingfluid", "Drilling Fluid", LIQUID, 295); ItemList.sToluene = GT_FluidFactory.builder("liquid_toluene") .withLocalizedName("Toluene") .withStateAndTemperature(LIQUID, 295) @@ -1321,21 +1319,23 @@ public class GT_Loader_Item_Block_And_Fluid implements Runnable { for (byte i = 0; i < Dyes.VALUES.length; i = (byte) (i + 1)) { Dyes tDye = Dyes.VALUES[i]; Fluid tFluid; - tDye.addFluidDye((Fluid) + tDye.addFluidDye( GT_FluidFactory.builder("dye.watermixed." + tDye.name().toLowerCase(Locale.ENGLISH)) .withTextureName("dyes") .withLocalizedName("Water Mixed " + tDye.mName + " Dye") .withColorRGBA(tDye.getRGBA()) .withStateAndTemperature(LIQUID, 295) - .buildAndRegister()); - tDye.addFluidDye((Fluid) GT_FluidFactory.builder( - "dye.chemical." + tDye.name().toLowerCase(Locale.ENGLISH)) - .withTextureName("dyes") - .withLocalizedName("Chemical " + tDye.mName + " Dye") - .withColorRGBA(tDye.getRGBA()) - .withStateAndTemperature(LIQUID, 295) - .buildAndRegister() - .registerContainers(ItemList.SPRAY_CAN_DYES[i].get(1L), ItemList.Spray_Empty.get(1L), 2304)); + .buildAndRegister() + .asFluid()); + tDye.addFluidDye( + GT_FluidFactory.builder("dye.chemical." + tDye.name().toLowerCase(Locale.ENGLISH)) + .withTextureName("dyes") + .withLocalizedName("Chemical " + tDye.mName + " Dye") + .withColorRGBA(tDye.getRGBA()) + .withStateAndTemperature(LIQUID, 295) + .buildAndRegister() + .registerContainers(ItemList.SPRAY_CAN_DYES[i].get(1L), ItemList.Spray_Empty.get(1L), 2304) + .asFluid()); } GT_FluidFactory.builder("ice") .withLocalizedName("Crushed Ice") -- cgit