简介
众多 Minecraft 模组已在 2D 和 3D 环境中集成了功能性特性[1][2][3],但暴力方法往往效率低下。在这方面,我们推出了 Tetrachord Lib,这是一个轻量级的库模组,旨在优化各种数据结构。
相关工作
服务端优化模组
jellysquid3_[4] 推出了 Lithium,这是一款开创性的优化模组,增强了 Minecraft 服务器的各个方面。该模组采用精确算法来最小化区块和方块的访问,不仅提升了世界生成,还改善了生物 AI、碰撞检测、兴趣点(poi)发现以及其他关键方面,从而提高了计算效率并降低了服务器的每秒毫秒数(mspt)。
Spottedstar[5] 推出了 Starlight,这是一款创新模组,重新定义了 Minecraft 的光照引擎,以改善区块生成、方块放置和破坏时的性能。与 Phosphor[6] 不同,Starlight 并没有改变原版光照引擎系统——相反,它通过引入新算法对其进行了革新。
数据结构
KD 树[7] 是一种用于高维空间中存储和组织 k 维数据点的数据结构。作为二叉树,KD 树中的每个节点代表一个 k 维数据点,并根据数据点的特征值(维度)进行分区。KD 树特别适用于在高维数据集上进行范围查询和最近邻搜索,同时也有助于优化 Minecraft 世界中的数据检索。

线段树[8] 是一种用于处理范围更新和查询的数据结构。它将一个区间划分为更小的子区间,并以树状结构层次化地组织它们。线段树在更新和查询数据范围时非常高效。在表示为 3D 张量的 Minecraft 世界背景下,当涉及频繁的范围更新和查询时,使用线段树可以大幅提高性能。

实验
评估
Spark[9] 是一款轻量级性能分析模组,它可以显示模组的详细时间成本、内存和 CPU 使用情况、每秒毫秒数(mspt)以及客户端和服务器的其他性能指标。我们使用了 Spark,并选择时间成本和 mspt 作为指标来评估 Tetrachord Lib 的优化能力。
基准测试
我们实现了上述数据结构,并使用以下基准进行测试:
篝火周围无敌对生物
在特定场景中,当玩家点燃篝火时,周围几个方块半径内的区域将不再刷怪。原始模组[1] 提供的方法涉及多次方块访问,导致服务器 mspt 显著增加,从而拖慢游戏进程。我们选择利用 KD 树来实现这一需求。我们使用 Spark 分析器在不同参数设置下记录了 1 分钟的正常游戏进度,实验结果如下图所示:

信标附近的矿石方块增加经验掉落
考虑到玩家在靠近信标的地方挖掘方块时,可以根据被挖掘方块周围的矿石方块数量获得额外的经验奖励。下表说明了每种矿石方块对应的响应区域和“矿石分数”:
| 矿石类型 | Copper | Iron | Gold | Diamond | Netherite |
|---|---|---|---|---|---|
| 响应区域 | 5x5 | 9x9 | 13x13 | 17x17 | 19x19 |
| 矿石分数 | 1 | 1 | 1 | 2 | 3 |
我们使用 Spark 分析器在不同参数设置下记录了 32 次矿石方块放置和 32 次方块挖掘,实验结果如下图所示:

结论
实验表明,Tetrachord lib 在不同场景下都发挥了显著作用,并为实现 2D 和 3D 空间更新与查询的某些需求提供了一种高效的方式。
Tetrachord Lib 模组目前作为库运行,因此开发者可以将其作为依赖项来改进其模组性能。
参考文献
[1] Serilum. No Hostiles Around Campfire. Modrinth 2022.
[2] Serilum. Healing Campfire. Modrinth 2022.
[3] Mikul, chubbymomo, skinnymomo. Cold Sweat. Modrinth 2023.
[4] jellysquid3_. Lithium. Modrinth 2021.
[5] Spottedstar. Starlight. Modrinth 2021.
[6] jellysquid3_. Phosphor. Modrinth 2021.
[7] Jon Louis Bentley. Multidimensional binary search trees used for associative searching. Commun. ACM 18, 9 (Sept. 1975), 509–517.
[8] Jon Louis Bentley. Solutions to Klee's rectangle problems, Unpublished Manuscript, 1977.
[9] Iucko. Spark. Modrinth 2021.
Introduction
Numerous Minecraft mods have integrated functional features within both 2D and 3D environments[1][2][3], yet brute-force methods frequently prove inefficient. In this regard, we introduce Tetrachord Lib, a lightweight library modification designed to optimize diverse data structures.
Related Works
Server-side Optimization Mods
jellysquid3_[4] introduced Lithium, a groundbreaking optimization mod that enhances various facets of Minecraft servers. Employing precise algorithms to minimize chunk and block access, this mod enhances not only world generation but also AI for mobs, collision detection, discovery of points of interests (poi), and other crucial aspects to boost computational efficiency and decrease milliseconds per tick (mspt) of servers.
Spottedstar[5] introduced Starlight, an innovative modification that redefines the light engine of Minecraft to improve performance in chunk generation, block placement and destruction. In contrast to Phosphor[6], Starlight does not alter the vanilla light engine system - instead, it revolutionizes it by introducing a new algorithm.
Data Structures
The KD Tree[7] is a data structure utilized in high-dimensional spaces for the storage and organization of k-dimensional data points. Functioning as a binary tree, each node within the KD Tree represents a k-dimensional data point and is partitioned according to the feature values (dimensions) of the data point. KD trees are particularly well-suited for conducting range queries and nearest neighbor searches within high-dimensional datasets, and they can also contribute to optimizing data retrieval within the Minecraft world.

The Segment Tree[8] is a data structure utilized for handling range updates and queries. It divides a segment into smaller subsections and organizes them hierarchically in a tree structure. Segment trees are efficient for updating and querying data ranges. In the context of a Minecraft world represented as a 3D tensor, employing a segment tree can greatly improve performance when frequent range updates and queries are involved.

Experiments
Evaluation
Spark[9] is a lightweight performance profiler mod, which shows detailed time costs of mods, memory and CPU usage, milliseconds per tick (mspt) and other metrics of performance of clients and servers. We utilized Spark and chose time costs and mspt as metrics to evaluate the capability of optimization of Tetrachord Lib.
Benchmarks
We implemented the aforementioned data structures and conducted experiments using the following benchmarks:
No Hostiles around Campfire
In a specific scenario, when players light campfires, the surrounding areas within a radius of several blocks will no longer spawn monsters. The original mod[1] offers a brute-force method that involves multiple block accesses, leading to a significant increase in mspt on the server and slowing down the game program. We chose to utilize KD Tree to implement this requirement. We utilized Spark profiler to record 1 minute of normal game progress under different parameter setting, and the experimental results are shown in the following figure:

Ore Blocks near Beacon Increase Xp Drop
Considering the scenario where players mine blocks close to a beacon, they can receive an additional XP reward based on the number of ore blocks surrounding the mined block. The table below illustrates the response area and "ore score" associated with each type of ore block:
| Type of Ore | Copper | Iron | Gold | Diamond | Netherite |
|---|---|---|---|---|---|
| Response Area | 5x5 | 9x9 | 13x13 | 17x17 | 19x19 |
| Ore Score | 1 | 1 | 1 | 2 | 3 |
We utilized Spark profiler to record 32 ore block placing and 32 block mining under different parameter setting, and the experimental results are shown in the following figure:

Conclusion
Experiments show that Tetrachord lib plays an emphatic role in different situation, and provides a highly efficient way to implement some requirements on 2D and 3D space updates and queries.
Tetrachord Lib mod is currently working as a library, so developers can use it as a dependency to improve their mod performance.
References
[1] Serilum. No Hostiles Around Campfire. Modrinth 2022.
[2] Serilum. Healing Campfire. Modrinth 2022.
[3] Mikul, chubbymomo, skinnymomo. Cold Sweat. Modrinth 2023.
[4] jellysquid3_. Lithium. Modrinth 2021.
[5] Spottedstar. Starlight. Modrinth 2021.
[6] jellysquid3_. Phosphor. Modrinth 2021.
[7] Jon Louis Bentley. Multidimensional binary search trees used for associative searching. Commun. ACM 18, 9 (Sept. 1975), 509–517.
[8] Jon Louis Bentley. Solutions to Klee's rectangle problems, Unpublished Manuscript, 1977.
[9] Iucko. Spark. Modrinth 2021.
下载 Tetrachord Lib
需要联机服务器吗?
稳定流畅、一键部署,几分钟即可和朋友联机开服
最低仅需 8 元/月 即可畅快联机
下载 Tetrachord Lib
需要联机服务器吗?
稳定流畅、一键部署,几分钟即可和朋友联机开服
最低仅需 8 元/月 即可畅快联机
下载 Tetrachord Lib
需要联机服务器吗?
稳定流畅、一键部署,几分钟即可和朋友联机开服
最低仅需 8 元/月 即可畅快联机
下载 Tetrachord Lib
需要联机服务器吗?
稳定流畅、一键部署,几分钟即可和朋友联机开服
最低仅需 8 元/月 即可畅快联机
下载 Tetrachord Lib
需要联机服务器吗?
稳定流畅、一键部署,几分钟即可和朋友联机开服
最低仅需 8 元/月 即可畅快联机
下载 Tetrachord Lib
需要联机服务器吗?
稳定流畅、一键部署,几分钟即可和朋友联机开服
最低仅需 8 元/月 即可畅快联机
下载 Tetrachord Lib
下载 Tetrachord Lib
需要联机服务器吗?
稳定流畅、一键部署,几分钟即可和朋友联机开服
最低仅需 8 元/月 即可畅快联机
下载 Tetrachord Lib
需要联机服务器吗?
稳定流畅、一键部署,几分钟即可和朋友联机开服
最低仅需 8 元/月 即可畅快联机
下载 Tetrachord Lib
需要联机服务器吗?
稳定流畅、一键部署,几分钟即可和朋友联机开服
最低仅需 8 元/月 即可畅快联机
暂无更新日志
关于这个资源的讨论、问题反馈与使用心得
还没有讨论,来发第一帖吧
你是这个资源的作者?登录后可认领此资源。
相似资源
模组
缓冲的原始输入和线程化的事件轮询
模组
一个用于收集生物掉落物的多区块模组。
模组
显示你正在注视的方块的信息。(适用于 Minecraft 1.16+ 的 Hwyla/Waila 分支)
模组
原版世界生成优化模组
模组
查看物品与配方
模组
使用 JavaScript 编辑配方、添加自定义物品、编写世界事件!
评论 0
登录后参与评分
还没有评论,来抢沙发吧