Skip to content

Hook Development Guide

ItemPluginHook Interface

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

java
public class MyPluginHook implements ItemPluginHook {
    
    @Override
    public ItemProvider itemProvider() {
        return new MyPluginItemProvider();
    }

    @Override
    public String pluginName() {
        return "MyPlugin";
    }



}
java
public class MyPluginItemProvider implements ItemProvider {

    @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 NamespacedItemIdStack matchItemId(ItemStack itemStack, boolean ignoreAmount) {
        // Reverse-lookup item ID from ItemStack
        String id = MyPluginAPI.getItemId(itemStack);
        if (id == null) {
            return null;
        }
        if (ignoreAmount) {
            return new NamespacedItemIdStack(new NamespacedItemId(namespace(), id));
        } else {
            return new NamespacedItemIdStack(new NamespacedItemId(namespace(), id), itemStack.getAmount());
        }
    }
}

Registering Hooks

Register during plugin startup:

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

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 许可证发布