Jump to content

[1.18.1] Item to shoot fireball where player is looking on use


Recommended Posts

Posted

Hello!  I am trying to create an item that shoots a fireball in the direction of the player's view.  Currently, it does shoot the fireball but the fireball is curving a bit depending on where the player is looking (also, when looking down, even slightly, it shoots the fireball directly below the player).  I am struggling to figure out the problem.  I have already looked at other Minecraft classes, such as the Ghast and Bow classes.  Any help would be appreciated, thanks!

 

import net.minecraft.sounds.SoundEvents;
import net.minecraft.sounds.SoundSource;
import net.minecraft.world.InteractionHand;
import net.minecraft.world.InteractionResult;
import net.minecraft.world.InteractionResultHolder;
import net.minecraft.world.entity.player.Player;
import net.minecraft.world.entity.projectile.LargeFireball;
import net.minecraft.world.item.Item;
import net.minecraft.world.item.ItemStack;
import net.minecraft.world.level.Level;
import net.minecraft.world.phys.Vec3;

import java.util.Random;

public class FlameWandItem extends Item {
    public FlameWandItem() {
        super(new Item.Properties().tab(CreativeModeTab.TAB_COMBAT).durability(64));
    }

    @Override
    public InteractionResultHolder<ItemStack> use(Level level, Player player, InteractionHand usedHand) {
        ItemStack itemStack = player.getItemInHand(usedHand);
        Vec3 vec3 = player.getViewVector(1.0f);
        Random random = new Random();
        if (!level.isClientSide) {
            LargeFireball largeFireball = new LargeFireball(level, player, player.getX(), player.getEyeY(), player.getZ(), 1);
            largeFireball.shootFromRotation(player, player.getXRot(), player.getYRot(), 0.0F, 3.0F, 0.0F);
            level.addFreshEntity(largeFireball);
            level.playSound((Player)null, player.getX(), player.getY(), player.getZ(), SoundEvents.GHAST_SHOOT, SoundSource.NEUTRAL, 0.5F, 0.4F / (random.nextFloat() * 0.4F + 0.8F));
            if (!player.isCreative()) {
                itemStack.setDamageValue(itemStack.getDamageValue() + 1);
            }
            return new InteractionResultHolder<>(InteractionResult.SUCCESS, itemStack);
        }
        return new InteractionResultHolder<>(InteractionResult.FAIL, itemStack);
    }
}

 

Posted
6 hours ago, Luis_ST said:

try to use 1.0F as last parameter in shootFromRotation

The last parameter in the shootFromRotation method is for the inaccuracy.  In my case, it has nothing to do with the issue of the fireballs practically looping in circles whenever I use the wand item.

  • 4 months later...
  • 2 years later...
Posted

why you need ved3 variable if u dont use it?

 

On 2/6/2022 at 12:25 AM, jaxbymc42 said:

The last parameter in the shootFromRotation method is for the inaccuracy.  In my case, it has nothing to do with the issue of the fireballs practically looping in circles whenever I use the wand item.

why u use ved3 variable if u dont use it?

 

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.
Note: Your post will require moderator approval before it will be visible.

Guest
Unfortunately, your content contains terms that we do not allow. Please edit your content to remove the highlighted words below.
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

By using this site, you agree to our Terms of Use.