Skip to content

Commit

Permalink
Added additional check to read player nbt when logging in, prevents f…
Browse files Browse the repository at this point in the history
…ood stats from getting reset and not replaced on client. Fixes #169
  • Loading branch information
alcatrazEscapee committed Jul 14, 2019
1 parent b9b28f5 commit 43259e7
Showing 1 changed file with 18 additions and 2 deletions.
20 changes: 18 additions & 2 deletions src/main/java/net/dries007/tfc/CommonEventHandler.java
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,8 @@
import net.minecraft.init.Items;
import net.minecraft.init.SoundEvents;
import net.minecraft.item.*;
import net.minecraft.nbt.NBTTagCompound;
import net.minecraft.server.MinecraftServer;
import net.minecraft.util.EnumActionResult;
import net.minecraft.util.FoodStats;
import net.minecraft.util.SoundCategory;
Expand Down Expand Up @@ -285,10 +287,24 @@ public static void onPlayerLoggedIn(PlayerEvent.PlayerLoggedInEvent event)
CalendarTFC.INSTANCE.update(player);

// Food Stats
FoodStats originalStats = event.player.getFoodStats();
FoodStats originalStats = player.getFoodStats();
if (!(originalStats instanceof FoodStatsTFC))
{
event.player.foodStats = new FoodStatsTFC(event.player, originalStats);
player.foodStats = new FoodStatsTFC(player, originalStats);

// Also need to read the food stats from nbt, as they were not present when the player was loaded
MinecraftServer server = player.world.getMinecraftServer();
if (server != null)
{
NBTTagCompound nbt = server.getPlayerList().getPlayerNBT(player);
// This can be null if the server is unable to read the file
//noinspection ConstantConditions
if (nbt != null)
{
player.foodStats.readNBT(nbt);
}
}

TerraFirmaCraft.getNetwork().sendTo(new PacketFoodStatsReplace(), (EntityPlayerMP) event.player);
}
}
Expand Down

0 comments on commit 43259e7

Please sign in to comment.