Changes

301 bytes added ,  16:56, 17 November 2021
m
Add Groovy language code examples
Line 8: Line 8:  
=== Creating Color Handlers ===
 
=== Creating Color Handlers ===
 
<code>BlockColor</code>s need to be registered to the <code>BlockColors</code> instance of the game. <code>BlockColors</code> can be acquired through <code>ColorHandlerEvent$Block</code>, and an <code>BlockColor</code> can be registered by <code><nowiki>BlockColors#register</nowiki></code>. Note that this does not cause the <code>BlockItem</code> for the given block to be colored. <code>BlockItem</code> are items and need to colored with an <code>ItemColor</code>.
 
<code>BlockColor</code>s need to be registered to the <code>BlockColors</code> instance of the game. <code>BlockColors</code> can be acquired through <code>ColorHandlerEvent$Block</code>, and an <code>BlockColor</code> can be registered by <code><nowiki>BlockColors#register</nowiki></code>. Note that this does not cause the <code>BlockItem</code> for the given block to be colored. <code>BlockItem</code> are items and need to colored with an <code>ItemColor</code>.
<syntaxhighlight lang="java">
+
{{Template:Tabs/Code_Snippets
public void registerBlockColors(ColorHandlerEvent.Block event){
+
|java=public void registerBlockColors(final ColorHandlerEvent.Block event) {
 
     event.getBlockColors().register(myBlockColor, coloredBlock1, coloredBlock2, ...);
 
     event.getBlockColors().register(myBlockColor, coloredBlock1, coloredBlock2, ...);
 
}
 
}
</syntaxhighlight>
+
|groovy=void registerBlockColors(final ColorHandlerEvent.Block event) {
 +
    event.blockColors.register(myBlockColor, coloredBlock1, coloredBlock2, ...);
 +
}
 +
|}}
 
<code>ItemColor</code>s need to be registered to the <code>ItemColors</code> instance of the game. <code>ItemColors</code> can be acquired through <code><nowiki>ColorHandlerEvent$Item</nowiki></code>, and an <code>ItemColor</code> can be registered by <code><nowiki>ItemColors#register</nowiki></code>. This method is overloaded to also take <code>Block</code>s, which simply registers the color handler for the item <code><nowiki>Block#asItem</nowiki></code> (i.e. the block’s <code>BlockItem</code>).
 
<code>ItemColor</code>s need to be registered to the <code>ItemColors</code> instance of the game. <code>ItemColors</code> can be acquired through <code><nowiki>ColorHandlerEvent$Item</nowiki></code>, and an <code>ItemColor</code> can be registered by <code><nowiki>ItemColors#register</nowiki></code>. This method is overloaded to also take <code>Block</code>s, which simply registers the color handler for the item <code><nowiki>Block#asItem</nowiki></code> (i.e. the block’s <code>BlockItem</code>).
<syntaxhighlight lang="java">
+
{{Template:Tabs/Code_Snippets
public void registerItemColors(ColorHandlerEvent.Item event){
+
|java=public void registerItemColors(final ColorHandlerEvent.Item event) {
 
     event.getItemColors().register(myItemColor, coloredItem1, coloredItem2, ...);
 
     event.getItemColors().register(myItemColor, coloredItem1, coloredItem2, ...);
 
}
 
}
</syntaxhighlight>
+
|groovy=void registerBlockColors(final ColorHandlerEvent.Item event) {
 +
    event.itemColors.register(myItemColor, coloredItem1, coloredItem2, ...);
 +
}
 +
|}}
 
This registration must be done client-side, in the initialization phase.
 
This registration must be done client-side, in the initialization phase.