Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Hunger reset to fixed value on dimension change #2

Closed
CplPibald opened this issue Mar 4, 2019 · 1 comment · Fixed by #4
Closed

Hunger reset to fixed value on dimension change #2

CplPibald opened this issue Mar 4, 2019 · 1 comment · Fixed by #4

Comments

@CplPibald
Copy link

Every time one of the players on my server changes dimension (nether portal, teleport, etc), their hunger is immediately reset to a fixed value (usually full hunger bar and around 6 points of saturation).

Our server has vertically stacked overworld and skyblock, so people change dimension often. This means that any food eaten over 3 shanks of saturation is wasted whenever you switch maps, and some players have learned they no longer need to eat as long as they step through once in a while.

@CplPibald
Copy link
Author

The problem appears to be in MyEventHandler.java, where whenever a player joins a world, the mod replaces the player's foodStats with a new custom FoodStats object which has been initialized with default values of 20 food and 5 saturation.

The fix is twofold. First, check if the FoodStats object is already from this mod, in which case no action is needed. This solves the problem of the stats getting reset when a player changes dimensions. To fix the stats reset when a player logs out and back in, you can copy the values from the old FoodStats before replacing them.

@Mod.EventBusSubscriber(modid = Oversaturation.MODID)
public class MyEventHandler {

    @SubscribeEvent
    public static void onEntityJoinWorld(EntityJoinWorldEvent event) {
        if (event.getEntity() instanceof EntityPlayer){
            EntityPlayer player = (EntityPlayer) event.getEntity();
            FoodStats oldStats = player.getFoodStats();

            if (null != oldStats && !(oldStats instanceof com.nachie.oversaturation.FoodStats)) {
                FoodStats newStats = new FoodStats();
                NBTTagCompound foodnbt = new NBTTagCompound();
                oldStats.writeNBT(foodnbt);
                newStats.readNBT(foodnbt);
                player.foodStats = newStats;
            }
        }
    }
}

The repository doesn't appear to be in a buildable state (no build.gradle), so I haven't tested this fix. Please let me know if you need anything further.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging a pull request may close this issue.

1 participant