squeek502 / AppleCore

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

Add access to max foodLevel. #90

Closed primetoxinz closed 7 years ago

primetoxinz commented 7 years ago

I would like to port Better With Mods Hardcore hunger over to AppleCore entirely. To do this without overwriting EntityPlayer.foodStats, a method to changing the maximum for FoodStats.foodLevel. There are multiple places where the maximum is in effect, including this.foodLevel = Math.min(foodLevelIn + this.foodLevel, **20** ); and public boolean needFood() { return this.foodLevel < **20**; }

I'm willing to make the PR if need be, but I'm not exactly sure how you'd want it implemented.

Additionally, an event called on FoodStats::addExhaustion would be with parts of this.

squeek502 commented 7 years ago

Sorry for not following up on this the last time I mentioned it. I began implementing this quite a while ago and now forget why I didn't finish it (I remember kinda getting tripped up by something but not sure what it was).

I pushed my WIP branch here if you want to give feedback on the implementation: https://github.com/squeek502/AppleCore/tree/1.10.2-max-hunger

primetoxinz commented 7 years ago

I after attempting to run that branch, I found the problem you ran into. When trying to replace the int for the vanilla max with the lookup from GetMaxHunger it throws java.lang.ClassCastException: org.objectweb.asm.tree.IntInsnNode cannot be cast to org.objectweb.asm.tree.VarInsnNode. Guess it doesn't like trying to replace one with the other. I don't know enough about java bytecode to fix that.

primetoxinz commented 7 years ago

Ok, it seems like simply changing the VarInsNodes to IntInsNodes worked haha. So, GetMaxHunger is correctly working, yet the hunger bar doesn't scale by default in AppleCore, not sure if you are worried about that; I am going to render the hunger bar custom either way, so it doesn't really matter for HCHunger

squeek502 commented 7 years ago

Yeah I think AppleCore should scale the HUD accordingly, will work on that (but it will still use only the 1/2 and full hunger icons so it won't be as precise as BWM's).

primetoxinz commented 7 years ago

Thanks! A port of those changes to 1.11.2 (and hopefully 1.12 soon) would be most appreciated :)

squeek502 commented 7 years ago

Will do.