|
32 | 32 | import net.minecraft.tags.FluidTags;
|
33 | 33 | import net.minecraft.util.Mth;
|
34 | 34 | import net.minecraft.world.level.BlockAndTintGetter;
|
| 35 | +import net.minecraft.world.level.block.Block; |
35 | 36 | import net.minecraft.world.level.block.SupportType;
|
36 | 37 | import net.minecraft.world.level.block.state.BlockState;
|
37 | 38 | import net.minecraft.world.level.material.Fluid;
|
@@ -75,14 +76,32 @@ public FluidRenderer(ColorProviderRegistry colorProviderRegistry, LightPipelineP
|
75 | 76 | }
|
76 | 77 |
|
77 | 78 | private boolean isFluidOccluded(BlockAndTintGetter world, int x, int y, int z, Direction dir, Fluid fluid) {
|
| 79 | + // Check if the fluid adjacent to us in the given direction is the same |
| 80 | + if (world.getFluidState(this.scratchPos.set(x + dir.getStepX(), y + dir.getStepY(), z + dir.getStepZ())).getType().isSame(fluid)) { |
| 81 | + return true; |
| 82 | + } |
| 83 | + |
| 84 | + // Stricter than vanilla: check whether the containing block can occlude, has a sturdy face on the given side, |
| 85 | + // and has a solid occlusion shape. If so, assume the fluid inside is not visible on that side. |
| 86 | + // This avoids rendering the top face of water inside an upper waterlogged slab, for instance. |
78 | 87 | BlockPos pos = this.scratchPos.set(x, y, z);
|
79 | 88 | BlockState blockState = world.getBlockState(pos);
|
80 |
| - BlockPos adjPos = this.scratchPos.set(x + dir.getStepX(), y + dir.getStepY(), z + dir.getStepZ()); |
81 | 89 |
|
82 |
| - if (blockState.canOcclude()) { |
83 |
| - return world.getFluidState(adjPos).getType().isSame(fluid) || blockState.isFaceSturdy(world, pos, dir, SupportType.FULL); |
| 90 | + if (!blockState.canOcclude() || !blockState.isFaceSturdy(world, pos, dir, SupportType.FULL)) { |
| 91 | + return false; |
| 92 | + } |
| 93 | + |
| 94 | + VoxelShape sideShape = blockState.getFaceOcclusionShape(world, pos, dir); |
| 95 | + if (sideShape == Shapes.block()) { |
| 96 | + // The face fills the 1x1 area, so the fluid is occluded |
| 97 | + return true; |
| 98 | + } else if (sideShape == Shapes.empty()) { |
| 99 | + // The face does not exist, so the fluid is not occluded |
| 100 | + return false; |
| 101 | + } else { |
| 102 | + // Check if the face fills the 1x1 area |
| 103 | + return Block.isShapeFullBlock(sideShape); |
84 | 104 | }
|
85 |
| - return world.getFluidState(adjPos).getType().isSame(fluid); |
86 | 105 | }
|
87 | 106 |
|
88 | 107 | private boolean isSideExposed(BlockAndTintGetter world, int x, int y, int z, Direction dir, float height) {
|
|
0 commit comments