Skip to content

Hook Development Guide

ItemPluginHook Interface

To integrate a custom item plugin with Craftorithm, implement the ItemPluginHook interface:

java
public class MyPluginHook implements ItemPluginHook {

    @Override
    public String namespace() {
        return "myplugin"; // Namespace for item ID prefix
    }

    @Override
    public ItemStack matchItem(String id) {
        // Convert "myplugin:sword" to ItemStack
        return MyPluginAPI.getItem(id);
    }

    @Override
    public String matchItemId(ItemStack itemStack) {
        // Reverse-lookup item ID from ItemStack
        String id = MyPluginAPI.getItemId(itemStack);
        return id != null ? "myplugin:" + id : null;
    }
}

Registering Hooks

Register during plugin startup:

java
CraftorithmAPI.INSTANCE.registerItemPluginHook(new MyPluginHook());

Module Structure

If developing as an independent Gradle submodule, reference the existing implementations under hook/:

hook/
├── myplugin/
│   ├── build.gradle.kts
│   └── src/main/java/.../MyPluginHook.java

Add the submodule in settings.gradle.kts:

kotlin
include(":hook:myplugin")

Existing Hook Reference

ModuleDescription
hook/itemsadderItemsAdder integration (with reload listener)
hook/oraxenOraxen integration (with reload listener)
hook/mythicmobsMythicMobs items
hook/mmoitemsMMOItems items
hook/ecoitemsEcoItems items
hook/neigeitemsNeigeItems items
hook/nexoNexo items
hook/azureflowAzureFlow items
hook/craftengineCraftEngine items
hook/executableitemsExecutableItems items
hook/sx-itemSX-Item items
hook/protocollibProtocolLib fake result preview
hook/packeteventsPacketEvents fake result preview

Notes

  • Hook classes are initialized after Craftorithm starts but before recipes load
  • matchItem() should return null if the item is not found
  • matchItemId() should return null if the item does not belong to that plugin
  • Avoid performing expensive operations in hooks

基于 GPL-3.0 许可证发布