Advertisement
Guest User

Untitled

a guest
Sep 13th, 2013
70
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.46 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. EntityPlayer player = (EntityPlayer) event.entity;
  24. World world = player.worldObj;;
  25. NBTTagCompound nbt = world.getWorldInfo().getPlayerNBTTagCompound();
  26. theNBT = nbt;
  27.  
  28. theNBT.getInteger("gold");
  29.  
  30. }
  31.  
  32. }
  33.  
  34. public static void editGold(int amount, int mode)
  35. {
  36.  
  37. //MODE 0 = SET | MODE 1 = ADD | MODE 2 = REMOVE
  38.  
  39. int currentAmount = theNBT.getInteger("gold");
  40.  
  41. if(mode == 0)
  42. {
  43.  
  44. theNBT.setInteger("gold", amount);
  45.  
  46. }
  47.  
  48. if(mode == 1)
  49. {
  50.  
  51. theNBT.setInteger("gold", (currentAmount + amount));
  52.  
  53. }
  54.  
  55. if(mode == 2)
  56. {
  57.  
  58. theNBT.setInteger("gold", (currentAmount - amount));
  59.  
  60. }
  61.  
  62. }
  63.  
  64. public static int getGold()
  65. {
  66.  
  67. return theNBT.getInteger("gold");
  68.  
  69. }
  70.  
  71. @Override
  72. public void readFromNBT(NBTTagCompound nbttagcompound){}
  73. @Override
  74. public void writeToNBT(NBTTagCompound nbttagcompound){}
  75.  
  76. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement