Jump to content

Can't create Fireball


Vamaka12

Recommended Posts

I am trying to spawn Fireball when player right clicks, I was following 1.12.2 tutorial but I am modding for 1.18.1. So I changed up code but it doesn't works
This is my code:
 

package com.vamaka12.magiccraft.objects.tools;

import net.minecraft.core.BlockPos;
import net.minecraft.world.InteractionHand;
import net.minecraft.world.InteractionResult;
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.level.block.state.BlockState;
import net.minecraft.world.phys.BlockHitResult;
import net.minecraft.world.phys.Vec3;


public class FireStaff extends Item {
    public FireStaff(Properties properties)
    {
        super(properties);
    }

//    @Override Gives error, It was in tutorial
    public InteractionResult use(BlockState state, Level level, BlockPos pos, Player player, InteractionHand hand, BlockHitResult hit) {
        ItemStack item = player.getItemInHand(hand);
        Vec3 aim = player.getLookAngle();
        LargeFireball fireBall = new LargeFireball(level, player, 1, 1, 1); // gives error "Cannot resolve constructor", I don't know why
        fireBall.setPos(player.position().x + aim.x * 1.5D, player.position().y + aim.y * 1.5D, player.position().z + aim.z * 1.5D);
//        fireBall.accelerationX = aim.x * 0.1; fireBall.accelerationY = aim.y * 0.1; fireBall.accelerationZ = aim.z * 0.1; acceleration doesn't exists
//        level.spawnEntity doesn't exists
        item.setDamageValue(1);

        return InteractionResult.SUCCESS;
    }
}

Tutorial code:

public class FireStaff extends ItemBase
{
    public FireStaff(String name)
    {
        super(name);
    }

    @Override
    public ActionResult<ItemStack> onItemRightClick(World worldIn, EntityPlayer playerIn, EnumHand handIn)
    {
        ItemStack item = playerIn.getHeldItem(handIn);
        Vec3d aim = playerIn.getLookVec();
        EntityLargeFireBall fireball = new EntityLargeFirball(worldIn, playerIn, 1, 1 , 1);
        
        fireball.setPosition(playerIn.posX + aim.x * 1.5D, playerIn.posY + aim.y * 1.5D, playerIn.posZ + aim.z * 1.5D);
        fireBall.accelerationX = aim.x * 0.1; fireBall.accelerationY = aim.y * 0.1; fireBall.accelerationZ = aim.z * 0.1;
        worldIn.spawnEntity(fireball);
        
        item.damageItem(1, playerIn);
        return new ActionResult<ItemStack>(EnumActionResult.SUCCESS, item);
    }
}

Somebody please help, I spended already 1 day

Link to comment
Share on other sites

1 hour ago, Vamaka12 said:
//    @Override Gives error, It was in tutorial

use your IDE to find the method with the correct parameters (Item#use)

1 hour ago, Vamaka12 said:
gives error "Cannot resolve constructor", I don't know why

iirc the class is called Fireball or FireballEntity, use the screach function of your IDE to find the class and the correct constructor 

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.

Announcements



×
×
  • Create New...

Important Information

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