Advertisement
Guest User

Untitled

a guest
Sep 21st, 2013
86
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.61 KB | None | 0 0
  1. package tlhpoe.darkorigins.item;
  2.  
  3. import java.awt.List;
  4.  
  5. import net.minecraft.entity.player.EntityPlayer;
  6. import net.minecraft.item.ItemStack;
  7. import net.minecraft.nbt.NBTTagCompound;
  8. import net.minecraft.util.ChunkCoordinates;
  9. import net.minecraft.world.World;
  10. import tlhpoe.darkorigins.helper.CreativeTabHelper;
  11. import tlhpoe.darkorigins.util.InfoUtil;
  12.  
  13. public class ItemExpContainer extends ItemBase
  14. {
  15.  
  16. public ItemExpContainer(int id, String name)
  17. {
  18.  
  19. super(id, name);
  20.  
  21. setMaxStackSize(1);
  22. setUnlocalizedName(name);
  23. setCreativeTab(CreativeTabHelper.items);
  24.  
  25. }
  26.  
  27. public static void createNBT(ItemStack itemStack)
  28. {
  29.  
  30. InfoUtil.print("Creating NBTTag...");
  31.  
  32. itemStack.stackTagCompound = new NBTTagCompound();
  33.  
  34. itemStack.stackTagCompound.setFloat("stored", 0.0F);
  35. itemStack.stackTagCompound.setInteger("mode", 0);
  36.  
  37. }
  38.  
  39. @Override
  40. public void onCreated(ItemStack itemStack, World world, EntityPlayer player)
  41. {
  42.  
  43. createNBT(itemStack);
  44.  
  45. }
  46.  
  47. public void addInformation(ItemStack itemStack, EntityPlayer player, List list, boolean par4)
  48. {
  49.  
  50. if(itemStack.stackTagCompound == null)
  51. {
  52.  
  53. createNBT(itemStack);
  54.  
  55. }
  56.  
  57. float amount = itemStack.stackTagCompound.getFloat("stored");
  58. int mode = itemStack.stackTagCompound.getInteger("mode");
  59. String modeD = "";
  60.  
  61. switch(mode)
  62. {
  63. case(0):{modeD = "Deposit";}
  64. case(1):{modeD = "Withdraw";}
  65. }
  66.  
  67. list.add("Exp Stored: " + amount);
  68. list.add("Mode: " + modeD);
  69.  
  70. }
  71.  
  72. @Override
  73. public ItemStack onItemRightClick(ItemStack itemStack, World world, EntityPlayer player)
  74. {
  75.  
  76. if(itemStack.stackTagCompound == null)
  77. {
  78.  
  79. createNBT(itemStack);
  80.  
  81. }
  82.  
  83. if(player.isSneaking())
  84. {
  85.  
  86. int mode = itemStack.stackTagCompound.getInteger("mode");
  87.  
  88. switch(mode)
  89. {
  90.  
  91. case(0):{itemStack.stackTagCompound.setInteger("mode", 1);}
  92. case(1):{itemStack.stackTagCompound.setInteger("mode", 0);}
  93.  
  94. }
  95.  
  96. }
  97.  
  98. if(!player.isSneaking())
  99. {
  100.  
  101. int mode = itemStack.stackTagCompound.getInteger("mode");
  102. float xp = itemStack.stackTagCompound.getFloat("stored");
  103.  
  104. switch(mode)
  105. {
  106.  
  107. case(0):
  108. {
  109.  
  110. if(player.experienceLevel >= 1)
  111. {
  112.  
  113. player.experienceLevel--;
  114. itemStack.stackTagCompound.setFloat("stored", xp++);
  115.  
  116. }
  117.  
  118. }
  119.  
  120. case(1):
  121. {
  122.  
  123. if(xp >= 1)
  124. {
  125.  
  126. player.experienceLevel++;
  127. itemStack.stackTagCompound.setFloat("stored", xp--);
  128.  
  129. }
  130.  
  131. }
  132.  
  133. }
  134.  
  135. }
  136.  
  137. return itemStack;
  138.  
  139. }
  140.  
  141. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement