Create Recipe Hooks
Create Recipe Hooks 是适用于 Minecraft 1.20.1(Forge 和 Fabric)的服务端库,当 Create 模组中的机器完成配方处理或处理世界方块时触发相应事件:包括钻头采矿、收割机收割以及锯子砍伐树木。它提供了一个统一的 API,使集成类模组——例如任务书、自动化脚本和分析工具——能够响应 Create 的生产活动,而无需编写自己的 Mixin。
功能说明
该模组在字节码层面挂钩 Create 的机器,并触发三种事件:
- recipeFinished - Create 机器完成了某个配方(搅拌机、风扇、压板、磨石、粉碎轮、锯子、机械酿造台、发射器、注液口、物品排液口、砂纸、序列组装、CEI 打印机)
- blockProcessed - 机器处理了世界中的方块:每个由机械钻头破坏的方块、每株被机械收割机切割的植物、每个被水平机械锯切割的独立方块各触发一次事件
- treeCut - 机械锯砍伐整棵树,包含精确的原木和树叶数量统计
所有事件均携带以下信息:
- Source(来源) - 执行工作的机器类型
- Player attribution(玩家归属) - 放置该机器的玩家的 UUID(对于粉碎轮:指投入物品的玩家,若无法确定则回退至放置粉碎轮的玩家,用于皮带和漏斗输入)。此信息在服务端重启后依然保留,并在移动的装置中持续传递
- Recipe ID(配方 ID)、物品输入与输出、流体输出 - 针对配方事件
- Block id(方块 ID)、方块状态、contraption flag(装置标志)、log count(原木数量) - 针对方块事件
- Block position(方块位置) - 事件在世界发生的具体坐标
支持的机器
| Machine(机器) |
Source constant(来源常量) |
Event(事件) |
| Basin (Mixing / Compacting)(搅拌盆/压缩) | BASIN | recipeFinished |
| Crushing Wheels(粉碎轮) | CRUSHING_WHEEL | recipeFinished |
| Mechanical Saw (recipes)(机械锯 - 配方) | MECHANICAL_SAW | recipeFinished |
| Spout (recipe and bucket filling)(注液口 - 配方与桶装) | SPOUT_FILLING | recipeFinished |
| Millstone(磨石) | MILLSTONE | recipeFinished |
| Mechanical Press (belt and world)(机械压力机 - 皮带与世界) | MECHANICAL_PRESS | recipeFinished |
| Mechanical Crafter(机械酿造台) | MECHANICAL_CRAFTER | recipeFinished |
| Deployer(发射器) | DEPLOYER_BELT | recipeFinished |
| Encased Fan (belt and world)(包裹式风扇 - 皮带与世界) | FAN_BLASTING / FAN_HAUNTING / FAN_SPLASHING / FAN_SMOKING | recipeFinished |
| Item Drain (recipes, buckets, potions)(物品排液口 - 配方、桶装、药水) | ITEM_DRAIN_EMPTYING | recipeFinished |
| Sand Paper(砂纸) | SAND_PAPER | recipeFinished |
| Sequenced Assembly (final step)(序列组装 - 最后一步) | SEQUENCED_ASSEMBLY | recipeFinished |
| CEI Printer (optional, Forge only)(CEI 打印机 - 可选,仅 Forge) | CEI_PRINTER | recipeFinished |
| Mechanical Drill (stationary and contraption)(机械钻头 - 固定与装置) | MECHANICAL_DRILL | blockProcessed |
| Mechanical Harvester (contraption)(机械收割机 - 装置) | MECHANICAL_HARVESTER | blockProcessed |
| Mechanical Saw, horizontal (stationary and contraption)(机械锯 - 水平方向,固定与装置) | MECHANICAL_SAW | treeCut / blockProcessed |
KubeJS 脚本支持,无需额外插件
CRH 注册了自己的 KubeJS 事件组。相同的脚本可在 Forge 和 Fabric 上无缝运行,并支持可选的来源过滤及内置的所有者解析:
CRHEvents.recipeFinished('MILLSTONE', event => {
const player = event.getOwner();
if (!player) return;
player.server.runCommandSilent('give ' + player.name.string + ' minecraft:emerald 1');
});
CRHEvents.treeCut('MECHANICAL_SAW', event => {
// event.getLogCount(), event.getBlockId(), event.getOwner()
});
README 中提供了即用型脚本示例,包括 FTB Quests 集成、输出过滤、按玩家计数、钻头采矿任务以及原木计数等功能。
为何使用本模组
如果你正在构建任务系统集成(如 FTB Quests),可以在 Create 机器完成的瞬间触发任务进度,并正确关联到对应玩家——而不仅仅是等待物品落入库存时才触发。诸如“用风扇冶炼 64 个铁锭”、“用钻头开采 500 个石头”或“用锯子砍伐 50 棵树”等任务,各自只需简短的一行脚本即可实现。
如果你正在为服务器编写分析或日志记录工具,你可以获得一个统一且可靠的事件流,涵盖所有 Create 生产活动。
本模组本身不会在游戏中产生任何可见效果。它是一个服务端库——你不会看到任何游戏内界面、物品或方块。当其他模组或脚本需要依赖它时再安装。由于它是服务端组件,未安装该模组的客户端也可以加入已安装该模组的服务端。对于单人游戏,请在你的实例中安装它。
要求
- Minecraft 1.20.1
- Forge 版本:Forge 47 或更高版本,Create 6.0.8 或更高版本。同时兼容 NeoForge 1.20.1,已在客户端和专用服务器上验证通过
- Fabric 版本:Fabric Loader 0.15+,Fabric API,Create Fabric 6.0.8.1 或更高版本。同样支持 Quilt
- KubeJS - 可选,仅用于 JS 脚本编写(无需 EventJS 或其他附加插件)
- Create Enchantment Industry - 可选的软依赖项,仅限 Forge;仅在安装了 CEI 时才会触发 CEI 打印机相关事件
面向开发者
在模组初始化期间注册监听器,两种加载器的做法相同:
CreateRecipeHooks.register(ctx -> {
if (ctx.getSource() == RecipeSource.BASIN) {
// ctx.getRecipeId(), ctx.getItemOutputs(), ctx.getBlockPos(), ...
}
});
CreateRecipeHooks.registerBlockProcessed(ctx -> {
// ctx.getBlockId(), ctx.isContraption(), ctx.getMetadata()
});
CreateRecipeHooks.registerTreeCut(ctx -> {
// ctx.getLogCount(), ctx.getLeafCount()
});
在 Forge 上,事件也会发布到事件总线(CreateRecipeFinishedEvent、
CreateBlockProcessedEvent、CreateTreeCutEvent);而在 Fabric 上,它们是标准的
回调函数(CreateRecipeFinishedCallback、CreateBlockProcessedCallback、
CreateTreeCutCallback)。
Forge 提供调试模式以便进行测试。使用 JVM 参数
-Dcrh.debug=true 启动,可将每次配方完成的信息写入
logs/crh-events.log。
完整的 API 文档可在
GitHub 仓库 中各加载器专属的 README 文件中找到。
许可证
LGPL-3.0-or-later — 可自由用于公共和私有的整合包,也可作为其他模组的依赖项。
分叉项目及其衍生模组必须保持开源,并沿用相同许可证,同时需注明出处。
Create Recipe Hooks
Create Recipe Hooks is a server-side library for Minecraft 1.20.1 (Forge and Fabric) that fires
events whenever a Create machine finishes processing a recipe, and whenever a Create machine processes a world
block: Drill mining, Harvester reaping, Saw felling trees. It provides a unified API so that integration mods -
such as quest books, automation scripts, and analytics tools, can react to Create production without writing
their own mixins.
What it does
The mod hooks into Create's machines at the bytecode level and fires three events:
- recipeFinished - a Create machine completed a recipe (Basin, Fan, Press, Millstone, Crushing Wheels, Saw, Crafter, Deployer, Spout, Item Drain, Sand Paper, Sequenced Assembly, CEI Printer)
- blockProcessed - a machine processed a world block: one event per block broken by a Mechanical Drill, per plant cut by a Mechanical Harvester, per lone block cut by a horizontal Mechanical Saw
- treeCut - a Mechanical Saw felled a whole tree, with the exact log and leaf counts
Every event carries:
- Source - which machine did the work
- Player attribution - the UUID of the player who placed the machine (for Crushing Wheels: who threw the item, with a fallback to whoever placed the wheels for belt and hopper input). Persisted across server restarts and carried along inside moving contraptions
- Recipe ID, item inputs and outputs, fluid outputs - for recipe events
- Block id, block state, contraption flag, log count - for block events
- Block position - where it happened in the world
Supported machines
| Machine |
Source constant |
Event |
| Basin (Mixing / Compacting) | BASIN | recipeFinished |
| Crushing Wheels | CRUSHING_WHEEL | recipeFinished |
| Mechanical Saw (recipes) | MECHANICAL_SAW | recipeFinished |
| Spout (recipe and bucket filling) | SPOUT_FILLING | recipeFinished |
| Millstone | MILLSTONE | recipeFinished |
| Mechanical Press (belt and world) | MECHANICAL_PRESS | recipeFinished |
| Mechanical Crafter | MECHANICAL_CRAFTER | recipeFinished |
| Deployer | DEPLOYER_BELT | recipeFinished |
| Encased Fan (belt and world) | FAN_BLASTING / FAN_HAUNTING / FAN_SPLASHING / FAN_SMOKING | recipeFinished |
| Item Drain (recipes, buckets, potions) | ITEM_DRAIN_EMPTYING | recipeFinished |
| Sand Paper | SAND_PAPER | recipeFinished |
| Sequenced Assembly (final step) | SEQUENCED_ASSEMBLY | recipeFinished |
| CEI Printer (optional, Forge only) | CEI_PRINTER | recipeFinished |
| Mechanical Drill (stationary and contraption) | MECHANICAL_DRILL | blockProcessed |
| Mechanical Harvester (contraption) | MECHANICAL_HARVESTER | blockProcessed |
| Mechanical Saw, horizontal (stationary and contraption) | MECHANICAL_SAW | treeCut / blockProcessed |
KubeJS scripting, no addons needed
CRH registers its own KubeJS event group. The same scripts run unchanged on Forge and Fabric,
with an optional source filter and built-in owner resolution:
CRHEvents.recipeFinished('MILLSTONE', event => {
const player = event.getOwner();
if (!player) return;
player.server.runCommandSilent('give ' + player.name.string + ' minecraft:emerald 1');
});
CRHEvents.treeCut('MECHANICAL_SAW', event => {
// event.getLogCount(), event.getBlockId(), event.getOwner()
});
Ready-to-use script examples (FTB Quests integration, output filtering, per-player counters,
drill mining quests, log counting) are available in the README.
Why you might want this
If you are building a quest integration (FTB Quests etc.), you can trigger quest progress the moment
a Create machine finishes, attributed to the right player - not just when items land in an inventory.
Quests like "smelt 64 iron with a Fan", "mine 500 stone with a Drill" or "fell 50 trees with a Saw"
become one short script each.
If you are writing analytics or logging tools for a server, you get a single reliable event stream for all Create
production.
This mod does nothing visible on its own. It is a library - you will not see any in-game UI, items, or blocks.
Install it when another mod or script requires it. It is server-side: clients without the mod can join a server
that has it. For singleplayer, install it in your instance.
Requirements
- Minecraft 1.20.1
- Forge file: Forge 47 or newer, Create 6.0.8 or newer. Also runs on NeoForge 1.20.1, verified on clients and dedicated servers
- Fabric file: Fabric Loader 0.15+, Fabric API, Create Fabric 6.0.8.1 or newer. Works on Quilt
- KubeJS - optional, only for JS scripting (no EventJS or other addons required)
- Create Enchantment Industry - optional soft dependency on Forge; CEI Printer events are only fired when CEI is installed
For developers
Register listeners during mod initialization, identical on both loaders:
CreateRecipeHooks.register(ctx -> {
if (ctx.getSource() == RecipeSource.BASIN) {
// ctx.getRecipeId(), ctx.getItemOutputs(), ctx.getBlockPos(), ...
}
});
CreateRecipeHooks.registerBlockProcessed(ctx -> {
// ctx.getBlockId(), ctx.isContraption(), ctx.getMetadata()
});
CreateRecipeHooks.registerTreeCut(ctx -> {
// ctx.getLogCount(), ctx.getLeafCount()
});
On Forge the events are also posted on the event bus (CreateRecipeFinishedEvent,
CreateBlockProcessedEvent, CreateTreeCutEvent); on Fabric they are standard
callbacks (CreateRecipeFinishedCallback, CreateBlockProcessedCallback,
CreateTreeCutCallback).
A debug mode is available for testing on Forge. Launch with the JVM argument
-Dcrh.debug=true to write every recipe completion to
logs/crh-events.log.
Full API documentation is available in the per-loader READMEs on the
GitHub repository.
License
LGPL-3.0-or-later - free to use in public and private modpacks and as a dependency in other mods.
Forks and derivative mods must remain open source under the same license with attribution.
评论 0
登录后参与评分
还没有评论,来抢沙发吧