Better Enchant Commands
以扩展附魔等级、简化语法、预设以及经过审计确认/撤销工作流,重写 /enchant、/give 及其相关命令,适用于 Minecraft 1.21.x。
原版 /enchant 拒绝非整数等级并在附魔所规定的上限处停止。原版 /give 需要冗长的组件语法才能赋予附魔物品。Better Enchant Commands 替换了这两个核心命令,并添加了一系列工作流程辅助功能,所有操作均限制在操作者等级 2 及以上,并由结构化的审计日志提供支持。
功能特性
/enchant — 突破原版附魔限制
作为原版 /enchant 的直接替代品。可将任何附魔应用于玩家手中物品,等级范围为 1–255。
/enchant @s minecraft:sharpness 255
/enchant aGamingGod minecraft:protection 10
/enchant list
/enchant list 会打印执行命令的玩家手中物品的附魔信息。
/give — 内联附魔语法
作为原版 /give 的直接替代品。在不使用附魔时,其用法与正常情况完全一致。追加一个可选的 enchantments: 块即可瞬间生成附魔物品:
/give @s minecraft:netherite_chestplate enchantments:protection:10,unbreaking:3
/give @s minecraft:diamond_sword 1 enchantments:sharpness:255,fire_aspect:5,looting:10
minecraft: 命名空间是可选的 —— 使用 sharpness:255 同样有效。无需 JSON、无需括号、无需引号。Tab 补全会将候选项过滤为仅与所选物品兼容的附魔。
/enchantpreset — 保存和重放附魔组合包
/enchantpreset save <name> — 保存当前手持物品的附魔
/enchantpreset apply <name> <targets>
/enchantpreset delete <name>
/enchantpreset list
名称需经过验证(长度 1–64 个字符,仅限 A–Z、a–z、0–9、_、-)。对于空手的目标将跳过处理,并在输出中报告。
/unenchant, /enchantinfo, /enchantlist
清理与检查辅助命令:
/unenchant <targets> — 移除所有附魔
/unenchant <targets> <enchantment> — 移除单一附魔
/enchantinfo — 查看手中物品的详细信息
/enchantlist [filter] — 注册表列表,可选择性进行过滤
/repair — 一条命令修复带有修补术的装备
发放任意物品的副本,并预先应用修补术(以及兼容情况下的耐久 III)。反射兼容性查找会在每个会话期间缓存,因此重复调用速度极快。
/enchants — 批量操作、撤销与配置
/enchants undo — 恢复你上一次的批量修改
/enchants confirm <token> — 完成受限的批量操作
/enchants status
/enchants allow_all_enchantments true|false
影响超过 confirmation_threshold 数量的目标的操作需要一个有时效性的令牌 —— 避免意外“给整个服务器都附魔”的事故。撤销功能是一个有界的每操作者双端队列(默认 8 条记录)。
设计亮点
- 安全失败验证。 附魔字符串在被解析为完全验证的
(Identifier, level) 对之前,不会触碰任何物品。解析失败时物品保持未修改状态。
- 结构化审计日志。 每个特权操作都会发送到专用的 SLF4J
[AUDIT] 日志记录器,其中包含经过清理的操作者、目标和标签字段 —— 可安全地路由到日志聚合管道。
- 防日志注入加固。 源自玩家输入的任何字符串在格式化入日志行之前,都会被剥离 ASCII 控制字符,以防止伪造或破坏审计条目(例如通过精心构造的记分板名称)。
- 有界批量修改。 影响目标数量超过
confirmation_threshold 的命令需要基于令牌的确认往返流程。
- 反射兼容性层。 权限检查、注册表查找和组件读取通过按类缓存的方法形状启发式解析,使得同一个 jar 包可以在 所有 1.21.x 小版本 上运行而无需重新编译。
- 零 Mixins。 纯 Fabric API 命令注册 —— 与其他模组实现最大程度的兼容。
- 仅服务端。 客户端无需安装此模组。
为什么选择 Better Enchant Commands?
- 直接替代。 直接覆盖原版
/enchant 和 /give;核心工作流程无需记忆新命令。
- 完全向后兼容。
/give @s diamond 64 的行为与原版完全一致。
- 轻量级。 约 105 KB,仅服务端,无 tick 钩子,无 mixins。
- 防崩溃。 每个代码路径均有防御性包装;格式错误的输入会给出有用的错误消息,绝不会导致服务器崩溃。
- 跨版本支持。 基于 1.21 基础构建 —— 可在所有 1.21.x 子版本上运行而无需重新编译。
- 预设驱动的工作流。 一次保存标准配置;通过一条命令将其应用到任意数量的玩家身上。
- 审计追踪。 操作者可以对其附魔了谁、附魔了什么以及何时进行的负责。
要求
- Minecraft 1.21.x(任意子版本)
- Fabric Loader 0.16.0+
- Fabric API
权限
所有命令均需 操作者等级 2,与原版 /enchant 和 /give 保持一致。
技术说明
Better Enchant Commands 直接写入物品堆栈上的 DataComponents.ENCHANTMENTS 组件,绕过了原版的等级验证,但强制执行自身的边界限制(1–255)。附魔的存储方式与原版完全相同 —— 没有自定义数据,也不会因其他模组读取你的物品而产生兼容性问题。
Better Enchant Commands
Override /enchant, /give, and friends with extended enchantment levels, simplified syntax, presets, and an audited confirmation/undo workflow for Minecraft 1.21.x.
Vanilla /enchant refuses non-integer levels and caps out where the enchantment says so. Vanilla /give needs verbose component syntax for enchanted items. Better Enchant Commands replaces the two core commands and adds a handful of workflow helpers, all gated behind op level 2 and backed by a structured audit log.
Features
/enchant — enchant beyond vanilla limits
Drop-in replacement for vanilla /enchant. Apply any enchantment to the item in a player's hand at levels 1–255.
/enchant @s minecraft:sharpness 255
/enchant aGamingGod minecraft:protection 10
/enchant list
/enchant list prints the enchantments on the held item of the player running the command.
/give — inline enchantment syntax
Drop-in replacement for vanilla /give. Works exactly like normal when used without enchantments. Append an optional enchantments: block for instant enchanted items:
/give @s minecraft:netherite_chestplate enchantments:protection:10,unbreaking:3
/give @s minecraft:diamond_sword 1 enchantments:sharpness:255,fire_aspect:5,looting:10
The minecraft: namespace is optional — sharpness:255 works. No JSON, no brackets, no quotes. Tab completion filters candidates to enchantments actually compatible with the chosen item.
/enchantpreset — save and replay enchantment bundles
/enchantpreset save <name> — save currently-held item's enchantments
/enchantpreset apply <name> <targets>
/enchantpreset delete <name>
/enchantpreset list
Names are validated (1–64 chars, A–Z, a–z, 0–9, _, -). Skipped empty-hand targets are reported in the output.
/unenchant, /enchantinfo, /enchantlist
Cleanup and inspection helpers:
/unenchant <targets> — strip all enchantments
/unenchant <targets> <enchantment> — strip one
/enchantinfo — full detail on held item
/enchantlist [filter] — registry listing, optionally filtered
/repair — mended gear in one command
Hands out a copy of any item with Mending (and Unbreaking III where compatible) pre-applied. The reflective compat lookup is cached per session so repeat invocations are fast.
/enchants — bulk operations, undo, and config
/enchants undo — restore your last bulk modification
/enchants confirm <token> — complete a gated bulk operation
/enchants status
/enchants allow_all_enchantments true|false
Operations over confirmation_threshold targets require a short-lived token — no more accidental "enchanted the entire server" incidents. Undo is a bounded per-operator deque (default 8 entries).
Design highlights
- Fail-safe validation. Enchantment strings parse into fully-validated
(Identifier, level) pairs before any item is touched. Parse failures leave items unmodified.
- Structured audit log. Every privileged action is emitted to a dedicated SLF4J
[AUDIT] logger with sanitised operator, target, and label fields — safe to route to a log-aggregation pipeline.
- Log-injection hardened. Any string originating from player input is stripped of ASCII control characters before being formatted into log lines, so a crafted scoreboard name can't forge or break audit entries.
- Bounded bulk modifications. Commands that affect more targets than
confirmation_threshold require a token-based confirmation round-trip.
- Reflective compatibility layer. Permission checks, registry lookups, and component reads resolve via method-shape heuristics cached per class, so the same jar runs across all 1.21.x minor versions without recompilation.
- Zero mixins. Pure Fabric API command registration — maximum compatibility with other mods.
- Server-side only. Clients don't need the mod installed.
Why Better Enchant Commands?
- Drop-in replacements. Overrides vanilla
/enchant and /give directly; no new commands to memorise for the core workflow.
- Fully backward compatible.
/give @s diamond 64 still works exactly like vanilla.
- Lightweight. ~105 KB, server-side only, no tick hooks, no mixins.
- Crash-proof. Every code path is defensively wrapped; malformed input gives helpful error messages, never a server crash.
- Cross-version. Built against 1.21 base — works on every 1.21.x subversion without recompilation.
- Preset-driven workflow. Save standard loadouts once; apply them to any number of players with one command.
- Audit trail. Operators can be held accountable for what they enchanted, for whom, and when.
Requirements
- Minecraft 1.21.x (any subversion)
- Fabric Loader 0.16.0+
- Fabric API
Permissions
All commands require operator level 2, matching vanilla /enchant and /give.
Technical notes
Better Enchant Commands writes directly to the DataComponents.ENCHANTMENTS component on item stacks, bypassing vanilla's level validation but enforcing its own bounds (1–255). Enchantments are stored exactly like vanilla ones — no custom data, no compatibility issues with other mods reading your items.
评论 0
登录后参与评分
还没有评论,来抢沙发吧