diff --git a/src/main/java/de/bixilon/minosoft/config/config/game/GameConfig.kt b/src/main/java/de/bixilon/minosoft/config/config/game/GameConfig.kt
index 62883176b..67a8608da 100644
--- a/src/main/java/de/bixilon/minosoft/config/config/game/GameConfig.kt
+++ b/src/main/java/de/bixilon/minosoft/config/config/game/GameConfig.kt
@@ -15,9 +15,10 @@ package de.bixilon.minosoft.config.config.game
import de.bixilon.minosoft.config.config.game.controls.ControlsGameConfig
import de.bixilon.minosoft.config.config.game.elements.ElementsGameConfig
+import de.bixilon.minosoft.config.config.game.graphics.GraphicsGameConfig
data class GameConfig(
- var animations: AnimationsGameConfig = AnimationsGameConfig(),
+ var graphics: GraphicsGameConfig = GraphicsGameConfig(),
var other: OtherGameConfig = OtherGameConfig(),
var hud: HUDGameConfig = HUDGameConfig(),
var controls: ControlsGameConfig = ControlsGameConfig(),
diff --git a/src/main/java/de/bixilon/minosoft/config/config/game/AnimationsGameConfig.kt b/src/main/java/de/bixilon/minosoft/config/config/game/graphics/AnimationsGameConfig.kt
similarity index 93%
rename from src/main/java/de/bixilon/minosoft/config/config/game/AnimationsGameConfig.kt
rename to src/main/java/de/bixilon/minosoft/config/config/game/graphics/AnimationsGameConfig.kt
index 84e96e9cc..14f5e6080 100644
--- a/src/main/java/de/bixilon/minosoft/config/config/game/AnimationsGameConfig.kt
+++ b/src/main/java/de/bixilon/minosoft/config/config/game/graphics/AnimationsGameConfig.kt
@@ -11,7 +11,7 @@
* This software is not affiliated with Mojang AB, the original developer of Minecraft.
*/
-package de.bixilon.minosoft.config.config.game
+package de.bixilon.minosoft.config.config.game.graphics
data class AnimationsGameConfig(
var textures: Boolean = true,
diff --git a/src/main/java/de/bixilon/minosoft/config/config/game/graphics/GraphicsGameConfig.kt b/src/main/java/de/bixilon/minosoft/config/config/game/graphics/GraphicsGameConfig.kt
new file mode 100644
index 000000000..ff1fa94bb
--- /dev/null
+++ b/src/main/java/de/bixilon/minosoft/config/config/game/graphics/GraphicsGameConfig.kt
@@ -0,0 +1,21 @@
+/*
+ * Minosoft
+ * Copyright (C) 2021 Moritz Zwerger
+ *
+ * This program is free software: you can redistribute it and/or modify it under the terms of the GNU General Public License as published by the Free Software Foundation, either version 3 of the License, or (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License along with this program.If not, see .
+ *
+ * This software is not affiliated with Mojang AB, the original developer of Minecraft.
+ */
+
+package de.bixilon.minosoft.config.config.game.graphics
+
+import com.squareup.moshi.Json
+
+data class GraphicsGameConfig(
+ var animations: AnimationsGameConfig = AnimationsGameConfig(),
+ @Json(name = "biome_blend_radius") var biomeBlendRadius: Int = 3,
+)
diff --git a/src/main/java/de/bixilon/minosoft/data/mappings/blocks/Block.kt b/src/main/java/de/bixilon/minosoft/data/mappings/blocks/Block.kt
index a9f96bfe5..a37486779 100644
--- a/src/main/java/de/bixilon/minosoft/data/mappings/blocks/Block.kt
+++ b/src/main/java/de/bixilon/minosoft/data/mappings/blocks/Block.kt
@@ -55,7 +55,8 @@ data class Block(
hasDynamicShape = data["has_dynamic_shape"]?.asBoolean ?: false,
tintColor = data["tint_color"]?.asInt?.let { TintColorCalculator.getJsonColor(it) },
itemId = data["item"]?.asInt ?: 0,
- tint = data["tint"]?.asString?.let { ResourceLocation(it) })
+ tint = data["tint"]?.asString?.let { ResourceLocation(it) },
+ )
// block states
diff --git a/src/main/java/de/bixilon/minosoft/data/world/World.kt b/src/main/java/de/bixilon/minosoft/data/world/World.kt
index aa2242c1e..6bf4b6d66 100644
--- a/src/main/java/de/bixilon/minosoft/data/world/World.kt
+++ b/src/main/java/de/bixilon/minosoft/data/world/World.kt
@@ -121,4 +121,21 @@ class World : BiomeAccessor {
override fun getBiome(blockPosition: Vec3i): Biome? {
return biomeAccessor.getBiome(blockPosition)
}
+
+ fun getBlocks(start: Vec3i, end: Vec3i): Map {
+ val blocks: MutableMap = mutableMapOf()
+
+ for (z in start.z until end.z) {
+ for (y in start.y until end.y) {
+ for (x in start.x until end.x) {
+ val blockPosition = Vec3i(x, y, z)
+ getBlockState(blockPosition)?.let {
+ blocks[blockPosition] = it
+ }
+ }
+ }
+ }
+
+ return blocks.toMap()
+ }
}
diff --git a/src/main/java/de/bixilon/minosoft/data/world/palette/IndirectPalette.kt b/src/main/java/de/bixilon/minosoft/data/world/palette/IndirectPalette.kt
index 76b376a5b..fcec2edd0 100644
--- a/src/main/java/de/bixilon/minosoft/data/world/palette/IndirectPalette.kt
+++ b/src/main/java/de/bixilon/minosoft/data/world/palette/IndirectPalette.kt
@@ -25,18 +25,18 @@ class IndirectPalette(
private val connection = buffer.connection
private var palette = buffer.readVarIntArray()
- override fun blockById(blockId: Int): BlockState? {
- var realBlockId = blockId
- if (realBlockId < palette.size) {
- realBlockId = palette[realBlockId]
+ override fun blockById(id: Int): BlockState? {
+ var blockId = id
+ if (blockId < palette.size) {
+ blockId = palette[blockId]
}
- val block = connection.mapping.getBlockState(realBlockId)
+ val block = connection.mapping.getBlockState(blockId)
- if (StaticConfiguration.DEBUG_MODE && block == null && realBlockId != ProtocolDefinition.NULL_BLOCK_ID) {
+ if (StaticConfiguration.DEBUG_MODE && block == null && blockId != ProtocolDefinition.NULL_BLOCK_ID) {
val blockName: String = if (connection.version.isFlattened()) {
- realBlockId.toString()
+ blockId.toString()
} else {
- "(${realBlockId shr 4}:${realBlockId and 0x0F}"
+ "(${blockId shr 4}:${blockId and 0x0F}"
}
Log.warn("Server sent unknown block: $blockName")
}
diff --git a/src/main/java/de/bixilon/minosoft/gui/rendering/RenderWindow.kt b/src/main/java/de/bixilon/minosoft/gui/rendering/RenderWindow.kt
index c3db87657..ca73e0788 100644
--- a/src/main/java/de/bixilon/minosoft/gui/rendering/RenderWindow.kt
+++ b/src/main/java/de/bixilon/minosoft/gui/rendering/RenderWindow.kt
@@ -71,7 +71,7 @@ class RenderWindow(
private var mouseCatch = !StaticConfiguration.DEBUG_MODE
private val screenshotTaker = ScreenshotTaker(this)
- val tintColorCalculator = TintColorCalculator()
+ val tintColorCalculator = TintColorCalculator(connection.world)
val font = Font()
val textures = TextureArray(mutableListOf())
diff --git a/src/main/java/de/bixilon/minosoft/gui/rendering/TintColorCalculator.kt b/src/main/java/de/bixilon/minosoft/gui/rendering/TintColorCalculator.kt
index c4472f3d2..3cc8adf66 100644
--- a/src/main/java/de/bixilon/minosoft/gui/rendering/TintColorCalculator.kt
+++ b/src/main/java/de/bixilon/minosoft/gui/rendering/TintColorCalculator.kt
@@ -13,17 +13,19 @@
package de.bixilon.minosoft.gui.rendering
+import de.bixilon.minosoft.Minosoft
import de.bixilon.minosoft.config.StaticConfiguration
import de.bixilon.minosoft.data.assets.MinecraftAssetsManager
import de.bixilon.minosoft.data.mappings.ResourceLocation
import de.bixilon.minosoft.data.mappings.biomes.Biome
import de.bixilon.minosoft.data.mappings.blocks.BlockState
import de.bixilon.minosoft.data.text.RGBColor
+import de.bixilon.minosoft.data.world.World
import de.bixilon.minosoft.gui.rendering.textures.Texture
import glm_.vec3.Vec3i
-class TintColorCalculator {
+class TintColorCalculator(val world: World) {
private lateinit var grassColorMap: Array
private lateinit var foliageColorMap: Array
@@ -32,7 +34,47 @@ class TintColorCalculator {
foliageColorMap = assetsManager.readPixelArrayAsset(Texture.getResourceTextureIdentifier(textureName = "colormap/foliage.png"))
}
- fun getTint(biome: Biome?, blockState: BlockState, blockPosition: Vec3i): RGBColor? {
+ fun getAverageTint(biome: Biome?, blockState: BlockState, blockPosition: Vec3i): RGBColor? {
+ val biomeBlendRadius = Minosoft.getConfig().config.game.graphics.biomeBlendRadius
+ val selfTint = getTint(biome, blockState, blockPosition)
+
+ if (selfTint == null || biomeBlendRadius == 0) {
+ return selfTint
+ }
+
+ val blendStart = Vec3i(blockPosition.x - biomeBlendRadius, blockPosition.y, blockPosition.z - biomeBlendRadius)
+ val blendEnd = Vec3i(blockPosition.x + biomeBlendRadius, blockPosition.y + 1, blockPosition.z + biomeBlendRadius)
+
+
+ var totalRed = 0L
+ var totalGreen = 0L
+ var totalBlue = 0L
+ var count = 0
+
+
+ for (z in blendStart.z until blendEnd.z) {
+ for (y in blendStart.y until blendEnd.y) {
+ for (x in blendStart.x until blendEnd.x) {
+ val blendBlockPosition = Vec3i(x, y, z)
+ getTint(world.getBiome(blendBlockPosition), blockState, blendBlockPosition)?.let {
+ totalRed += it.red
+ totalGreen += it.green
+ totalBlue += it.blue
+
+ count++
+ }
+ }
+ }
+ }
+
+ if ((totalRed == 0L && totalGreen == 0L && totalBlue == 0L) || count == 0) {
+ return null
+ }
+
+ return RGBColor((totalRed / count).toInt(), (totalGreen / count).toInt(), (totalBlue / count).toInt())
+ }
+
+ private fun getTint(biome: Biome?, blockState: BlockState, blockPosition: Vec3i): RGBColor? {
return when {
biome == null -> null
StaticConfiguration.BIOME_DEBUG_MODE -> RGBColor(biome.hashCode())
@@ -42,11 +84,10 @@ class TintColorCalculator {
}
}
- fun calculateTint(tint: ResourceLocation, biome: Biome, blockPosition: Vec3i): RGBColor? {
+ private fun calculateTint(tint: ResourceLocation, biome: Biome, blockPosition: Vec3i): RGBColor? {
return when (tint) {
- ResourceLocation("water_tint") -> biome.waterColor
- ResourceLocation("grass_tint"), ResourceLocation("sugar_cane_tint"), ResourceLocation("shearing_double_plant_tint") -> {
- // ToDo: color overrider in < 1.16
+ WATER_TINT_RESOURCE_LOCATION -> biome.waterColor
+ GRASS_TINT_RESOURCE_LOCATION, SUGAR_CANE_TINT_RESOURCE_LOCATION, SHEARING_DOUBLE_PLANT_TINT_RESOURCE_LOCATION -> {
biome.grassColorOverride?.let { return it }
val colorMapPixelIndex = biome.downfallColorMapCoordinate shl 8 or biome.temperatureColorMapCoordinate
@@ -60,18 +101,25 @@ class TintColorCalculator {
}
biome.grassColorModifier.modifier.invoke(color)
}
- ResourceLocation("foliage_tint") -> {
+ FOLIAGE_TINT_RESOURCE_LOCATION -> {
biome.foliageColorOverride?.let { return it }
- // ToDo: color overrider in < 1.16
foliageColorMap[biome.downfallColorMapCoordinate shl 8 or biome.getClampedTemperature(blockPosition.y)]
}
- ResourceLocation("lily_pad_tint") -> RenderConstants.LILY_PAD_BLOCK_COLOR
+ LILY_PAD_TINT_RESOURCE_LOCATION -> RenderConstants.LILY_PAD_BLOCK_COLOR
else -> null
}
}
companion object {
+ private val WATER_TINT_RESOURCE_LOCATION = ResourceLocation("water_tint")
+ private val GRASS_TINT_RESOURCE_LOCATION = ResourceLocation("grass_tint")
+ private val SUGAR_CANE_TINT_RESOURCE_LOCATION = ResourceLocation("sugar_cane_tint")
+ private val SHEARING_DOUBLE_PLANT_TINT_RESOURCE_LOCATION = ResourceLocation("shearing_double_plant_tint")
+ private val FOLIAGE_TINT_RESOURCE_LOCATION = ResourceLocation("foliage_tint")
+ private val LILY_PAD_TINT_RESOURCE_LOCATION = ResourceLocation("lily_pad_tint")
+
+
fun getJsonColor(color: Int): RGBColor? {
if (color == 0) {
return null
diff --git a/src/main/java/de/bixilon/minosoft/gui/rendering/chunk/WorldRenderer.kt b/src/main/java/de/bixilon/minosoft/gui/rendering/chunk/WorldRenderer.kt
index bb62598a1..34ecd0c28 100644
--- a/src/main/java/de/bixilon/minosoft/gui/rendering/chunk/WorldRenderer.kt
+++ b/src/main/java/de/bixilon/minosoft/gui/rendering/chunk/WorldRenderer.kt
@@ -78,11 +78,11 @@ class WorldRenderer(
val biome = world.getBiome(blockPosition)
- val tintColor = renderWindow.tintColorCalculator.getTint(biome, blockState, blockPosition)
+ val tintColor = renderWindow.tintColorCalculator.getAverageTint(biome, blockState, blockPosition)
if (blockState.properties[BlockProperties.WATERLOGGED] == true) {
- val waterTintColor = renderWindow.tintColorCalculator.getTint(biome, WATER_BLOCK_STATE, blockPosition)
+ val waterTintColor = renderWindow.tintColorCalculator.getAverageTint(biome, WATER_BLOCK_STATE, blockPosition)
BlockState.SPECIAL_RENDERERS["water"]?.render(blockState, world.worldLightAccessor, waterTintColor, blockPosition, meshCollection, neighborBlocks, world)
}
diff --git a/src/main/java/de/bixilon/minosoft/gui/rendering/textures/TextureArray.kt b/src/main/java/de/bixilon/minosoft/gui/rendering/textures/TextureArray.kt
index a9da8f92b..026fcd949 100644
--- a/src/main/java/de/bixilon/minosoft/gui/rendering/textures/TextureArray.kt
+++ b/src/main/java/de/bixilon/minosoft/gui/rendering/textures/TextureArray.kt
@@ -178,7 +178,7 @@ class TextureArray(val allTextures: MutableList) {
if (!initialized) {
return
}
- if (!Minosoft.getConfig().config.game.animations.textures) {
+ if (!Minosoft.getConfig().config.game.graphics.animations.textures) {
return
}