Diet (Fabric/Forge/Quilt)

Diet (Fabric/Forge/Quilt)

6M Downloads

No way to give corrected nutrition values for incoming ItemStack

Wabbit0101 opened this issue ยท 4 comments

commented

Diet: 1.16.5-0.11

For dynamic items (where the actual heal/saturation depends on the ItemStack and can differ from the base Food values of the Item), returning the incoming stack in the Triple results in an infinite loop in the DietTooltip's call to DietCalculator::getGroups. Returning an empty list from the Triple doesn't help (the original item is never put into the stack list for checking against groups).

Example: I have a food item "Salad" that a player can use multiple times. The "food" value is fixed at 100heal +0.5sat. but each use is for a value that is defined in the stack's NBT or a smaller portion value. The salad item is correctly assigned to the 'vegetables' group. I just want to adjust the heal/sat values. A hard example would be I have a custom salad were I want to tell Diet the value is "10pts/0.7sa" for a particular salad stack.

This does not work (loops on game load):

(playr,salad_stack) -> {
    Pair<Integer,Float> portion = getPortion(playr,salad_stack);//...read NBT or use default portion size
    return Triple.of(Collections.singletonList(salad_stack),portion.getLeft(),portion.getRight());
}

This does not work (no tooltip shown):

(playr,salad_stack) -> {
    Pair<Integer,Float> portion = getPortion(playr,salad_stack);//...read NBT or use default portion size
    return Triple.of(Collections.EMPTY_LIST,portion.getLeft(),portion.getRight());
}

Assuming I've got the idea/code right...how do I accomplish this?

commented

Hmm, probably just a small oversight where I need to adjust the code to check for potential infinite loops. Your first example is the intended correct way, although I'll probably add in some checks so that the second example will work as well.

commented

I've got a working solution in-dev; however, I'd like to see if it works for your use-case. Can you try this jar and see if you're able to do what you need? You should be able to send either an empty list or the list with the incoming stack.

diet-forge-1.16.5-0.12-SNAPSHOT.zip

commented

Yes that worked! (FYI: while testing found that /diet clear @p doesn't seem to clear stuff...)

commented

Note that /diet clear is actually for clearing the dietary effects. If you're trying to reset all of the values, it would be /diet reset. Unless you actually intended the former, which would mean it's a bug.