返回顶部

[管理] [全版本]NBT-API - 添加自定义 NBT 标签或修改没有 NMS 的项目

[复制链接]
像素搬运菌Lv.7 显示全部楼层 发表于 2024-4-4 02:40:28 |阅读模式 打印 上一主题 下一主题 来自 亚太地区
服务器插件
中文名称:
英文名称: NBT-API
插件来源: 转载
适用服务端: CraftBukkit Spigot Paper Catserver Mohist Arclight 
插件类型: 前置API
语言支持: 中文 英文 
适用版本: 全版本 
前置插件/mod:
下载地址: https://modrinth.com/plugin/nbtapi
原贴地址:

马上登录/注册,结交更多好友,享用更多功能,让你轻松玩转社区。

您需要 登录 才可以下载或查看,没有账号?立即注册

x
NBT API 允许您将自定义 NBT 标签添加到 Itemstacks、TileEntities 和 Entities,或修改 excisting 标签!
它完全使用反射与 NMS 代码进行交互,并与所有最新版本一起使用。在服务器启动时,插件会检查所有反射。

在 Spigot 上测试

  • (1.7*)1.8.8-1.20.4
  • 1.7.10 Crucible
  • 在启动时,如果存在版本问题,您将收到通知!
* 1.7 注意:使用 R4 (1.7.10) 的 1.7,NBTLists 可能无法工作,使用 Gson 的所有内容都被禁用(在 NBTAPI 加载之前添加 Gson,以重新打开它),并且您无法获得 NBTTypes,因为 1.7 缺少此功能。显然 1.7 有一个错误,即项目可能会丢失其 nbt 数据。TLDR:1.7.10 有些损坏,由于 1.7.10 的限制/旧错误,并非所有内容都可以正常工作。



作为服务器所有者,我需要做什么?
只需下载 jar 并将其放入 plugins 文件夹即可。做。
请注意,过时的插件可能会要求“ItemNBTAPI”。在这种情况下,请从版本选项卡下载版本 1.8.3。过时的“ItemNBTAPI”和“NBTApi”可以同时使用。
对于版本 2.0.0 很重要:使用 NBTInjector 时不要重新加载。一般来说,重新加载是一件可怕的事情,它会以可怕的方式破坏 NBTInjector!更新插件/更改配置时,请始终正常重启服务器!

如何以开发者身份使用 API?
创建 NBT 包装机:
<span style="font-family: Consolas, "courier new", Courier, monospace; font-size: 13.3333px; text-wrap: nowrap; background-color: rgb(251, 251, 251);">NBTItem nbti = new NBTItem(item);</span>
<span style="font-family: Consolas, "courier new", Courier, monospace; font-size: 13.3333px; text-wrap: nowrap; background-color: rgb(251, 251, 251);">NBTEntity nbtent = new NBTEntity(zombie); //Only for vanilla tags!</span>
<span style="font-family: Consolas, "courier new", Courier, monospace; font-size: 13.3333px; text-wrap: nowrap; background-color: rgb(251, 251, 251);">NBTTileEntity tent = new NBTTileEntity(block.getState()); //Only for vanilla tags!</span>
<span style="font-family: Consolas, "courier new", Courier, monospace; font-size: 13.3333px; text-wrap: nowrap; background-color: rgb(251, 251, 251);">NBTFile file = new NBTFile(new File(getDataFolder(), "test.nbt"));</span>
<span style="font-family: Consolas, "courier new", Courier, monospace; font-size: 13.3333px; text-wrap: nowrap; background-color: rgb(251, 251, 251);">NBTContainer container =  new NBTContainer(json); //Parse in json</span>
添加/获取/覆盖 NBT 标签:
//Set
nbti.setString("Stringtest", "Teststring");
nbti.setInteger("Inttest", 42);
nbti.setDouble("Doubletest", 1.5d);
nbti.setBoolean("Booleantest", true);
//More are avaible!
//Get
nbti.getString("Stringtest");
nbti.getInteger("Inttest");
nbti.getDouble("Doubletest");
nbti.getBoolean("Booleantest");
//Get all Tags
nbti.getKeys();
//Check for an tag
nbti.hasKey("Key");
//Remove a tag
nbti.removeKey("Key");
//or
nbti.setString("Stringtest", null);
//Create NBTTagCombounds(Imagine folders)
nbti.addCompound("subtag");
//Get Compound
NBTCompound comp = nbti.getCompound("subtag");
//Get Compound parent(null at root)
comp.getParent();
//Save Objects via Gson
nbti.setObject("myobject", new SimpleJsonTestObject());
//Get Objects
SimpleJsonTestObject simpleObject = nbti.getObject("myobject", SimpleJsonTestObject.class);
//Merge the data from compound A into B (Like the /data merge command)
B.mergeCompound(A);
//Get the nbt as json
comp.asNBTString();

//Access/create lists
nbtent.getCompoundList("Attributes");
nbtent.getStringList("Attributes");
 
最后取回 Bukkit Itemstack(瓷砖/实体上的更改将直接发生):
nbti.getItem();
保存 NBTFile:
file.save();
关于切片/实体
的重要说明:从 1.14+ 开始,您可以使用 getPersistentDataContainer() (for NBT(Block)-Entities) 来保存自定义标签。

item-nbt-api-plugin-2.12.3.jar (1.02 MB, 下载次数: 3)

帖子地址: 

回复

使用道具 举报

您需要登录后才可以回帖 登录 | 立即注册

本版积分规则

像素世界 成立于2022年8月,是中国开发者开创的一个综合像素沙盒游戏交流社区,拥有稳定的开发维护及运营技术,提供长期交流需求。本社区开放了我的世界模组、地图、插件等资源交流版块,集中了大量资源为玩家和开发者提供了优质的游戏环境。
  • 官方B站

  • 微信公众号

  • 商务合作