Skip to content

Addons Home

DarkBladeDev edited this page Jul 23, 2026 · 1 revision

Addon Development (Lifecycle & Discovery)

MultiBlockEngine (MBE) relies on an API-First and Contract-Based model. The core provides the infrastructure, service discovery, and lifecycle management, while addons implement specific domain logic (energy, wiring, crafting, custom UIs, etc.).

Addons in MBE are extraordinarily powerful. They aren't just listeners hooked into events; they are first-class modules that can shape the entire ecosystem by registering their own services.


🏗️ Architectural Philosophy

The golden rule of addon development in MBE is: Never depend on the core module.

Your addon should only interact with the engine through the api layer. By adhering to this:

  • Platform Agnostic: Your addon becomes immune to Minecraft version changes because it contains no Bukkit/Spigot imports.
  • Loose Coupling: You can swap implementations without breaking the engine.
  • Service-Oriented: You use the @InjectService pattern to access engine features.

(If you need to interact with items or the world, read about Platform Bridges).


🔄 Addon Discovery & Lifecycle

When the server starts, the AddonLifecycleService takes control and orchestrates the loading of all addons through specific phases.

Every addon must implement the main MultiblockAddon interface (or a provided abstract class).

Lifecycle Phases:

  1. onDiscovery(): The engine finds your addon. This is where you declare your dependencies (e.g., if your addon requires mbe-energy to function).
  2. onRegister(): Your addon is instantiated. This is where you expose your own services to the MBEServiceRegistry.
  3. onInitialize(): Your injected services (@InjectService) are now populated. You can perform setup tasks, but do not start active loops yet.
  4. onEnable(): The server is fully loaded. You can now register event listeners, start background tasks, and spawn entities.
  5. onDisable(): Triggered during a shutdown or /mbe reload. Save your data and clean up any visual elements.

🔗 Core Contracts (API)

Familiarize yourself with these core interfaces in the API module:

  • Main Interface: MultiblockAddon.java
  • Lifecycle Context: AddonContext.java
  • Error Handling: AddonException.java

💉 Exposing and Injecting Services

Injecting an existing service

To use a service (whether from the core or another addon), simply annotate a field:

public class MyMachineLogic {
    @InjectService
    private EnergyService energyService;
}

Exposing your own service

In your addon's onRegister phase, you can push your own services to the registry:

@Override
public void onRegister(AddonContext context) {
    // Registering a custom ManaService so other addons can inject it
    context.getRegistry().registerService(ManaService.class, new ManaServiceImpl());
}

This flexibility allows a decentralized ecosystem where addons can seamlessly interact with each other. For a full list of available core services, refer to the Service Registry.

Clone this wiki locally