diff --git a/nova/src/main/kotlin/xyz/xenondevs/nova/util/data/NBTUtils.kt b/nova/src/main/kotlin/xyz/xenondevs/nova/util/data/NBTUtils.kt index 6fad829af7..991c87d5e5 100644 --- a/nova/src/main/kotlin/xyz/xenondevs/nova/util/data/NBTUtils.kt +++ b/nova/src/main/kotlin/xyz/xenondevs/nova/util/data/NBTUtils.kt @@ -16,9 +16,6 @@ import net.minecraft.nbt.StringTag import net.minecraft.nbt.Tag import net.minecraft.nbt.TagType import net.minecraft.world.item.ItemStack -import xyz.xenondevs.cbf.CBF -import xyz.xenondevs.nova.data.serialization.cbf.CBFCompoundTag -import xyz.xenondevs.nova.data.serialization.cbf.NamespacedCompound import java.util.stream.Stream object NBTUtils { @@ -75,12 +72,6 @@ object NBTUtils { return tag.stream().map { ItemStack.of(it as CompoundTag) } } - internal fun reserializeCBFCompoundTag(cbfTag: Any): CBFCompoundTag { - val toByteArrayMethod = cbfTag::class.java.getMethod("getAsByteArray") - val serializedCBFCompound = toByteArrayMethod.invoke(cbfTag) as ByteArray - return CBFCompoundTag(CBF.read(serializedCBFCompound)!!) - } - } @Suppress("UNCHECKED_CAST") @@ -99,48 +90,4 @@ fun CompoundTag.getOrNull(key: String): T? { return if (contains(key)) { get(key) as? T } else null -} - -internal fun CompoundTag.getOrPutCBFCompoundTag(key: String, defaultValue: () -> CBFCompoundTag): CBFCompoundTag { - var value = getCBFCompoundTag(key) - if (value != null) - return value - - value = defaultValue() - put(key, value) - - return value -} - -internal fun CompoundTag.getCBFCompoundTag(key: String): CBFCompoundTag? { - val tag = get(key) ?: return null - if (tag !is CBFCompoundTag) { - val newTag = NBTUtils.reserializeCBFCompoundTag(tag) - put(key, newTag) - return newTag - } - - return tag -} - -internal fun MutableMap.getCBFCompoundTag(key: String): CBFCompoundTag? { - val tag = get(key) ?: return null - if (tag !is CBFCompoundTag) { - val newTag = NBTUtils.reserializeCBFCompoundTag(tag) - put(key, newTag) - return newTag - } - - return tag -} - -internal fun MutableMap.getOrPutCBFCompoundTag(key: String, defaultValue: () -> CBFCompoundTag): CBFCompoundTag { - var value = getCBFCompoundTag(key) - if (value != null) - return value - - value = defaultValue() - put(key, value) - - return value } \ No newline at end of file diff --git a/nova/src/main/kotlin/xyz/xenondevs/nova/util/item/ItemUtils.kt b/nova/src/main/kotlin/xyz/xenondevs/nova/util/item/ItemUtils.kt index 744b37e306..41f3793bb8 100644 --- a/nova/src/main/kotlin/xyz/xenondevs/nova/util/item/ItemUtils.kt +++ b/nova/src/main/kotlin/xyz/xenondevs/nova/util/item/ItemUtils.kt @@ -44,10 +44,8 @@ import xyz.xenondevs.nova.util.bukkitMirror import xyz.xenondevs.nova.util.component.adventure.toAdventureComponent import xyz.xenondevs.nova.util.component.adventure.toJson import xyz.xenondevs.nova.util.data.NBTUtils -import xyz.xenondevs.nova.util.data.getCBFCompoundTag import xyz.xenondevs.nova.util.data.getOrNull import xyz.xenondevs.nova.util.data.getOrPut -import xyz.xenondevs.nova.util.data.getOrPutCBFCompoundTag import xyz.xenondevs.nova.util.get import xyz.xenondevs.nova.util.name import xyz.xenondevs.nova.util.nmsCopy @@ -208,8 +206,8 @@ var ItemStack.novaCompound: NamespacedCompound return handle.novaCompound val unhandledTags = backingItemMeta!!.unhandledTags - val tag = unhandledTags.getOrPutCBFCompoundTag("nova_cbf", ::CBFCompoundTag) as? CBFCompoundTag - return tag!!.compound + val tag = unhandledTags.getOrPut("nova_cbf", ::CBFCompoundTag) as CBFCompoundTag + return tag.compound } set(value) { val handle = handle @@ -226,19 +224,19 @@ val ItemStack.novaCompoundOrNull: NamespacedCompound? if (handle != null) return handle.novaCompoundOrNull - return backingItemMeta?.unhandledTags?.getCBFCompoundTag("nova_cbf")?.compound + return (backingItemMeta?.unhandledTags?.get("nova_cbf") as? CBFCompoundTag)?.compound } // // var MojangStack.novaCompound: NamespacedCompound - get() = orCreateTag.getOrPutCBFCompoundTag("nova_cbf", ::CBFCompoundTag).compound + get() = orCreateTag.getOrPut("nova_cbf", ::CBFCompoundTag).compound set(value) { orCreateTag.put("nova_cbf", CBFCompoundTag(value)) } val MojangStack.novaCompoundOrNull: NamespacedCompound? - get() = tag?.getCBFCompoundTag("nova_cbf")?.compound + get() = (tag?.get("nova_cbf") as? CBFCompoundTag)?.compound // //