Falling Block Hits Ground

Discussion in 'Plugin Development' started by NoLiver92, May 31, 2013.

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

    NoLiver92

    what is the event that is fired when a falling block hits the ground/stops falling?
     
  2. BlockFormEvent I think, used it in the past...

    Edit: It's EntityChangeBlockEvent
     
  3. Offline

    NoLiver92

    Hellsing Is it possible you could give an example on how to use it? im planning for when it hits the ground it will cause damage to the block it hits and its surrounding area then dissapear. if lots of blocks hit the block on the ground then the blocks in the ground will dissapear.

    I know how to do the falling blocks its just when they hit the ground
     
  4. Code:java
    1. public void onEntityChangeBlock(EntityChangeBlockEvent event)
    2. {
    3. if (event.getEntity() instanceof FallingBlock)
    4. {
    5. Block blockWhereFallingLands = event.getBlock();
    6. }
    7. }

    This is how you get the block where the falling block lands, hope it helps...
     
  5. Offline

    NoLiver92

    ahh this helps alot i should be able to use this easily. The only other question at this point, when a block is spawned in, when it starts to fall will this event be fired?

    Is there a way to determine what the block changed from and changed to?
     
  6. Offline

    NoLiver92

    This does not work, the block will not dissapear
     
  7. Never said they will disappear, you will need to do it manually, dunno if you can cancel the event, if not, just set the "blockWhere fallingLands" to Material.AIR and you are all good ;)
     
  8. Offline

    NoLiver92

    i did that, it doesnt seem to fire
     
  9. Offline

    creepers84

    This could work: blockWhereFallingLands.breakNaturally();
    Although I couldnt get it to work =P
     
  10. I did exactly the same and succeed and I did this:
    1: get all blocks in an explosion
    2: get all blocks above if not air and add to list
    3: replace the blocks in the list by a falling block (don't forget to change the velocity because when using isOnGround the block will say true when the first block hits the ground so when u dlete it all blocks will dissapear) also add them to a second list. Then remove them from the first list.
    4: run a repeating task that loops trough the fallingblocks list and whne the block is onground replace it by air and play particle effect.
    5: profit and enjoy playing around.

    (I answer with those steps since I know you are probably trying to create a realistic explosions plugin)
     
  11. Offline

    NoLiver92

    CaptainBern
    I believe i got it, but am slightly unclear on steps 3 and 4,

    where is ths isonground method? and when do i delete the block and replace it with a falling block entity?
     
  12. Offline

    TheUpdater

    any know how to make falling block not place when landed?
     
  13. Offline

    NoLiver92

    im working on that too, if you find out let me know please and if i find out ill post here
     
  14. Offline

    TheUpdater

    ok good =D

    i looked at another thread and saw this
    http://jd.bukkit.org/rb/apidocs/org/bukkit/event/entity/EntityChangeBlockEvent.html
    does this help us? cus i cant understand that

    EDIT by Moderator: merged posts, please use the edit button instead of double posting.
     
    Last edited by a moderator: Jun 1, 2016
  15. Offline

    skore87

    TheUpdater yeah, that's the event that is fired when a FallingBlock forms a block. Just compare UUIDs to ensure the entity is in fact the one you're expecting it to be.
     
  16. Offline

    TheUpdater

    defuq?
    example plz
     
  17. Offline

    NoLiver92

    I tried this and set it to air no matter what the falling block was but it never worked.
    Code:
    public void onEntityChangeBlock(EntityChangeBlockEvent event)
        {
            if (event.getEntity() instanceof FallingBlock)
            {
                event.getBlock().getLocation().getWorld().getBlockAt(event.getBlock().getLocation()).setType(Material.AIR);
                //event.getBlock().setType(Material.AIR);
                //event.getEntity().remove();
            }
        }
    this is what i used, the comments show the other things i tried (and yes the listener was registered)
     
  18. Offline

    skore87

    When you create the FallingBlock you have access to the entity where there is a method to get the UUID. Store that, then compare in the block form event. Shouldn't need an example for that.


    Just cancel the event if it is the FallingBlock that you want to disapear.

    EDIT by Moderator: merged posts, please use the edit button instead of double posting.
     
    Last edited by a moderator: Jun 1, 2016
  19. Offline

    NoLiver92

    skore87 sorry but how would canceling the block change make it dissapear?
     
  20. Normally you can do: fallingblocks.isOnGround(), and just to say: http://forums.bukkit.org/threads/realistic-explosions.149482/ I that code (of my post) just changed it a bit (the velocity of the falling block) and it worked... So people stop saying random stuff...

    You can also use the other guy's post...
     
  21. Offline

    skore87

    Don't quote me, but I'm under the impression that the FallingBlock "dies" when it falls so it will disappear on it's own. Otherwise you could cancel it and mark it for deletion.
     
  22. Offline

    TheUpdater

    have skype if so we can work !
    add tomastero

    wm coming no where i cant event get the falling block lol in that event

    EDIT by Moderator: merged posts, please use the edit button instead of double posting.
     
    Last edited by a moderator: Jun 1, 2016
  23. Offline

    NoLiver92

    which skype is yours i have 2 for that name.
     
  24. Offline

    TheUpdater

    add both
    dude i almost got it =D to work i can get the block that is falling + change it but i dont know what to change it to

    EDIT by Moderator: merged posts, please use the edit button instead of double posting.
     
    Last edited by a moderator: Jun 1, 2016
  25. Offline

    NoLiver92

    change it to air when it hits ground
     
  26. Offline

    TheUpdater

    dident work it just disepeard

    it just goes back to a block of stone =/

    EDIT by Moderator: merged posts, please use the edit button instead of double posting.
     
    Last edited by a moderator: Jun 1, 2016
  27. Offline

    NoLiver92

    It would dissapear your setting it to air.... nothing.

    what did you want to change it to?
    are you using the block change event?
     
  28. Offline

    TheUpdater

    i dont want it to change to antthing i want to keep it as a falling block when it lands
     
  29. Offline

    Drew1080

    I was messing around with this myself a few weeks ago now, here's the code that I used to stop it from forming a block when it hits the ground.

    Code:
    List<String> entityList = new ArrayList<String>();
     
     
        @EventHandler
        public void onEntityChangeBlock(EntityChangeBlockEvent event)
        {
            if (event.getEntity() instanceof FallingBlock)
            {
                if (this.containsBlock(event.getEntity().getUniqueId()))
                {
                    event.setCancelled(true);
                    this.removeEntityBlock(event.getEntity().getUniqueId());
                }
                else
                {
     
                }
            }
        }
     
        public void addEntityUUID(UUID id)
        {
            String uuid = id.toString();
            this.entityList.add(uuid);
        }
     
        public void removeEntityBlock(UUID id)
        {
            String uuid = id.toString();
            if (this.entityList.contains(uuid)) this.entityList.remove(uuid);
        }
     
        public boolean containsBlock(UUID id)
        {
            String uuid = id.toString();
            if (this.entityList.contains(uuid))
            {
                return true;
            }
            return false;
        }
    Now when the explosion happens and you make the FallingBlock entity you add it to the list.
     
  30. Offline

    NoLiver92

    Drew1080
    This looks great and i will implement it when i can.

    Thank you for helping with this as it was causing a problem. We didn't realise we had to cancel the event to stop it
     
Thread Status:
Not open for further replies.

Share This Page