Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- 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<ItemStack> 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)
- {
- double d1 = 4.0D;
- Vec3d vec3d = playerIn.getLook(1.0F);
- double d2 = playerIn.getPosX() - (playerIn.getPosX() + vec3d.x * 4.0D);
- double d3 = playerIn.getPosYHeight(0.5D) - (0.5D + playerIn.getPosYHeight(0.5D));
- double d4 = playerIn.getPosZ() - (playerIn.getPosZ() + vec3d.z * 4.0D);
- worldIn.playEvent((PlayerEntity)null, 1016, new BlockPos(playerIn), 0);
- //234, 243, 423, 432, 324, 342
- FireballEntity fireballentity = new FireballEntity(worldIn, playerIn, -d2, -d3, -d4);
- fireballentity.explosionPower = 1;
- fireballentity.setPosition(playerIn.getPosX() + vec3d.x * 4.0D, playerIn.getPosYHeight(0.5D) + 0.5D, fireballentity.getPosZ() + vec3d.z * 4.0D);
- worldIn.addEntity(fireballentity);
- }
- }
- playerIn.addStat(Stats.ITEM_USED.get(this));
- if (!playerIn.abilities.isCreativeMode) {
- itemstack.shrink(1);
- }
- return ActionResult.resultSuccess(itemstack);
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement