-
Notifications
You must be signed in to change notification settings - Fork 0
Injection Annotations
The injection annotations provide the core dependency injection and metadata processing infrastructure for the Temporal API framework. These annotations enable automatic registration, configuration, and execution of various framework components including event handlers, processors, strategies, and factories.
The injection annotations are responsible for:
- Dependency Management: Automatic injection and registration of framework components
- Event Handling: Declarative registration of event handlers for Minecraft and mod events
- Metadata Processing: Configuration of annotation processors and processing strategies
- Factory Registration: Automatic registration of factory classes for object creation
- Configuration Management: Registration of mod configuration classes
- Component Lifecycle: Managing the initialization and execution order of framework components
The injection system operates through a multi-layered processing approach:
- Component Discovery: The framework scans classes for injection annotations during initialization
- Registration: Components are automatically registered in appropriate registries or pools
- Dependency Resolution: Dependencies between components are resolved and injected
- Execution: Components are executed at the appropriate time in the mod lifecycle
- Context Management: Components are provided with necessary context and dependencies
The injection annotations are processed by the core framework during mod initialization, ensuring proper setup before any game logic executes.
Registers event handlers for specific Minecraft or mod events.
@Handler(FMLLoadCompleteEvent.class)
public class ExampleHelloWorldEventHandler implements EventHandler {
@Override
public void handle() {
this.subscribeModEvent(FMLLoadCompleteEvent.class, event -> {
System.out.println("Hello World!");
}, EventPriority.HIGHEST);
}
}Parameters:
- value (Class<? extends Event>): The event class to handle
- override (Class<? extends EventHandler>): Optional override handler class
Registers annotation processors for custom metadata processing.
@Processor(ExampleAnnotationProcessor.NAME)
public class ExampleAnnotationProcessor extends AbstractAnnotationProcessor {
public static final String NAME = "example";
@Override
public void process() {
this.processAll(MetadataLayer.SIMPLE_STRATEGY_CONSUMER, ModContext.NEO_MOD.getClasses());
}
}Parameters:
- value (String): The processor name/identifier
- override (Class<? extends AnnotationProcessor>): Optional override processor class
Registers annotation processing strategies for specific annotation types.
@Strategy(ExampleAnnotationFieldStrategy.EXAMPLE_FIELD)
public class ExampleAnnotationFieldStrategy implements FieldAnnotationStrategy<ExampleAnnotation> {
public static final String EXAMPLE_FIELD = "example_field";
@Override
public void execute(Field field, Object object, ExampleAnnotation annotation) throws Exception {
System.out.println(field.getName() + " : " + annotation.value());
}
@Override
public Class<ExampleAnnotation> getAnnotationClass() {
return ExampleAnnotation.class;
}
@Override
public ProcessorScope getProcessorScope() {
return new ProcessorScope(ExampleAnnotationProcessor.NAME);
}
}Parameters:
- value (String): The strategy pool identifier
- override (Class<? extends AnnotationStrategy>): Optional override strategy class
Marks classes for automatic injection and registration as framework components.
@Injected
public final class ExampleItemFactory extends ItemFactory implements SwordSubFactory,
BowSubFactory,
CrossbowSubFactory,
ArmorSubFactory,
SignSubFactory,
HangingSignSubFactory,
BoatSubFactory,
SpawnEggSubFactory,
SmithingTemplateSubFactory,
BannerPatternSubFactory,
MusicDiscSubFactory,
InstrumentSubFactory {
}Parameters:
- value (String): Optional component identifier
- isContextObject (boolean): Whether this is a context object (default: true)
- mandatoryMod (String): Optional mandatory mod dependency
Registers factory classes for automatic dependency injection.
public final class ExampleFactories {
@RegisterFactory
public static final ExampleItemFactory ITEM_FACTORY = new ExampleItemFactory();
}Registers mod configuration classes with specific configuration types.
@RegisterConfig(ModConfig.Type.COMMON)
public class ExampleConfig {
@TranslateAmericanEnglish("Hello World Config")
public static volatile ModConfigSpec.ConfigValue<Boolean> sayHelloConfigValue;
public ExampleConfig(ModConfigSpec.Builder builder) {
sayHelloConfigValue = builder.comment("Whether to say \"Hello World\" or not")
.translation("config.example.hello_world")
.define("Say Hello World", true);
}
}Parameters:
- value (ModConfig.Type): The configuration type (COMMON, CLIENT, SERVER)
Marks fields or parameters for dependency injection.
public class ExampleService {
@Inject
private ExampleDependency dependency;
@Inject("customName")
private AnotherDependency customDependency;
}Parameters:
- value (String): Optional injection name/qualifier
Marks fields as dependencies that should be resolved before component initialization.
public class ExampleComponent {
@Dependency("exampleService")
private ExampleService service;
}Parameters:
- value (String): The dependency identifier
Marks methods for execution during specific phases of mod initialization.
public class ExampleExecutor {
@Execute(mod = "example_mod")
public void executeTask() {
// Custom execution logic
}
}Parameters:
- mod (String): Optional mod identifier for mod-specific execution
The injection system can be extended by:
- Custom Processors: Create new annotation processors for custom metadata processing
- Custom Strategies: Implement new processing strategies for specific annotation types
- Custom Handlers: Create event handlers for new event types
- Custom Factories: Implement factory classes for specialized object creation
- Override Mechanisms: Use override parameters to replace default implementations
Use injection annotations when:
- Creating framework components that need automatic registration
- Implementing custom annotation processing logic
- Creating event handlers for Minecraft or mod events
- Setting up mod configuration
- Creating factory classes for object creation
- Managing dependencies between components
- Implementing custom metadata processing strategies
- Use
@Injectedfor framework components that need automatic registration - Use
@Handlerfor event handling to ensure proper event subscription - Use
@Processorand@Strategyfor custom annotation processing - Use
@RegisterConfigfor mod configuration to ensure proper loading - Use
@Injectfor dependency injection within framework components - Use
@Dependencyfor explicit dependency declaration - Use
@Executefor initialization tasks that need specific timing - Use
@RegisterFactoryfor factory classes that provide object creation services
🚀 Getting Started
🧩 Core Concepts
⚙️ Data Generation
- ⚙️ Advancement
- ⚙️ Damage Type
- ⚙️ Chest Loot Modifier
- ⚙️ Recipe
- ⚙️ Sound
- ⚙️ Jukebox Song
- ⚙️ Enchantment
- ⚙️ Trim Material
- ⚙️ Trim Pattern
- ⚙️ Banner Pattern
- ⚙️ Painting Variant
- ⚙️ Particle Sprite Set
- ⚙️ Wolf Variant
- ⚙️ Item Model
- ⚙️ Block Model
- ⚙️ Block Loot Table
- ⚙️ Tag
- ⚙️ Language Translation
- ⚙️ World Feature
- ⚙️ Custom Properties
🚨 Events
🛠 Engine Layers
🧪 Resources
- 🧪 Examples