Advertisement
Guest User

Untitled

a guest
Apr 12th, 2020
530
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.67 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. double d1 = 4.0D;
  34. Vec3d vec3d = playerIn.getLook(1.0F);
  35. double d2 = playerIn.getPosX() - (playerIn.getPosX() + vec3d.x * 4.0D);
  36. double d3 = playerIn.getPosYHeight(0.5D) - (0.5D + playerIn.getPosYHeight(0.5D));
  37. double d4 = playerIn.getPosZ() - (playerIn.getPosZ() + vec3d.z * 4.0D);
  38. worldIn.playEvent((PlayerEntity)null, 1016, new BlockPos(playerIn), 0);
  39. //234, 243, 423, 432, 324, 342
  40. FireballEntity fireballentity = new FireballEntity(worldIn, playerIn, -d2, -d3, -d4);
  41. fireballentity.explosionPower = 1;
  42. fireballentity.setPosition(playerIn.getPosX() + vec3d.x * 4.0D, playerIn.getPosYHeight(0.5D) + 0.5D, fireballentity.getPosZ() + vec3d.z * 4.0D);
  43. worldIn.addEntity(fireballentity);
  44. }
  45. }
  46.  
  47. playerIn.addStat(Stats.ITEM_USED.get(this));
  48. if (!playerIn.abilities.isCreativeMode) {
  49. itemstack.shrink(1);
  50. }
  51.  
  52. return ActionResult.resultSuccess(itemstack);
  53. }
  54. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement