squeek502 / AppleCore

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

Exhaustion is hard-capped at 40 (10 food points) #152

Closed James103 closed 4 years ago

James103 commented 4 years ago

As of AppleCore-mc1.12.2-3.3.0 for MC 1.12.2, when the max exhaustion is set to the default value of 4, exhaustion is hard-capped at 40. In other words, you can only have 10 food points queued up to be deduced from your hunger bar. Exhaustion can be manually set to be more than 40, and it will deduct the proper amount of food points, but this can only be done in an NBT editor while the game is closed.

Bulk operations that have been set to cost a lot of food points, such as placing a block when the following CraftTweaker script is used, do not deduct the full amount of food points that they're supposed to deduct.

events.onBlockPlace(function(event as crafttweaker.event.BlockPlaceEvent){
    event.player.foodStats.addExhaustion(100); // Supposed to deduct 25 food points
});

Even though I have those mods loaded, I don't think it has to do with Scaling Feast 1.4.0 or AppleSkin 1.0.9. It may even be a vanilla limitation.

squeek502 commented 4 years ago

I'm not sure I'm following. You're saying that foodStats.addExhaustion(100); will actually only set exhaustion to 40?

yeelp commented 4 years ago

I can confirm the following behaviour. I'm the developer of Scaling Feast and I've been working on a handful of features around exhaustion and I've been getting similar results. I have a scenario set up that should set the player's exhaustion level far above 40 (280 to be exact). Saving and quitting as soon as it happens and checking NBTExplorer shows this: exhaust So it would seem that in my case, calling player.addExhaustion(280) seems to yield the same result as player.addExhaustion(40).

In fact, looking at the source code reveals this to be entirely correct. This is FoodStats#addExhaustion(float) on line 148 in FoodStats.class. dundundun

So it turns out this is intentional behaviour by vanilla. Could this be patched by AppleCore?

squeek502 commented 4 years ago

Thanks for the clarification.

Could this be patched by AppleCore?

Yep, I'm imagining a ExhaustionEvent.GetExhaustionCap event that works like ExhaustionEvent.GetMaxExhaustion.

squeek502 commented 4 years ago

With the changes to the example mod in 5ee853c to set the cap to 90 (and the 'exhausted' max to 30), the log outputs:

[14:02:18] [Server thread/INFO] [applecoreexample]: onExhausted exhaustion=90.0
[14:02:18] [Server thread/INFO] [applecoreexample]: onExhausted exhaustion=60.0
[14:02:18] [Server thread/INFO] [applecoreexample]: onExhausted exhaustion=30.0

EDIT: Released in v3.4.0