Advertisement
Guest User

ItemBlasterWand

a guest
Oct 31st, 2014
422
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 3.08 KB | None | 0 0
  1. package wop.items;
  2.  
  3. import wop.lib.Constants;
  4. import cpw.mods.fml.common.registry.GameRegistry;
  5. import net.minecraft.creativetab.CreativeTabs;
  6. import net.minecraft.entity.Entity;
  7. import net.minecraft.entity.player.EntityPlayer;
  8. import net.minecraft.init.Items;
  9. import net.minecraft.item.ItemStack;
  10. import net.minecraft.world.World;
  11. import net.minecraftforge.common.MinecraftForge;
  12. import net.minecraftforge.event.entity.player.ArrowNockEvent;
  13.  
  14. public class ItemBlastingWand extends ModItems {
  15.  
  16. private String name = "blastingWand";
  17. int damageItem = 1;
  18. private boolean isactive = false;
  19. public ItemBlastingWand()
  20. {
  21.  
  22.  
  23. setMaxStackSize(18);
  24. setMaxDamage(200);
  25. setUnlocalizedName(Constants.MODID + "_" + name);
  26. setCreativeTab(CreativeTabs.tabCombat);
  27. GameRegistry.registerItem(this, name);
  28. }
  29.  
  30. public void onUpdate(ItemStack par1ItemStack, World par2World, Entity par3Entity, int par4, boolean par5)
  31. {
  32. if (par1ItemStack.getItemDamage() < par1ItemStack.getMaxDamage())
  33. {
  34. par1ItemStack.setItemDamage(par1ItemStack.getItemDamage() - 1);
  35. //System.out.println(par1ItemStack.getItemDamage());
  36. }
  37.  
  38. if (par5 && (par3Entity instanceof EntityPlayer))
  39. {
  40. EntityPlayer entityplayer = (EntityPlayer)par3Entity;
  41. if (!par2World.isRemote && !entityplayer.capabilities.isCreativeMode)
  42. {
  43. if (entityplayer.getCurrentEquippedItem().getItem() == ModItems.MagicBlaster)
  44. {
  45. if (par1ItemStack.getItemDamage() > 0)
  46. {
  47. entityplayer.fallDistance = 0.0F;
  48. }
  49. }
  50. }
  51. }
  52.  
  53. if (par1ItemStack.getItemDamage() < par1ItemStack.getMaxDamage())
  54. {
  55. if (par3Entity instanceof EntityPlayer)
  56. {
  57. EntityPlayer entityplayer = (EntityPlayer)par3Entity;
  58. if (this.isactive)
  59. {
  60. for (int cp = 0; cp <= 10; cp++)
  61. {
  62. double d0 = itemRand.nextGaussian() * 0.02D;
  63. double d1 = itemRand.nextGaussian() * 0.02D;
  64. double d2 = itemRand.nextGaussian() * 0.02D;
  65.  
  66. double dx = entityplayer.posX;
  67. double dy = entityplayer.posY - 1.8;
  68. double dz = entityplayer.posZ;
  69.  
  70. par2World.spawnParticle("cloud", dx, dy, dz, d0, d1, d2);
  71. }
  72. }
  73.  
  74. }
  75. }
  76. }
  77. public ItemStack onItemRightClick(ItemStack stack, World world, EntityPlayer player) {
  78.  
  79.  
  80. if (player.capabilities.isCreativeMode || player.inventory.hasItem(Items.arrow))
  81. {
  82. if(stack.getItemDamage() == 0){
  83. player.inventory.consumeInventoryItem(Items.arrow);
  84. //stack.attemptDamageItem(damageItem, itemRand);
  85. stack.damageItem(199, player);
  86. this.isactive = true;
  87. }
  88. return stack;
  89. }
  90. ArrowNockEvent event = new ArrowNockEvent(player, stack);
  91. MinecraftForge.EVENT_BUS.post(event);
  92. if (event.isCanceled())
  93. {
  94. return event.result;
  95. }
  96.  
  97. world.playSoundAtEntity(player, "random.bow", 0.5F, 0.4F / (itemRand.nextFloat() * 0.4F + 0.8F));
  98.  
  99. if (!world.isRemote) {
  100. world.spawnEntityInWorld(new EntityWandBolt(world, player));
  101. }
  102.  
  103. return stack;
  104. }
  105. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement