diff options
author | Léa Gris <lea.gris@noiraude.net> | 2022-09-08 08:11:18 +0200 |
---|---|---|
committer | GitHub <noreply@github.com> | 2022-09-08 08:11:18 +0200 |
commit | d0ecbfa6e361b354ef7074ba8194510fc257c352 (patch) | |
tree | 09bfcac07d604060d115c9b37fb724c3296ca9f6 /src/main/java/gregtech/common/fluid/GT_Fluid.java | |
parent | f14ab9d942ee11aff20f5d328b57d26c77c96cb7 (diff) | |
download | GT5-Unofficial-d0ecbfa6e361b354ef7074ba8194510fc257c352.tar.gz GT5-Unofficial-d0ecbfa6e361b354ef7074ba8194510fc257c352.tar.bz2 GT5-Unofficial-d0ecbfa6e361b354ef7074ba8194510fc257c352.zip |
fix(API): GT_Fluid (#1349)
* fix(API): GT_Fluid
- Fix: Use registeredFluid instead of GT_Fluid to configure Materials and containers to prevent crashes when retrieving fluids referrences from those.
- Impr: Adjust fluid luminosity computation to better fit with Tungsten as maximum
- Impr: Remove transparency from the fluid.molten.autogenerated.png texture to prevent molten materials to appear dilluted.
* ./gradlew :spotlessApply
* rev(comment): address review comment from @Glease
rev: https://github.com/GTNewHorizons/GT5-Unofficial/pull/1349#pullrequestreview-1098651647
fix: Logic to handle working with own registered fluids and
already registered fluids.
imp: Some IGT_Fluid methods requires the fluid to be registered,
throws an IllegalStateException on use at an unregistered fluid.
imp: Normalizes @inheritDoc no additionnal text allowed
Diffstat (limited to 'src/main/java/gregtech/common/fluid/GT_Fluid.java')
-rw-r--r-- | src/main/java/gregtech/common/fluid/GT_Fluid.java | 93 |
1 files changed, 48 insertions, 45 deletions
diff --git a/src/main/java/gregtech/common/fluid/GT_Fluid.java b/src/main/java/gregtech/common/fluid/GT_Fluid.java index 4e4131bb2f..6d5231fe00 100644 --- a/src/main/java/gregtech/common/fluid/GT_Fluid.java +++ b/src/main/java/gregtech/common/fluid/GT_Fluid.java @@ -22,6 +22,7 @@ public class GT_Fluid extends Fluid implements IGT_Fluid, Runnable { private final short[] colorRGBA; private final FluidState fluidState; private final int temperature; + private Fluid registeredFluid; /** * Constructs this {@link IGT_Fluid} implementation from an {@link GT_FluidBuilder} instance @@ -41,7 +42,7 @@ public class GT_Fluid extends Fluid implements IGT_Fluid, Runnable { } /** - * @inheritDoc from {@link Fluid#getColor()} + * @inheritDoc */ @Override public int getColor() { @@ -54,7 +55,7 @@ public class GT_Fluid extends Fluid implements IGT_Fluid, Runnable { * This {@link Runnable#run()} implementation is scheduled within the {@link GregTech_API#sGTBlockIconload} * to load this {@link IGT_Fluid}'s texture icons. * - * @inheritDoc from {@link Runnable#run()} + * @see Runnable#run() */ @Override public void run() { @@ -68,29 +69,40 @@ public class GT_Fluid extends Fluid implements IGT_Fluid, Runnable { } /** - * @inheritDoc from {@link IGT_Fluid#addFluid()} + * @inheritDoc */ @Override public IGT_Fluid addFluid() { - // Adds self the block icons loader run() tasks - GregTech_API.sGTBlockIconload.add(this); - GT_LanguageManager.addStringLocalization(this.getUnlocalizedName(), localizedName); - final Fluid registeredFluid = registerFluid(); - if (registeredFluid.getTemperature() == new Fluid("test").getTemperature()) { - registeredFluid.setTemperature(temperature); + if (FluidRegistry.registerFluid(this)) { + // Registered as a new Fluid + // Adds self as Runnable to the block icons loader run() tasks + GregTech_API.sGTBlockIconload.add(this); + // Adds a server-side localized-name + GT_LanguageManager.addStringLocalization(this.getUnlocalizedName(), localizedName); + registeredFluid = this; + } else { + // Promotes Fluid from the registry to enable GT_Fluid methods + registeredFluid = FluidRegistry.getFluid(fluidName); + // Sets temperature of already registered fluids if they use the default (temperature = 300) + if (registeredFluid.getTemperature() == new Fluid("test").getTemperature()) { + registeredFluid.setTemperature(temperature); + } } return this; } /** - * @inheritDoc from {@link IGT_Fluid#registerContainers(ItemStack, ItemStack, int)} + * @inheritDoc */ @Override public IGT_Fluid registerContainers( final ItemStack fullContainer, final ItemStack emptyContainer, final int containerSize) { if (fullContainer == null || emptyContainer == null) return this; - final FluidStack fluidStack = new FluidStack(this, containerSize); + if (registeredFluid == null) { + throw new IllegalStateException("Cannot register containers for an unregistered fluid"); + } + final FluidStack fluidStack = new FluidStack(registeredFluid, containerSize); if (!FluidContainerRegistry.registerFluidContainer(fluidStack, fullContainer, emptyContainer)) { GT_Values.RA.addFluidCannerRecipe( fullContainer, GT_Utility.getContainerItem(fullContainer, false), null, fluidStack); @@ -99,7 +111,7 @@ public class GT_Fluid extends Fluid implements IGT_Fluid, Runnable { } /** - * @inheritDoc from {@link IGT_Fluid#registerBContainers(ItemStack, ItemStack)} + * @inheritDoc */ @Override public IGT_Fluid registerBContainers(final ItemStack fullContainer, final ItemStack emptyContainer) { @@ -107,7 +119,7 @@ public class GT_Fluid extends Fluid implements IGT_Fluid, Runnable { } /** - * @inheritDoc from {@link IGT_Fluid#registerPContainers(ItemStack, ItemStack)} + * @inheritDoc */ @Override public IGT_Fluid registerPContainers(final ItemStack fullContainer, final ItemStack emptyContainer) { @@ -115,7 +127,7 @@ public class GT_Fluid extends Fluid implements IGT_Fluid, Runnable { } /** - * @inheritDoc from {@link IGT_Fluid#getStillIconResourceLocation()} + * @inheritDoc */ @Override public ResourceLocation getStillIconResourceLocation() { @@ -123,7 +135,7 @@ public class GT_Fluid extends Fluid implements IGT_Fluid, Runnable { } /** - * @inheritDoc from {@link IGT_Fluid#getFlowingIconResourceLocation()} + * @inheritDoc */ @Override public ResourceLocation getFlowingIconResourceLocation() { @@ -131,26 +143,29 @@ public class GT_Fluid extends Fluid implements IGT_Fluid, Runnable { } /** - * @throws IllegalStateException if {@link FluidState} in invalid - * @inheritDoc from {@link IGT_Fluid#configureMaterials(Materials)} + * @inheritDoc */ @Override public IGT_Fluid configureMaterials(final Materials material) { + if (registeredFluid == null) { + throw new IllegalStateException("Cannot configure Materials with an unregistered fluid"); + } + switch (fluidState) { case SLURRY: - material.mSolid = this; + material.mSolid = registeredFluid; break; case LIQUID: - material.mFluid = this; + material.mFluid = registeredFluid; break; case GAS: - material.mGas = this; + material.mGas = registeredFluid; break; case PLASMA: - material.mPlasma = this; + material.mPlasma = registeredFluid; break; case MOLTEN: - material.mStandardMoltenFluid = this; + material.mStandardMoltenFluid = registeredFluid; break; default: throw new IllegalStateException("Unexpected FluidState: " + fluidState); @@ -159,49 +174,37 @@ public class GT_Fluid extends Fluid implements IGT_Fluid, Runnable { } /** - * @inheritDoc from {@link IGT_Fluid#asFluid()} + * @inheritDoc */ @Override public Fluid asFluid() { - return this; + return registeredFluid == null ? this : registeredFluid; } /** * Adjusts this {@link Fluid}'s settings based on this {@link IGT_Fluid}'s state * - * @throws IllegalStateException if {@link FluidState} in invalid + * @throws IllegalStateException if {@link FluidState} is unknown */ protected void configureFromStateTemperature() { switch (fluidState) { - case SLURRY: // Solid + case SLURRY: setGaseous(false).setViscosity(10000); break; - case LIQUID: // Fluid - case MOLTEN: // Molten - setGaseous(false) - .setViscosity(1000) - .setLuminosity( - temperature >= 5000 - ? 15 - : temperature < 1000 ? 0 : 14 * (temperature - 1000) / 4000 + 1); + case LIQUID: + case MOLTEN: + final int luminosity = + temperature >= 3500 ? 15 : temperature < 1000 ? 0 : 14 * (temperature - 1000) / 2500 + 1; + setGaseous(false).setViscosity(1000).setLuminosity(luminosity); break; - case GAS: // Gas + case GAS: setGaseous(true).setDensity(-100).setViscosity(200); break; - case PLASMA: // Plasma + case PLASMA: setGaseous(true).setDensity(55536).setViscosity(10).setLuminosity(15); break; default: throw new IllegalStateException("Unexpected FluidState: " + fluidState); } } - - /** - * Registers this {@link IGT_Fluid} to the {@link FluidRegistry} - * - * @return the {@link Fluid} from the {@link FluidRegistry} - */ - protected Fluid registerFluid() { - return FluidRegistry.registerFluid(this) ? this : FluidRegistry.getFluid(this.fluidName); - } } |