public class FlameWandItem extends Item { public FlameWandItem(Item.Properties builder) { super(builder); } private RayTraceResult rayTrace(World world, PlayerEntity player) { float rotationPitch = player.rotationPitch; float rotationYaw = player.rotationYaw; Vec3d eyePosition = player.getEyePosition(1.0f); //Normalize the look vector float f2 = MathHelper.cos(-rotationYaw * ((float)Math.PI / 180f) - (float)Math.PI); float f3 = MathHelper.sin(-rotationYaw * ((float)Math.PI / 180f) - (float)Math.PI); float f4 = MathHelper.cos(-rotationPitch * ((float)Math.PI / 180f)); float f5 = MathHelper.sin(-rotationPitch * ((float)Math.PI / 180f)); float f6 = f3 * f4; float f7 = f2 * f4; double rayTraceDistance = 32; //Take the start position and add the look vector multiplied by the rayTraceDistance Vec3d endPosition = eyePosition.add((double)f6 * rayTraceDistance, (double)f5 * rayTraceDistance, (double)f7 * rayTraceDistance); return world.rayTraceBlocks(new RayTraceContext(eyePosition, endPosition, RayTraceContext.BlockMode.OUTLINE, FluidMode.NONE, player)); } public ActionResult onItemRightClick(World worldIn, PlayerEntity playerIn, Hand handIn) { ItemStack itemstack = playerIn.getHeldItem(handIn); RayTraceResult result = this.rayTrace(worldIn, playerIn); 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)); if (!worldIn.isRemote) { if(result instanceof RayTraceResult) { FireballEntity fireballentity = new FireballEntity(worldIn, playerIn, 1.0f, 1.0f, 1.0f); worldIn.addEntity(fireballentity); } } playerIn.addStat(Stats.ITEM_USED.get(this)); if (!playerIn.abilities.isCreativeMode) { itemstack.shrink(1); } return ActionResult.resultSuccess(itemstack); } }