1
1
package net .vulkanmod .render .chunk .build ;
2
2
3
+ import net .fabricmc .fabric .api .client .render .fluid .v1 .FluidRenderHandler ;
4
+ import net .fabricmc .fabric .api .client .render .fluid .v1 .FluidRenderHandlerRegistry ;
3
5
import net .minecraft .client .Minecraft ;
4
- import net .minecraft .client .renderer .BiomeColors ;
5
6
import net .minecraft .client .renderer .texture .TextureAtlasSprite ;
6
- import net .minecraft .client .resources .model .ModelBakery ;
7
7
import net .minecraft .core .BlockPos ;
8
8
import net .minecraft .core .Direction ;
9
9
import net .minecraft .tags .FluidTags ;
10
10
import net .minecraft .util .Mth ;
11
11
import net .minecraft .world .level .BlockAndTintGetter ;
12
12
import net .minecraft .world .level .BlockGetter ;
13
- import net .minecraft .world .level .block .Block ;
14
- import net .minecraft .world .level .block .Blocks ;
15
- import net .minecraft .world .level .block .HalfTransparentBlock ;
16
- import net .minecraft .world .level .block .LeavesBlock ;
17
13
import net .minecraft .world .level .block .state .BlockState ;
18
14
import net .minecraft .world .level .material .Fluid ;
19
15
import net .minecraft .world .level .material .FluidState ;
16
+ import net .minecraft .world .level .material .Fluids ;
20
17
import net .minecraft .world .phys .Vec3 ;
21
18
import net .minecraft .world .phys .shapes .Shapes ;
22
19
import net .minecraft .world .phys .shapes .VoxelShape ;
34
31
35
32
public class LiquidRenderer {
36
33
private static final float MAX_FLUID_HEIGHT = 0.8888889F ;
37
- private final TextureAtlasSprite [] lavaIcons = new TextureAtlasSprite [2 ];
38
- private final TextureAtlasSprite [] waterIcons = new TextureAtlasSprite [2 ];
39
- private TextureAtlasSprite waterOverlay ;
40
34
41
35
private final BlockPos .MutableBlockPos mBlockPos = new BlockPos .MutableBlockPos ();
42
36
@@ -54,14 +48,6 @@ public void renderLiquid(BlockState blockState, FluidState fluidState, BlockPos
54
48
tessellate (blockState , fluidState , blockPos , vertexConsumer );
55
49
}
56
50
57
- public void setupSprites () {
58
- this .lavaIcons [0 ] = Minecraft .getInstance ().getModelManager ().getBlockModelShaper ().getBlockModel (Blocks .LAVA .defaultBlockState ()).getParticleIcon ();
59
- this .lavaIcons [1 ] = ModelBakery .LAVA_FLOW .sprite ();
60
- this .waterIcons [0 ] = Minecraft .getInstance ().getModelManager ().getBlockModelShaper ().getBlockModel (Blocks .WATER .defaultBlockState ()).getParticleIcon ();
61
- this .waterIcons [1 ] = ModelBakery .WATER_FLOW .sprite ();
62
- this .waterOverlay = ModelBakery .WATER_OVERLAY .sprite ();
63
- }
64
-
65
51
private boolean isFaceOccludedByState (BlockGetter blockGetter , float h , Direction direction , BlockPos blockPos , BlockState blockState ) {
66
52
mBlockPos .set (blockPos ).offset (Direction .DOWN .getNormal ());
67
53
@@ -102,9 +88,11 @@ public BlockState getAdjBlockState(BlockAndTintGetter blockAndTintGetter, int x,
102
88
public void tessellate (BlockState blockState , FluidState fluidState , BlockPos blockPos , TerrainBufferBuilder vertexConsumer ) {
103
89
BlockAndTintGetter region = this .resources .region ;
104
90
105
- boolean bl = fluidState .is (FluidTags .LAVA );
106
- TextureAtlasSprite [] sprites = bl ? this .lavaIcons : this .waterIcons ;
107
- int color = bl ? 16777215 : BiomeColors .getAverageWaterColor (region , blockPos );
91
+ final FluidRenderHandler handler = getFluidRenderHandler (fluidState );
92
+ int color = handler .getFluidColor (region , blockPos , fluidState );
93
+
94
+ TextureAtlasSprite [] sprites = handler .getFluidSprites (region , blockPos , fluidState );
95
+
108
96
float r = ColorUtil .ARGB .unpackR (color );
109
97
float g = ColorUtil .ARGB .unpackG (color );
110
98
float b = ColorUtil .ARGB .unpackB (color );
@@ -333,20 +321,21 @@ public void tessellate(BlockState blockState, FluidState fluidState, BlockPos bl
333
321
if (isFaceOccludedByState (region , Math .max (h1 , h2 ), direction , blockPos , adjState ))
334
322
continue ;
335
323
336
- BlockPos blockPos2 = blockPos .relative (direction );
337
- TextureAtlasSprite sprite2 = sprites [1 ];
338
- if (!bl ) {
339
- Block block = region .getBlockState (blockPos2 ).getBlock ();
340
- if (block instanceof HalfTransparentBlock || block instanceof LeavesBlock ) {
341
- sprite2 = this .waterOverlay ;
324
+ TextureAtlasSprite sprite = sprites [1 ];
325
+ boolean isOverlay = false ;
326
+
327
+ if (sprites .length > 2 ) {
328
+ if (FluidRenderHandlerRegistry .INSTANCE .isBlockTransparent (adjState .getBlock ())) {
329
+ sprite = sprites [2 ];
330
+ isOverlay = true ;
342
331
}
343
332
}
344
333
345
- float u0 = sprite2 .getU (0.0F );
346
- float u1 = sprite2 .getU (0.5F );
347
- float v0 = sprite2 .getV ((1.0F - h1 ) * 0.5F );
348
- float v1 = sprite2 .getV ((1.0F - h2 ) * 0.5F );
349
- float v2 = sprite2 .getV (0.5F );
334
+ float u0 = sprite .getU (0.0F );
335
+ float u1 = sprite .getU (0.5F );
336
+ float v0 = sprite .getV ((1.0F - h1 ) * 0.5F );
337
+ float v1 = sprite .getV ((1.0F - h2 ) * 0.5F );
338
+ float v2 = sprite .getV (0.5F );
350
339
351
340
float brightness = region .getShade (direction , true );
352
341
@@ -360,13 +349,24 @@ public void tessellate(BlockState blockState, FluidState fluidState, BlockPos bl
360
349
361
350
putQuad (modelQuad , vertexConsumer , x0 , y0 , z0 , false );
362
351
363
- if (sprite2 != this . waterOverlay ) {
352
+ if (! isOverlay ) {
364
353
putQuad (modelQuad , vertexConsumer , x0 , y0 , z0 , true );
365
354
}
366
355
367
356
}
368
357
}
369
358
359
+ private static FluidRenderHandler getFluidRenderHandler (FluidState fluidState ) {
360
+ FluidRenderHandler handler = FluidRenderHandlerRegistry .INSTANCE .get (fluidState .getType ());
361
+
362
+ // Fallback to water in case no handler was found
363
+ if (handler == null ) {
364
+ handler = FluidRenderHandlerRegistry .INSTANCE .get (Fluids .WATER );
365
+ }
366
+
367
+ return handler ;
368
+ }
369
+
370
370
private float calculateAverageHeight (BlockAndTintGetter blockAndTintGetter , Fluid fluid , float f , float g , float h , BlockPos blockPos ) {
371
371
if (!(h >= 1.0F ) && !(g >= 1.0F )) {
372
372
float [] fs = new float [2 ];
0 commit comments