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:
Moritz Zwerger 2023-07-29 21:03:47 +02:00
parent 9ec4eb8278
commit f33f302c15
No known key found for this signature in database
GPG Key ID: 5CAD791931B09AC4
5 changed files with 12 additions and 12 deletions

View File

@ -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!")
}

View File

@ -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()

View File

@ -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()

View File

@ -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) }

View File

@ -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}")