dannydjdk / Nutritional-Balance

A Minecraft mod that enhances the food system to encourage you to eat a balanced diet.
https://www.curseforge.com/minecraft/mc-mods/nutritional-balance
GNU General Public License v3.0
3 stars 5 forks source link

[DEV] Provide a separate api jar on CurseForge for devs to integrate with #1

Closed Wabbit0101 closed 2 years ago

Wabbit0101 commented 3 years ago

Would like to add support for my mods, but though I see the caps in your source, there isn't a published API. Would it be possible to add such a jar to your CF downloads esp now that we're about to have a split in mappings (old vs Mojang)? (A deobf would be also appreciated, but that's icing...)

dannydjdk commented 3 years ago

Are you interested in adding foods and/or nutrients? In that case, you just need to add the appropriate tags. No API needed. (see this wiki page) A deopf would be helpful. I'll look into that. I haven't done that before, so it's something I need to experience anyway.

dannydjdk commented 3 years ago

I published a source jar (https://www.curseforge.com/minecraft/mc-mods/nutritional-balance/files/3243752). Let me know if this is what you need. I've been a solo freelancer for many years, so I've gotten rusty on how to play with other devs. ;)

Wabbit0101 commented 3 years ago

Backgound: I have some dynamic foods in my mods (they are composite foods and are dynamic in their food values as they depend on what went into crafting them...the recipes are custom). Ideally I would like to hook into an api that is asking me what the food values for a particular stack should be. (Also note the values can depend on things the player has done post crafting (like reheating) and potion effects the player is experiencing (like a 'supremely stuffed' buff).

So for example, if the player makes a sandwich with ingredients A,B,C the total food points will differ from a sandwich made with ingredient D,E,F. I would (if possible) like the nutrition applied to reflect the difference.

dannydjdk commented 3 years ago

Nice! That sounds really interesting. I think I have to expose more functionality to the INutritionalBalancePlayer interface to make that work. Currently, it's setting the nutrient values in a black box by updating the nutrition values directly in the item use event. It should, instead, pass that functionality through the interface so you can call some method when food is consumed. Correct? Would you be passing healing and saturation along with nutrients?

Wabbit0101 commented 3 years ago

Mostly. Hopefully this isn't too long an explanation. Looking at other integrations I need two hooks:

1) To tell your mod something has been consumed (ie. interactions that are not related to the standard item use event; for example: effects, baubles, sipping from modded blocks (tanks, fluid sources, etc.), and other hidden applications). Something like Diet's IDietTracker::consume(ItemStack) for the player. Use case: I added drinkability to buckets of fluids like milk, honey, etc., and updates from special buffs.

2) To tell your mod processing of the normal item use event the details you need for dynamic foods including food value, saturation, and included ingredients(items) so you can assign points to proper nutrient groups. Diet (yea...I'm using that a lot) does this via IMC and functional interfaces which is nice as it means your mod doesn't even need an additional API if it does not want to support case #1. So something like an IMC message like shown in that mod. (Use case: I added the dynamic food items using this technique after adding the Item itself to each nutrient group as it's possible they'd contain ingredients from any group.)

Thanks for your time.

dannydjdk commented 3 years ago

My plan is to add 2 methods to the INutritionalBalancePlayer interface:

void consume(ItemStack itemStack);
void consume(List<IPlayerNutrient> nutrients, float health, float saturation);

The first one will process the itemstack using the default implementation. The second one, obviously will just use the values you give it. I actually think you will need to use the second one for all your use cases. The default implementation checks the items getFood() method, and will only process the itemStack if it's food.

One possible issue I may need to account for is that it will process any food item used by the player, so if any of your custom items are recognized by Minecraft as foods (i.e. getFood() returns a Food object), then both of our mods will process them. If this is the case, I may need to structure it so that the default class is called last and that you have a way of indicating that you've handled the event. I'll have to think about how to approach that. However, if it's not needed, I won't bother.

dannydjdk commented 3 years ago

Also, you can currently directly change a players nutrient values with the IPlayerNutrient interface. IPlayerNutrient.void changeValue(float i) lets you pass a value to increment/decrement nutritional units. I'm going to add JavaDocs to all these methods so it's easier to understand how to use them.

Wabbit0101 commented 3 years ago

Ok. Been offline for a few days but I will work with the new release in couple days --Thanks!

dannydjdk commented 3 years ago

Sounds good. It's not on Curseforge yet. I'll get it posted today. Definitely feel free to hit me up with questions or suggestions. I don't have any documentation on the wiki for the api, just the JavaDocs in code. Your questions may help me direct that documentation.