From 7e9352e60a50b3c7a976757c5c061e658be5e803 Mon Sep 17 00:00:00 2001 From: DBotThePony Date: Mon, 2 Sep 2024 20:31:02 +0700 Subject: [PATCH] Fix slot charge flags being lost during deserialization due to internal changes in CompoundTag code --- .../dbotthepony/mc/otm/capability/MatteryPlayer.kt | 12 +++--------- .../ru/dbotthepony/mc/otm/core/nbt/CompoundTagExt.kt | 12 ------------ 2 files changed, 3 insertions(+), 21 deletions(-) diff --git a/src/main/kotlin/ru/dbotthepony/mc/otm/capability/MatteryPlayer.kt b/src/main/kotlin/ru/dbotthepony/mc/otm/capability/MatteryPlayer.kt index dff6f0d84..f69b60f3d 100644 --- a/src/main/kotlin/ru/dbotthepony/mc/otm/capability/MatteryPlayer.kt +++ b/src/main/kotlin/ru/dbotthepony/mc/otm/capability/MatteryPlayer.kt @@ -96,7 +96,6 @@ import ru.dbotthepony.mc.otm.core.math.Decimal import ru.dbotthepony.mc.otm.core.math.RGBColorDFUCodec import ru.dbotthepony.mc.otm.core.math.minus import ru.dbotthepony.mc.otm.core.nbt.getCompoundList -import ru.dbotthepony.mc.otm.core.nbt.getIntList import ru.dbotthepony.mc.otm.core.nbt.getStringList import ru.dbotthepony.mc.otm.core.nbt.set import ru.dbotthepony.mc.otm.core.util.Savetables @@ -950,12 +949,7 @@ class MatteryPlayer(val ply: Player) { } } - tag["slotsChargeFlag"] = ListTag().also { - for (value in slotsChargeFlag) { - it.add(IntTag.valueOf(value)) - } - } - + tag.putIntArray("slotsChargeFlag", slotsChargeFlag.toIntArray()) return tag } @@ -986,8 +980,8 @@ class MatteryPlayer(val ply: Player) { } if ("slotsChargeFlag" in tag) { - for (v in tag.getIntList("slotsChargeFlag")) { - this.slotsChargeFlag.add(v.asInt) + for (v in tag.getIntArray("slotsChargeFlag")) { + this.slotsChargeFlag.add(v) } } else { slotChargeToDefault() diff --git a/src/main/kotlin/ru/dbotthepony/mc/otm/core/nbt/CompoundTagExt.kt b/src/main/kotlin/ru/dbotthepony/mc/otm/core/nbt/CompoundTagExt.kt index 22230c67e..9387c88e2 100644 --- a/src/main/kotlin/ru/dbotthepony/mc/otm/core/nbt/CompoundTagExt.kt +++ b/src/main/kotlin/ru/dbotthepony/mc/otm/core/nbt/CompoundTagExt.kt @@ -79,18 +79,6 @@ fun CompoundTag.mapString(index: String, mapper: (String) -> T, orElse: T): } } -@Suppress("unchecked_cast") // type is checked inside getList -fun CompoundTag.getByteList(key: String): MutableList = getList(key, Tag.TAG_BYTE.toInt()) as MutableList -@Suppress("unchecked_cast") // type is checked inside getList -fun CompoundTag.getShortList(key: String): MutableList = getList(key, Tag.TAG_SHORT.toInt()) as MutableList -@Suppress("unchecked_cast") // type is checked inside getList -fun CompoundTag.getIntList(key: String): MutableList = getList(key, Tag.TAG_INT.toInt()) as MutableList -@Suppress("unchecked_cast") // type is checked inside getList -fun CompoundTag.getLongList(key: String): MutableList = getList(key, Tag.TAG_LONG.toInt()) as MutableList -@Suppress("unchecked_cast") // type is checked inside getList -fun CompoundTag.getFloatList(key: String): MutableList = getList(key, Tag.TAG_FLOAT.toInt()) as MutableList -@Suppress("unchecked_cast") // type is checked inside getList -fun CompoundTag.getDoubleList(key: String): MutableList = getList(key, Tag.TAG_DOUBLE.toInt()) as MutableList @Suppress("unchecked_cast") // type is checked inside getList fun CompoundTag.getByteArrayList(key: String): MutableList = getList(key, Tag.TAG_BYTE_ARRAY.toInt()) as MutableList @Suppress("unchecked_cast") // type is checked inside getList