mirror of
https://gitlab.bixilon.de/bixilon/minosoft.git
synced 2025-09-15 10:25:06 -04:00
rendering: tinting: color all static colored blocks
This commit is contained in:
parent
a81db59e45
commit
4c9d61c197
@ -18,12 +18,14 @@ import de.bixilon.minosoft.data.mappings.Item
|
|||||||
import de.bixilon.minosoft.data.mappings.ModIdentifier
|
import de.bixilon.minosoft.data.mappings.ModIdentifier
|
||||||
import de.bixilon.minosoft.data.mappings.RegistryItem
|
import de.bixilon.minosoft.data.mappings.RegistryItem
|
||||||
import de.bixilon.minosoft.data.mappings.versions.VersionMapping
|
import de.bixilon.minosoft.data.mappings.versions.VersionMapping
|
||||||
|
import de.bixilon.minosoft.data.text.RGBColor
|
||||||
|
|
||||||
data class Block(
|
data class Block(
|
||||||
val identifier: ModIdentifier,
|
val identifier: ModIdentifier,
|
||||||
val explosionResistance: Float = 0.0f,
|
val explosionResistance: Float = 0.0f,
|
||||||
val hasCollision: Boolean = false,
|
val hasCollision: Boolean = false,
|
||||||
val hasDynamicShape: Boolean = false,
|
val hasDynamicShape: Boolean = false,
|
||||||
|
val tintColor: RGBColor? = null,
|
||||||
private val itemId: Int = 0,
|
private val itemId: Int = 0,
|
||||||
) : RegistryItem {
|
) : RegistryItem {
|
||||||
lateinit var item: Item
|
lateinit var item: Item
|
||||||
@ -40,6 +42,7 @@ data class Block(
|
|||||||
explosionResistance = data["explosion_resistance"]?.asFloat ?: 0.0f,
|
explosionResistance = data["explosion_resistance"]?.asFloat ?: 0.0f,
|
||||||
hasCollision = data["has_collision"]?.asBoolean ?: false,
|
hasCollision = data["has_collision"]?.asBoolean ?: false,
|
||||||
hasDynamicShape = data["has_dynamic_shape"]?.asBoolean ?: false,
|
hasDynamicShape = data["has_dynamic_shape"]?.asBoolean ?: false,
|
||||||
|
tintColor = data["tint_color"]?.asInt?.let { RGBColor.noAlpha(it) },
|
||||||
itemId = data["item"]?.asInt ?: 0,
|
itemId = data["item"]?.asInt ?: 0,
|
||||||
)
|
)
|
||||||
|
|
||||||
|
@ -18,6 +18,7 @@ import com.google.gson.JsonObject
|
|||||||
import com.google.gson.JsonPrimitive
|
import com.google.gson.JsonPrimitive
|
||||||
import de.bixilon.minosoft.Minosoft
|
import de.bixilon.minosoft.Minosoft
|
||||||
import de.bixilon.minosoft.data.mappings.ModIdentifier
|
import de.bixilon.minosoft.data.mappings.ModIdentifier
|
||||||
|
import de.bixilon.minosoft.data.text.RGBColor
|
||||||
import de.bixilon.minosoft.data.world.BlockPosition
|
import de.bixilon.minosoft.data.world.BlockPosition
|
||||||
import de.bixilon.minosoft.gui.rendering.chunk.models.loading.BlockModel
|
import de.bixilon.minosoft.gui.rendering.chunk.models.loading.BlockModel
|
||||||
import de.bixilon.minosoft.gui.rendering.chunk.models.renderable.BlockRenderer
|
import de.bixilon.minosoft.gui.rendering.chunk.models.renderable.BlockRenderer
|
||||||
@ -29,6 +30,7 @@ data class BlockState(
|
|||||||
val properties: Set<BlockProperties> = setOf(),
|
val properties: Set<BlockProperties> = setOf(),
|
||||||
val rotation: BlockRotations = BlockRotations.NONE,
|
val rotation: BlockRotations = BlockRotations.NONE,
|
||||||
val renders: Set<BlockRenderer> = setOf(),
|
val renders: Set<BlockRenderer> = setOf(),
|
||||||
|
val tintColor: RGBColor? = null,
|
||||||
) {
|
) {
|
||||||
|
|
||||||
override fun hashCode(): Int {
|
override fun hashCode(): Int {
|
||||||
@ -165,12 +167,15 @@ data class BlockState(
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
val tintColor: RGBColor? = data["tint_color"]?.asInt?.let { RGBColor.noAlpha(it) } ?: owner.tintColor
|
||||||
|
|
||||||
|
|
||||||
return BlockState(
|
return BlockState(
|
||||||
owner = owner,
|
owner = owner,
|
||||||
properties = properties.toSet(),
|
properties = properties.toSet(),
|
||||||
rotation = rotation,
|
rotation = rotation,
|
||||||
renders = renders.toSet(),
|
renders = renders.toSet(),
|
||||||
|
tintColor = tintColor
|
||||||
)
|
)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -86,4 +86,8 @@ public final class RGBColor implements ChatCode {
|
|||||||
public int getColor() {
|
public int getColor() {
|
||||||
return this.color;
|
return this.color;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public static RGBColor noAlpha(int color) {
|
||||||
|
return new RGBColor(color << 8 | 0xFF);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
@ -15,6 +15,7 @@ package de.bixilon.minosoft.gui.rendering.chunk.models.renderable
|
|||||||
|
|
||||||
import com.google.gson.JsonObject
|
import com.google.gson.JsonObject
|
||||||
import de.bixilon.minosoft.data.Directions
|
import de.bixilon.minosoft.data.Directions
|
||||||
|
import de.bixilon.minosoft.data.text.RGBColor
|
||||||
import de.bixilon.minosoft.data.world.BlockInfo
|
import de.bixilon.minosoft.data.world.BlockInfo
|
||||||
import de.bixilon.minosoft.gui.rendering.chunk.models.loading.BlockModel
|
import de.bixilon.minosoft.gui.rendering.chunk.models.loading.BlockModel
|
||||||
import de.bixilon.minosoft.gui.rendering.textures.Texture
|
import de.bixilon.minosoft.gui.rendering.textures.Texture
|
||||||
@ -88,7 +89,10 @@ class BlockRenderer(data: JsonObject, parent: BlockModel) {
|
|||||||
if (neighbourBlockFullFace && cullFace) {
|
if (neighbourBlockFullFace && cullFace) {
|
||||||
continue
|
continue
|
||||||
}
|
}
|
||||||
element.render(textureMapping, modelMatrix, direction, data)
|
|
||||||
|
val tintColor: RGBColor? = blockInfo.block.tintColor
|
||||||
|
|
||||||
|
element.render(tintColor, textureMapping, modelMatrix, direction, data)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -49,7 +49,7 @@ class ElementRenderer(element: BlockModelElement, rotation: Vec3, uvlock: Boolea
|
|||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
fun render(textureMapping: MutableMap<String, Texture>, modelMatrix: Mat4, direction: Directions, data: MutableList<Float>) {
|
fun render(tintColor: RGBColor?, textureMapping: MutableMap<String, Texture>, modelMatrix: Mat4, direction: Directions, data: MutableList<Float>) {
|
||||||
val realDirection = directionMapping[direction]!!
|
val realDirection = directionMapping[direction]!!
|
||||||
val positionTemplate = BlockModelElement.FACE_POSITION_MAP_TEMPLATE[realDirection.ordinal]
|
val positionTemplate = BlockModelElement.FACE_POSITION_MAP_TEMPLATE[realDirection.ordinal]
|
||||||
|
|
||||||
@ -76,10 +76,10 @@ class ElementRenderer(element: BlockModelElement, rotation: Vec3, uvlock: Boolea
|
|||||||
data.add(texture.animations.toFloat())
|
data.add(texture.animations.toFloat())
|
||||||
data.add(texture.heightFactor)
|
data.add(texture.heightFactor)
|
||||||
|
|
||||||
if (texture.tintIndex == 1) {
|
if (tintColor == null) {
|
||||||
data.add(Float.fromBits(RGBColor(0x10, 0xee, 0x10).color))
|
|
||||||
} else {
|
|
||||||
data.add(0f)
|
data.add(0f)
|
||||||
|
} else {
|
||||||
|
data.add(Float.fromBits(tintColor.color))
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -36,8 +36,6 @@ class Texture(
|
|||||||
var animations: Int = 0
|
var animations: Int = 0
|
||||||
var animationFrameTime: Int = 0
|
var animationFrameTime: Int = 0
|
||||||
|
|
||||||
var tintIndex = 0
|
|
||||||
|
|
||||||
fun load(assetsManager: AssetsManager) {
|
fun load(assetsManager: AssetsManager) {
|
||||||
if (loaded) {
|
if (loaded) {
|
||||||
return
|
return
|
||||||
@ -48,10 +46,6 @@ class Texture(
|
|||||||
"minecraft/textures/${name}.png"
|
"minecraft/textures/${name}.png"
|
||||||
}
|
}
|
||||||
|
|
||||||
if (texturePath == "minecraft/textures/block/grass_block_top.png") {
|
|
||||||
tintIndex = 1
|
|
||||||
}
|
|
||||||
|
|
||||||
val decoder = PNGDecoder(assetsManager.readAssetAsStream(texturePath))
|
val decoder = PNGDecoder(assetsManager.readAssetAsStream(texturePath))
|
||||||
buffer = BufferUtils.createByteBuffer(decoder.width * decoder.height * PNGDecoder.Format.RGBA.numComponents)
|
buffer = BufferUtils.createByteBuffer(decoder.width * decoder.height * PNGDecoder.Format.RGBA.numComponents)
|
||||||
decoder.decode(buffer, decoder.width * PNGDecoder.Format.RGBA.numComponents, PNGDecoder.Format.RGBA)
|
decoder.decode(buffer, decoder.width * PNGDecoder.Format.RGBA.numComponents, PNGDecoder.Format.RGBA)
|
||||||
|
Loading…
x
Reference in New Issue
Block a user