User Tools

Site Tools


tutorial:events

Differences

This shows you the differences between two versions of the page.

Link to this comparison view

Both sides previous revisionPrevious revision
Next revisionBoth sides next revision
tutorial:events [2019/07/03 00:29] – added javadoc description draylartutorial:events [2019/07/03 00:31] – tell people to return PASS in listeners draylar
Line 9: Line 9:
  
 ==== Creating a Callback Interface ==== ==== Creating a Callback Interface ====
-The callback interface is the core of your event. It stores a list of all registered listeners (which are like responses to an event)and calls them all when the action occurs. Each listener can then say "cancel this," "approve this," or "I don't care, leave it to the next guy," while doing whatever response they need to.+The callback interface is the core of your event. It stores a list of all registered listeners (which are like responses to an event) and calls them all when the action occurs. Each listener can then say "cancel this," "approve this," or "I don't care, leave it to the next guy," while doing whatever response they need to.
  
 You'll need to create an interface that has an ''Event'' instance and method for response implementation. A basic setup for our sheep shear callback is: You'll need to create an interface that has an ''Event'' instance and method for response implementation. A basic setup for our sheep shear callback is:
Line 96: Line 96:
 }); });
 </code> </code>
-Note that this event also sets the sheep to be sheared manually, as it is normally canceled if we return FAIL.+Note that this event also sets the sheep to be sheared manually, as it is normally canceled if we return FAIL. If you don't //need// to cancel the event, make sure you return ''PASS'' so other listeners are allowed to operate as well. Failing to follow these "not spoken rules" may result in angry modders on your doorstep.
  
 If you enter into your game and shear a sheep, a diamond should drop instead of wool. If you enter into your game and shear a sheep, a diamond should drop instead of wool.
 {{https://i.imgur.com/dG73Z6G.mp4?400|}} {{https://i.imgur.com/dG73Z6G.mp4?400|}}
tutorial/events.txt · Last modified: 2021/05/28 00:31 by 127.0.0.1