use of net.fabricmc.fabric.api.client.render.fluid.v1.FluidRenderHandler in project Primeval by devs-immortal.
the class PrimevalFluids method setupFluidRendering.
/*
* Fluid rendering setup from Spectrum,
* Made by DaFaqs, credit to him for this
* method
*/
@Environment(EnvType.CLIENT)
private static void setupFluidRendering(final Fluid still, final Fluid flowing, final Identifier textureFluidId, final int color) {
final Identifier stillSpriteId = new Identifier(textureFluidId.getNamespace(), "block/" + textureFluidId.getPath());
final Identifier flowingSpriteId = new Identifier(textureFluidId.getNamespace(), "block/" + textureFluidId.getPath() + "_flow");
// If they're not already present, add the sprites to the block atlas
ClientSpriteRegistryCallback.event(SpriteAtlasTexture.BLOCK_ATLAS_TEXTURE).register((atlasTexture, registry) -> {
registry.register(stillSpriteId);
registry.register(flowingSpriteId);
});
final Identifier fluidId = Registry.FLUID.getId(still);
final Identifier listenerId = new Identifier(fluidId.getNamespace(), fluidId.getPath() + "_reload_listener");
final Sprite[] fluidSprites = { null, null };
ResourceManagerHelper.get(ResourceType.CLIENT_RESOURCES).registerReloadListener(new SimpleSynchronousResourceReloadListener() {
/**
* Get the sprites from the block atlas when resources are reloaded
*/
@Override
public void reload(ResourceManager manager) {
final Function<Identifier, Sprite> atlas = MinecraftClient.getInstance().getSpriteAtlas(SpriteAtlasTexture.BLOCK_ATLAS_TEXTURE);
fluidSprites[0] = atlas.apply(stillSpriteId);
fluidSprites[1] = atlas.apply(flowingSpriteId);
}
@Override
public Identifier getFabricId() {
return listenerId;
}
});
// The FluidRenderer gets the sprites and color from a FluidRenderHandler during rendering
final FluidRenderHandler renderHandler = new FluidRenderHandler() {
@Override
public Sprite[] getFluidSprites(BlockRenderView view, BlockPos pos, FluidState state) {
return fluidSprites;
}
@Override
public int getFluidColor(BlockRenderView view, BlockPos pos, FluidState state) {
return color;
}
};
FluidRenderHandlerRegistry.INSTANCE.register(still, renderHandler);
// FluidRenderHandlerRegistry.INSTANCE.register(flowing, renderHandler); // Temp removed because of flowing shenanigans
}
use of net.fabricmc.fabric.api.client.render.fluid.v1.FluidRenderHandler in project fabric by FabricMC.
the class MixinFluidRenderer method tesselate.
@Inject(at = @At("HEAD"), method = "tesselate", cancellable = true)
public void tesselate(ExtendedBlockView view, BlockPos pos, BufferBuilder bufferBuilder, FluidState state, CallbackInfoReturnable<Boolean> info) {
FluidRendererHookContainer ctr = fabric_renderHandler.get();
FluidRenderHandler handler = FluidRenderHandlerRegistryImpl.INSTANCE.getOverride(state.getFluid());
if (handler == null) {
return;
}
/* ActionResult hResult = handler.tesselate(view, pos, bufferBuilder, state);
if (hResult != ActionResult.PASS) {
info.setReturnValue(hResult == ActionResult.SUCCESS);
return;
} */
ctr.view = view;
ctr.pos = pos;
ctr.state = state;
ctr.handler = handler;
}
use of net.fabricmc.fabric.api.client.render.fluid.v1.FluidRenderHandler in project Indium by comp500.
the class MixinFluidRendererSodium method onGetLavaSprites.
// Not strictly necessary, but I feel like a mod should be able to add a fluid that has the lava tag with custom sprites!
@Redirect(method = "render", at = @At(value = "FIELD", target = "Lme/jellysquid/mods/sodium/client/render/pipeline/FluidRenderer;lavaSprites"), remap = false)
private Sprite[] onGetLavaSprites(FluidRenderer fluidRenderer, BlockRenderView world, FluidState fluidState, BlockPos pos, ChunkModelBuffers buffers) {
Fluid fluid = fluidState.getFluid();
FluidRenderHandler handler = FluidRenderHandlerRegistry.INSTANCE.get(fluid);
return handler.getFluidSprites(world, pos, fluidState);
}
use of net.fabricmc.fabric.api.client.render.fluid.v1.FluidRenderHandler in project Indium by comp500.
the class MixinFluidRendererSodium method onGetWaterSprites.
@Redirect(method = "render", at = @At(value = "FIELD", target = "Lme/jellysquid/mods/sodium/client/render/pipeline/FluidRenderer;waterSprites"), remap = false)
private Sprite[] onGetWaterSprites(FluidRenderer fluidRenderer, BlockRenderView world, FluidState fluidState, BlockPos pos, ChunkModelBuffers buffers) {
Fluid fluid = fluidState.getFluid();
FluidRenderHandler handler = FluidRenderHandlerRegistry.INSTANCE.get(fluid);
return handler.getFluidSprites(world, pos, fluidState);
}
use of net.fabricmc.fabric.api.client.render.fluid.v1.FluidRenderHandler in project Indium by comp500.
the class MixinFluidRendererSodium method onCalculateQuadColors.
@Redirect(method = "render", at = @At(value = "INVOKE", target = "Lme/jellysquid/mods/sodium/client/render/pipeline/FluidRenderer;calculateQuadColors"), remap = false)
private void onCalculateQuadColors(FluidRenderer fluidRenderer, ModelQuadView quad, BlockRenderView world, BlockPos pos, LightPipeline lighter, Direction dir, float brightness, boolean notLava, BlockRenderView _world, FluidState fluidState, BlockPos _pos, ChunkModelBuffers buffers) {
// When implementing this you'd probably want to reuse the calculations done earlier, this is just an easier way of implementing the mixin
Fluid fluid = fluidState.getFluid();
boolean isWater = fluid.isIn(FluidTags.WATER);
FluidRenderHandler handler = FluidRenderHandlerRegistry.INSTANCE.get(fluid);
QuadLightData light = this.quadLightData;
lighter.calculate(quad, pos, light, dir, false);
int[] biomeColors = null;
int tint = 0xFFFFFFFF;
if (isWater) {
// This should probably be cleaned up a bit, maybe refactor getColors?
biomeColors = this.biomeColorBlender.getColors(((bs, view1, pos1, tintIndex) -> handler.getFluidColor(view1, pos1, fluidState)), world, world.getBlockState(pos), pos, quad);
} else {
tint = handler.getFluidColor(world, pos, fluidState);
}
for (int i = 0; i < 4; i++) {
this.quadColors[i] = ColorABGR.mul(biomeColors != null ? biomeColors[i] : tint, light.br[i] * brightness);
}
}
Aggregations