squeek502 / AppleCore

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

[Feature Request] Checking 'edibility status' of food items #148

Closed yeelp closed 4 years ago

yeelp commented 4 years ago

The ItemFood class has a private field alwaysEdible to determine if a food item can be eaten regardless if a player has full hunger or not. Now it's obviously possible to access this field via reflection, but a much more elegant solution in my opinion would be a method in the IAppleCoreAccessor class to do this. I imagine AppleCore could provide an implementation that is much more efficient than reflection.

I find this to be a huge pitfall with the ItemFood class. You can set if a food item is always edible, but not get this property. This seems like a natural addition to the API.

squeek502 commented 4 years ago

Seems reasonable. Happy to take a PR for this if you'd like to write one.

yeelp commented 4 years ago

I'll see what I can do. I'm kind of new to the modding scene, but proficient in Java, so I imagine I could do it nicely, given enough time.

squeek502 commented 4 years ago

Reposting my comment from here for visibility

If the intention is just to provide a field getter for ItemFood.alwaysEdible, just using reflection should be fine. Shouldn't need ASM for this.

EDIT: Example from AppleSkin:

yeelp commented 4 years ago

No kidding? I'm all for just using reflection. My original concern with this approach was a potential lack of efficiency.

squeek502 commented 4 years ago

As far as I'm aware, the cost of reflection for this sort of thing is pretty minimal, and is mostly just an upfront cost (as long as you store the Field instead of looking it up each time). Could be wrong about that, though, never looked into it too deeply.