From d74054c1e73e53b3d485adb6e523ec7478e7c1f2 Mon Sep 17 00:00:00 2001 From: JellySquid <1363084+jellysquid3@users.noreply.github.com> Date: Fri, 9 Feb 2024 08:04:51 -0600 Subject: [PATCH] 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 --- .../render/fluid/v1/FluidRenderHandlerRegistry.java | 13 +++++++++++++ .../fluid/FluidRenderHandlerRegistryImpl.java | 13 +++++++++---- .../client/rendering/fluid/FluidRendererMixin.java | 2 +- 3 files changed, 23 insertions(+), 5 deletions(-) diff --git a/fabric-rendering-fluids-v1/src/client/java/net/fabricmc/fabric/api/client/render/fluid/v1/FluidRenderHandlerRegistry.java b/fabric-rendering-fluids-v1/src/client/java/net/fabricmc/fabric/api/client/render/fluid/v1/FluidRenderHandlerRegistry.java index 49ead64267..6394d9934d 100644 --- a/fabric-rendering-fluids-v1/src/client/java/net/fabricmc/fabric/api/client/render/fluid/v1/FluidRenderHandlerRegistry.java +++ b/fabric-rendering-fluids-v1/src/client/java/net/fabricmc/fabric/api/client/render/fluid/v1/FluidRenderHandlerRegistry.java @@ -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. * diff --git a/fabric-rendering-fluids-v1/src/client/java/net/fabricmc/fabric/impl/client/rendering/fluid/FluidRenderHandlerRegistryImpl.java b/fabric-rendering-fluids-v1/src/client/java/net/fabricmc/fabric/impl/client/rendering/fluid/FluidRenderHandlerRegistryImpl.java index d2715db977..86737d1b45 100644 --- a/fabric-rendering-fluids-v1/src/client/java/net/fabricmc/fabric/impl/client/rendering/fluid/FluidRenderHandlerRegistryImpl.java +++ b/fabric-rendering-fluids-v1/src/client/java/net/fabricmc/fabric/impl/client/rendering/fluid/FluidRenderHandlerRegistryImpl.java @@ -19,6 +19,8 @@ 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 FluidRenderHandlerRegistryImpl() { } @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 Sprite[] getFluidSprites(BlockRenderView view, BlockPos pos, FluidState s } }; - 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() diff --git a/fabric-rendering-fluids-v1/src/client/java/net/fabricmc/fabric/mixin/client/rendering/fluid/FluidRendererMixin.java b/fabric-rendering-fluids-v1/src/client/java/net/fabricmc/fabric/mixin/client/rendering/fluid/FluidRendererMixin.java index 5ec9625e36..81735984e1 100644 --- a/fabric-rendering-fluids-v1/src/client/java/net/fabricmc/fabric/mixin/client/rendering/fluid/FluidRendererMixin.java +++ b/fabric-rendering-fluids-v1/src/client/java/net/fabricmc/fabric/mixin/client/rendering/fluid/FluidRendererMixin.java @@ -85,7 +85,7 @@ public void tesselate(BlockRenderView view, BlockPos pos, VertexConsumer vertexC @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;