Changes

776 bytes added ,  19:22, 24 September 2022
Undo revision 3332 by Nexus-Dino
Line 373: Line 373:     
<syntaxhighlight lang="java">
 
<syntaxhighlight lang="java">
@AutoRegisterCapability // This annotation registers the capability for you automatically!
+
@AutoRegisterCapability
 
public interface MyCapability {
 
public interface MyCapability {
 
     String getValue();
 
     String getValue();
Line 402: Line 402:  
sections [[#Exposing a Capability|Exposing a Capability]] and [[#Attaching a Capability|Attaching a Capability]]: refer
 
sections [[#Exposing a Capability|Exposing a Capability]] and [[#Attaching a Capability|Attaching a Capability]]: refer
 
to those for more information.
 
to those for more information.
 +
 +
=== Tying it All Together ===
 +
 +
Once all components of a Capability have been created, they must be registered so that the game is aware of the
 +
capability's presence. The registration requires specifying only the Capability Interface.
 +
 +
The registration can be performed by calling the <code>register</code> method within the <code>RegisterCapabilitiesEvent</code> which is fired on the <code>MOD</code> event bus. The
 +
registration will also automatically inject the created Capability into all relevant fields and methods: refer to
 +
[[#Obtaining a Capability|Obtaining a Capability]] for more information.
 +
 +
An example of registration can be found in the snippet that follows:
 +
 +
<syntaxhighlight lang="java">
 +
@SubscribeEvent
 +
public void registerCaps(RegisterCapabilitiesEvent event) {
 +
    event.register(MyCapability.class);
 +
}
 +
</syntaxhighlight>
    
=== Class Diagram ===
 
=== Class Diagram ===