Skip to content

Commit

Permalink
Add support for new NeoForge fluid overlay API
Browse files Browse the repository at this point in the history
  • Loading branch information
IMS212 authored and jellysquid3 committed Dec 3, 2024
1 parent 4a125ec commit 63ebaef
Show file tree
Hide file tree
Showing 4 changed files with 27 additions and 8 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -65,7 +65,7 @@ public DefaultFluidRenderer(LightPipelineProvider lighters) {
this.lighters = lighters;
}

private boolean isFluidOccluded(BlockAndTintGetter world, int x, int y, int z, Direction dir, BlockState blockState, Fluid fluid) {
private boolean isFluidOccluded(BlockAndTintGetter world, int x, int y, int z, Direction dir, BlockState blockState, FluidState fluid) {
//Test own block state first, this prevents waterlogged blocks from having hidden internal geometry
// which can result in z-fighting
var pos = this.scratchPos.set(x, y, z);
Expand All @@ -76,7 +76,7 @@ private boolean isFluidOccluded(BlockAndTintGetter world, int x, int y, int z, D
//Test neighboring block state
var adjPos = this.scratchPos.set(x + dir.getStepX(), y + dir.getStepY(), z + dir.getStepZ());
BlockState adjBlockState = world.getBlockState(adjPos);
if (adjBlockState.getFluidState().getType().isSame(fluid)) {
if (PlatformBlockAccess.getInstance().shouldOccludeFluid(dir.getOpposite(), adjBlockState, fluid)) {
return true;
}
return adjBlockState.canOcclude() && dir != Direction.UP && adjBlockState.isFaceSturdy(world, adjPos, dir.getOpposite(), SupportType.FULL);
Expand Down Expand Up @@ -109,13 +109,13 @@ public void render(LevelSlice level, BlockState blockState, FluidState fluidStat

Fluid fluid = fluidState.getType();

boolean sfUp = this.isFluidOccluded(level, posX, posY, posZ, Direction.UP, blockState, fluid);
boolean sfDown = this.isFluidOccluded(level, posX, posY, posZ, Direction.DOWN, blockState, fluid) ||
boolean sfUp = this.isFluidOccluded(level, posX, posY, posZ, Direction.UP, blockState, fluidState);
boolean sfDown = this.isFluidOccluded(level, posX, posY, posZ, Direction.DOWN, blockState, fluidState) ||
!this.isSideExposed(level, posX, posY, posZ, Direction.DOWN, 0.8888889F);
boolean sfNorth = this.isFluidOccluded(level, posX, posY, posZ, Direction.NORTH, blockState, fluid);
boolean sfSouth = this.isFluidOccluded(level, posX, posY, posZ, Direction.SOUTH, blockState, fluid);
boolean sfWest = this.isFluidOccluded(level, posX, posY, posZ, Direction.WEST, blockState, fluid);
boolean sfEast = this.isFluidOccluded(level, posX, posY, posZ, Direction.EAST, blockState, fluid);
boolean sfNorth = this.isFluidOccluded(level, posX, posY, posZ, Direction.NORTH, blockState, fluidState);
boolean sfSouth = this.isFluidOccluded(level, posX, posY, posZ, Direction.SOUTH, blockState, fluidState);
boolean sfWest = this.isFluidOccluded(level, posX, posY, posZ, Direction.WEST, blockState, fluidState);
boolean sfEast = this.isFluidOccluded(level, posX, posY, posZ, Direction.EAST, blockState, fluidState);

if (sfUp && sfDown && sfEast && sfWest && sfNorth && sfSouth) {
return;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -85,4 +85,13 @@ static PlatformBlockAccess getInstance() {
* @return Whether this block entity should activate the outline shader.
*/
boolean shouldBlockEntityGlow(BlockEntity blockEntity, LocalPlayer player);

/**
* Determines if a fluid adjacent to the block on the given side should not be rendered.
*
* @param adjDirection the face of this block that the fluid is adjacent to
* @param fluid the fluid that is touching that face
* @return if this block should cause the fluid's face to not render
*/
boolean shouldOccludeFluid(Direction adjDirection, BlockState adjBlockState, FluidState fluid);
}
Original file line number Diff line number Diff line change
Expand Up @@ -90,4 +90,9 @@ public AmbientOcclusionMode usesAmbientOcclusion(BakedModel model, BlockState st
public boolean shouldBlockEntityGlow(BlockEntity blockEntity, LocalPlayer player) {
return false;
}

@Override
public boolean shouldOccludeFluid(Direction adjDirection, BlockState adjBlockState, FluidState fluid) {
return adjBlockState.getFluidState().getType().isSame(fluid.getType());
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -58,4 +58,9 @@ public AmbientOcclusionMode usesAmbientOcclusion(BakedModel model, BlockState st
public boolean shouldBlockEntityGlow(BlockEntity blockEntity, LocalPlayer player) {
return blockEntity.hasCustomOutlineRendering(player);
}

@Override
public boolean shouldOccludeFluid(Direction adjDirection, BlockState adjBlockState, FluidState fluid) {
return adjBlockState.shouldHideAdjacentFluidFace(adjDirection, fluid);
}
}

0 comments on commit 63ebaef

Please sign in to comment.