From 59e4d0c60213739451dcbeddfae69b97521ef35f Mon Sep 17 00:00:00 2001 From: octarine-noise Date: Sun, 4 Dec 2016 20:12:18 +0100 Subject: [PATCH] fix saturation threshold not being respected for grass textures --- .../betterfoliage/client/texture/GrassRegistry.kt | 11 ++++++++++- src/main/kotlin/mods/octarinecore/Utils.kt | 3 +++ .../kotlin/mods/octarinecore/client/resource/Utils.kt | 2 +- 3 files changed, 14 insertions(+), 2 deletions(-) diff --git a/src/main/kotlin/mods/betterfoliage/client/texture/GrassRegistry.kt b/src/main/kotlin/mods/betterfoliage/client/texture/GrassRegistry.kt index bdd52f4..f716a57 100644 --- a/src/main/kotlin/mods/betterfoliage/client/texture/GrassRegistry.kt +++ b/src/main/kotlin/mods/betterfoliage/client/texture/GrassRegistry.kt @@ -22,6 +22,7 @@ import net.minecraft.world.IBlockAccess import net.minecraftforge.common.MinecraftForge import net.minecraftforge.fml.relauncher.Side import net.minecraftforge.fml.relauncher.SideOnly +import org.apache.logging.log4j.Level const val defaultGrassColor = 0 @@ -92,8 +93,16 @@ object StandardGrassSupport : } fun registerGrass(texture: TextureAtlasSprite, atlas: TextureMap) { + logger.log(Level.DEBUG, "$logName: texture ${texture.iconName}") val hsb = HSB.fromColor(texture.averageColor ?: defaultGrassColor) - val overrideColor = if (hsb.saturation > Config.shortGrass.saturationThreshold) hsb.copy(brightness = 0.8f).asColor else null + val overrideColor = if (hsb.saturation >= Config.shortGrass.saturationThreshold) { + logger.log(Level.DEBUG, "$logName: saturation ${hsb.saturation} >= ${Config.shortGrass.saturationThreshold}, using texture color") + hsb.copy(brightness = 0.9f).asColor + } else { + logger.log(Level.DEBUG, "$logName: saturation ${hsb.saturation} < ${Config.shortGrass.saturationThreshold}, using block color") + null + } + textureToValue[texture] = GrassInfo(texture, overrideColor) } } \ No newline at end of file diff --git a/src/main/kotlin/mods/octarinecore/Utils.kt b/src/main/kotlin/mods/octarinecore/Utils.kt index 5365bf2..dfef9a8 100644 --- a/src/main/kotlin/mods/octarinecore/Utils.kt +++ b/src/main/kotlin/mods/octarinecore/Utils.kt @@ -8,7 +8,10 @@ import java.lang.Math.* const val PI2 = 2.0 * PI +/** Strip the given prefix off the start of the string, if present */ inline fun String.stripStart(str: String) = if (startsWith(str)) substring(str.length) else this + +/** Strip the given prefix off the start of the resource path, if present */ inline fun ResourceLocation.stripStart(str: String) = ResourceLocation(resourceDomain, resourcePath.stripStart(str)) /** Mutating version of _map_. Replace each element of the list with the result of the given transformation. */ diff --git a/src/main/kotlin/mods/octarinecore/client/resource/Utils.kt b/src/main/kotlin/mods/octarinecore/client/resource/Utils.kt index 1a7b6ca..56a9fac 100644 --- a/src/main/kotlin/mods/octarinecore/client/resource/Utils.kt +++ b/src/main/kotlin/mods/octarinecore/client/resource/Utils.kt @@ -63,7 +63,7 @@ val BufferedImage.asStream: InputStream get() = * and the result transformed back to the RGB color space. */ val TextureAtlasSprite.averageColor: Int? get() { - val locationNoDirs = ResourceLocation(iconName) + val locationNoDirs = ResourceLocation(iconName).stripStart("blocks/") val locationWithDirs = ResourceLocation(locationNoDirs.resourceDomain, "textures/blocks/%s.png".format(locationNoDirs.resourcePath)) val image = resourceManager[locationWithDirs]?.loadImage() ?: return null