一个用于向区块添加自定义数据的模组,无需编写自定义数据包、事件处理、加载钩子等繁琐操作。
根据 LGPLv3 许可证授权
最初由 FalsePattern 开发
模组标志由 Houstonruss 设计
目标
旨在提供一种无需修改任何原版类即可向区块添加自定义数据的方法。API 还将提供实现自定义数据序列化/反序列化的简便方法,适用于网络传输和 NBT 格式。可选目标是提供为自定义数据注册 DFU(数据修复器)的方法,但这并非优先事项。
非目标
除了保存/加载和网络代码外,本模组不提供任何形式的回调/钩子系统。任何额外的行为都应在使用 ChunkAPI 的模组中自行实现。
API 不提供存储功能,用户需自行实现存储系统。一个好的示例是使用 Mixin 向区块类添加字段,并利用该字段来存储数据。
动机
修改区块数据包涉及不兼容地修改网络数据包、区块类以及安格尔区块加载器,这对于一个简单的功能来说工作量巨大。本模组提供了一种向区块添加自定义数据的方法,而无需你自己修改任何原版类。
API 和规范
API 提供了向区块添加自定义数据的方法,以及为数据注册自定义序列化器的方法。
ChunkDataManager
ChunkDataManager 本身是用于管理注册的主要类,但它本身不实现功能。为此,你需要使用包含在 ChunkDataManager 类中的 PacketDataManager、ChunkNBTDataManager 和 SectionNBTDataManager 接口。
ChunkDataManager.PacketData
此接口用于将数据从服务器同步到客户端。如果你的数据仅需要在服务器上存在,你可以自由跳过实现此接口。
ChunkDataManager.ChunkNBTData
此接口用于从区块 NBT 中保存/加载数据。如果你希望在世界重载之间保留持久数据,这是必需的。注意,如果你在区块中按块存储数据,应改用 SectionNBTData,因为它是针对内部区块格式设计的。
ChunkDataManager.SectionNBTData
此接口与 ChunkNBTData 基本相同,但专为在区块中按块存储数据而设计。它不是每个区块调用一次,而是每个区块段(16x16x16 个方块,即 ExtendedBlockStage 类)调用一次。
ChunkDataRegistry
这是你实际注册管理器的地方。你需要在 init 阶段内完成所有注册。你也可以通过调用 disableDataManager 禁用特定的管理器 ID,但不推荐这样做,仅在你清楚自己在做什么的情况下才使用。你需要在 postInit 阶段内完成所有禁用操作。
数据包规范
ChunkAPI 修改了 S21PacketChunkData 和 S26PacketMapChunkBulk 原版数据包,并覆盖了它们的默认格式。
下表中的所有大小均以字节为单位指定。
S21PacketChunkData 新格式:
| 大小 (字节) | 数据类型 | 名称 |
|---|---|---|
| 4 | int | X 坐标 |
| 4 | int | Z 坐标 |
| 1 | bool | 强制更新 |
| 2 | short | ExtendedBlockStorage 掩码 |
| 4 | int | 未压缩数据长度 |
| 4 | int | (n) 压缩数据长度 |
| n | byte[n] | 压缩数据 |
S26PacketMapChunkBulk 新格式:
| 大小 (字节) | 数据类型 | 名称 |
|---|---|---|
| 2 | short | (n) 数据包中的区块数量 |
| n * 4 | int[n] | 未压缩区块数据长度 |
| 4 | int | (m) 压缩数据长度 |
| 1 | 1 | 包含天空光数据 |
| m | byte[m] | 压缩数据 |
| n * 10 | (int, int, short)[n] | 区块头部 (x, z, ebs 掩码) |
在这两种情况下,压缩数据均通过 ChunkDataRegistryImpl.writeToBuffer 方法填充。此数据的布局如下:
| 大小 (字节) | 数据类型 | 名称 |
|---|---|---|
| 4 | int | (n) 管理器数量 |
| n * varying | MGRData | 管理器数据 |
管理器数据:
| 大小 (字节) | 数据类型 | 名称 |
|---|---|---|
| 4 | int | (n) 管理器名称长度 |
| n | UTF-8 str | 管理器名称 |
| 4 | int | (m) 管理器数据长度 |
| m | byte[m] | 管理器数据 |
依赖项
A mod for adding custom data to chunks without the hassle of writing custom packets, event handling, loading hooks, and more.
Licensed under the LGPLv3 license
Originally developed by FalsePattern
Mod logo by Houstonruss
Goals
It is a goal to provide a way to add custom data to chunks without having to modify any vanilla classes. The API will also provide a simple way to implement the custom serialization/deserialization of the data, both for the networking and the NBT format. An optional goal is to provide a way to register DFUs for the custom data, but this is not a priority.
Non-Goals
It is not a goal to provide any kind of callback/hook system for anything except saving/loading and netcode, any kind of extra behavior should be implemented in the mod using ChunkAPI.
Storage is not provided by the API, the user is expected to implement their own storage system. A good example is using a mixin to add a field to the chunk class, and using that field to store the data.
Motivation
Modifying chunk packet data involved incompatibly modifying network packets, the chunk class, and the anvil chunk loader, which is a lot of work for a simple feature. This mod provides a way to add custom data to chunks without having to modify any of the vanilla classes yourself.
API and spec
The API exposes a way to add custom data to chunks, and a way to register custom serializers for the data.
ChunkDataManager
The ChunkDataManager itself is the primary class used for managing registrations, but does not implement functionality
by itself. For that, you need to use the PacketDataManager, ChunkNBTDataManager, and SectionNBTDataManager
interfaces included inside the ChunkDataManager class.
ChunkDataManager.PacketData
This interface is used for synchronizing data from the server to the client. If your data is only required on the server, you can freely skip implementing this interface.
ChunkDataManager.ChunkNBTData
This interface is used for saving/loading data from the chunk NBT. This is required if you want to keep persistent data
across world reloads. Note, if you store data per block in the chunk, you should use SectionNBTData instead, as it
is designed with the internal chunk format in mind.
ChunkDataManager.SectionNBTData
This interface is mostly identical to ChunkNBTData, but is designed for storing data per block in the chunk.
Instead of being called once per chunk, it is called once per chunk section (16x16x16 blocks, ExtendedBlockStage class).
ChunkDataRegistry
This is where you actually register your manager. You need to do all registrations inside the init phase.
You can also disable specific manager IDs by calling disableDataManager, but this is not recommended, and should
only be used if you know what you are doing. You need to do all the disabling inside the postInit phase.
Packet specification
ChunkAPI modifies the S21PacketChunkData and S26PacketMapChunkBulk vanilla packets, and overwrites their default formats.
All sizes in the tables below are specified in bytes.
S21PacketChunkData new format:
| Size (bytes) | Datatype | Name |
|---|---|---|
| 4 | int | X position |
| 4 | int | Z position |
| 1 | bool | Force Update |
| 2 | short | ExtendedBlockStorage mask |
| 4 | int | Uncompressed data length |
| 4 | int | (n) Compressed data length |
| n | byte[n] | Compressed data |
S26PacketMapChunkBulk new format:
| Size (bytes) | Datatype | Name |
|---|---|---|
| 2 | short | (n) Chunk count in packet |
| n * 4 | int[n] | Uncompressed chunk data lengths |
| 4 | int | (m) Compressed data length |
| 1 | 1 | Contains skylight data |
| m | byte[m] | Compressed data |
| n * 10 | (int, int, short)[n] | Chunk Headers (x, z, ebs mask) |
In both cases, the compressed data is populated through the ChunkDataRegistryImpl.writeToBuffer method. The layout of this data is as follows:
| Size (bytes) | Datatype | Name |
|---|---|---|
| 4 | int | (n) Manager count |
| n * varying | MGRData | Manager data |
Manager data:
| Size (bytes) | Datatype | Name |
|---|---|---|
| 4 | int | (n) Manager name length |
| n | UTF-8 str | Manager name |
| 4 | int | (m) Manager data length |
| m | byte[m] | Manager data |
Dependencies
下载 ChunkAPI
下载 ChunkAPI
下载 ChunkAPI
下载 ChunkAPI
下载 ChunkAPI
下载 ChunkAPI
下载 ChunkAPI
下载 ChunkAPI
下载 ChunkAPI
下载 ChunkAPI
关于这个资源的讨论、问题反馈与使用心得
还没有讨论,来发第一帖吧
你是这个资源的作者?登录后可认领此资源。
相似资源
模组
一个用于收集生物掉落物的多区块模组。
模组
显示你正在注视的方块的信息。(适用于 Minecraft 1.16+ 的 Hwyla/Waila 分支)
模组
查看物品与配方
模组
使用 JavaScript 编辑配方、添加自定义物品、编写世界事件!
模组
适用于 MC 1.18+ 的 Effekseer 加载器
模组
添加区块认领和玩家组队功能,并与 Xaero's Minimap 和 World Map 集成
评论 0
登录后参与评分
还没有评论,来抢沙发吧