From e51d8193ac5dbe204eae814eecc230493f7fe5f1 Mon Sep 17 00:00:00 2001 From: Metaflame Date: Thu, 20 Jun 2024 14:30:22 +0200 Subject: [PATCH 1/3] Fix multiple transformers fighting for inputStack, setting the NBT to null, and causing a NPE later on Whenever two (or more) transformers would fulfil their conditions at once, the first one would correctly pass the tank's fluid over to inputStack and remove the fluid, but the second transformer would retrieve the null fluid and assign it to inputStack. This would set the NBT data to null, causing a NPE both in the barrel's render method due to a null stack, and in the update method due to passing null to the transformer. --- .../exnihiloadscensio/barrel/modes/fluid/BarrelModeFluid.java | 4 +--- 1 file changed, 1 insertion(+), 3 deletions(-) diff --git a/src/main/java/exnihiloadscensio/barrel/modes/fluid/BarrelModeFluid.java b/src/main/java/exnihiloadscensio/barrel/modes/fluid/BarrelModeFluid.java index ec0001b6..7aa644df 100644 --- a/src/main/java/exnihiloadscensio/barrel/modes/fluid/BarrelModeFluid.java +++ b/src/main/java/exnihiloadscensio/barrel/modes/fluid/BarrelModeFluid.java @@ -174,7 +174,6 @@ public void update(TileBarrel barrel) { List transformers = FluidTransformRegistry .getFluidTransformers(barrel.getTank().getFluid().getFluid().getName()); - boolean found = false; for (int radius = 0; radius <= 2; radius++) { for (FluidTransformer transformer : transformers) { if (!BarrelLiquidBlacklistRegistry.isBlacklisted(barrel.getTier(), transformer.getOutputFluid()) @@ -194,10 +193,9 @@ public void update(TileBarrel barrel) { mode.setOutputStack(FluidRegistry.getFluidStack(transformer.getOutputFluid(), 1000)); PacketHandler.sendNBTUpdate(barrel); - found = true; + return; } } - if (found) break; } } } From f1a0c7ae953f3e9e56fde7493955a8fbd22f4223 Mon Sep 17 00:00:00 2001 From: Metaflame Date: Thu, 20 Jun 2024 14:32:44 +0200 Subject: [PATCH 2/3] Add null check to Util.getTextureFromFluidStack This previously caused a crash when stack itself was null, and now defaults to a missing sprite --- src/main/java/exnihiloadscensio/util/Util.java | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/main/java/exnihiloadscensio/util/Util.java b/src/main/java/exnihiloadscensio/util/Util.java index 7a08c46d..0d07a374 100644 --- a/src/main/java/exnihiloadscensio/util/Util.java +++ b/src/main/java/exnihiloadscensio/util/Util.java @@ -87,7 +87,7 @@ public static TextureAtlasSprite getTextureFromBlockState(IBlockState state) { public static TextureAtlasSprite getTextureFromFluidStack(FluidStack stack) { - if(stack.getFluid() != null) + if(stack != null && stack.getFluid() != null) { Fluid fluid = stack.getFluid(); From 611a7ba659e95e40c3942d6f7412f654863cb22a Mon Sep 17 00:00:00 2001 From: Metaflame Date: Thu, 20 Jun 2024 14:34:19 +0200 Subject: [PATCH 3/3] Add null checks to BarrelModeFluidTransform.update This previously caused a crash when inputStack was null. The method now checks for both, but remains lenient if transformer is already set. --- .../barrel/modes/transform/BarrelModeFluidTransform.java | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/main/java/exnihiloadscensio/barrel/modes/transform/BarrelModeFluidTransform.java b/src/main/java/exnihiloadscensio/barrel/modes/transform/BarrelModeFluidTransform.java index 428346cc..72281f85 100644 --- a/src/main/java/exnihiloadscensio/barrel/modes/transform/BarrelModeFluidTransform.java +++ b/src/main/java/exnihiloadscensio/barrel/modes/transform/BarrelModeFluidTransform.java @@ -112,7 +112,7 @@ public float getFilledLevelForRender(TileBarrel barrel) { @Override public void update(TileBarrel barrel) { - if (transformer == null) { + if (transformer == null && inputStack != null && outputStack != null) { transformer = FluidTransformRegistry.getFluidTransformer(inputStack .getFluid().getName(), outputStack.getFluid().getName()); }