Guest User

Untitled

a guest
Sep 21st, 2013
122
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.58 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. itemStack.stackTagCompound = new NBTTagCompound();
  31.  
  32. itemStack.stackTagCompound.setFloat("stored", 0.0F);
  33. itemStack.stackTagCompound.setInteger("mode", 0);
  34.  
  35. }
  36.  
  37. @Override
  38. public void onCreated(ItemStack itemStack, World world, EntityPlayer player)
  39. {
  40.  
  41. createNBT(itemStack);
  42.  
  43. }
  44.  
  45. public void addInformation(ItemStack itemStack, EntityPlayer player, List list, boolean par4)
  46. {
  47.  
  48. if(itemStack.stackTagCompound == null)
  49. {
  50.  
  51. createNBT(itemStack);
  52. return;
  53.  
  54. }
  55.  
  56. float amount = itemStack.stackTagCompound.getFloat("stored");
  57. int mode = itemStack.stackTagCompound.getInteger("mode");
  58. String modeD = "";
  59.  
  60. switch(mode)
  61. {
  62. case(0):{modeD = "Deposit";}
  63. case(1):{modeD = "Withdraw";}
  64. }
  65.  
  66. list.add("Exp Stored: " + amount);
  67. list.add("Mode: " + modeD);
  68.  
  69. }
  70.  
  71. @Override
  72. public ItemStack onItemRightClick(ItemStack itemStack, World world, EntityPlayer player)
  73. {
  74.  
  75. if(itemStack.stackTagCompound == null)
  76. {
  77.  
  78. createNBT(itemStack);
  79.  
  80. }
  81.  
  82. if(player.isSneaking())
  83. {
  84.  
  85. int mode = itemStack.stackTagCompound.getInteger("mode");
  86.  
  87. switch(mode)
  88. {
  89.  
  90. case(0):{itemStack.stackTagCompound.setInteger("mode", 1);}
  91. case(1):{itemStack.stackTagCompound.setInteger("mode", 0);}
  92.  
  93. }
  94.  
  95. }
  96.  
  97. if(!player.isSneaking())
  98. {
  99.  
  100. int mode = itemStack.stackTagCompound.getInteger("mode");
  101. float xp = itemStack.stackTagCompound.getInteger("stored");
  102.  
  103. switch(mode)
  104. {
  105.  
  106. case(0):
  107. {
  108.  
  109. if(player.experienceLevel >= 1)
  110. {
  111.  
  112. player.experienceLevel--;
  113. itemStack.stackTagCompound.setFloat("stored", xp++);
  114.  
  115. }
  116.  
  117. }
  118.  
  119. case(1):
  120. {
  121.  
  122. if(xp >= 1)
  123. {
  124.  
  125. player.experienceLevel++;
  126. itemStack.stackTagCompound.setFloat("stored", xp--);
  127.  
  128. }
  129.  
  130. }
  131.  
  132. }
  133.  
  134. }
  135.  
  136. return itemStack;
  137.  
  138. }
  139.  
  140. }
Advertisement
Add Comment
Please, Sign In to add comment