Advertisement
Guest User

Untitled

a guest
Sep 13th, 2013
62
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.40 KB | None | 0 0
  1. package terramagna.utils;
  2.  
  3. import net.minecraft.entity.player.EntityPlayer;
  4. import net.minecraft.nbt.NBTTagCompound;
  5. import net.minecraft.world.*;
  6. import net.minecraftforge.event.ForgeSubscribe;
  7. import net.minecraftforge.event.entity.EntityJoinWorldEvent;
  8.  
  9. public class PlayerStatsUtil extends WorldSavedData
  10. {
  11.  
  12. public PlayerStatsUtil(String par1Str){super(par1Str);}
  13.  
  14. public static NBTTagCompound theNBT;
  15.  
  16. @ForgeSubscribe
  17. public void onEntityJoinWorld(EntityJoinWorldEvent event)
  18. {
  19.  
  20. if (event.entity instanceof EntityPlayer)
  21. {
  22.  
  23. World world = event.world;
  24. NBTTagCompound nbt = world.getWorldInfo().getPlayerNBTTagCompound();
  25. theNBT = nbt;
  26.  
  27. theNBT.getInteger("gold");
  28.  
  29. }
  30.  
  31. }
  32.  
  33. public static void editGold(int amount, int mode)
  34. {
  35.  
  36. //MODE 0 = SET | MODE 1 = ADD | MODE 2 = REMOVE
  37.  
  38. int currentAmount = theNBT.getInteger("gold");
  39.  
  40. if(mode == 0)
  41. {
  42.  
  43. theNBT.setInteger("gold", amount);
  44.  
  45. }
  46.  
  47. if(mode == 1)
  48. {
  49.  
  50. theNBT.setInteger("gold", (currentAmount + amount));
  51.  
  52. }
  53.  
  54. if(mode == 2)
  55. {
  56.  
  57. theNBT.setInteger("gold", (currentAmount - amount));
  58.  
  59. }
  60.  
  61. }
  62.  
  63. public static int getGold()
  64. {
  65.  
  66. return theNBT.getInteger("gold");
  67.  
  68. }
  69.  
  70. @Override
  71. public void readFromNBT(NBTTagCompound nbttagcompound){}
  72. @Override
  73. public void writeToNBT(NBTTagCompound nbttagcompound){}
  74.  
  75. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement