Guest User

Untitled

a guest
Sep 8th, 2013
125
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.51 KB | None | 0 0
  1. package terramagna.helpers;
  2.  
  3. import net.minecraft.entity.player.EntityPlayer;
  4. import net.minecraft.nbt.NBTTagCompound;
  5. import net.minecraft.world.WorldSavedData;
  6. import net.minecraftforge.event.ForgeSubscribe;
  7. import net.minecraftforge.event.entity.EntityJoinWorldEvent;
  8.  
  9. public class PlayerStatsHelper extends WorldSavedData
  10. {
  11.  
  12. private static int experience;
  13.  
  14. public PlayerStatsHelper(String par1Str)
  15. {
  16.  
  17. super(par1Str);
  18.  
  19. }
  20.  
  21. @ForgeSubscribe
  22. public void onEntityJoinWorld(EntityJoinWorldEvent event)
  23. {
  24.  
  25. if (!event.entity.worldObj.isRemote && event.entity instanceof EntityPlayer)
  26. {
  27.  
  28. EntityPlayer player = (EntityPlayer) event.entity;
  29. NBTTagCompound nbt = player.getEntityData().getCompoundTag("PlayerPersisted");
  30.  
  31. nbt.getInteger("Experience");
  32.  
  33. if(nbt.getInteger("Experience") == 0)
  34. {
  35.  
  36. nbt.setInteger("Experience", 0);
  37.  
  38. }
  39.  
  40. this.experience = nbt.getInteger("Experience");
  41.  
  42. }
  43.  
  44. }
  45.  
  46. @Override
  47. public void readFromNBT(NBTTagCompound nbttagcompound) {
  48. // TODO Auto-generated method stub
  49.  
  50. }
  51.  
  52. @Override
  53. public void writeToNBT(NBTTagCompound nbttagcompound) {
  54. // TODO Auto-generated method stub
  55.  
  56. }
  57.  
  58. public static int getExperience()
  59. {
  60.  
  61. return experience;
  62.  
  63. }
  64.  
  65. public static void addExperience(int amount)
  66. {
  67.  
  68. experience = experience + amount;
  69.  
  70. }
  71.  
  72. public static void removeExperience(int amount)
  73. {
  74.  
  75. experience = experience - amount;
  76.  
  77. }
  78.  
  79. }
Advertisement
Add Comment
Please, Sign In to add comment