squeek502 / AppleCore

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

Crashing when paired with Oversaturation #124

Open truenachtara opened 6 years ago

truenachtara commented 6 years ago

I'm the Oversaturation dev. I'm modifying FoodStats, which is causing some players who use both this mod and my mod to crash when they eat food. However, in the dev environment, I'm experiencing a full-on crash when I load the world. Do you have any information on stopping this?

Here's my mod: https://github.com/truenachtara/Oversaturation My dev environment crash: https://pastebin.com/Sw9XdLaC An issue report detailing a player experiencing this issue in-game (contains crash report): https://github.com/Cazsius/Spice-of-Life-Carrot-Edition/issues/32

squeek502 commented 6 years ago

Overloading FoodStats will not be compatible with AppleCore (and with any other mods that overload FoodStats). Instead, when you detect AppleCore is installed, you should use AppleCore's events to modify the saturation like so:

@SubscribeEvent
public void getFoodValues(FoodEvent.GetPlayerFoodValues event)
{
    int maxHunger = AppleCoreAPI.accessor.getMaxHunger(event.player);
    int curHunger = event.player.getFoodStats().getFoodLevel();
    int extraSaturation = event.foodStats.hunger - (maxHunger - curHunger);
    if (extraSaturation > 0) {
        int newHunger = maxHunger - curHunger;
        float newSaturationModifier = event.foodValues.saturationModifier + extraSaturation;
        event.foodValues = new FoodValues(newHunger, newSaturationModifier);
    }
}

Note: the above should be in its own class that is only loaded when "applecore" is loaded.

See here for how to include the AppleCore API in your dev environment.

squeek502 commented 6 years ago

Actually, I missed that your mod removes the maxSaturation == currentHunger limitation, so instead you'll need to use the method outlined here: https://github.com/TheRandomLabs/RandomTweaks/issues/18

Darkmega18 commented 6 years ago

oh dear. so I must be getting something very similar with maybe pams if I had to guess. Cause I'm getting world load crashes due to overloaded food values also... so time to downdate and just stick with what worked till everyone catches this... :V

squeek502 commented 6 years ago

@Darkmega18 It's probably not Harvestcraft, judging from its source code. Note also that anything that crashes now would probably have always caused hidden problems (like AppleCore events not firing, etc).

Darkmega18 commented 6 years ago

atleast they never outright crashed. and I say harvestcraft cause it's the only thing i know that adds foods that give you restoration bigger than a full bar and I don't have oversaturation. what exactly causes this overload thing anyways? cause at first it had noppes in the crash so I thought it was it's scripted items playing up, but even after taking that out it still kept exploding. :V unless perhaps it was... abyssalcraft and it's food plates and other bits? I'm just trying to think what other stuff in my game add food... like actually additions.

squeek502 commented 6 years ago

'Overloads' is a programming term, it has nothing to do with anything in-game.

It's hard to know which mod is causing it, but it's much more likely that its an obscure or rarely used mod than a popular one (otherwise it probably would have been reported earlier). If you could paste the exact error you get, that would be helpful (because it will contain the class name of the overwritten FoodStats, which will generally give enough clues to figure out what mod it's coming from).

Darkmega18 commented 6 years ago

2018-06-14-3.log.gz

That one has what happens when custom NPCs was in.

2018-06-14-4.log.gz

so next I took it out and loaded the world and it got rid of the custom npcs stuff but still went down.

Good luck, and sorry if you don't like direct upload logs. :V

squeek502 commented 6 years ago

AppleCore 3.1.2 was bugged and had a startup crash regardless of any other mods. Please use 3.1.3 instead.