Custom enchant and fireball

Status
This thread has been locked.

Clems02

Feedback score
0
Posts
15
Reactions
0
Resources
0
Hi,

I'm looking to a custom enchant when you are mining, a fireball is falling in to the mine and create an explosion.




I succesful to create a coordinate above the player and put down a fireball with the following code:
Code:
    @EventHandler
    public void onBlockBreak(BlockBreakEvent e) {
       
        Player player = e.getPlayer();
       
        Location loc = e.getBlock().getLocation();
        loc.setY(loc.getY() + 20);
       
        Vector v = new Vector(0, -1, 0);

        Fireball f = player.getWorld().spawn(loc, Fireball.class);
        f.setDirection(v);
        f.setIsIncendiary(false);





However I want to change the speed of the fall of the fireball, but I don't succes...
I try use f.setvelocity() but it's not work. The speed don't change.




The second problem is that the explosion does not happen. I want the blocks to explode.



I managed to create this explosion and change the speed with this code but the vector is not good, I can't make the ball launch towards the ground from the sky ...
Code:
    @EventHandler
    public void onBlockBreak(BlockBreakEvent e) {
       
        Player player = e.getPlayer();
       
        Location loc = e.getBlock().getLocation();
        loc.setY(loc.getY() + 20);
       
        double pitch = ((loc.getPitch() - 180) * Math.PI) / 180;
        double yaw  = ((loc.getYaw() + 90)  * Math.PI) / 180;
   
        double x = Math.sin(pitch) * Math.cos(yaw);
        double y = Math.sin(pitch) * Math.sin(yaw);
        double z = Math.cos(pitch);
       
        Vector vector = new Vector(x, z, y);
       
        Projectile p = player.launchProjectile(Fireball.class, vector);
        p.teleport(loc);





Do you have a solution to drop a ball of fire from the sky and explode the blocks on reaching the ground?

Need to change the speed too.

Thank's for your help.
 
PebbleHost
High performance, consistent uptime and fast support. Minecraft hosting that just works.

madk0ur

Music Producer
Premium
Feedback score
2
Posts
142
Reactions
26
Resources
0
I think you should create a ProjectileHit event, so once you shoot the fireball from your pickaxe (or any item), it creates an explosion in the mine.
Anyways, Goodluck!
 
Status
This thread has been locked.
Top