mirror of
https://gitlab.bixilon.de/bixilon/minosoft.git
synced 2025-09-14 18:05:51 -04:00
fix model paths (pre/post flattening)
This commit is contained in:
parent
9fa3313885
commit
b83d421416
@ -27,14 +27,12 @@ class LavaFluidModel : FluidModel {
|
||||
override val transparency = TextureTransparencies.OPAQUE// TODO: from texture
|
||||
|
||||
override fun load(context: RenderContext) {
|
||||
still = context.textures.staticTextures.createTexture(if (context.connection.version.flattened) STILL else STILL_LEGACY)
|
||||
flowing = context.textures.staticTextures.createTexture(if (context.connection.version.flattened) FLOWING else FLOWING_LEGACY)
|
||||
still = context.textures.staticTextures.createTexture(context.models.block.fixPath(STILL).texture())
|
||||
flowing = context.textures.staticTextures.createTexture(context.models.block.fixPath(FLOWING).texture())
|
||||
}
|
||||
|
||||
companion object {
|
||||
private val STILL = minecraft("block/lava_still").texture()
|
||||
private val STILL_LEGACY = minecraft("blocks/lava_still").texture() // TODO: pack_format < 4
|
||||
private val FLOWING = minecraft("block/lava_flow").texture()
|
||||
private val FLOWING_LEGACY = minecraft("blocks/lava_flow").texture() // TODO: pack_format < 4
|
||||
}
|
||||
}
|
||||
|
@ -31,14 +31,12 @@ class WaterFluidModel : FluidModel {
|
||||
override val transparency = TextureTransparencies.TRANSLUCENT// TODO: from texture
|
||||
|
||||
override fun load(context: RenderContext) {
|
||||
still = context.textures.staticTextures.createTexture(if (context.connection.version.flattened) STILL else STILL_LEGACY)
|
||||
flowing = context.textures.staticTextures.createTexture(if (context.connection.version.flattened) FLOWING else FLOWING_LEGACY)
|
||||
still = context.textures.staticTextures.createTexture(context.models.block.fixPath(STILL).texture())
|
||||
flowing = context.textures.staticTextures.createTexture(context.models.block.fixPath(FLOWING).texture())
|
||||
}
|
||||
|
||||
companion object {
|
||||
private val STILL = minecraft("block/water_still").texture()
|
||||
private val STILL_LEGACY = minecraft("blocks/water_still").texture() // TODO: pack_format < 4
|
||||
private val FLOWING = minecraft("block/water_flow").texture()
|
||||
private val FLOWING_LEGACY = minecraft("blocks/water_flow").texture() // TODO: pack_format < 4
|
||||
private val STILL = minecraft("block/water_still")
|
||||
private val FLOWING = minecraft("block/water_flow")
|
||||
}
|
||||
}
|
||||
|
@ -21,6 +21,7 @@ import de.bixilon.minosoft.data.registries.identified.ResourceLocation
|
||||
import de.bixilon.minosoft.gui.rendering.models.block.BlockModel
|
||||
import de.bixilon.minosoft.gui.rendering.models.block.BlockModelPrototype
|
||||
import de.bixilon.minosoft.gui.rendering.models.block.state.DirectBlockModel
|
||||
import de.bixilon.minosoft.gui.rendering.models.loader.ModelFixer.fixPrefix
|
||||
import de.bixilon.minosoft.gui.rendering.models.loader.ModelLoader.Companion.model
|
||||
import de.bixilon.minosoft.gui.rendering.models.loader.legacy.CustomModel
|
||||
import de.bixilon.minosoft.util.KUtil.toResourceLocation
|
||||
@ -31,7 +32,7 @@ class BlockLoader(private val loader: ModelLoader) {
|
||||
val version = loader.context.connection.version
|
||||
|
||||
fun loadBlock(name: ResourceLocation): BlockModel? {
|
||||
val file = name.model("block/")
|
||||
val file = name.blockModel()
|
||||
cache[file]?.let { return it }
|
||||
val data = assets.getOrNull(file)?.readJsonObject() ?: return null
|
||||
|
||||
@ -73,6 +74,14 @@ class BlockLoader(private val loader: ModelLoader) {
|
||||
this.cache.clear()
|
||||
}
|
||||
|
||||
fun fixPath(name: ResourceLocation): ResourceLocation {
|
||||
return ResourceLocation(name.namespace, name.path.fixPrefix(loader.packFormat, 4, "block/", "blocks/"))
|
||||
}
|
||||
|
||||
private fun ResourceLocation.blockModel(): ResourceLocation {
|
||||
return fixPath(this).model()
|
||||
}
|
||||
|
||||
|
||||
companion object {
|
||||
|
||||
|
@ -22,6 +22,7 @@ import de.bixilon.minosoft.data.registries.item.items.block.BlockItem
|
||||
import de.bixilon.minosoft.data.registries.item.items.block.legacy.PixLyzerBlockItem
|
||||
import de.bixilon.minosoft.gui.rendering.models.item.ItemModel
|
||||
import de.bixilon.minosoft.gui.rendering.models.item.ItemModelPrototype
|
||||
import de.bixilon.minosoft.gui.rendering.models.loader.ModelFixer.fixPrefix
|
||||
import de.bixilon.minosoft.gui.rendering.models.loader.ModelLoader.Companion.model
|
||||
import de.bixilon.minosoft.gui.rendering.models.loader.legacy.CustomModel
|
||||
import de.bixilon.minosoft.util.KUtil.toResourceLocation
|
||||
@ -32,7 +33,7 @@ class ItemLoader(private val loader: ModelLoader) {
|
||||
val version = loader.context.connection.version
|
||||
|
||||
fun loadItem(name: ResourceLocation): ItemModel? {
|
||||
val file = name.model("item/")
|
||||
val file = name.itemModel()
|
||||
cache[file]?.let { return it }
|
||||
val data = assets.getOrNull(file)?.readJsonObject() ?: return null
|
||||
|
||||
@ -71,4 +72,12 @@ class ItemLoader(private val loader: ModelLoader) {
|
||||
fun cleanup() {
|
||||
this.cache.clear()
|
||||
}
|
||||
|
||||
fun fixPath(name: ResourceLocation): ResourceLocation {
|
||||
return ResourceLocation(name.namespace, name.path.fixPrefix(loader.packFormat, 4, "item/", "items/"))
|
||||
}
|
||||
|
||||
private fun ResourceLocation.itemModel(): ResourceLocation {
|
||||
return fixPath(this).model()
|
||||
}
|
||||
}
|
||||
|
@ -0,0 +1,27 @@
|
||||
/*
|
||||
* Minosoft
|
||||
* Copyright (C) 2020-2023 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 <https://www.gnu.org/licenses/>.
|
||||
*
|
||||
* This software is not affiliated with Mojang AB, the original developer of Minecraft.
|
||||
*/
|
||||
|
||||
package de.bixilon.minosoft.gui.rendering.models.loader
|
||||
|
||||
object ModelFixer {
|
||||
|
||||
fun String.fixPrefix(packFormat: Int, version: Int, pre: String, post: String): String {
|
||||
var path = this
|
||||
|
||||
path = path.removePrefix(pre)
|
||||
path = path.removePrefix(post)
|
||||
|
||||
val prefix = if (packFormat < version) pre else post
|
||||
return prefix + path
|
||||
}
|
||||
}
|
@ -24,6 +24,7 @@ import de.bixilon.minosoft.util.logging.LogMessageType
|
||||
class ModelLoader(
|
||||
val context: RenderContext,
|
||||
) {
|
||||
val packFormat = context.connection.assetsManager.properties?.pack?.format ?: if (context.connection.version.flattened) Int.MAX_VALUE else 0 // TODO: integrate with assets/refactor_atlas
|
||||
val fluids = FluidModelLoader(this)
|
||||
val entities = EntityModels(this)
|
||||
val block = BlockLoader(this)
|
||||
@ -54,16 +55,12 @@ class ModelLoader(
|
||||
|
||||
companion object {
|
||||
|
||||
fun ResourceLocation.model(prefix: String? = null): ResourceLocation {
|
||||
var path = this.path
|
||||
if (prefix != null && !path.startsWith(prefix)) {
|
||||
path = prefix + path
|
||||
}
|
||||
fun ResourceLocation.model(): ResourceLocation {
|
||||
return ResourceLocation(this.namespace, "models/$path.json")
|
||||
}
|
||||
|
||||
fun ResourceLocation.bbModel(): ResourceLocation {
|
||||
return ResourceLocation(this.namespace, "models/" + this.path + ".bbmodel")
|
||||
return ResourceLocation(this.namespace, "models/$path.bbmodel")
|
||||
}
|
||||
}
|
||||
}
|
||||
|
Loading…
x
Reference in New Issue
Block a user