Integrated Dynamics

Integrated Dynamics

88M Downloads

Non-fluid-containing items can be placed in LP fluid slots

met4000 opened this issue ยท 2 comments

commented

Issue type:

  • ๐Ÿ› Bug

Short description:

Items that don't contain fluids (e.g. variable cards) can be placed in fluid slots of the LP (e.g. fluid tab, list tab set to fluids) and silently fail to empty fluids, instead of erroring like invalid blocks do or like they used to in mc 1.12.

Steps to reproduce the problem:

  1. Place a non-fluid-containing item (e.g. variable card) into a LP fluid slot. See below.

Image

Expected behaviour:

The block tab on 1.20:
Image

The fluid tab on 1.12:
Image


Versions:

Might affect +1.14 (see notes below), but tested on:

  • This mod: 1.25.6
  • Minecraft: 1.20.1
  • Mod loader version: Forge 47.2.0

and

  • This mod: 1.25.12
  • Minecraft: 1.21.1
  • Mod loader version: NeoForge 1.21.122

and

  • This mod: 1.1.11
  • Minecraft: 1.12.2
  • Mod loader version: Forge 14.23.5.2859

Log file:

N/A

Notes:

Looking at the source code, it seems like while the docs for Helper.getFluidStack say it should return null if the item doesn't contain a fluid, when updating to 1.14 it was modified to return FluidStack.EMPTY instead of null - see line 48 below. Since the fluid validation tests for the return of the helper being null, this change might be what is causing the fluid validation to silently fail as an empty fluid.

1.21:

/**
* Get the fluidstack from the given itemstack.
* @param itemStack The itemstack.
* @return The fluidstack or null.
*/
public static FluidStack getFluidStack(ItemStack itemStack) {
FluidStack fluidStack = FluidUtil.getFluidContained(itemStack).orElse(FluidStack.EMPTY);
if (fluidStack.isEmpty()
&& itemStack.getItem() instanceof BlockItem
&& ((BlockItem) itemStack.getItem()).getBlock() instanceof LiquidBlock) {
fluidStack = new FluidStack(((LiquidBlock) ((BlockItem) itemStack.getItem()).getBlock()).fluid, FluidHelpers.BUCKET_VOLUME);
}
return fluidStack;
}

1.12:
public static FluidStack getFluidStack(ItemStack itemStack) {
FluidStack fluidStack = FluidUtil.getFluidContained(itemStack);
if (fluidStack == null
&& itemStack.getItem() instanceof ItemBlock
&& ((ItemBlock) itemStack.getItem()).getBlock() instanceof IFluidBlock) {
fluidStack = new FluidStack(((IFluidBlock) ((ItemBlock) itemStack.getItem()).getBlock()).getFluid(), Fluid.BUCKET_VOLUME);
}
return fluidStack;
}

Fluid validation:
@Override
public Component validate(ItemStack itemStack) {
return itemStack.isEmpty() || Helpers.getFluidStack(itemStack) != null ? null : Component.translatable(L10NValues.VALUETYPE_OBJECT_FLUID_ERROR_NOFLUID);
}

commented

Thanks for reporting!

commented

I'll add myself to watch as I was the noob that got trapped by this. Glad to hear it recognized as a problem!