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.RegistryItem
|
||||
import de.bixilon.minosoft.data.mappings.versions.VersionMapping
|
||||
import de.bixilon.minosoft.data.text.RGBColor
|
||||
|
||||
data class Block(
|
||||
val identifier: ModIdentifier,
|
||||
val explosionResistance: Float = 0.0f,
|
||||
val hasCollision: Boolean = false,
|
||||
val hasDynamicShape: Boolean = false,
|
||||
val tintColor: RGBColor? = null,
|
||||
private val itemId: Int = 0,
|
||||
) : RegistryItem {
|
||||
lateinit var item: Item
|
||||
@ -40,6 +42,7 @@ data class Block(
|
||||
explosionResistance = data["explosion_resistance"]?.asFloat ?: 0.0f,
|
||||
hasCollision = data["has_collision"]?.asBoolean ?: false,
|
||||
hasDynamicShape = data["has_dynamic_shape"]?.asBoolean ?: false,
|
||||
tintColor = data["tint_color"]?.asInt?.let { RGBColor.noAlpha(it) },
|
||||
itemId = data["item"]?.asInt ?: 0,
|
||||
)
|
||||
|
||||
|
@ -18,6 +18,7 @@ import com.google.gson.JsonObject
|
||||
import com.google.gson.JsonPrimitive
|
||||
import de.bixilon.minosoft.Minosoft
|
||||
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.gui.rendering.chunk.models.loading.BlockModel
|
||||
import de.bixilon.minosoft.gui.rendering.chunk.models.renderable.BlockRenderer
|
||||
@ -29,6 +30,7 @@ data class BlockState(
|
||||
val properties: Set<BlockProperties> = setOf(),
|
||||
val rotation: BlockRotations = BlockRotations.NONE,
|
||||
val renders: Set<BlockRenderer> = setOf(),
|
||||
val tintColor: RGBColor? = null,
|
||||
) {
|
||||
|
||||
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(
|
||||
owner = owner,
|
||||
properties = properties.toSet(),
|
||||
rotation = rotation,
|
||||
renders = renders.toSet(),
|
||||
tintColor = tintColor
|
||||
)
|
||||
}
|
||||
|
||||
|
@ -86,4 +86,8 @@ public final class RGBColor implements ChatCode {
|
||||
public int getColor() {
|
||||
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 de.bixilon.minosoft.data.Directions
|
||||
import de.bixilon.minosoft.data.text.RGBColor
|
||||
import de.bixilon.minosoft.data.world.BlockInfo
|
||||
import de.bixilon.minosoft.gui.rendering.chunk.models.loading.BlockModel
|
||||
import de.bixilon.minosoft.gui.rendering.textures.Texture
|
||||
@ -88,7 +89,10 @@ class BlockRenderer(data: JsonObject, parent: BlockModel) {
|
||||
if (neighbourBlockFullFace && cullFace) {
|
||||
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 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.heightFactor)
|
||||
|
||||
if (texture.tintIndex == 1) {
|
||||
data.add(Float.fromBits(RGBColor(0x10, 0xee, 0x10).color))
|
||||
} else {
|
||||
if (tintColor == null) {
|
||||
data.add(0f)
|
||||
} else {
|
||||
data.add(Float.fromBits(tintColor.color))
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -36,8 +36,6 @@ class Texture(
|
||||
var animations: Int = 0
|
||||
var animationFrameTime: Int = 0
|
||||
|
||||
var tintIndex = 0
|
||||
|
||||
fun load(assetsManager: AssetsManager) {
|
||||
if (loaded) {
|
||||
return
|
||||
@ -48,10 +46,6 @@ class Texture(
|
||||
"minecraft/textures/${name}.png"
|
||||
}
|
||||
|
||||
if (texturePath == "minecraft/textures/block/grass_block_top.png") {
|
||||
tintIndex = 1
|
||||
}
|
||||
|
||||
val decoder = PNGDecoder(assetsManager.readAssetAsStream(texturePath))
|
||||
buffer = BufferUtils.createByteBuffer(decoder.width * decoder.height * PNGDecoder.Format.RGBA.numComponents)
|
||||
decoder.decode(buffer, decoder.width * PNGDecoder.Format.RGBA.numComponents, PNGDecoder.Format.RGBA)
|
||||
|
Loading…
x
Reference in New Issue
Block a user