Advertisement
Guest User

Untitled

a guest
Aug 9th, 2014
273
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 9.21 KB | None | 0 0
  1. package com.liquidpotions.wrink;
  2.  
  3. import java.util.HashMap;
  4. import java.util.Iterator;
  5. import java.util.List;
  6. import java.util.Map;
  7. import java.util.Map.Entry;
  8.  
  9. import com.google.common.collect.HashMultimap;
  10.  
  11. import cpw.mods.fml.relauncher.Side;
  12. import cpw.mods.fml.relauncher.SideOnly;
  13.  
  14. import net.minecraft.client.renderer.texture.IIconRegister;
  15. import net.minecraft.creativetab.CreativeTabs;
  16. import net.minecraft.entity.ai.attributes.AttributeModifier;
  17. import net.minecraft.entity.ai.attributes.IAttribute;
  18. import net.minecraft.entity.player.EntityPlayer;
  19. import net.minecraft.entity.projectile.EntityPotion;
  20. import net.minecraft.init.Items;
  21. import net.minecraft.item.Item;
  22. import net.minecraft.item.ItemPotion;
  23. import net.minecraft.item.ItemStack;
  24. import net.minecraft.potion.Potion;
  25. import net.minecraft.potion.PotionEffect;
  26. import net.minecraft.potion.PotionHelper;
  27. import net.minecraft.util.EnumChatFormatting;
  28. import net.minecraft.util.IIcon;
  29. import net.minecraft.util.StatCollector;
  30. import net.minecraft.world.World;
  31.  
  32. public class ItemPotionLP extends ItemPotion
  33. {
  34.  
  35. private IIcon bottle;
  36. private IIcon splashbottle;
  37. private IIcon liquid;
  38.  
  39. @Override
  40. @SideOnly(Side.CLIENT)
  41. public void registerIcons(IIconRegister iconRegister)
  42. {
  43. this.bottle = iconRegister.registerIcon("minecraft:potion_bottle_drinkable");
  44. this.splashbottle = iconRegister.registerIcon("minecraft:potion_bottle_splash");
  45. this.liquid = iconRegister.registerIcon("minecraft:potion_overlay");
  46. }
  47.  
  48. @Override
  49. @SideOnly(Side.CLIENT)
  50. public IIcon getIconFromDamage(int metadata)
  51. {
  52. return PotionHelperLP.isSplash(metadata) ? this.splashbottle : this.bottle;
  53. }
  54.  
  55. @Override
  56. @SideOnly(Side.CLIENT)
  57. public IIcon getIcon(ItemStack stack, int pass)
  58. {
  59. return pass == 0 ? this.liquid : this.getIconFromDamage(stack.getItemDamage());
  60. }
  61.  
  62. @Override
  63. public boolean requiresMultipleRenderPasses()
  64. {
  65. return true;
  66. }
  67.  
  68. public boolean isWater(ItemStack potionStack)
  69. {
  70. return potionStack.getItemDamage() == 0;
  71. }
  72.  
  73. public int getAmplifier(ItemStack potionStack)
  74. {
  75. return PotionHelperLP.getPotionAmplifier(potionStack.getItemDamage());
  76. }
  77.  
  78. public boolean isBasePotion(ItemStack potionStack)
  79. {
  80. return PotionHelperLP.isBasePotion(potionStack.getItemDamage());
  81. }
  82.  
  83. public boolean isExtendable(ItemStack potionStack)
  84. {
  85. return PotionHelperLP.getPotionDurationModifier(potionStack.getItemDamage()) < 7;
  86. }
  87.  
  88. public boolean isInvertable(ItemStack potionStack) {
  89. return PotionHelperLP.isInvertable(potionStack.getItemDamage());
  90. }
  91.  
  92. public boolean isSplash(ItemStack potionStack) {
  93. return PotionHelperLP.isSplash(potionStack.getItemDamage());
  94. }
  95.  
  96. @Override
  97. public ItemStack onEaten(ItemStack potionStack, World world, EntityPlayer player)
  98. {
  99. if (!player.capabilities.isCreativeMode)
  100. {
  101. --potionStack.stackSize;
  102. }
  103.  
  104. if (!world.isRemote)
  105. {
  106. player.addPotionEffect(PotionHelperLP.getPotionEffects(potionStack.getItemDamage()));
  107. }
  108.  
  109. if (!player.capabilities.isCreativeMode)
  110. {
  111. if (potionStack.stackSize <= 0)
  112. {
  113. return new ItemStack(Items.glass_bottle);
  114. }
  115.  
  116. player.inventory.addItemStackToInventory(new ItemStack(Items.glass_bottle));
  117. }
  118.  
  119. return potionStack;
  120. }
  121.  
  122. @Override
  123. @SideOnly(Side.CLIENT)
  124. public int getColorFromDamage(int damage)
  125. {
  126. return PotionHelperLP.getColor(damage);
  127. }
  128.  
  129. @Override
  130. @SideOnly(Side.CLIENT)
  131. public int getColorFromItemStack(ItemStack p_82790_1_, int p_82790_2_)
  132. {
  133. return p_82790_2_ > 0 ? 16777215 : this.getColorFromDamage(p_82790_1_.getItemDamage());
  134. }
  135.  
  136. @Override
  137. @SideOnly(Side.CLIENT)
  138. public boolean isEffectInstant(int damage)
  139. {
  140. return Potion.potionTypes[PotionHelperLP.getPotionEffects(damage).getPotionID()].isInstant();
  141. }
  142.  
  143. public String getItemStackDisplayName(ItemStack p_77653_1_)
  144. {
  145. return PotionHelperLP.getPotionName(p_77653_1_.getItemDamage());
  146. }
  147.  
  148. @SideOnly(Side.CLIENT)
  149. public void addInformation(ItemStack p_77624_1_, EntityPlayer p_77624_2_, List p_77624_3_, boolean p_77624_4_)
  150. {
  151. if (p_77624_1_.getItemDamage() != 0)
  152. {
  153. List list1 = Items.potionitem.getEffects(p_77624_1_);
  154. PotionEffect effect = PotionHelperLP.getPotionEffects(p_77624_1_.getItemDamage());
  155. HashMultimap hashmultimap = HashMultimap.create();
  156. Iterator iterator1;
  157.  
  158. if (list1 != null && !list1.isEmpty())
  159. {
  160. String s1 = StatCollector.translateToLocal(effect.getEffectName()).trim();
  161. Potion potion = Potion.potionTypes[effect.getPotionID()];
  162.  
  163. if (effect.getAmplifier() > 0)
  164. {
  165. s1 = s1 + " " + StatCollector.translateToLocal("potion.potency." + effect.getAmplifier()).trim();
  166. }
  167.  
  168. if (effect.getDuration() > 20)
  169. {
  170. s1 = s1 + " (" + Potion.getDurationString(effect) + ")";
  171. }
  172.  
  173. if (potion.isBadEffect())
  174. {
  175. p_77624_3_.add(EnumChatFormatting.RED + s1);
  176. }
  177. else
  178. {
  179. p_77624_3_.add(EnumChatFormatting.GRAY + s1);
  180. }
  181.  
  182. p_77624_3_.add("");
  183. p_77624_3_.add(EnumChatFormatting.DARK_PURPLE + StatCollector.translateToLocal("potion.effects.whenDrank"));
  184. }
  185. else
  186. {
  187. String s = StatCollector.translateToLocal("potion.empty").trim();
  188. p_77624_3_.add(EnumChatFormatting.GRAY + s);
  189. }
  190.  
  191. if (!hashmultimap.isEmpty())
  192. {
  193. p_77624_3_.add("");
  194. p_77624_3_.add(EnumChatFormatting.DARK_PURPLE + StatCollector.translateToLocal("potion.effects.whenDrank"));
  195. iterator1 = hashmultimap.entries().iterator();
  196.  
  197. while (iterator1.hasNext())
  198. {
  199. Entry entry1 = (Entry)iterator1.next();
  200. AttributeModifier attributemodifier2 = (AttributeModifier)entry1.getValue();
  201. double d0 = attributemodifier2.getAmount();
  202. double d1;
  203.  
  204. if (attributemodifier2.getOperation() != 1 && attributemodifier2.getOperation() != 2)
  205. {
  206. d1 = attributemodifier2.getAmount();
  207. }
  208. else
  209. {
  210. d1 = attributemodifier2.getAmount() * 100.0D;
  211. }
  212.  
  213. if (d0 > 0.0D)
  214. {
  215. p_77624_3_.add(EnumChatFormatting.BLUE + StatCollector.translateToLocalFormatted("attribute.modifier.plus." + attributemodifier2.getOperation(), new Object[] {ItemStack.field_111284_a.format(d1), StatCollector.translateToLocal("attribute.name." + (String)entry1.getKey())}));
  216. }
  217. else if (d0 < 0.0D)
  218. {
  219. d1 *= -1.0D;
  220. p_77624_3_.add(EnumChatFormatting.RED + StatCollector.translateToLocalFormatted("attribute.modifier.take." + attributemodifier2.getOperation(), new Object[] {ItemStack.field_111284_a.format(d1), StatCollector.translateToLocal("attribute.name." + (String)entry1.getKey())}));
  221. }
  222. }
  223. }
  224. }
  225. }
  226.  
  227. @SideOnly(Side.CLIENT)
  228. public boolean hasEffect(ItemStack stack)
  229. {
  230. return PotionHelperLP.getPotionEffects(stack.getItemDamage()) != null;
  231. }
  232.  
  233. public void getSubItems(Item p_150895_1_, CreativeTabs p_150895_2_, List p_150895_3_)
  234. {
  235. Iterator iterator = PotionHelperLP.getRegisteredPotions().iterator();
  236. while(iterator.hasNext())
  237. {
  238. p_150895_3_.add(new ItemStack(p_150895_1_, 1, (Integer) iterator.next()));
  239. }
  240. iterator = PotionHelperLP.getRegisteredSplashPotions().iterator();
  241. while(iterator.hasNext())
  242. {
  243. p_150895_3_.add(new ItemStack(p_150895_1_, 1, (Integer) iterator.next()));
  244. }
  245. }
  246.  
  247. /**
  248. * Called whenever this item is equipped and the right mouse button is pressed. Args: itemStack, world, entityPlayer
  249. */
  250. @Override
  251. public ItemStack onItemRightClick(ItemStack p_77659_1_, World p_77659_2_, EntityPlayer p_77659_3_)
  252. {
  253. int damage = p_77659_1_.getItemDamage();
  254. if (isSplash(p_77659_1_))
  255. {
  256. if (!p_77659_3_.capabilities.isCreativeMode)
  257. {
  258. --p_77659_1_.stackSize;
  259. }
  260.  
  261. p_77659_2_.playSoundAtEntity(p_77659_3_, "random.bow", 0.5F, 0.4F / (itemRand.nextFloat() * 0.4F + 0.8F));
  262.  
  263. if (!p_77659_2_.isRemote)
  264. {
  265. p_77659_2_.spawnEntityInWorld(new EntityPotionLP(p_77659_2_, p_77659_3_, damage));
  266. }
  267.  
  268. return p_77659_1_;
  269. }
  270. else
  271. {
  272. p_77659_3_.setItemInUse(p_77659_1_, this.getMaxItemUseDuration(p_77659_1_));
  273. return p_77659_1_;
  274. }
  275. }
  276. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement