From 2135d96c878221d11b6a3ff734f279f72d704525 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E5=98=BF=E9=B9=B0?= Date: Thu, 11 Jul 2024 10:31:55 +0800 Subject: [PATCH] [nms-tag] update itemTagReader MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit inline itemTagReader 获取到 NBT 时可以直接返回 返回 Reader --- .../main/kotlin/taboolib/module/nms/ItemTagReader.kt | 10 ++++++---- 1 file changed, 6 insertions(+), 4 deletions(-) diff --git a/module/module-nms-util-tag/src/main/kotlin/taboolib/module/nms/ItemTagReader.kt b/module/module-nms-util-tag/src/main/kotlin/taboolib/module/nms/ItemTagReader.kt index 8b2f060fb..ab5b12c02 100644 --- a/module/module-nms-util-tag/src/main/kotlin/taboolib/module/nms/ItemTagReader.kt +++ b/module/module-nms-util-tag/src/main/kotlin/taboolib/module/nms/ItemTagReader.kt @@ -23,14 +23,16 @@ fun ItemStack?.ifAir(): ItemStack? { * * 注: 如果修改了ItemTag 需要使用 write 设置回去 */ -fun ItemTag.reader(reader: ItemTagReader.() -> Unit) { +inline fun ItemTag.reader(reader: ItemTagReader.() -> Unit): ItemTagReader { val itemTagReader = ItemTagReader(this) reader.invoke(itemTagReader) + return itemTagReader } -fun ItemStack?.itemTagReader(reader: ItemTagReader.() -> Unit) { - val item = this.ifAir() ?: return - item.getItemTag().reader(reader) +inline fun ItemStack?.itemTagReader(reader: ItemTagReader.() -> Unit): ItemTagReader? { + val item = this.ifAir() ?: return null + return item.getItemTag().reader(reader) + } data class ItemTagReader(var itemTag: ItemTag) {