squeek502 / AppleCore

An API for modifying the food and hunger mechanics of Minecraft
The Unlicense
55 stars 24 forks source link

Problems with events listening #120

Closed VladoCC closed 6 years ago

VladoCC commented 6 years ago

I am trying to deny exhaustion lowering if play don't have hunger and saturation, but for some reasones Forge not calling my listener Code: @SubscribeEvent public void onExhausted(ExhaustionEvent.Exhausted event){ if (!(event.player.getFoodStats().getSaturationLevel() > 0 && event.player.getFoodStats().getFoodLevel() > 0)){ event.deltaExhaustion = 0; event.deltaHunger = 0; event.deltaSaturation = 0; } }

Another listener (don't work too): @SubscribeEvent public void onWork(FoodEvent.FoodEaten event){ System.out.println(event.hungerAdded); }

I am wotking in dev workspace without other mods What am I do wrong?

squeek502 commented 6 years ago

What Minecraft version are you working on? How are you including AppleCore in your dev environment?

VladoCC commented 6 years ago

@squeek502 1.12.2 I did it using second method in your guide: include mod, not only api

squeek502 commented 6 years ago

Strange. Does AppleCore show up in your mod list in game? Are you sure your event listener class is registered on the Forge EVENT_BUS?

You can find an example of a simple working setup here (it compiles against 1.12 instead of 1.12.2, though): https://github.com/squeek502/HungerInPeace/tree/1.12

VladoCC commented 6 years ago

@squeek502 Yes, AppleCire show up in my mod list ingame, I have chat commands fron it and more.. Forge even calls your default realization of Exhausted event.

And, no, I am not sure that event listener is registered. Code in first topic is all that I did to make this listener to work.

I checked your example and seems that my code is writen the same way as yours.

What I did wrong?

squeek502 commented 6 years ago

See the Forge docs on events

VladoCC commented 6 years ago

@squeek502 ok I'd missed it