Search in sources :

Example 1 with FluidRenderHandler

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
}
Also used : SimpleSynchronousResourceReloadListener(net.fabricmc.fabric.api.resource.SimpleSynchronousResourceReloadListener) Function(java.util.function.Function) Identifier(net.minecraft.util.Identifier) BlockRenderView(net.minecraft.world.BlockRenderView) Sprite(net.minecraft.client.texture.Sprite) BlockPos(net.minecraft.util.math.BlockPos) ResourceManager(net.minecraft.resource.ResourceManager) FluidRenderHandler(net.fabricmc.fabric.api.client.render.fluid.v1.FluidRenderHandler) FluidState(net.minecraft.fluid.FluidState) Environment(net.fabricmc.api.Environment)

Example 2 with FluidRenderHandler

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;
}
Also used : FluidRendererHookContainer(net.fabricmc.fabric.impl.client.render.fluid.FluidRendererHookContainer) FluidRenderHandler(net.fabricmc.fabric.api.client.render.fluid.v1.FluidRenderHandler) Inject(org.spongepowered.asm.mixin.injection.Inject)

Example 3 with FluidRenderHandler

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);
}
Also used : Fluid(net.minecraft.fluid.Fluid) FluidRenderHandler(net.fabricmc.fabric.api.client.render.fluid.v1.FluidRenderHandler) Redirect(org.spongepowered.asm.mixin.injection.Redirect)

Example 4 with FluidRenderHandler

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);
}
Also used : Fluid(net.minecraft.fluid.Fluid) FluidRenderHandler(net.fabricmc.fabric.api.client.render.fluid.v1.FluidRenderHandler) Redirect(org.spongepowered.asm.mixin.injection.Redirect)

Example 5 with FluidRenderHandler

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);
    }
}
Also used : Fluid(net.minecraft.fluid.Fluid) FluidRenderHandler(net.fabricmc.fabric.api.client.render.fluid.v1.FluidRenderHandler) QuadLightData(me.jellysquid.mods.sodium.client.model.light.data.QuadLightData) Redirect(org.spongepowered.asm.mixin.injection.Redirect)

Aggregations

FluidRenderHandler (net.fabricmc.fabric.api.client.render.fluid.v1.FluidRenderHandler)8 Sprite (net.minecraft.client.texture.Sprite)4 FluidState (net.minecraft.fluid.FluidState)4 BlockPos (net.minecraft.util.math.BlockPos)4 Function (java.util.function.Function)3 SimpleSynchronousResourceReloadListener (net.fabricmc.fabric.api.resource.SimpleSynchronousResourceReloadListener)3 Fluid (net.minecraft.fluid.Fluid)3 ResourceManager (net.minecraft.resource.ResourceManager)3 Identifier (net.minecraft.util.Identifier)3 BlockRenderView (net.minecraft.world.BlockRenderView)3 Redirect (org.spongepowered.asm.mixin.injection.Redirect)3 QuadLightData (me.jellysquid.mods.sodium.client.model.light.data.QuadLightData)1 Environment (net.fabricmc.api.Environment)1 FluidRendererHookContainer (net.fabricmc.fabric.impl.client.render.fluid.FluidRendererHookContainer)1 ExtendedBlockView (net.minecraft.world.ExtendedBlockView)1 Inject (org.spongepowered.asm.mixin.injection.Inject)1