RandomTweaks

RandomTweaks

13M Downloads

Incompatible with AppleCore

squeek502 opened this issue ยท 4 comments

commented

RandomTweaks overloads FoodStats, which causes an incompatibility with AppleCore (and with any other mod that overloads FoodStats). To fix this, you can overload FoodStats only when AppleCore is not installed, and use AppleCore's events when it is.

Your FoodStats modifications can be replicated by using the FoodEvent.FoodStatsAddition event like so:

@SubscribeEvent
public void onFoodStatsAddition(FoodEvent.FoodStatsAddition event)
{
	event.setCanceled(true);

	// your code, but using event.player.getFoodStats() and AppleCoreAPI.mutator.setSaturation
}

Another example can be found here: squeek502/AppleCore#121

Relevant issues/links:

commented

Alright, I'm using the FoodStatsAddition event now. Are there any problems with the way I've done it?

commented

Two potential problems I see:

  1. AppleCoreEventHandler probably needs to be its own class, not an inner class, as the import squeek.applecore.api.food.FoodEvent will likely cause problems when AppleCore is not installed and RTFoodStats is loaded.
  2. Once moved into its own class, stats.foodSaturationLevel = newStats.getValue(); will no longer work (since foodSaturationLevel is private and FoodStats.setFoodSaturationLevel is client-only). You can use AppleCoreAPI.mutator.setSaturation(stats, newStats.getValue()); to get around that (and stats.setFoodLevel() for hunger).
commented

I don't think #1 will be an issue, but I'll test it anyway.
#2 isn't an issue either since I'm using access transformers.

EDIT: Worked fine with just RandomTweaks installed.

commented

Nice work ๐Ÿ‘