User Tools

Site Tools


tutorial:fluids

Differences

This shows you the differences between two versions of the page.

Link to this comparison view

Both sides previous revisionPrevious revision
Next revisionBoth sides next revision
tutorial:fluids [2019/09/24 10:46] – fluid implementation alexiytutorial:fluids [2019/09/24 11:28] – client side operations (rendering) alexiy
Line 290: Line 290:
  
 Now we can assert that the Acid class is complete. Now we can assert that the Acid class is complete.
 +
 +===== Rendering setup =====
 +
 +Time to do client-side things. In your **ClientModInitializer** you need to specify locations of sprites for your fluids and define their rendering. I will reuse water textures and just change the color applied to them.
 +
 +<code java>
 +    @Override
 +    public void onInitializeClient()
 +    {
 +        Identifier stillSpriteLocation=new Identifier("block/water_still");
 +        Identifier dynamicSpriteLocation=new Identifier("block/water_flow");
 +        // here I tell to use only 16x16 area of the water texture
 +        FabricSprite stillAcidSprite = new FabricSprite(stillSpriteLocation,16,16);
 +        // same, but 32
 +        FabricSprite dynamicAcidSprite=new FabricSprite(dynamicSpriteLocation,32,32);
 +        
 +        // adding the sprites to the block texture atlas
 +        ClientSpriteRegistryCallback.event(SpriteAtlasTexture.BLOCK_ATLAS_TEX).register((spriteAtlasTexture, registry) -> {
 +            registry.register(stillAcidSprite);
 +            registry.register(dynamicAcidSprite);
 +        });
 +
 +        // this renderer is responsible for drawing fluids in a world
 +        FluidRenderHandler acidRenderHandler=new FluidRenderHandler()
 +        {
 +            // return the sprites: still sprite goes first into the array, flowing/dynamic goes last
 +            @Override
 +            public Sprite[] getFluidSprites(ExtendedBlockView extendedBlockView, BlockPos blockPos, FluidState fluidState)
 +            {
 +                return new Sprite[]{stillAcidSprite,dynamicAcidSprite};
 +            }
 +
 +            // apply light green color
 +            @Override
 +            public int getFluidColor(ExtendedBlockView view, BlockPos pos, FluidState state)
 +            {
 +                return 0x4cc248;
 +            }
 +        };
 +
 +        // registering the same renderer for both fluid variants is intentional
 +
 +        FluidRenderHandlerRegistry.INSTANCE.register([ModInitializer].stillAcid,acidRenderHandler);
 +        FluidRenderHandlerRegistry.INSTANCE.register([ModInitializer].flowingAcid,acidRenderHandler);
 +</code>
 +
 +Then what's left to do is to create necessary Json files and textures, but you should know how to do that at this point.
tutorial/fluids.txt · Last modified: 2023/05/04 11:31 by solidblock