mirror of
https://gitlab.bixilon.de/bixilon/minosoft.git
synced 2025-09-16 10:55:01 -04:00
block models: fix wrong texture caching
This commit is contained in:
parent
4cea3d9bc2
commit
528b64bae5
@ -28,6 +28,9 @@ import de.bixilon.minosoft.gui.rendering.system.base.texture.TextureManager
|
|||||||
import de.bixilon.minosoft.gui.rendering.system.base.texture.texture.Texture
|
import de.bixilon.minosoft.gui.rendering.system.base.texture.texture.Texture
|
||||||
import de.bixilon.minosoft.gui.rendering.textures.TextureUtil.texture
|
import de.bixilon.minosoft.gui.rendering.textures.TextureUtil.texture
|
||||||
import de.bixilon.minosoft.util.KUtil.toResourceLocation
|
import de.bixilon.minosoft.util.KUtil.toResourceLocation
|
||||||
|
import de.bixilon.minosoft.util.logging.Log
|
||||||
|
import de.bixilon.minosoft.util.logging.LogLevels
|
||||||
|
import de.bixilon.minosoft.util.logging.LogMessageType
|
||||||
import java.util.*
|
import java.util.*
|
||||||
|
|
||||||
data class BlockModel(
|
data class BlockModel(
|
||||||
@ -37,8 +40,9 @@ data class BlockModel(
|
|||||||
val textures: Map<String, Any>?, // either String or ResourceLocation
|
val textures: Map<String, Any>?, // either String or ResourceLocation
|
||||||
val ambientOcclusion: Boolean = true,
|
val ambientOcclusion: Boolean = true,
|
||||||
) {
|
) {
|
||||||
|
val loadedTextures: HashMap<String, Texture> = hashMapOf()
|
||||||
|
|
||||||
fun getTexture(name: String, textures: TextureManager): Texture? {
|
fun createTexture(name: String, textures: TextureManager): Texture? {
|
||||||
if (!name.startsWith("#")) {
|
if (!name.startsWith("#")) {
|
||||||
return textures.staticTextures.createTexture(name.toResourceLocation())
|
return textures.staticTextures.createTexture(name.toResourceLocation())
|
||||||
}
|
}
|
||||||
@ -46,9 +50,33 @@ data class BlockModel(
|
|||||||
if (texture == null || texture !is ResourceLocation) {
|
if (texture == null || texture !is ResourceLocation) {
|
||||||
return null
|
return null
|
||||||
}
|
}
|
||||||
|
|
||||||
return textures.staticTextures.createTexture(texture)
|
return textures.staticTextures.createTexture(texture)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
fun getOrNullTexture(name: String, textures: TextureManager): Texture? {
|
||||||
|
this.loadedTextures[name]?.let { return it }
|
||||||
|
|
||||||
|
val texture = createTexture(name, textures) ?: return null
|
||||||
|
|
||||||
|
this.loadedTextures[name] = texture
|
||||||
|
return texture
|
||||||
|
}
|
||||||
|
|
||||||
|
fun getTexture(name: String, textures: TextureManager): Texture {
|
||||||
|
val texture = getOrNullTexture(name, textures)
|
||||||
|
if (texture == null) {
|
||||||
|
Log.log(LogMessageType.LOADING, LogLevels.WARN) { "Can not find mapped texture ${name}, please check for broken resource packs!" }
|
||||||
|
return textures.debugTexture
|
||||||
|
}
|
||||||
|
|
||||||
|
return texture
|
||||||
|
}
|
||||||
|
|
||||||
|
fun getTexture(name: String): Texture? {
|
||||||
|
return this.loadedTextures[name]
|
||||||
|
}
|
||||||
|
|
||||||
companion object {
|
companion object {
|
||||||
|
|
||||||
fun display(data: JsonObject, parent: Map<DisplayPositions, ModelDisplay>?): Map<DisplayPositions, ModelDisplay>? {
|
fun display(data: JsonObject, parent: Map<DisplayPositions, ModelDisplay>?): Map<DisplayPositions, ModelDisplay>? {
|
||||||
|
@ -23,11 +23,7 @@ import de.bixilon.minosoft.gui.rendering.models.block.BlockModel
|
|||||||
import de.bixilon.minosoft.gui.rendering.models.block.element.ModelElement.Companion.BLOCK_SIZE
|
import de.bixilon.minosoft.gui.rendering.models.block.element.ModelElement.Companion.BLOCK_SIZE
|
||||||
import de.bixilon.minosoft.gui.rendering.models.block.state.apply.SingleBlockStateApply.Companion.rotation
|
import de.bixilon.minosoft.gui.rendering.models.block.state.apply.SingleBlockStateApply.Companion.rotation
|
||||||
import de.bixilon.minosoft.gui.rendering.system.base.texture.TextureManager
|
import de.bixilon.minosoft.gui.rendering.system.base.texture.TextureManager
|
||||||
import de.bixilon.minosoft.gui.rendering.system.base.texture.texture.Texture
|
|
||||||
import de.bixilon.minosoft.gui.rendering.tint.TintManager
|
import de.bixilon.minosoft.gui.rendering.tint.TintManager
|
||||||
import de.bixilon.minosoft.util.logging.Log
|
|
||||||
import de.bixilon.minosoft.util.logging.LogLevels
|
|
||||||
import de.bixilon.minosoft.util.logging.LogMessageType
|
|
||||||
import de.bixilon.minosoft.util.nbt.tag.NBTUtil.listCast
|
import de.bixilon.minosoft.util.nbt.tag.NBTUtil.listCast
|
||||||
import java.util.*
|
import java.util.*
|
||||||
|
|
||||||
@ -37,15 +33,10 @@ data class ModelFace(
|
|||||||
val rotation: Int,
|
val rotation: Int,
|
||||||
val tintIndex: Int = -1,
|
val tintIndex: Int = -1,
|
||||||
) {
|
) {
|
||||||
var loadedTexture: Texture? = null
|
|
||||||
|
|
||||||
|
|
||||||
fun load(model: BlockModel, textures: TextureManager) {
|
fun load(model: BlockModel, textures: TextureManager) {
|
||||||
this.loadedTexture = model.getTexture(this.texture, textures)
|
model.getTexture(this.texture, textures)
|
||||||
if (this.loadedTexture == null) {
|
|
||||||
Log.log(LogMessageType.LOADING, LogLevels.WARN) { "Can not find mapped texture ${texture}, please check for broken resource packs!" }
|
|
||||||
this.loadedTexture = textures.debugTexture
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
@ -121,7 +121,7 @@ data class SingleBlockStateApply(
|
|||||||
|
|
||||||
override fun load(textures: TextureManager) {
|
override fun load(textures: TextureManager) {
|
||||||
if (model.elements == null) return
|
if (model.elements == null) return
|
||||||
particle = model.getTexture("#particle", textures)
|
particle = model.getOrNullTexture("#particle", textures)
|
||||||
|
|
||||||
for (element in model.elements) {
|
for (element in model.elements) {
|
||||||
element.load(model, textures)
|
element.load(model, textures)
|
||||||
@ -161,7 +161,7 @@ data class SingleBlockStateApply(
|
|||||||
|
|
||||||
for (element in model.elements) {
|
for (element in model.elements) {
|
||||||
for ((direction, face) in element.faces) {
|
for ((direction, face) in element.faces) {
|
||||||
val texture = face.loadedTexture ?: continue
|
val texture = model.getTexture(face.texture) ?: continue
|
||||||
|
|
||||||
val rotatedDirection = direction
|
val rotatedDirection = direction
|
||||||
.rotateX(this.x)
|
.rotateX(this.x)
|
||||||
|
Loading…
x
Reference in New Issue
Block a user