Skip to content

Commit

Permalink
Correct behaviour for coloring modded fluids
Browse files Browse the repository at this point in the history
Fixes #11
  • Loading branch information
Asek3 committed Feb 10, 2024
1 parent 809b1d3 commit cbd90a0
Showing 1 changed file with 17 additions and 5 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -40,8 +40,10 @@
import java.util.Objects;

public class FluidRenderer {

private static final float EPSILON = 0.001f;

private static final float EPSILON = 0.001f;

private static final IBlockColor FLUID_COLOR_PROVIDER = (state, world, pos, tintIndex) -> WorldUtil.getFluid(state).getColor();

private final BlockPos.MutableBlockPos scratchPos = new BlockPos.MutableBlockPos();

Expand Down Expand Up @@ -78,7 +80,7 @@ private boolean isFluidOccluded(IBlockAccess world, int x, int y, int z, EnumFac
if (blockState.getMaterial().isOpaque()) {
return fluid == adjFluid || blockState.isSideSolid(world,pos,dir);
// fluidlogged or next to water, occlude sides that are solid or the same liquid
}
}
return fluid == adjFluid;
}

Expand Down Expand Up @@ -310,7 +312,7 @@ public boolean render(IBlockAccess world, IBlockState fluidState, BlockPos pos,
TextureAtlasSprite oSprite = sprites[2];

if (oSprite != null) {
BlockPos adjPos = this.scratchPos.setPos(adjX, adjY, adjZ);
BlockPos adjPos = this.scratchPos.setPos(adjX, adjY, adjZ);
IBlockState adjBlock = world.getBlockState(adjPos);

if (adjBlock.getBlockFaceShape(world, adjPos, dir.getOpposite()) == net.minecraft.block.state.BlockFaceShape.SOLID) {
Expand All @@ -334,7 +336,7 @@ public boolean render(IBlockAccess world, IBlockState fluidState, BlockPos pos,
float br = dir.getAxis() == EnumFacing.Axis.Z ? 0.8F : 0.6F;

ModelQuadFacing facing = ModelQuadFacing.fromDirection(dir);

this.calculateQuadColors(quad, world, pos, lighter, dir, br, hc);
this.flushQuad(buffers, quad, facing, false);

Expand Down Expand Up @@ -363,8 +365,18 @@ private void calculateQuadColors(ModelQuadView quad, IBlockAccess world, BlockPo
if (colorized) {
IBlockState state = world.getBlockState(pos);
IBlockColor colorProvider = ((BlockColorsExtended)this.vanillaBlockColors).getColorProvider(state);
boolean containsColoredQuad = false;
if(colorProvider != null) {
biomeColors = this.biomeColorBlender.getColors(colorProvider, world, state, pos, quad);
for(int color : biomeColors) {
if(color != 0xFFFFFF) {
containsColoredQuad = true;
break;
}
}
}
if(!containsColoredQuad) {
biomeColors = this.biomeColorBlender.getColors(FLUID_COLOR_PROVIDER, world, state, pos, quad);
}
}

Expand Down

0 comments on commit cbd90a0

Please sign in to comment.