Advertisement
ButterAleks

RightClickTest

Jan 20th, 2019
108
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 3.06 KB | None | 0 0
  1. package com.ButterAleks.RandomIdeas.items.tools;
  2.  
  3. import com.ButterAleks.RandomIdeas.items.ItemBase;
  4.  
  5. import net.minecraft.entity.item.EntityTNTPrimed;
  6. import net.minecraft.entity.player.EntityPlayer;
  7. import net.minecraft.item.ItemStack;
  8. import net.minecraft.util.ActionResult;
  9. import net.minecraft.util.EnumActionResult;
  10. import net.minecraft.util.EnumFacing;
  11. import net.minecraft.util.EnumHand;
  12. import net.minecraft.util.math.BlockPos;
  13. import net.minecraft.util.math.Vec3d;
  14. import net.minecraft.world.World;
  15.  
  16. public class RightClickTest extends ItemBase
  17. {
  18.  
  19. public RightClickTest(String name)
  20. {
  21. super(name);
  22. }
  23. @Override
  24. public ActionResult<ItemStack> onItemRightClick(World worldIn, EntityPlayer playerIn, EnumHand handIn)
  25. {
  26. ItemStack item = playerIn.getHeldItem(handIn);
  27. //For firing
  28. Vec3d aim = playerIn.getLookVec();
  29. EntityTNTPrimed tnt = new EntityTNTPrimed(worldIn, 3, 3, 3, playerIn);
  30.  
  31. tnt.setPosition(playerIn.posX + aim.x * 1.5D, playerIn.posY + aim.y * 1.5D, playerIn.posZ + aim.z * 1.5D);
  32. worldIn.spawnEntity(tnt);
  33. tnt.motionX = aim.x * 0.1; tnt.motionY = aim.y * 0.1; tnt.motionZ = aim.z * 0.1;
  34.  
  35. item.damageItem(1, playerIn);
  36. return new ActionResult<ItemStack>(EnumActionResult.SUCCESS, item);
  37. }
  38. //If you want to be used on a block
  39. //@Override
  40. //public EnumActionResult onItemUse(EntityPlayer player, World worldIn, BlockPos pos, EnumHand hand, EnumFacing facing, float hitX, float hitY, float hitZ)
  41. //{
  42. //return super.onItemUse(player, worldIn, pos, hand, facing, hitX, hitY, hitZ);
  43. //}
  44.  
  45. }
  46. package com.ButterAleks.RandomIdeas.items.tools;
  47.  
  48. import com.ButterAleks.RandomIdeas.items.ItemBase;
  49.  
  50. import net.minecraft.entity.item.EntityTNTPrimed;
  51. import net.minecraft.entity.player.EntityPlayer;
  52. import net.minecraft.item.ItemStack;
  53. import net.minecraft.util.ActionResult;
  54. import net.minecraft.util.EnumActionResult;
  55. import net.minecraft.util.EnumFacing;
  56. import net.minecraft.util.EnumHand;
  57. import net.minecraft.util.math.BlockPos;
  58. import net.minecraft.util.math.Vec3d;
  59. import net.minecraft.world.World;
  60.  
  61. public class RightClickTest extends ItemBase
  62. {
  63.  
  64. public RightClickTest(String name)
  65. {
  66. super(name);
  67. }
  68. @Override
  69. public ActionResult<ItemStack> onItemRightClick(World worldIn, EntityPlayer playerIn, EnumHand handIn)
  70. {
  71. ItemStack item = playerIn.getHeldItem(handIn);
  72. //For firing
  73. Vec3d aim = playerIn.getLookVec();
  74. EntityTNTPrimed tnt = new EntityTNTPrimed(worldIn, 3, 3, 3, playerIn);
  75.  
  76. tnt.setPosition(playerIn.posX + aim.x * 1.5D, playerIn.posY + aim.y * 1.5D, playerIn.posZ + aim.z * 1.5D);
  77. worldIn.spawnEntity(tnt);
  78. tnt.motionX = aim.x * 0.1; tnt.motionY = aim.y * 0.1; tnt.motionZ = aim.z * 0.1;
  79.  
  80. item.damageItem(1, playerIn);
  81. return new ActionResult<ItemStack>(EnumActionResult.SUCCESS, item);
  82. }
  83. //If you want to be used on a block
  84. //@Override
  85. //public EnumActionResult onItemUse(EntityPlayer player, World worldIn, BlockPos pos, EnumHand hand, EnumFacing facing, float hitX, float hitY, float hitZ)
  86. //{
  87. //return super.onItemUse(player, worldIn, pos, hand, facing, hitX, hitY, hitZ);
  88. //}
  89.  
  90. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement