Create explosion at X,Y,Z?

Discussion in 'Plugin Development' started by Windows_i7_920, Apr 15, 2011.

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

    Windows_i7_920

    I am building for the latest Bukkit. Does the API allow spawning an explosion at specific coords?
     
  2. Offline

    Joey Clover

    EDIT: Yes, spawn a TNT and explode it :)
     
  3. Offline

    Windows_i7_920

    ... and how would I do that?
     
  4. Offline

    Tempelchat

    I can think of this: set the material of the block on x,y,z to tnt and the on x,y+1,z to fire.
    This may work but is not tested and only a suggestion
     
  5. Offline

    Daniel Heppner

    Spawn a TNT entity.
     
  6. Offline

    weasel5i2

    Here's how I determined how to do it. You don't even see a TNT, it just makes an explosion at X,Y,Z. Weird Minecraft or Bukkit bug, perhaps..? No idea how to set the timing on it, it explodes immediately upon spawning. I try and setFireTicks() on it but it doesn't seem to do anything.

    You need these imports (I think I got em all):
    Code:
    import net.minecraft.server.EntityTNTPrimed;
    import org.bukkit.Location;
    import org.bukkit.World;
    import org.bukkit.craftbukkit.CraftWorld;
    import org.bukkit.craftbukkit.entity.CraftPlayer;
    import org.bukkit.entity.Player;
    
    And here is the code:
    Code:
    EntityTNTPrimed e = null;
    CraftPlayer cPlayer = (CraftPlayer)player;
    CraftWorld cWorld = (CraftWorld)cPlayer.getWorld();
    net.minecraft.server.World world = (net.minecraft.server.World)(cWorld.getHandle());
    e = new EntityTNTPrimed(world);
    org.bukkit.entity.Entity TNT = e.getBukkitEntity();
    world.a(e);
    
    // Define your X/Y/Z coordinates here.. (double)
    // Obviously you'll want to change these ^_^
    
    Double X = 123;
    Double Y = 456;
    Double Z = 789;
    
    Location location = new Location( player.getWorld(), X, Y, Z );
    
    TNT.teleport( location );
    
    
    Hope this helps :) For fun, you could set the location to player.getTargetBlock(null,60).getLocation(), then the explosion would occur at the target block instead..

    --W5i2
     
  7. Offline

    nisovin

    Well, if you're going to compile against CraftBukkit, you could just do this:

    ((CraftWorld)player.getWorld()).a(null, x, y, z, 4);

    That will directly call the explosion method, creating one instantly. You can even specify the size of the explosion. I'm not sure if this will make the explosion sound though, probably not.

    If you want to do it the proper way though (and compile against Bukkit), you'll have to do what was already suggested, and spawn TNT with fire above.
     
  8. Offline

    KoryuObihiro

    @nisovin Unfortunately, that method seems to be deprecated - I can't find anything like it anywhere! There is now an Explosion class, but I've no idea how to spawn it in the world once created. Any help, y'all?
     
  9. Offline

    nisovin

    Whoops, it should have looked like this:

    ((CraftWorld)player.getWorld()).getHandle().a(null, x, y, z, 4);

    However, for readability, it appears you can also do this:

    ((CraftWorld)player.getWorld()).getHandle().createExplosion(null, x, y, z, 4, mysterious_bool);

    I'm not sure what that boolean does though.
     
  10. Offline

    KoryuObihiro

    LOL, found it right before you posted. I appreciate the help! I wonder what that last flag parameter at the end does.
     
  11. If anyone is interested:
    world.a(e);
    has to be:
    world.addEntity(e);
     
Thread Status:
Not open for further replies.

Share This Page