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