mirror of
https://gitlab.bixilon.de/bixilon/minosoft.git
synced 2025-09-16 10:55:01 -04:00
fix loading crash with no assets
Reported-By: turtius
This commit is contained in:
parent
702aee0974
commit
7ba4e45edf
@ -40,7 +40,7 @@ class BlockModelTest {
|
|||||||
assets.push(minosoft("models/block/named.json"), json)
|
assets.push(minosoft("models/block/named.json"), json)
|
||||||
|
|
||||||
|
|
||||||
return loader.block.loadBlock(minosoft("block/named"))
|
return loader.block.loadBlock(minosoft("block/named"))!!
|
||||||
}
|
}
|
||||||
|
|
||||||
fun emptyModel() {
|
fun emptyModel() {
|
||||||
|
@ -198,8 +198,8 @@ data class SingleBlockStateApply(
|
|||||||
return SingleBlockStateApply(model, uvLock, x, y)
|
return SingleBlockStateApply(model, uvLock, x, y)
|
||||||
}
|
}
|
||||||
|
|
||||||
fun deserialize(loader: BlockLoader, data: JsonObject): SingleBlockStateApply {
|
fun deserialize(loader: BlockLoader, data: JsonObject): SingleBlockStateApply? {
|
||||||
val model = loader.loadBlock(data["model"].toString().toResourceLocation())
|
val model = loader.loadBlock(data["model"].toString().toResourceLocation()) ?: return null
|
||||||
|
|
||||||
return deserialize(model, data)
|
return deserialize(model, data)
|
||||||
}
|
}
|
||||||
|
@ -53,9 +53,10 @@ data class WeightedBlockStateApply(
|
|||||||
for (entry in data) {
|
for (entry in data) {
|
||||||
var weight = entry["weight"]?.toInt() ?: 1
|
var weight = entry["weight"]?.toInt() ?: 1
|
||||||
if (weight < 0) weight = 1
|
if (weight < 0) weight = 1
|
||||||
val apply = SingleBlockStateApply.deserialize(loader, entry)
|
val apply = SingleBlockStateApply.deserialize(loader, entry) ?: continue
|
||||||
models += WeightedApply(weight, apply)
|
models += WeightedApply(weight, apply)
|
||||||
}
|
}
|
||||||
|
if(models.isEmpty()) return null
|
||||||
|
|
||||||
return WeightedBlockStateApply(models)
|
return WeightedBlockStateApply(models)
|
||||||
}
|
}
|
||||||
|
@ -27,9 +27,9 @@ class BlockLoader(private val loader: ModelLoader) {
|
|||||||
val assets = loader.context.connection.assetsManager
|
val assets = loader.context.connection.assetsManager
|
||||||
val version = loader.context.connection.version
|
val version = loader.context.connection.version
|
||||||
|
|
||||||
fun loadBlock(name: ResourceLocation): BlockModel {
|
fun loadBlock(name: ResourceLocation): BlockModel? {
|
||||||
val file = name.model("block/")
|
val file = name.model("block/")
|
||||||
val data = assets[file].readJsonObject()
|
val data = assets.getOrNull(file)?.readJsonObject() ?: return null
|
||||||
|
|
||||||
val parent = data["parent"]?.toString()?.let { loadBlock(it.toResourceLocation()) }
|
val parent = data["parent"]?.toString()?.let { loadBlock(it.toResourceLocation()) }
|
||||||
|
|
||||||
@ -39,7 +39,7 @@ class BlockLoader(private val loader: ModelLoader) {
|
|||||||
|
|
||||||
fun loadState(block: Block): DirectBlockModel? {
|
fun loadState(block: Block): DirectBlockModel? {
|
||||||
val file = (if (block is CustomBlockModel) block.getModelName(version) else block.identifier)?.blockState() ?: return null
|
val file = (if (block is CustomBlockModel) block.getModelName(version) else block.identifier)?.blockState() ?: return null
|
||||||
val data = assets[file].readJsonObject()
|
val data = assets.getOrNull(file)?.readJsonObject() ?: return null
|
||||||
|
|
||||||
return DirectBlockModel.deserialize(this, data)
|
return DirectBlockModel.deserialize(this, data)
|
||||||
}
|
}
|
||||||
|
Loading…
x
Reference in New Issue
Block a user