prevent nbt editing from causing crashes on foci and such

This commit is contained in:
yrsegal@gmail.com 2022-06-12 22:33:48 -04:00
parent fef331d8e0
commit 10c9d074b8
2 changed files with 57 additions and 52 deletions

View file

@ -143,7 +143,7 @@ class SpellDatum<T : Any> private constructor(val payload: T) {
fun fromNBT(nbt: CompoundTag, world: ServerLevel): SpellDatum<*> {
val keys = nbt.allKeys
if (keys.size != 1)
throw IllegalArgumentException("Expected exactly one kv pair: $nbt")
return SpellDatum(Widget.GARBAGE) // Invalid iota format
return when (val key = keys.iterator().next()) {
TAG_ENTITY -> {
@ -164,7 +164,7 @@ class SpellDatum<T : Any> private constructor(val payload: T) {
TAG_PATTERN -> {
SpellDatum(HexPattern.fromNBT(nbt.getCompound(TAG_PATTERN)))
}
else -> throw IllegalArgumentException("Unknown key $key: $nbt")
else -> SpellDatum(Widget.GARBAGE) // Invalid iota type
}
}
@ -181,10 +181,11 @@ class SpellDatum<T : Any> private constructor(val payload: T) {
@JvmStatic
fun displayFromNBT(nbt: CompoundTag): Component {
val keys = nbt.allKeys
if (keys.size != 1)
throw IllegalArgumentException("Expected exactly one kv pair: $nbt")
val out = "".asTextComponent
if (keys.size != 1)
out += "hexcasting.spelldata.unknown".asTranslatedComponent.white
else {
when (val key = keys.iterator().next()) {
TAG_DOUBLE -> out += String.format(
"%.4f",
@ -236,7 +237,10 @@ class SpellDatum<T : Any> private constructor(val payload: T) {
out += Component.Serializer.fromJson(json)?.aqua
?: "hexcasting.spelldata.entity.whoknows".asTranslatedComponent.white
}
else -> throw IllegalArgumentException("Unknown key $key: $nbt")
else -> {
out += "hexcasting.spelldata.unknown".asTranslatedComponent.white
}
}
}
return out
}

View file

@ -135,6 +135,7 @@
"hexcasting.tooltip.brainsweep.product": "Mindless Body",
"hexcasting.spelldata.onitem": "Contains: %s",
"hexcasting.spelldata.anything": "Anything",
"hexcasting.spelldata.unknown": "Unknown data (this is a bug)",
"hexcasting.spelldata.entity.whoknows": "An Entity (this should only show up if this was stored before the 0.5.0 update, use Scribe's Reflection, Scribe's Gambit to fix)",
"hexcasting.spelldata.akashic.nopos": "The owning record does not know of any iota here (this is a bug)",