mirror of
https://gitlab.bixilon.de/bixilon/minosoft.git
synced 2025-09-15 02:15:34 -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.textures.TextureUtil.texture
|
||||
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.*
|
||||
|
||||
data class BlockModel(
|
||||
@ -37,8 +40,9 @@ data class BlockModel(
|
||||
val textures: Map<String, Any>?, // either String or ResourceLocation
|
||||
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("#")) {
|
||||
return textures.staticTextures.createTexture(name.toResourceLocation())
|
||||
}
|
||||
@ -46,9 +50,33 @@ data class BlockModel(
|
||||
if (texture == null || texture !is ResourceLocation) {
|
||||
return null
|
||||
}
|
||||
|
||||
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 {
|
||||
|
||||
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.state.apply.SingleBlockStateApply.Companion.rotation
|
||||
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.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 java.util.*
|
||||
|
||||
@ -37,15 +33,10 @@ data class ModelFace(
|
||||
val rotation: Int,
|
||||
val tintIndex: Int = -1,
|
||||
) {
|
||||
var loadedTexture: Texture? = null
|
||||
|
||||
|
||||
fun load(model: BlockModel, textures: TextureManager) {
|
||||
this.loadedTexture = 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
|
||||
}
|
||||
model.getTexture(this.texture, textures)
|
||||
}
|
||||
|
||||
|
||||
|
@ -121,7 +121,7 @@ data class SingleBlockStateApply(
|
||||
|
||||
override fun load(textures: TextureManager) {
|
||||
if (model.elements == null) return
|
||||
particle = model.getTexture("#particle", textures)
|
||||
particle = model.getOrNullTexture("#particle", textures)
|
||||
|
||||
for (element in model.elements) {
|
||||
element.load(model, textures)
|
||||
@ -161,7 +161,7 @@ data class SingleBlockStateApply(
|
||||
|
||||
for (element in model.elements) {
|
||||
for ((direction, face) in element.faces) {
|
||||
val texture = face.loadedTexture ?: continue
|
||||
val texture = model.getTexture(face.texture) ?: continue
|
||||
|
||||
val rotatedDirection = direction
|
||||
.rotateX(this.x)
|
||||
|
Loading…
x
Reference in New Issue
Block a user