Advertisement
Guest User

Untitled

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