Closed primetoxinz closed 6 years ago
By the time the int, float
version of addStats
is called, we no longer have a reference to the FoodValues instance, so there's not really a getSaturationIncrement
function that can be called (except on a new instance of FoodValues, but that'd bypass any customization unless I'm thinking about this wrong).
I see two possibilities:
FoodEvent.FoodStatsAddition
, canceling it, and then modifying the FoodStats
fields yourself (essentially reimplement/override FoodStats.addStats
)Untested example code:
@SubscribeEvent
public void onFoodStatsAddition(FoodEvent.FoodStatsAddition event)
{
// cancel the default
event.setCanceled(true);
int maxHunger = AppleCoreAPI.accessor.getMaxHunger(event.player);
int newHunger = Math.min(event.player.getFoodStats().getFoodLevel() + event.foodValuesToBeAdded.hunger, maxHunger);
event.player.getFoodStats().setFoodLevel(newHunger);
float saturationIncrement = event.foodValuesToBeAdded.hunger * event.foodValuesToBeAdded.saturationModifier * 2f;
float newSaturation = Math.min(event.player.getFoodStats().getSaturationLevel() + saturationIncrement, newHunger);
AppleCoreAPI.mutator.setSaturation(event.player, newSaturation);
}
Yeah, you're right. I overlooked that this was the int,float version. Thought it was still the itemstack one, my bad. The event will do. Thanks :)
I was attempting to override how saturation values are retrieved for a HCHunger bug and noticed that at this line, the additional saturation value is calculated from the FoodValues field rather than the
getSaturationIncrement
method.