mirror of
https://gitlab.bixilon.de/bixilon/minosoft.git
synced 2025-09-14 09:56:37 -04:00
don't require assets to be loaded
This fixes some loading crashes when all assets are disabled in the `resources.json`. Reported-By: turtius
This commit is contained in:
parent
9ec4eb8278
commit
f33f302c15
@ -54,7 +54,6 @@ interface AssetsManager {
|
||||
return list
|
||||
}
|
||||
|
||||
@Throws(FileNotFoundException::class)
|
||||
fun getAll(path: ResourceLocation): List<InputStream> {
|
||||
return getAllOrNull(path) ?: throw FileNotFoundException("Can not find any assets matching $path!")
|
||||
}
|
||||
|
@ -81,8 +81,9 @@ object LanguageUtil {
|
||||
return ChatComponent.of(key.toString() + "->" + data.contentToString(), null, parent, restricted)
|
||||
}
|
||||
|
||||
fun loadLanguage(language: String, assetsManager: AssetsManager, json: Boolean, path: ResourceLocation): Translator {
|
||||
val assets = assetsManager.getAll(ResourceLocation(path.namespace, path.path + language + if (json) ".json" else ".lang"))
|
||||
fun loadLanguage(language: String, assetsManager: AssetsManager, json: Boolean, path: ResourceLocation): Translator? {
|
||||
val assets = assetsManager.getAllOrNull(ResourceLocation(path.namespace, path.path + language + if (json) ".json" else ".lang")) ?: return null
|
||||
if (assets.isEmpty()) return null
|
||||
val languages: MutableList<Language> = mutableListOf()
|
||||
|
||||
for (asset in assets) {
|
||||
@ -106,9 +107,9 @@ object LanguageUtil {
|
||||
|
||||
|
||||
if (name != FALLBACK_LANGUAGE) {
|
||||
ExceptionUtil.tryCatch(FileNotFoundException::class.java, executor = { languages += loadLanguage(name, assetsManager, json, path) })
|
||||
ExceptionUtil.tryCatch(FileNotFoundException::class.java, executor = { languages += loadLanguage(name, assetsManager, json, path) ?: return@tryCatch })
|
||||
}
|
||||
languages += loadLanguage(FALLBACK_LANGUAGE, assetsManager, json, path)
|
||||
loadLanguage(FALLBACK_LANGUAGE, assetsManager, json, path)?.let { languages += it }
|
||||
|
||||
if (languages.size == 1) {
|
||||
return languages.first()
|
||||
|
@ -150,10 +150,10 @@ class SolidCullSectionPreparer(
|
||||
light[O_UP] = sectionLight[(y + 1) shl 8 or baseIndex]
|
||||
}
|
||||
|
||||
checkNorth(neighbourBlocks, neighbours, x, y, z, light, position, neighbourChunks, section, chunk)
|
||||
checkSouth(neighbourBlocks, neighbours, x, y, z, light, position, neighbourChunks, section, chunk)
|
||||
checkWest(neighbourBlocks, neighbours, x, y, z, light, position, neighbourChunks, section, chunk)
|
||||
checkEast(neighbourBlocks, neighbours, x, y, z, light, position, neighbourChunks, section, chunk)
|
||||
checkNorth(neighbourBlocks, neighbours, x, y, z, light, position, neighbourChunks, section, chunk)
|
||||
checkSouth(neighbourBlocks, neighbours, x, y, z, light, position, neighbourChunks, section, chunk)
|
||||
|
||||
if (position.y - 1 >= maxHeight) {
|
||||
light[O_UP] = (light[O_UP].toInt() or 0xF0).toByte()
|
||||
|
@ -53,7 +53,7 @@ class ModelLoader(
|
||||
}
|
||||
|
||||
private fun loadBlockStates(block: Block) {
|
||||
val blockStateJson = assetsManager[block.identifier.blockState()].readJsonObject()
|
||||
val blockStateJson = assetsManager.getOrNull(block.identifier.blockState())?.readJsonObject() ?: return
|
||||
|
||||
val model = RootModel(this, blockStateJson)
|
||||
|
||||
@ -87,12 +87,12 @@ class ModelLoader(
|
||||
fun loadItem(item: Item) {
|
||||
val model = loadItemModel(item.identifier.prefix("item/"))
|
||||
|
||||
item.model = model.bake(context).unsafeCast()
|
||||
item.model = model?.bake(context).unsafeCast()
|
||||
}
|
||||
|
||||
fun loadItemModel(name: ResourceLocation): GenericUnbakedModel {
|
||||
fun loadItemModel(name: ResourceLocation): GenericUnbakedModel? {
|
||||
unbakedBlockModels[name]?.let { return it.unsafeCast() }
|
||||
val data = assetsManager[name.model()].readJsonObject()
|
||||
val data = assetsManager.getOrNull(name.model())?.readJsonObject() ?: return null
|
||||
|
||||
val parent = data["parent"]?.toResourceLocation()?.let { loadItemModel(it) }
|
||||
|
||||
|
@ -25,7 +25,7 @@ class CloudMatrix {
|
||||
|
||||
|
||||
fun load(assetsManager: AssetsManager) {
|
||||
val data = assetsManager[CLOUD_MATRIX].readTexture()
|
||||
val data = assetsManager.getOrNull(CLOUD_MATRIX)?.readTexture() ?: return
|
||||
|
||||
if (data.size.x != CLOUD_MATRIX_SIZE || data.size.y != CLOUD_MATRIX_SIZE) {
|
||||
throw IllegalStateException("Cloud matrix has invalid size: ${data.size}")
|
||||
|
Loading…
x
Reference in New Issue
Block a user