Guest User

Lightning

a guest
Jul 3rd, 2014
295
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 6.70 KB | None | 0 0
  1. package fourswords.items.swords;
  2.  
  3. import net.minecraft.block.Block;
  4. import net.minecraft.block.material.Material;
  5. import net.minecraft.client.renderer.texture.IconRegister;
  6. import net.minecraft.entity.EntityLivingBase;
  7. import net.minecraft.entity.SharedMonsterAttributes;
  8. import net.minecraft.entity.ai.attributes.AttributeModifier;
  9. import net.minecraft.entity.effect.EntityLightningBolt;
  10. import net.minecraft.entity.player.EntityPlayer;
  11. import net.minecraft.item.EnumAction;
  12. import net.minecraft.item.EnumToolMaterial;
  13. import net.minecraft.item.Item;
  14. import net.minecraft.item.ItemStack;
  15. import net.minecraft.util.EnumMovingObjectType;
  16. import net.minecraft.util.MathHelper;
  17. import net.minecraft.util.MovingObjectPosition;
  18. import net.minecraft.util.Vec3;
  19. import net.minecraft.world.World;
  20.  
  21. import com.google.common.collect.Multimap;
  22.  
  23. import cpw.mods.fml.relauncher.Side;
  24. import cpw.mods.fml.relauncher.SideOnly;
  25. import fourswords.creativetabs.CTabs;
  26. import fourswords.lib.ModInfo;
  27.  
  28. public class SwordThor extends Item
  29. {
  30. private final float weaponDamage;
  31. private final EnumToolMaterial toolMaterial;
  32.  
  33. public SwordThor(int par1, EnumToolMaterial par2EnumToolMaterial)
  34. {
  35. super(par1);
  36. this.toolMaterial = par2EnumToolMaterial;
  37. this.maxStackSize = 1;
  38. this.setUnlocalizedName("thorsword");
  39. this.setCreativeTab(CTabs.swordTab);
  40. this.setMaxDamage(1000);
  41. this.weaponDamage = 11.0F + par2EnumToolMaterial.getDamageVsEntity();
  42. }
  43.  
  44. public float func_82803_g()
  45. {
  46. return this.toolMaterial.getDamageVsEntity();
  47. }
  48.  
  49. /**
  50. * Returns the strength of the stack against a given block. 1.0F base,
  51. * (Quality+1)*2 if correct blocktype, 1.5F if sword
  52. */
  53. @Override
  54. public float getStrVsBlock(ItemStack par1ItemStack, Block par2Block)
  55. {
  56. if (par2Block.blockID == Block.web.blockID)
  57. {
  58. return 20.0F;
  59. }
  60. else
  61. {
  62. Material material = par2Block.blockMaterial;
  63. return material != Material.plants && material != Material.vine
  64. && material != Material.coral
  65. && material != Material.leaves
  66. && material != Material.pumpkin ? 1.0F : 1.5F;
  67. }
  68. }
  69.  
  70. /**
  71. * Current implementations of this method in child classes do not use the
  72. * entry argument beside ev. They just raise the damage on the stack.
  73. */
  74. @Override
  75. public boolean hitEntity(ItemStack par1ItemStack,
  76. EntityLivingBase par2EntityLivingBase,
  77. EntityLivingBase par3EntityLivingBase)
  78. {
  79. par1ItemStack.damageItem(1, par3EntityLivingBase);
  80. return true;
  81. }
  82.  
  83. @Override
  84. public boolean onBlockDestroyed(ItemStack par1ItemStack, World par2World,
  85. int par3, int par4, int par5, int par6,
  86. EntityLivingBase par7EntityLivingBase)
  87. {
  88. if (Block.blocksList[par3]
  89. .getBlockHardness(par2World, par4, par5, par6) != 0.0D)
  90. {
  91. par1ItemStack.damageItem(2, par7EntityLivingBase);
  92. }
  93.  
  94. return true;
  95. }
  96.  
  97. @Override
  98. @SideOnly(Side.CLIENT)
  99. /**
  100. * Returns True is the item is renderer in full 3D when hold.
  101. */
  102. public boolean isFull3D()
  103. {
  104. return true;
  105. }
  106.  
  107. /**
  108. * returns the action that specifies what animation to play when the items
  109. * is being used
  110. */
  111. @Override
  112. public EnumAction getItemUseAction(ItemStack par1ItemStack)
  113. {
  114. return EnumAction.block;
  115. }
  116.  
  117. /**
  118. * How long it takes to use or consume an item
  119. */
  120. @Override
  121. public int getMaxItemUseDuration(ItemStack par1ItemStack)
  122. {
  123. return 72000;
  124. }
  125.  
  126. @Override
  127. public ItemStack onItemRightClick(ItemStack itemstack, World world,
  128. EntityPlayer entityplayer) {
  129.  
  130. float f = 2.0F;
  131.  
  132. float f1 = entityplayer.prevRotationPitch
  133. + (entityplayer.rotationPitch - entityplayer.prevRotationPitch)
  134. * f;
  135.  
  136. float f2 = entityplayer.prevRotationYaw
  137. + (entityplayer.rotationYaw - entityplayer.prevRotationYaw) * f;
  138.  
  139. double d = entityplayer.prevPosX
  140. + (entityplayer.posX - entityplayer.prevPosX) * f;
  141.  
  142. double d1 = (entityplayer.prevPosY
  143. + (entityplayer.posY - entityplayer.prevPosY) * f +
  144.  
  145. 1.6200000000000001D)
  146. - entityplayer.yOffset;
  147.  
  148. double d2 = entityplayer.prevPosZ
  149. + (entityplayer.posZ - entityplayer.prevPosZ) * f;
  150. Vec3 vec3d = null;
  151. vec3d = vec3d.createVectorHelper(d, d1, d2);
  152.  
  153. float f3 = MathHelper.cos(-f2 * 0.01745329F - 3.141593F);
  154.  
  155. float f4 = MathHelper.sin(-f2 * 0.01745329F - 3.141593F);
  156.  
  157. float f5 = -MathHelper.cos(-f1 * 0.01745329F);
  158.  
  159. float f6 = MathHelper.sin(-f1 * 0.01745329F);
  160.  
  161. float f7 = f4 * f5;
  162.  
  163. float f8 = f6;
  164.  
  165. float f9 = f3 * f5;
  166.  
  167. double d3 = 5000D;
  168.  
  169. Vec3 vec3d1 = vec3d.addVector(f7 * d3, f8 * d3,
  170. f9 * d3);
  171.  
  172. MovingObjectPosition movingobjectposition = world.rayTraceBlocks_do_do(
  173. vec3d, vec3d1, false, true);
  174.  
  175. if (movingobjectposition == null)
  176.  
  177. {
  178.  
  179. return itemstack;
  180.  
  181. }
  182.  
  183. if (movingobjectposition.typeOfHit == EnumMovingObjectType.TILE)
  184.  
  185. {
  186.  
  187. int i = movingobjectposition.blockX;
  188.  
  189. int j = movingobjectposition.blockY;
  190.  
  191. int k = movingobjectposition.blockZ;
  192.  
  193. for (int l = 0; l < 32; l += 4) {
  194. world.spawnEntityInWorld(new EntityLightningBolt(world,
  195. i, j, (k + l)));
  196. }
  197. if (!entityplayer.capabilities.isCreativeMode) {
  198. itemstack.damageItem(5, entityplayer);
  199. }
  200. }
  201. return itemstack;
  202. }
  203.  
  204. /**
  205. * Returns if the item (tool) can harvest results from the block type.
  206. */
  207. @Override
  208. public boolean canHarvestBlock(Block par1Block)
  209. {
  210. return par1Block.blockID == Block.web.blockID;
  211. }
  212.  
  213. /**
  214. * Return the enchantability factor of the item, most of the time is based
  215. * on material.
  216. */
  217. @Override
  218. public int getItemEnchantability()
  219. {
  220. return this.toolMaterial.getEnchantability();
  221. }
  222.  
  223. /**
  224. * Return the name for this tool's material.
  225. */
  226. public String getToolMaterialName()
  227. {
  228. return this.toolMaterial.toString();
  229. }
  230.  
  231. /**
  232. * Return whether this item is repairable in an anvil.
  233. */
  234. @Override
  235. public boolean getIsRepairable(ItemStack par1ItemStack,
  236. ItemStack par2ItemStack)
  237. {
  238. return this.toolMaterial.getToolCraftingMaterial() == par2ItemStack.itemID ? true
  239. : super.getIsRepairable(par1ItemStack, par2ItemStack);
  240. }
  241.  
  242. /**
  243. * Gets a map of item attribute modifiers, used by ItemSword to increase hit
  244. * damage.
  245. */
  246. @Override
  247. public Multimap getItemAttributeModifiers()
  248. {
  249. Multimap multimap = super.getItemAttributeModifiers();
  250. multimap.put(SharedMonsterAttributes.attackDamage
  251. .getAttributeUnlocalizedName(), new AttributeModifier(
  252. field_111210_e, "Weapon modifier", this.weaponDamage,
  253. 0));
  254. return multimap;
  255. }
  256.  
  257. @Override
  258. @SideOnly(Side.CLIENT)
  259. public void registerIcons(IconRegister icon) {
  260. itemIcon = icon.registerIcon(ModInfo.ID.toLowerCase() + ":"
  261. + "thorsword");
  262. }
  263. }
Advertisement
Add Comment
Please, Sign In to add comment