Fireball is invisible?

Discussion in 'Plugin Development' started by Chicken325, Aug 4, 2012.

Thread Status:
Not open for further replies.
  1. Offline

    Chicken325

    Hi, I'm new to the Bukkit API. :p

    I've been trying to spawn an EntityFireball ahead of a player. I've looked to others' code for guidance, but I haven't quite figured it out yet.

    This is my code thus far:
    Code:
                        Block target = player.getTargetBlock(null, 200);
                        Location playerLoc = player.getLocation();
    
                        double dx = target.getX() - playerLoc.getX();
                        double height = 1;
                        double dy = target.getY() + height / 2.0F - (playerLoc.getY() + height / 2.0F);
                        double dz = target.getZ() - playerLoc.getZ();
    
                        CraftPlayer craftPlayer = (CraftPlayer) player;
                        EntityLiving playerEntity = craftPlayer.getHandle();
                        EntityFireball fireball = new EntityFireball(((CraftWorld) player.getWorld()).getHandle(), playerEntity, dx, dy, dz);
    
                        // Start it off a bit away from the player
                        double distance = 4;
                        //Vector aim = targeting.getAimVector();
                        
                        Vector vel = new Vector(dx,dy,dz);
                        vel = vel.normalize().multiply(distance);
                        
                        fireball.locX = playerLoc.getX()+vel.getX();// + dx * distance;
                        fireball.locY = playerLoc.getY()+vel.getY() + (height / 2.0) + 0.5;
                        fireball.locZ = playerLoc.getZ()+vel.getZ();// + dz * distance;
    
                        ((CraftWorld) player.getWorld()).getHandle().entityList.add(fireball);
    Currently, it makes a fireball that blows up ahead of me. except it's invisible. I know it's there, just invisible, because it takes the correct amount of time before it blows up where I shot.

    Also, I believe this probably has a bug of being very inaccurate at close range- this is because getTargetBlock() will stop like 5 blocks in front of me if I'm looking at a wall, instead of going the full 200 blocks, for example. Is there a better way to get where the player is aiming?
     
  2. Offline

    skore87

    This is how I do it for TNT. Should be about the same thing.
    Code:
    TNTPrimed tnt = (TNTPrimed) e.getBlock().getWorld().spawn(dispLoc, TNTPrimed.class);
    Instead of EntityFireball, use Entity.Fireball

    Fireball fb = (Fireball) ............
     
  3. Offline

    Chicken325

    Hm... I'll try to use that. Thanks.
     
  4. Offline

    Njol

    Yes you are, because you are not using the Bukkit API, but CraftBukkit and native minecraft code which you should not use. You should only use classes and methods from the package org.bukkit.* so that your plugin will work with different versions of Bukkit/CarftBukkit/Minecraft and even other Bukkit implementations like Tekkit or Spout.
     
  5. Offline

    Chicken325

    Oh wow, okay. o_e I'll be careful from now on.
     
  6. Offline

    skore87

    Sure there is the chance that an update will break net.minecraft code, but the same can be true with build updates on bukkit. That is no reason to say that you should not use it, although if there are available methods in bukkit's api you should use them over the base code. It is sometimes impossible to get around not using net.minecraft code since not everything is in the wrapper that is in the core.
     
  7. Offline

    Taco

    When it comes to fireballs, iirc, you have to set a shooter for the fireball for it to not despawn.
     
  8. Offline

    skore87

    I toyed with it today actually, and I found this to be false. I have a TNTCannon plugin that, should be obvious what it shoots, fires a projectile and instead I tested it with a fireball. I simulated firing it from a dispenser although all I did was spawn it, give it a direction and watch it go boom.
     
  9. Offline

    Njol

    I guess one should preferably use player.launchProjectile(Class) as it likely directly sets the shooter and it even sets the projectiles's velocity correctly.
     
Thread Status:
Not open for further replies.

Share This Page