@@ -4,6 +4,8 @@ description: "Learn how to create custom events for your Hytale mod."
44authors :
55 - name : " Neil Revin"
66 link : " https://itsneil.dev"
7+ - name : " EllieAU"
8+ link : " https://ellie.au"
79---
810
911## Event Class
@@ -35,4 +37,53 @@ public class MyPlugin extends JavaPlugin {
3537 this . getEventRegistry(). registerGlobal(PlayerReadyEvent . class, ExampleEvent :: onPlayerReady);
3638 }
3739}
38- ```
40+ ```
41+
42+ ## ESC Event Classes
43+
44+ For events that fall under the [ ESC Events] ( ../../server/events#ecsevent ) list you will need to instead create and register an entity event system.
45+ An example is included below that will cancel the crafting of a recipe if it uses fibre as an input.
46+
47+ ``` java
48+ class ExampleCancelCraft extends EntityEventSystem<EntityStore , CraftRecipeEvent .Pre > {
49+ public ExampleCancelCraft () {
50+ super (CraftRecipeEvent . Pre . class);
51+ }
52+
53+ @Override
54+ public void handle (int index ,
55+ @NonNullDecl ArchetypeChunk<EntityStore > archetypeChunk ,
56+ @NonNullDecl Store<EntityStore > store ,
57+ @NonNullDecl CommandBuffer<EntityStore > commandBuffer ,
58+ @NonNullDecl CraftRecipeEvent .Pre craftRecipeEvent ) {
59+ CraftingRecipe recipe = craftRecipeEvent. getCraftedRecipe();
60+ if (recipe. getInput() != null ) {
61+ for (MaterialQuantity mq : recipe. getInput()) {
62+ if (Objects . equals(mq. getItemId(), " Ingredient_Fibre" )) {
63+ craftRecipeEvent. setCancelled(true );
64+ break ;
65+ }
66+ }
67+ }
68+ }
69+
70+ @Override
71+ public Query<EntityStore > getQuery () {
72+ return Archetype . empty();
73+ }
74+ }
75+ ```
76+
77+ ## Registering ESC Events
78+
79+ You will need to register the system in your plugin:
80+
81+ ``` java
82+ public class MyPlugin extends JavaPlugin {
83+
84+ @Override
85+ public void setup () {
86+ this . getEntityStoreRegistry(). registerSystem(new ExampleCancelCraft ());
87+ }
88+ }
89+ ```
0 commit comments