Solved Removing falling block after certain time

Discussion in 'Plugin Development' started by HeyAwesomePeople, Jun 25, 2014.

Thread Status:
Not open for further replies.
  1. Hello! I want to create a gravity effect type thing with my plugin, but I don't know exactly how to do it. I have tried to remove the falling block after a certain time, but by then it has already hit the ground and has become a block. Code:

    PHP:
        @EventHandler
        
    public void explode(EntityExplodeEvent e) {
            if (!
    e.blockList().isEmpty()) {
                final List<
    BlockStateblocks = new ArrayList<BlockState>();
                for (
    Block b e.blockList()) {
                    if (
    b.getType() != Material.AIR) {
                        if (!
    blocks.contains(b.getState())) {
                            
    blocks.add(b.getState());
                            final 
    FallingBlock fb b.getWorld().spawnFallingBlock(b.getLocation(), b.getType(), b.getData());
                            
    fb.setDropItem(false);
                            
    b.setType(Material.AIR);
                            new 
    BukkitRunnable() {
                                public 
    void run() {
                                    
    fb.remove();
                                    
    this.cancel();
                                }
                            }.
    runTaskTimer(plugin60L20L);
                        }
                    }
                }
                new 
    BukkitRunnable() {
                    public 
    void run() {
                        
    regen(blockstrue1);
                        
    this.cancel();
                    }
                }.
    runTaskTimer(plugin100L100L);
            }
        }
    How would I remove the block AFTER it has fallen to the floor?

    Thanks,
    HeyAwesomePeople
     
  2. Offline

    AoH_Ruthless

    HeyAwesomePeople
    Get the block, loop through all locations under it (by changing the y and not x or z) and check if any are air. If so, you know it's fallen. However, this might be an issue if there are caves under, so maybe loop through only 10 y values at most.

    Also, this is assuming that your blocks is still placed, and not a falling block drop.
     
  3. HeyAwesomePeople
    I'd suggest saving the block's location in an ArrayList<Location>. Then you can iterate over the list and set the block at that location to air. Might not necessarily be the best way to do it, but it's the first one that comes to mind at the moment.
     
  4. Offline

    fireblast709

  5. The Gaming Grunts AoH_Ruthless Well I don't see how that would work. I start off with a falling block entity, but when it lands on the floor, it becomes a block. And I have to remove it after it lands on the floor.
     
  6. Offline

    AoH_Ruthless

    HeyAwesomePeople
    If the block's fallen on a floor, there are probably no air blocks under it, right? So if there isn't an air block under it, you know it's fallen on the floor ...

    Edit: or do what fireblast709 said :p
     
  7. fireblast709 So like this?:

    Code:java
    1. public void removeFallingBlock(final EntityChangeBlockEvent e) {
    2. new BukkitRunnable() {
    3. public void run() {
    4. e.getBlock().setType(Material.AIR);
    5. this.cancel();
    6. }
    7. }.runTaskTimer(plugin, 0L, 20L);
    8. }
     
  8. Offline

    fireblast709

  9. fireblast709 Well I want to remove the falling block once it hits the ground.
     
  10. Offline

    fireblast709

    HeyAwesomePeople the falling block will die once that event has been handled
     
  11. Offline

    AoH_Ruthless

  12. The Gaming Grunts likes this.
Thread Status:
Not open for further replies.

Share This Page