Jump to content
View in the app

A better way to browse. Learn more.

Forge Forums

A full-screen app on your home screen with push notifications, badges and more.

To install this app on iOS and iPadOS
  1. Tap the Share icon in Safari
  2. Scroll the menu and tap Add to Home Screen.
  3. Tap Add in the top-right corner.
To install this app on Android
  1. Tap the 3-dot menu (⋮) in the top-right corner of the browser.
  2. Tap Add to Home screen or Install app.
  3. Confirm by tapping Install.

Featured Replies

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

 

  • Author
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...

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...

Important Information

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

Configure browser push notifications

Chrome (Android)
  1. Tap the lock icon next to the address bar.
  2. Tap Permissions → Notifications.
  3. Adjust your preference.
Chrome (Desktop)
  1. Click the padlock icon in the address bar.
  2. Select Site settings.
  3. Find Notifications and adjust your preference.