MekDefender
一款针对 Minecraft 1.21.1 + Mekanism 的 NeoForge 服务器保护模组。
一个 mekdefender 项目和一个 JAR 提供:
- 针对锚升级机器(Anchor Upgrade machines)和维度稳定器(Dimensional Stabilizer)的所有者感知区块加载;
- 针对四种已验证安全的 Mekanism S2C 有效载荷的有界最新状态同步。
区块加载策略
当所有者登出时,Mekanism 会立即或在配置的宽限期内释放其加载票证。登录恢复受到节流限制。默认情况下,无所有者的加载器会被禁用;无所有者/离线的维度稳定器也会跳过其能量消耗。
MekDefender 不拥有票证控制器或 Mekanism 保存格式。票证更改仍使用 Mekanism 的代码。唯一隔离的缓存文件是
world/data/mekdefender_loaders.dat(所有者到加载器位置)。移除该模组将移除其 Mixins,Mekanism 将恢复其正常行为;孤立的缓存将被忽略。
Mek 同步安全边界
仅以下可替换的绝对状态通道可以合并:
mekanism:update_tile
mekanism:network_scale
mekanism:fluid_network
mekanism:chemical_network
QIO、运输机、GUI/容器/物品栏、配置、安全、装备、玩家数据、C2S、Vanilla、未知有效载荷以及混合捆绑包均原样通过。有效载荷分类、Mekanism Mixin 调用契约、注入点、跟踪重新验证、实时对象解析和故障开放行为是固定的安全规则,而非管理员配置。
字节预算从 Minecraft 数据包编码器在压缩、封装和加密之前产生的实际 S2C 数据包大小中学习。每个通道都维护一个 EWMA(指数加权移动平均);initialEstimatedBytes 仅在真实样本到达之前使用。如果学习到的大小超过配置的突发阈值,则预算充电将限制在该突发值以内,以防止最新状态永远被延迟。诊断信息保留原始的 EWMA。字节遥测是可选的,从不参与取消原始 Mekanism 发送的决策。
默认同步模式为 OBSERVE,它记录统计数据但不会取消 Mekanism 的发送。在检查兼容性和统计数据后,使用 /mekdefender mode enforce 进行内存运行时覆盖。当模式或通道被禁用时,已被接受的最终状态会安全地排空。
统一配置
唯一的配置文件在游戏/服务器实例生成于:
config/mekdefender-server.toml
它使用 schemaVersion = 2 并包含:
chunkLoading.*:所有者策略、宽限期、登录重载预算和调试日志;
sync.channels.<channel>.*:独立的启用、间隔、截止时间和字节估算;
sync.budget.*:按玩家/全局的有效载荷和估计字节令牌预算;
sync.scheduler.*:队列、捆绑包、源工作、纪元、间隔和过期限制;
sync.pressure.*:软/临界压力和恢复阈值;
sync.circuitBreaker.*:有界的内部故障窗口和安全回退模式;
sync.metrics.*:热点/时间窗口、实际编码字节 EWMA 和真实客户端 A/B 默认值;
logging.* 和 permissions.*:冷却/转换日志以及读取/管理 OP 级别。
加载和重载是原子操作。未知的部分或键、重复声明、无效类型、超出范围的值、错误的架构以及相互矛盾的跨字段值会导致整个重载失败并显示行号错误;之前的实时快照保持活动状态。
游戏命令
/mekdefender status [compact|verbose]
/mekdefender compatibility
/mekdefender top [seconds] [limit]
/mekdefender channel <tile|scale|fluid|chemical>
/mekdefender player <name>
/mekdefender config <show|validate>
/mekdefender ab <status|start <seconds>|cancel>
/mekdefender mode <off|observe|enforce>
/mekdefender reload
/mekdefender resetstats
状态和通道输出将源请求/替换/物化与接收者入队/替换/发送单元分开。因此,显示的源和接收者缩减百分比是同类型单元的比率。configuredMode 和内存中的 runtimeMode 分别显示。读取和修改的 OP 级别独立配置。
/mekdefender ab start <seconds> 需要配置数量的真实非 FakePlayer 客户端(默认为两个)。它会预热并测量相等的 OBSERVE 和 ENFORCE 窗口,然后恢复之前的运行时模式。报告比较实际的预压缩编码 S2C 字节和数据包、平均/P95 MSPT、派生 TPS 以及平均/P95 玩家延迟。预热期间的流量被排除在内;如果客户端数量低于配置的最小值或某个阶段没有安全的 Mek 流量,则比较无效。
对于每个阶段的 30 分钟窗口(加上预热大约一小时),让两个客户端保持在同一条代表性路线上并运行:
/mekdefender ab start 1800
如果在电路断路器窗口内执行期间发生配置数量的内部调度器/钩子故障,优化器将切换到配置的安全模式并停止接受新工作。已被接受的最终状态仍然会排空。管理员必须显式运行模式命令来清除断路器并重新启用强制执行。
在持续的套接字压力下,流体和化学绝对状态更新保留优先级,而方块和比例更新保持有界且采用最新写入优先。它们在恢复后以其最新状态恢复;这保护了服务器,但不是严格的实时交付保证。
测量的优化效果
最终集成 JAR 在 Youer 1.21.1-4a57297f 上使用 NeoForge 21.1.241、Mekanism 10.7.19.85 进行了测试,世界包含活动的 Mekanism 缓冲网络,以及两个固定的 FakePlayer 接收者:
sourceRequested=25005
sourceReplaced=24981
payloadMaterialized=24
recipientSent=48
players=24/24
schedulerP95Ms=0.1887
networkIndexRebuilds=7
networkIndexScanned=21
networkIndexHits=72
failOpen=0
这是 99.904% 的源合并率:
24,981 / 25,005 = 99.904%。在仅有两名接收者的情况下,相同的受控工作负载会产生 50,010 次未合并的接收者发送;MekDefender 仅发送了 48 次,对于该固定测试拓扑结构而言,同样实现了 99.904% 的降低幅度。该结果展示了在高重复性网络工作负载下的优化路径;这并非普遍适用的降低保证。实际生产环境的节省取决于更新重复度、配置的间隔、追踪的玩家数量以及实际的机器/网络活动。请使用上述的真实客户端 A/B 命令来测量特定服务器。
构建与测试
需要 JDK 21:
./gradlew test build integrationTestJar
发布产物为 build/libs/mekdefender-1.2.0.jar。
mekdefender-1.2.0-integration-test.jar 是一个独立的临时世界测试变体,不会包含在发布 JAR 中。
构建过程会从 ModMaven 下载 mekanism:Mekanism:1.21.1-10.7.19.85 作为可重现的编译/测试基线。该产物不限制运行时兼容性,且 Mekanism 并未打包在 MekDefender 中。开发服务器运行还需要将正在测试的 Mekanism 构建放入 run/mods/ 中。
属性门控测试套件:
-Dmekdefender.integrationTest=true:拥有者在线/离线状态,能量和登录恢复;
-Dmekdefender.syncIntegrationTest=true:双 FakePlayer Mek 同步调度器压力测试。
兼容性
- Minecraft 1.21.1
- NeoForge 21.1.194 或更高版本(1.21.1 系列)
- 适用于 Minecraft 1.21.1 且保留所需 Mixin 合约的 Mekanism 构建
- Java 21
共享的兼容性插件仅检查由区块加载和同步 Mixins 转换的方法、字段和调用站点。无关的 Mekanism 字节码更改保持兼容。兼容性按功能报告:缺失的转换合约仅禁用该功能,并使其保持透传行为。参考构建使用 Mekanism 10.7.19.85 进行了测试,并在纯 NeoForge 21.1.241 开发服务器中也进行了冒烟测试,而不仅仅是 Youer;正式的生产环境验收仍需提供发布 JAR 和在代表性负载下的真实客户端。
MekDefender
A NeoForge server protection mod for Minecraft 1.21.1 + Mekanism.
One mekdefender project and one JAR provide:
- owner-aware chunk loading for Anchor Upgrade machines and the Dimensional Stabilizer;
- bounded latest-state synchronization for four proven-safe Mekanism S2C payloads.
Chunk-loading policy
When an owner logs out, Mekanism releases their loader tickets immediately or after the configured
grace period. Login recovery is throttled. An ownerless loader is disabled by default; an
ownerless/offline Dimensional Stabilizer also skips its energy drain.
MekDefender does not own a ticket controller or a Mekanism save format. Ticket changes still use
Mekanism's code. The only isolated saved cache is
world/data/mekdefender_loaders.dat (owner to loader positions). Removing this mod removes its
mixins and Mekanism resumes its normal behavior; the orphaned cache is ignored.
Mek synchronization safety boundary
Only these replaceable absolute-state channels may be coalesced:
mekanism:update_tile
mekanism:network_scale
mekanism:fluid_network
mekanism:chemical_network
QIO, transporter, GUI/container/inventory, configuration, security, equipment, player data, C2S,
vanilla, unknown payloads, and mixed bundles pass through unchanged. Payload classification,
Mekanism Mixin call contracts, injection points, tracking revalidation, live-object
resolution and fail-open behavior are fixed safety rules, not administrator configuration.
Byte budgets learn from the actual S2C packet sizes produced by Minecraft's packet encoder before
compression, framing and encryption. Each channel keeps an EWMA; initialEstimatedBytes is used
only until real samples arrive. If a learned size exceeds a configured burst, budget charging is
capped at that burst so the latest state cannot be deferred forever. Diagnostics retain the raw
EWMA. Byte telemetry is optional and never participates in the decision to cancel an original
Mekanism send.
The default sync mode is OBSERVE, which records statistics without cancelling Mekanism sends.
Use /mekdefender mode enforce for an in-memory runtime override after checking compatibility and
statistics. Already accepted final states drain safely when the mode or a channel is disabled.
Unified configuration
The only configuration file is generated for the game/server instance at:
config/mekdefender-server.toml
It uses schemaVersion = 2 and contains:
chunkLoading.*: owner policy, grace period, login reload budget and debug logging;
sync.channels.<channel>.*: independent enable, interval, deadline and byte estimate;
sync.budget.*: per-player/global payload and estimated-byte token budgets;
sync.scheduler.*: queue, bundle, source-work, epoch, interval and overdue limits;
sync.pressure.*: soft/critical pressure and recovery thresholds;
sync.circuitBreaker.*: bounded internal-failure window and safe fallback mode;
sync.metrics.*: hotspot/timing windows, actual encoded-byte EWMA and real-client A/B defaults;
logging.* and permissions.*: cooldown/transition logging and read/admin OP levels.
Loading and reloading are atomic. Unknown sections or keys, duplicate declarations, invalid types,
out-of-range values, a wrong schema and contradictory cross-field values reject the whole reload
with a line-numbered error; the previous live snapshot remains active.
Game commands
/mekdefender status [compact|verbose]
/mekdefender compatibility
/mekdefender top [seconds] [limit]
/mekdefender channel <tile|scale|fluid|chemical>
/mekdefender player <name>
/mekdefender config <show|validate>
/mekdefender ab <status|start <seconds>|cancel>
/mekdefender mode <off|observe|enforce>
/mekdefender reload
/mekdefender resetstats
Status and channel output split source requests/replacements/materialization from recipient
enqueue/replacement/send units. The displayed source and recipient reduction percentages are
therefore ratios of like units. configuredMode and the in-memory runtimeMode are shown
separately. The read and mutation OP levels are independently configurable.
/mekdefender ab start <seconds> requires the configured number of real, non-FakePlayer clients
(two by default). It warms and measures equal OBSERVE and ENFORCE windows, then restores the
previous runtime mode. The report compares actual pre-compression encoded S2C bytes and packets,
average/p95 MSPT, derived TPS, and average/p95 player latency. Traffic during warm-up is excluded;
a client count below the configured minimum or a phase with no safe Mek traffic marks the
comparison invalid.
For a 30-minute window per phase (about one hour plus warm-ups), keep both clients on the same
representative route and run:
/mekdefender ab start 1800
If the configured number of internal scheduler/hook failures occurs inside the circuit-breaker
window while enforcing, the optimizer switches to the configured safe mode and stops accepting
new work. Already accepted final states still drain. An administrator must explicitly run a mode
command to clear the breaker and re-enable enforcement.
During sustained socket pressure, fluid and chemical absolute-state updates retain priority while
tile and scale updates remain bounded and latest-write-wins. They resume with their newest state
after recovery; this protects the server but is not a strict real-time delivery guarantee.
Measured optimization effect
The final integration JAR was tested on Youer 1.21.1-4a57297f with NeoForge 21.1.241,
Mekanism 10.7.19.85, a world containing live Mekanism buffered networks, and two fixed
FakePlayer recipients:
sourceRequested=25005
sourceReplaced=24981
payloadMaterialized=24
recipientSent=48
players=24/24
schedulerP95Ms=0.1887
networkIndexRebuilds=7
networkIndexScanned=21
networkIndexHits=72
failOpen=0
This is a 99.904% source coalescing rate:
24,981 / 25,005 = 99.904%. With exactly two recipients, the same controlled workload would
have produced 50,010 uncoalesced recipient sends; MekDefender sent 48, also a 99.904% reduction
for that fixed test topology. The result demonstrates the optimization path under a repeat-heavy
network workload; it is not a universal reduction guarantee. Real production savings depend on
update repetition, configured intervals, tracking players and actual machine/network activity.
Use the real-client A/B command above to measure a specific server.
Building and tests
Requires JDK 21:
./gradlew test build integrationTestJar
The release artifact is build/libs/mekdefender-1.2.0.jar.
mekdefender-1.2.0-integration-test.jar is a separate disposable-world test variant and is never
included in the release JAR.
The build downloads mekanism:Mekanism:1.21.1-10.7.19.85 from ModMaven as a reproducible
compile/test baseline. That artifact does not restrict runtime compatibility, and Mekanism is not
bundled in MekDefender. Development server runs additionally need the Mekanism build under test in
run/mods/.
Property-gated test harnesses:
-Dmekdefender.integrationTest=true: owner online/offline, energy and login recovery;
-Dmekdefender.syncIntegrationTest=true: dual-FakePlayer Mek sync scheduler stress.
Compatibility
- Minecraft 1.21.1
- NeoForge 21.1.194 or newer in the 1.21.1 line
- A Mekanism build for Minecraft 1.21.1 that retains the required Mixin contracts
- Java 21
A shared compatibility plugin checks only the methods, fields and invocation sites transformed by
the chunk-loading and synchronization Mixins. Unrelated Mekanism bytecode changes remain
compatible. Compatibility is reported per feature: a missing transformation contract disables
only that feature and leaves it in pass-through behavior. The reference build was tested with
Mekanism 10.7.19.85 and was also smoke-tested in a pure NeoForge 21.1.241 development server, not
only Youer; formal production acceptance still requires the release JAR and real clients under
representative load.
评论 0
登录后参与评分
还没有评论,来抢沙发吧