diff options
author | Linnea Gräf <nea@nea.moe> | 2024-11-13 15:44:04 +0100 |
---|---|---|
committer | Linnea Gräf <nea@nea.moe> | 2024-11-15 18:40:19 +0100 |
commit | 59566bcab8a5861e0cb78e8c207884006828bd63 (patch) | |
tree | 4ce3b19b3ab1f78652d5d805d8b7f2def16a1167 /src/main/kotlin/gui/entity/EntityRenderer.kt | |
parent | 57cdcb21ec3aa6f4d4f4ab07a3e4e8fd7d32f28d (diff) | |
download | Firmament-59566bcab8a5861e0cb78e8c207884006828bd63.tar.gz Firmament-59566bcab8a5861e0cb78e8c207884006828bd63.tar.bz2 Firmament-59566bcab8a5861e0cb78e8c207884006828bd63.zip |
fix: Improve exception logging for entity widgets
Diffstat (limited to 'src/main/kotlin/gui/entity/EntityRenderer.kt')
-rw-r--r-- | src/main/kotlin/gui/entity/EntityRenderer.kt | 19 |
1 files changed, 7 insertions, 12 deletions
diff --git a/src/main/kotlin/gui/entity/EntityRenderer.kt b/src/main/kotlin/gui/entity/EntityRenderer.kt index ddb862f..022b9a3 100644 --- a/src/main/kotlin/gui/entity/EntityRenderer.kt +++ b/src/main/kotlin/gui/entity/EntityRenderer.kt @@ -3,7 +3,6 @@ package moe.nea.firmament.gui.entity import com.google.gson.Gson import com.google.gson.JsonArray import com.google.gson.JsonObject -import org.apache.logging.log4j.LogManager import org.joml.Quaternionf import org.joml.Vector3f import kotlin.math.atan @@ -15,8 +14,8 @@ import net.minecraft.entity.LivingEntity import net.minecraft.entity.SpawnReason import net.minecraft.util.Identifier import net.minecraft.world.World +import moe.nea.firmament.util.ErrorUtil import moe.nea.firmament.util.MC -import moe.nea.firmament.util.assertNotNullOr import moe.nea.firmament.util.iterate import moe.nea.firmament.util.openFirmamentResource import moe.nea.firmament.util.render.enableScissorWithTranslation @@ -76,18 +75,15 @@ object EntityRenderer { "name" to ModifyName, ) - val logger = LogManager.getLogger("Firmament.Entity") fun applyModifiers(entityId: String, modifiers: List<JsonObject>): LivingEntity? { - val entityType = assertNotNullOr(entityIds[entityId]) { - logger.error("Could not create entity with id $entityId") + val entityType = ErrorUtil.notNullOr(entityIds[entityId], "Could not create entity with id $entityId") { return null } - var entity = entityType() + var entity = ErrorUtil.catch("") { entityType() }.or { return null } for (modifierJson in modifiers) { - val modifier = assertNotNullOr(modifierJson["type"]?.asString?.let(entityModifiers::get)) { - logger.error("Unknown modifier $modifierJson") - return null - } + val modifier = ErrorUtil.notNullOr( + modifierJson["type"]?.asString?.let(entityModifiers::get), + "Could not create entity with id $entityId. Failed to apply modifier $modifierJson") { return null } entity = modifier.apply(entity, modifierJson) } return entity @@ -95,8 +91,7 @@ object EntityRenderer { fun constructEntity(info: JsonObject): LivingEntity? { val modifiers = (info["modifiers"] as JsonArray?)?.map { it.asJsonObject } ?: emptyList() - val entityType = assertNotNullOr(info["entity"]?.asString) { - logger.error("Missing entity type on entity object") + val entityType = ErrorUtil.notNullOr(info["entity"]?.asString, "Missing entity type on entity object") { return null } return applyModifiers(entityType, modifiers) |