Make a block break when hit by a snowball

Discussion in 'Plugin Development' started by BaconStripzMan, Jan 15, 2014.

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

    BaconStripzMan

    Hi, I'm sorta making my own version of Splegg but a lot different. If you would like to help, comment. If you would like to call me a copier go to some other thread.

    I just want an event that will break the block when hit by a snowball, I would also if you could show me how to make TNT blow up on hit by a snowball too.
     
  2. Offline

    DreadTank27

    That's pretty simple.

    First you need to find when a Snowball is fired what block hits (you can find how to it http://forums.bukkit.org/threads/tutorial-get-the-block-where-a-projectile-landed.176395/, if you have still problems how to get the hitBlock, I'll help you posting some code here). I suggest to have a list of ignored blocks or the players can destroy everything in your arena!

    For the TNT part, first you need to check if the hitBlock is a TNT block, then remove it and spawn a PrimedTNTEntity like that:
    Code:java
    1. TNTPrimed tnt = world.spawn(location, TNTPrimed.class);
    2. tnt.setFuseTicks(0);


    The tnt.setFuseTicks controls the duration of the "flashing" part, set to 0 to insta explode. Remember that number is in ticks, and a tick is 1/20 of second
     
  3. Offline

    blablubbabc

    Inside your ProjectileHitEvent handler:

    ball = the projecile
    Location = the location of the projectile

    // check for blocks in the direction of the fyling snowball in the range of 2
    BlockIterator iterator = new BlockIterator(location.getWorld(), location.toVector(), ball.getVelocity().normalize(), 0, 2);
    while (iterator.hasNext()) {
    Block hitBlock = iterator.next();
    if (hitBlock != null) {
    doTypeChecks and destroy if the block is part of the splegg arena
    break; // maybe break..
    }
    }

    Edit: ninja'd (did I really take that long to write this ? :/)
     
  4. Offline

    BaconStripzMan

    Would of been easier if you could put it in the code forum post thing but, I need to know how to check the location of the block it hit
     
  5. Offline

    DreadTank27

  6. Offline

    blablubbabc

    ?
    the ProjectileHitEvent gives you the projectile entity and projectile.getLocation() gives you the location of the snowball (which is very likly not the location of the hit block, if the hit block is not a half block, but a location next to it instead then), and block.getLocation() for the blocks the BlockIterator finds gives you the block locations next to the projectile.
     
Thread Status:
Not open for further replies.

Share This Page