Advertisement
Guest User

Untitled

a guest
Sep 14th, 2013
61
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.62 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. public static String theNAME;
  16.  
  17. @ForgeSubscribe
  18. public void onEntityJoinWorld(EntityJoinWorldEvent event)
  19. {
  20.  
  21. if (event.entity instanceof EntityPlayer)
  22. {
  23.  
  24. World world = event.world;
  25. EntityPlayer player = (EntityPlayer)event.entity;
  26. theNBT = world.getWorldInfo().getNBTTagCompound();
  27. theNAME = player.getDisplayName();
  28.  
  29. if(world == null || theNBT == null || player == null)
  30. {
  31.  
  32. return;
  33.  
  34. }
  35.  
  36. InfoUtil.print(theNAME);
  37.  
  38. theNBT.getInteger(theNAME);
  39.  
  40. }
  41.  
  42. }
  43.  
  44. public static void editGold(int amount, int mode)
  45. {
  46.  
  47. //MODE 0 = SET | MODE 1 = ADD | MODE 2 = REMOVE
  48.  
  49. int currentAmount = theNBT.getInteger("gold");
  50.  
  51. if(mode == 0)
  52. {
  53.  
  54. theNBT.setInteger("gold", amount);
  55.  
  56. }
  57.  
  58. if(mode == 1)
  59. {
  60.  
  61. theNBT.setInteger("gold", (currentAmount + amount));
  62.  
  63. }
  64.  
  65. if(mode == 2)
  66. {
  67.  
  68. theNBT.setInteger("gold", (currentAmount - amount));
  69.  
  70. }
  71.  
  72. }
  73.  
  74. public static int getGold()
  75. {
  76.  
  77. return theNBT.getInteger("gold");
  78.  
  79. }
  80.  
  81. @Override
  82. public void readFromNBT(NBTTagCompound nbttagcompound){}
  83. @Override
  84. public void writeToNBT(NBTTagCompound nbttagcompound){}
  85.  
  86. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement