mirror of
https://gitlab.bixilon.de/bixilon/minosoft.git
synced 2025-09-15 02:15:34 -04:00
rendering: tint: change grass color according to the height
This commit is contained in:
parent
e215afb42b
commit
ce4acbe725
@ -20,6 +20,7 @@ import de.bixilon.minosoft.data.mappings.versions.VersionMapping
|
||||
import de.bixilon.minosoft.data.text.RGBColor
|
||||
import de.bixilon.minosoft.gui.rendering.RenderConstants
|
||||
import de.bixilon.minosoft.gui.rendering.TintColorCalculator
|
||||
import de.bixilon.minosoft.protocol.protocol.ProtocolDefinition
|
||||
import de.bixilon.minosoft.util.MMath
|
||||
|
||||
data class Biome(
|
||||
@ -39,13 +40,21 @@ data class Biome(
|
||||
val grassColorModifier: GrassColorModifiers = GrassColorModifiers.NONE,
|
||||
) : RegistryItem {
|
||||
|
||||
val temperatureColorMapCoordinate = ((1.0 - MMath.clamp(temperature, 0.0f, 1.0f)) * RenderConstants.COLORMAP_SIZE).toInt()
|
||||
val downfallColorMapCoordinate = ((1.0 - (MMath.clamp(downfall, 0.0f, 1.0f) * MMath.clamp(temperature, 0.0f, 1.0f))) * RenderConstants.COLORMAP_SIZE).toInt()
|
||||
val temperatureColorMapCoordinate = getColorMapCoordinate(temperature)
|
||||
val downfallColorMapCoordinate = getColorMapCoordinate(downfall * temperature)
|
||||
|
||||
override fun toString(): String {
|
||||
return resourceLocation.toString()
|
||||
}
|
||||
|
||||
private fun getColorMapCoordinate(value: Float): Int {
|
||||
return ((1.0 - MMath.clamp(value, 0.0f, 1.0f)) * RenderConstants.COLORMAP_SIZE).toInt()
|
||||
}
|
||||
|
||||
fun getClampedTemperature(height: Int): Int {
|
||||
return getColorMapCoordinate(MMath.clamp(temperature + (MMath.clamp(height - ProtocolDefinition.SEA_LEVEL_HEIGHT, 1, Int.MAX_VALUE) * ProtocolDefinition.HEIGHT_SEA_LEVEL_MODIFIER), 0f, 1f))
|
||||
}
|
||||
|
||||
companion object : ResourceLocationDeserializer<Biome> {
|
||||
override fun deserialize(mappings: VersionMapping, resourceLocation: ResourceLocation, data: JsonObject): Biome {
|
||||
return Biome(
|
||||
@ -77,15 +86,11 @@ data class Biome(
|
||||
}
|
||||
|
||||
enum class GrassColorModifiers(val modifier: (color: RGBColor) -> RGBColor) {
|
||||
NONE({ color: RGBColor ->
|
||||
color
|
||||
}),
|
||||
DARK_FORREST({ color: RGBColor ->
|
||||
RGBColor(color.color + 2634762 shl 8)
|
||||
}),
|
||||
SWAMP({ color: RGBColor ->
|
||||
NONE({ color: RGBColor -> color }),
|
||||
DARK_FORREST({ color: RGBColor -> RGBColor(color.color + 2634762 shl 8) }),
|
||||
SWAMP({
|
||||
// ToDo: Minecraft uses PerlinSimplexNoise here
|
||||
color
|
||||
RGBColor("#6A7039")
|
||||
}),
|
||||
|
||||
}
|
||||
|
@ -17,6 +17,7 @@ import de.bixilon.minosoft.data.assets.AssetsManager
|
||||
import de.bixilon.minosoft.data.mappings.ResourceLocation
|
||||
import de.bixilon.minosoft.data.mappings.biomes.Biome
|
||||
import de.bixilon.minosoft.data.text.RGBColor
|
||||
import de.bixilon.minosoft.data.world.BlockPosition
|
||||
|
||||
class TintColorCalculator {
|
||||
private lateinit var grassColorMap: Array<RGBColor>
|
||||
@ -27,7 +28,7 @@ class TintColorCalculator {
|
||||
foliageColorMap = assetsManager.readPixelArray("minecraft/textures/colormap/foliage.png")
|
||||
}
|
||||
|
||||
fun calculateTint(tint: ResourceLocation, biome: Biome): RGBColor? {
|
||||
fun calculateTint(tint: ResourceLocation, biome: Biome, position: BlockPosition): RGBColor? {
|
||||
return when (tint) {
|
||||
ResourceLocation("water_tint") -> biome.waterColor
|
||||
ResourceLocation("grass_tint"), ResourceLocation("sugar_cane_tint"), ResourceLocation("shearing_double_plant_tint") -> {
|
||||
@ -43,7 +44,7 @@ class TintColorCalculator {
|
||||
biome.grassColorModifier.modifier.invoke(color)
|
||||
}
|
||||
ResourceLocation("foliage_tint") -> {
|
||||
foliageColorMap[biome.downfallColorMapCoordinate shl 8 or biome.temperatureColorMapCoordinate]
|
||||
foliageColorMap[biome.downfallColorMapCoordinate shl 8 or biome.getClampedTemperature(position.y)] // ToDo: hardcoded color values
|
||||
}
|
||||
ResourceLocation("lily_pad_tint") -> RenderConstants.LILY_PAD_BLOCK_COLOR
|
||||
else -> null
|
||||
|
@ -101,7 +101,7 @@ class ChunkRenderer(private val connection: Connection, private val world: World
|
||||
biome.foliageColor?.let { tintColor = it }
|
||||
|
||||
blockInfo.block.owner.tint?.let { tint ->
|
||||
tintColor = renderWindow.tintColorCalculator.calculateTint(tint, biome)
|
||||
tintColor = renderWindow.tintColorCalculator.calculateTint(tint, biome, blockPosition)
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -88,6 +88,10 @@ public final class ProtocolDefinition {
|
||||
public static final int TICKS_PER_SECOND = 20;
|
||||
public static final int TICK_TIME = 1000 / TICKS_PER_SECOND;
|
||||
|
||||
public static final int SEA_LEVEL_HEIGHT = 62;
|
||||
|
||||
public static final float HEIGHT_SEA_LEVEL_MODIFIER = 0.00166667f;
|
||||
|
||||
|
||||
public static final ResourceLocation DEFAULT_DIMENSION = new ResourceLocation("overworld");
|
||||
public static final ResourceLocation NETHER_DIMENSION = new ResourceLocation("nether");
|
||||
|
Loading…
x
Reference in New Issue
Block a user