Skip to content

Commit

Permalink
Experimental | Fix & Restructure and Move NBT
Browse files Browse the repository at this point in the history
NBT现已完全脱离对NMS的NBT的代理, 成为独立模块
  • Loading branch information
TheFloodDragon committed Aug 14, 2024
1 parent 0f71ae3 commit 33e662d
Show file tree
Hide file tree
Showing 54 changed files with 397 additions and 787 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -134,7 +134,7 @@ public Class<?> loadClass(String name, boolean resolve, boolean checkParents) th
private Class<?> findClassOrNull(String name) {
try {
return findClass(name);
} catch (ClassNotFoundException ignored) {
} catch (ClassNotFoundException | NoClassDefFoundError ignored) {
return null;
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ object JsonHandler {
// 目标值为 Compound 类型
is JsonObject -> (ownValue as? JsonObject)?.asMutable()
?.let { merge(it, targetValue, replace) }?.asImmutable() // 同类型合并
// 目标值为基础类型, 或者 List 类型
// 目标值为基础类型
else -> null
} ?: if (ownValue == null || replace) targetValue else return@forEach
}
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
package cn.fd.ratziel.module.item.api

import cn.fd.ratziel.module.item.nbt.NBTCompound
import cn.fd.ratziel.module.nbt.NBTCompound

/**
* ItemData - 物品数据
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
package cn.fd.ratziel.module.item.command

import cn.fd.ratziel.module.item.nbt.*
import cn.fd.ratziel.module.item.util.handleItemTag
import cn.fd.ratziel.module.nbt.*
import org.bukkit.entity.Player
import taboolib.common.platform.ProxyCommandSender
import taboolib.common.platform.ProxyPlayer
Expand Down Expand Up @@ -131,7 +131,7 @@ object NBTCommand {
*/
is NBTCompound -> {
var first = isFirst
nbt.toMapShallow().forEach { (shallow, value) ->
nbt.forEach { (shallow, value) ->
val deep = if (nodeDeep == null) shallow else nodeDeep + DeepVisitor.DEEP_SEPARATION + shallow // 深层节点的合成
if (!first) {
newLine(); repeat(level) { append(retractComponent) } // 缩进
Expand All @@ -149,13 +149,6 @@ object NBTCommand {
}
}

/**
* 转换成 Map 形式 (全部以浅层即一层节点表示)
*/
private fun NBTCompound.toMapShallow(source: Map<String, Any>? = this.sourceMap): Map<String, NBTData> = buildMap {
source?.forEach { shallow -> this[shallow.key] = NBTAdapter.adapt(shallow.value) }
}

/**
* 快捷创建键或值组件
*/
Expand Down Expand Up @@ -202,7 +195,7 @@ object NBTCommand {
*/
private fun asString(nbt: NBTData): String = when (nbt) {
is NBTString -> nbt.content
is NBTByte -> (NBTByte.adaptOrNull(nbt.content) ?: nbt.content).toString()
is NBTByte -> (NBTByte.parseBoolean(nbt.content) ?: nbt.content).toString()
is NBTInt -> nbt.content.toString()
is NBTFloat -> nbt.content.toString()
is NBTDouble -> nbt.content.toString()
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,9 +3,9 @@ package cn.fd.ratziel.module.item.impl
import cn.fd.ratziel.core.Identifier
import cn.fd.ratziel.core.IdentifierImpl
import cn.fd.ratziel.module.item.api.NeoItem
import cn.fd.ratziel.module.item.nbt.NBTCompound
import cn.fd.ratziel.module.item.nbt.NBTInt
import cn.fd.ratziel.module.item.nbt.NBTString
import cn.fd.ratziel.module.nbt.NBTCompound
import cn.fd.ratziel.module.nbt.NBTInt
import cn.fd.ratziel.module.nbt.NBTString
import cn.fd.ratziel.module.item.nms.ItemSheet
import cn.fd.ratziel.module.item.util.ComponentUtil

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,9 @@ import cn.fd.ratziel.core.IdentifierImpl
import cn.fd.ratziel.module.item.api.ItemData
import cn.fd.ratziel.module.item.api.NeoItem
import cn.fd.ratziel.module.item.impl.service.GlobalServiceManager
import cn.fd.ratziel.module.item.nbt.NBTCompound
import cn.fd.ratziel.module.item.nbt.NBTString
import cn.fd.ratziel.module.nbt.NBTCompound
import cn.fd.ratziel.module.nbt.NBTString
import cn.fd.ratziel.module.nbt.readString
import cn.fd.ratziel.module.item.nms.ItemSheet
import cn.fd.ratziel.module.item.nms.RefItemStack
import cn.fd.ratziel.module.item.util.handle
Expand Down Expand Up @@ -145,11 +146,11 @@ open class RatzielItem : NeoItem {
// 获取内部信息
val internal = data.read<NBTCompound>(INTERNAL_NODE) ?: return null
// 读取类型
val type = internal[INFO_TYPE.name] as? NBTString ?: return null
val type = internal.readString(INFO_TYPE.name) ?: return null
// 读取版本信息
val hash = internal[INFO_HASH.name] as? NBTString ?: return null
val hash = internal.readString(INFO_HASH.name) ?: return null
// 构造信息对象
return Info(type.content, hash.content)
return Info(type, hash)
}

/**
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ package cn.fd.ratziel.module.item.impl

import cn.fd.ratziel.module.item.api.ItemData
import cn.fd.ratziel.module.item.api.ItemMaterial
import cn.fd.ratziel.module.item.nbt.NBTCompound
import cn.fd.ratziel.module.nbt.NBTCompound

/**
* SimpleItemData
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,8 +7,8 @@ import cn.fd.ratziel.module.item.api.ItemMaterial
import cn.fd.ratziel.module.item.api.builder.ItemKSerializer
import cn.fd.ratziel.module.item.impl.component.*
import cn.fd.ratziel.module.item.impl.component.serializers.*
import cn.fd.ratziel.module.item.nbt.NBTData
import cn.fd.ratziel.module.item.nbt.NBTSerializer
import cn.fd.ratziel.module.nbt.NBTData
import cn.fd.ratziel.module.nbt.NBTSerializer
import kotlinx.serialization.DeserializationStrategy
import kotlinx.serialization.json.*
import kotlinx.serialization.modules.SerializersModule
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ import cn.fd.ratziel.module.item.impl.BukkitMaterial
import cn.fd.ratziel.module.item.impl.SimpleItemMaterial
import cn.fd.ratziel.module.item.impl.component.util.SkullData
import cn.fd.ratziel.module.item.impl.component.util.SkullUtil
import cn.fd.ratziel.module.item.nbt.NBTInt
import cn.fd.ratziel.module.nbt.NBTInt
import cn.fd.ratziel.module.item.nms.ItemSheet
import cn.fd.ratziel.module.item.nms.RefItemMeta
import cn.fd.ratziel.module.item.nms.RefItemStack
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,8 +7,8 @@ import cn.fd.ratziel.common.message.MessageComponent
import cn.fd.ratziel.core.serialization.EnhancedList
import cn.fd.ratziel.module.item.api.ItemData
import cn.fd.ratziel.module.item.api.builder.ItemTransformer
import cn.fd.ratziel.module.item.nbt.NBTList
import cn.fd.ratziel.module.item.nbt.NBTString
import cn.fd.ratziel.module.nbt.NBTList
import cn.fd.ratziel.module.nbt.NBTString
import cn.fd.ratziel.module.item.nms.ItemSheet
import cn.fd.ratziel.module.item.util.read
import cn.fd.ratziel.module.item.util.write
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,9 +4,9 @@ package cn.fd.ratziel.module.item.impl.component

import cn.fd.ratziel.module.item.api.ItemData
import cn.fd.ratziel.module.item.api.builder.ItemTransformer
import cn.fd.ratziel.module.item.nbt.NBTByte
import cn.fd.ratziel.module.item.nbt.NBTCompound
import cn.fd.ratziel.module.item.nbt.NBTInt
import cn.fd.ratziel.module.nbt.NBTByte
import cn.fd.ratziel.module.nbt.NBTCompound
import cn.fd.ratziel.module.nbt.NBTInt
import cn.fd.ratziel.module.item.nms.ItemSheet
import cn.fd.ratziel.module.item.util.read
import cn.fd.ratziel.module.item.util.write
Expand Down Expand Up @@ -48,11 +48,11 @@ data class ItemDurability(
// 无法破坏部分的特殊处理
if (MinecraftVersion.majorLegacy >= 12005) {
if (component.unbreakable == true && data.tag[ItemSheet.UNBREAKABLE.name] == null) {
data.tag.put(ItemSheet.UNBREAKABLE.name, NBTCompound())
data.tag[ItemSheet.UNBREAKABLE.name] = NBTCompound()
} else {
data.tag.remove(ItemSheet.UNBREAKABLE.name)
}
} else data.tag[ItemSheet.UNBREAKABLE.name] = component.unbreakable?.let { NBTByte(it) }
} else component.unbreakable?.let { data.tag[ItemSheet.UNBREAKABLE.name] = NBTByte(it) }
}

override fun detransform(data: ItemData): ItemDurability = ItemDurability().apply {
Expand All @@ -61,7 +61,7 @@ data class ItemDurability(
// 无法破坏部分的特殊处理
val unsure = data.tag[ItemSheet.UNBREAKABLE.name]
if (MinecraftVersion.majorLegacy >= 12005) this.unbreakable = unsure != null
else if (unsure != null) this.unbreakable = NBTByte.adapt((unsure as NBTByte).content)
else if (unsure != null) this.unbreakable = NBTByte.parseBooleanOrFalse((unsure as NBTByte).content)
}

}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ package cn.fd.ratziel.module.item.impl.component
import cn.fd.ratziel.module.item.api.ItemData
import cn.fd.ratziel.module.item.api.ItemMaterial
import cn.fd.ratziel.module.item.api.builder.ItemTransformer
import cn.fd.ratziel.module.item.nbt.NBTCompound
import cn.fd.ratziel.module.nbt.NBTCompound
import kotlinx.serialization.Contextual
import kotlinx.serialization.ExperimentalSerializationApi
import kotlinx.serialization.Serializable
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ package cn.fd.ratziel.module.item.impl.component

import cn.fd.ratziel.module.item.api.ItemData
import cn.fd.ratziel.module.item.api.builder.ItemTransformer
import cn.fd.ratziel.module.item.nbt.NBTInt
import cn.fd.ratziel.module.nbt.NBTInt
import cn.fd.ratziel.module.item.nms.ItemSheet
import cn.fd.ratziel.module.item.nms.RefItemMeta
import cn.fd.ratziel.module.item.util.read
Expand Down

This file was deleted.

This file was deleted.

This file was deleted.

Loading

0 comments on commit 33e662d

Please sign in to comment.