Fabric API

Fabric API

106M Downloads

Injected getFluidName method for fluids

Juuxel opened this issue ยท 1 comments

commented

Currently, if you only want to provide a name for a fluid that has no block, it's pretty cumbersome and needs you register an additional object like this:

FluidVariantAttributes.register(MY_FLUID, new FluidVariantAttributeHandler() {
    @Override
    public Text getName(FluidVariant variant) {
        return Text.translatable("fluid.my_mod.my_fluid");
    }
});

I'm proposing a FabricFluid injected interface with these methods:

public interface FabricFluid {
    default Text getFluidName() {
        // the current default in FluidVariantAttributeHandler
        return ((Fluid) this).getDefaultState().getBlockState().getBlock().getName();
    }

    // If this interface is part of the transfer API:
    default Text getFluidName(FluidVariant variant) {
        return getFluidName();
    }
}

The default fluid variant attribute handler would then delegate to these methods.

(getFluidName so that a fluid class doesn't end up inheriting both this unobfuscated method and method_5477 - present in many classes such as Nameable - which would cause a remapping conflict)

commented

I think a better fix is to change the default implementation of FluidVariantAttributeHandler to something like this:

	/**
	 * Return the name that should be used for the passed fluid variant.
	 */
	default Text getName(FluidVariant fluidVariant) {
		Block fluidBlock = return fluidVariant.getFluid().getDefaultState().getBlockState().getBlock();

		if (fluidBlock.isAir()) {
			// Some unplaceable fluids use air as their fluid block, use "block." translation key.
			return Text.translatable(Util.createTranslationKey("block", Registries.FLUID.getId(fluidVariant.getFluid())));
.getName();
		} else {
			return fluidBlock.getName();
	}

PR welcome of course.