Jump to content

1.19 problem with projectiles


Gvinz

Recommended Posts

Need help with making shooting book, in this code i can summon fireball but it goes inside or oposite way can you help me?

package net.LimboTeam.tropicmod.item.custom;

import net.LimboTeam.tropicmod.item.ModCreativeModTab;
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 FireballMagicBook extends Item {
    public FireballMagicBook(Properties properties) {
        super(new Item.Properties().tab(ModCreativeModTab.TropicModTab));
    }

    @Override
    public InteractionResultHolder<ItemStack> use(Level level, Player player, InteractionHand hand) {
        ItemStack itemStack = player.getItemInHand(hand);
        Random random = new Random();
        Vec3 vec3 = player.getViewVector(1.0f);
        if (!level.isClientSide && hand == InteractionHand.MAIN_HAND){

            double X = player.getX() - (player.getX() + vec3.x * 4.0);
            double Y = player.getY(0.5) - (0.5 + player.getY(0.5));
            double Z = player.getZ() - (player.getZ() + vec3.z * 4.0);


            LargeFireball fireball = new LargeFireball(level, player, X , Y, Z,1);
            fireball.setPos(player.getX(), player.getY(), player.getZ());
            level.addFreshEntity(fireball);

            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);
            }
            player.getCooldowns().addCooldown(this, 40 );
            return new InteractionResultHolder<>(InteractionResult.SUCCESS, itemStack);
        }
        return new InteractionResultHolder<>(InteractionResult.FAIL, itemStack);
    }
}

 

Link to comment
Share on other sites

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.