Jump to content

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


jaxbymc42

Recommended Posts

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);
    }
}

 

Link to comment
Share on other sites

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.

Link to comment
Share on other sites

  • 4 months later...

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.

Announcements



×
×
  • Create New...

Important Information

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