optimised setupColorAndTint, specifically part where it calculates if block is gray for no reason if it's not going to be tinted anyway.

This commit is contained in:
cola98765
2021-12-26 16:10:22 +01:00
parent b80d1c784d
commit bfbf987599
@@ -173,6 +173,9 @@ public class BlockColorWrapper implements IBlockColorWrapper
int numberOfGreyPixel = 0;
int tempColor;
int colorMultiplier;
boolean lookForTint = false;
if (grassInstance() || leavesInstance() || waterIstance())
lookForTint = true;
// generate the block's color
for (int frameIndex = 0; frameIndex < texture.getFrameCount(); frameIndex++)
@@ -188,12 +191,15 @@ public class BlockColorWrapper implements IBlockColorWrapper
if (ColorUtil.getAlpha(texture.getPixelRGBA(frameIndex, u, v)) == 0)
continue;
// determine if this pixel is gray
int colorMax = Math.max(Math.max(ColorUtil.getBlue(tempColor), ColorUtil.getGreen(tempColor)), ColorUtil.getRed(tempColor));
int colorMin = 4 + Math.min(Math.min(ColorUtil.getBlue(tempColor), ColorUtil.getGreen(tempColor)), ColorUtil.getRed(tempColor));
boolean isGray = colorMax < colorMin;
if (isGray)
numberOfGreyPixel++;
if (lookForTint)
{
// determine if this pixel is gray
int colorMax = Math.max(Math.max(ColorUtil.getBlue(tempColor), ColorUtil.getGreen(tempColor)), ColorUtil.getRed(tempColor));
int colorMin = 4 + Math.min(Math.min(ColorUtil.getBlue(tempColor), ColorUtil.getGreen(tempColor)), ColorUtil.getRed(tempColor));
boolean isGray = colorMax < colorMin;
if (isGray)
numberOfGreyPixel++;
}
// for flowers, weight their non-green color higher
@@ -228,7 +234,7 @@ public class BlockColorWrapper implements IBlockColorWrapper
}
// determine if this block should use the biome color tint
if ((grassInstance() || leavesInstance() || waterIstance()) && (float) numberOfGreyPixel / count > 0.75f)
if (lookForTint && (float) numberOfGreyPixel / count > 0.75f)
this.toTint = true;
// we check which kind of tint we need to apply