Guest User

Untitled

a guest
Apr 11th, 2020
434
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.98 KB | None | 0 0
  1. public class FlameWandItem extends Item
  2. {
  3. public FlameWandItem(Item.Properties builder)
  4. {
  5. super(builder);
  6. }
  7.  
  8. private RayTraceResult rayTrace(World world, PlayerEntity player)
  9. {
  10. float rotationPitch = player.rotationPitch;
  11. float rotationYaw = player.rotationYaw;
  12. Vec3d eyePosition = player.getEyePosition(1.0f);
  13. //Normalize the look vector
  14. float f2 = MathHelper.cos(-rotationYaw * ((float)Math.PI / 180f) - (float)Math.PI);
  15. float f3 = MathHelper.sin(-rotationYaw * ((float)Math.PI / 180f) - (float)Math.PI);
  16. float f4 = MathHelper.cos(-rotationPitch * ((float)Math.PI / 180f));
  17. float f5 = MathHelper.sin(-rotationPitch * ((float)Math.PI / 180f));
  18. float f6 = f3 * f4;
  19. float f7 = f2 * f4;
  20. double rayTraceDistance = 32;
  21. //Take the start position and add the look vector multiplied by the rayTraceDistance
  22. Vec3d endPosition = eyePosition.add((double)f6 * rayTraceDistance, (double)f5 * rayTraceDistance, (double)f7 * rayTraceDistance);
  23. return world.rayTraceBlocks(new RayTraceContext(eyePosition, endPosition, RayTraceContext.BlockMode.OUTLINE, FluidMode.NONE, player));
  24. }
  25.  
  26. public ActionResult<ItemStack> onItemRightClick(World worldIn, PlayerEntity playerIn, Hand handIn) {
  27. ItemStack itemstack = playerIn.getHeldItem(handIn);
  28. RayTraceResult result = this.rayTrace(worldIn, playerIn);
  29. worldIn.playSound((PlayerEntity)null, playerIn.getPosX(), playerIn.getPosY(), playerIn.getPosZ(), SoundEvents.ENTITY_GHAST_SHOOT, SoundCategory.NEUTRAL, 0.5F, 0.4F / (random.nextFloat() * 0.4F + 0.8F));
  30. if (!worldIn.isRemote) {
  31. if(result instanceof RayTraceResult)
  32. {
  33. FireballEntity fireballentity = new FireballEntity(worldIn, playerIn, 1.0f, 1.0f, 1.0f);
  34. worldIn.addEntity(fireballentity);
  35. }
  36. }
  37.  
  38. playerIn.addStat(Stats.ITEM_USED.get(this));
  39. if (!playerIn.abilities.isCreativeMode) {
  40. itemstack.shrink(1);
  41. }
  42.  
  43. return ActionResult.resultSuccess(itemstack);
  44. }
  45. }
Advertisement
Add Comment
Please, Sign In to add comment