Expose a function for querying the non-default fluid renderer (#3558)

* Expose a function for querying the non-default fluid renderer

* Do not register default handlers as overrides

* Add @Nullable to getOverride

* Add @Nullable to get

---------

Co-authored-by: modmuss50 <modmuss50@gmail.com>
(cherry picked from commit d74054c1e7)
This commit is contained in:
JellySquid 2024-02-09 08:04:51 -06:00 committed by modmuss50
parent 54b4400cee
commit 6e2af442ba
3 changed files with 23 additions and 5 deletions

View file

@ -16,6 +16,8 @@
package net.fabricmc.fabric.api.client.render.fluid.v1;
import org.jetbrains.annotations.Nullable;
import net.minecraft.block.Block;
import net.minecraft.block.LeavesBlock;
import net.minecraft.block.TransparentBlock;
@ -39,8 +41,19 @@ public interface FluidRenderHandlerRegistry {
* @param fluid The Fluid.
* @return The FluidRenderHandler.
*/
@Nullable
FluidRenderHandler get(Fluid fluid);
/**
* Get a {@link FluidRenderHandler} for a given Fluid, if it is not the
* default implementation. Supports vanilla and Fabric fluids.
*
* @param fluid The Fluid.
* @return The FluidRenderHandler.
*/
@Nullable
FluidRenderHandler getOverride(Fluid fluid);
/**
* Register a {@link FluidRenderHandler} for a given Fluid.
*

View file

@ -19,6 +19,8 @@ package net.fabricmc.fabric.impl.client.rendering.fluid;
import java.util.IdentityHashMap;
import java.util.Map;
import org.jetbrains.annotations.Nullable;
import net.minecraft.block.Block;
import net.minecraft.block.BlockState;
import net.minecraft.block.LeavesBlock;
@ -55,10 +57,13 @@ public class FluidRenderHandlerRegistryImpl implements FluidRenderHandlerRegistr
}
@Override
@Nullable
public FluidRenderHandler get(Fluid fluid) {
return handlers.get(fluid);
}
@Override
@Nullable
public FluidRenderHandler getOverride(Fluid fluid) {
return modHandlers.get(fluid);
}
@ -107,10 +112,10 @@ public class FluidRenderHandlerRegistryImpl implements FluidRenderHandlerRegistr
}
};
register(Fluids.WATER, waterHandler);
register(Fluids.FLOWING_WATER, waterHandler);
register(Fluids.LAVA, lavaHandler);
register(Fluids.FLOWING_LAVA, lavaHandler);
handlers.put(Fluids.WATER, waterHandler);
handlers.put(Fluids.FLOWING_WATER, waterHandler);
handlers.put(Fluids.LAVA, lavaHandler);
handlers.put(Fluids.FLOWING_LAVA, lavaHandler);
handlers.putAll(modHandlers);
SpriteAtlasTexture texture = MinecraftClient.getInstance()

View file

@ -85,7 +85,7 @@ public class FluidRendererMixin {
@Unique
private void tessellateViaHandler(BlockRenderView view, BlockPos pos, VertexConsumer vertexConsumer, BlockState blockState, FluidState fluidState, CallbackInfo info) {
FluidRendererHookContainer ctr = fabric_renderHandler.get();
FluidRenderHandler handler = ((FluidRenderHandlerRegistryImpl) FluidRenderHandlerRegistry.INSTANCE).getOverride(fluidState.getFluid());
FluidRenderHandler handler = FluidRenderHandlerRegistry.INSTANCE.get(fluidState.getFluid());
ctr.view = view;
ctr.pos = pos;