Search in sources :

Example 6 with FluidRenderHandler

use of net.fabricmc.fabric.api.client.render.fluid.v1.FluidRenderHandler in project Paradise-Lost by devs-immortal.

the class FluidRenderSetup method setupFluidRendering.

public 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() + "_still");
    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() {

        @Override
        public Identifier getFabricId() {
            return listenerId;
        }

        /**
         * Get the sprites from the block atlas when resources are reloaded
         */
        @Override
        public void apply(ResourceManager resourceManager) {
            final Function<Identifier, Sprite> atlas = MinecraftClient.getInstance().getSpriteAtlas(SpriteAtlasTexture.BLOCK_ATLAS_TEXTURE);
            fluidSprites[0] = atlas.apply(stillSpriteId);
            fluidSprites[1] = atlas.apply(flowingSpriteId);
        }
    });
    // 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);
}
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)

Example 7 with FluidRenderHandler

use of net.fabricmc.fabric.api.client.render.fluid.v1.FluidRenderHandler in project fabric by FabricMC.

the class FluidRenderHandlerRegistryImpl method onFluidRendererReload.

public void onFluidRendererReload(Sprite[] waterSprites, Sprite[] lavaSprites) {
    FluidRenderHandler waterHandler = new FluidRenderHandler() {

        @Override
        public Sprite[] getFluidSprites(ExtendedBlockView view, BlockPos pos, FluidState state) {
            return waterSprites;
        }

        @Override
        public int getFluidColor(ExtendedBlockView view, BlockPos pos, FluidState state) {
            if (view != null && pos != null) {
                return BiomeColors.getWaterColor(view, pos);
            } else {
                return Biomes.DEFAULT.getWaterColor();
            }
        }
    };
    // noinspection Convert2Lambda
    FluidRenderHandler lavaHandler = new FluidRenderHandler() {

        @Override
        public Sprite[] getFluidSprites(ExtendedBlockView view, BlockPos pos, FluidState state) {
            return lavaSprites;
        }
    };
    register(Fluids.WATER, waterHandler);
    register(Fluids.FLOWING_WATER, waterHandler);
    register(Fluids.LAVA, lavaHandler);
    register(Fluids.FLOWING_LAVA, lavaHandler);
    handlers.putAll(modHandlers);
}
Also used : Sprite(net.minecraft.client.texture.Sprite) BlockPos(net.minecraft.util.math.BlockPos) FluidRenderHandler(net.fabricmc.fabric.api.client.render.fluid.v1.FluidRenderHandler) ExtendedBlockView(net.minecraft.world.ExtendedBlockView) FluidState(net.minecraft.fluid.FluidState)

Example 8 with FluidRenderHandler

use of net.fabricmc.fabric.api.client.render.fluid.v1.FluidRenderHandler in project Paradise-Lost by devs-immortal.

the class FluidRenderSetup method setupDenseAercloudRenderingBecauseItJustNeedsToBeASpecialSnowflakeWithOnlyAStillState.

public static void setupDenseAercloudRenderingBecauseItJustNeedsToBeASpecialSnowflakeWithOnlyAStillState(final Fluid still, final Identifier textureFluidId) {
    final Identifier stillSpriteId = new Identifier(textureFluidId.getNamespace(), "block/" + textureFluidId.getPath() + "_still");
    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() {

        @Override
        public Identifier getFabricId() {
            return listenerId;
        }

        /**
         * Get the sprites from the block atlas when resources are reloaded
         */
        @Override
        public void apply(ResourceManager resourceManager) {
            final Function<Identifier, Sprite> atlas = MinecraftClient.getInstance().getSpriteAtlas(SpriteAtlasTexture.BLOCK_ATLAS_TEXTURE);
            fluidSprites[0] = atlas.apply(stillSpriteId);
            fluidSprites[1] = atlas.apply(flowingSpriteId);
        }
    });
    // 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 0xFFFFFF;
        }
    };
    FluidRenderHandlerRegistry.INSTANCE.register(still, renderHandler);
}
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)

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