Falling Block break event?

Discussion in 'Plugin Development' started by Goty_Metal, Jun 15, 2013.

Thread Status:
Not open for further replies.
  1. Well after some testings i discovered that falling blocks are extremely fragile, for example, if you add to the block a vertical vector to move it in an arc and doesn't lands in flat terrain, it will break, and if it gets too much velocity breaks too... so i want to cancel that to prevent the falling block breaks for those situations, but as a falling block is an entity... maybe entity damage? entity death? thanks!

    Tested with cobust(yea i don't know what more to try XD) event, damage event and death event and nothing...

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

    Lauryman

    I would probably find the event when the block gets destroyed, and just replace it at the exact location. You should probably do it only when it's falling though, because people will get really annoyed when they can't break anything. Infact it might just be easier to make sure that it is cancelled only when it's about to fall, using setCancelled(true).
     
  3. The block is defined with metadata don't worry about that, the problem is that i can't find the even in which a falling block (entity) is destroyed and transformed into a dropped item, for example a sand falling block into a sand block item (dropped item.)
     
  4. BUMP! Still can't find the even in which the falling block is destroyed and transformed into a dropped item :(
     
  5. Offline

    skipperguy12

  6. Offline

    desht

    NathanWolf likes this.
  7. Yes i tried entitychangeblockevent and doesn't work as desht said, dam... there's really no way to handle that? there's no way to stop falling blocks from breaking???
     
  8. Offline

    desht

    You can prevent item drops; call entity.setDropItem(false) when you spawn the FallingBlock entity.
     
  9. Yes but what i want is to prevent the block from breaking , OR replace it...
     
  10. Offline

    whitehooder

    The best way (I can think of) would be to run a scheduler checking for .isDead() and recreating it.
     
  11. Try EntityDeathEvent since the fallingblock is an entity...
     
  12. Offline

    whitehooder

    CaptainBern
     
    CaptainBern likes this.
  13. Offline

    desht

    Nope. EntityDeathEvent is only fired when a living entity dies.

    Goty_Metal as it happens, I've been doing a little experimentation with this myself. Your basic problem is that a falling block entity could land on a block boundary, half on an actual block, and half off. If the server decides that it isn't placeable (in particular, if there's no other block to place it against, because the block directly below is AIR), it'll drop an item - this avoids odd-looking hanging blocks.

    What you want to do is arrange for the entity's X/Z co-ords to be rounded to the nearest 0.5 just before the block lands, and its X/Z velocity to be 0.0. That will align the entity directly above the real block below it, and ensure it drops straight down. Then it will always land and form a block.

    Arranging that could be tricky, I admit, especially if you're flinging the entity a long distance. If you're only moving it a short way, a bit experimentation with a scheduled delayed task might be useful to halt the entity's lateral motion, align it as above, and then let it drop straight down.
     
  14. Well thanks to all, i think i can't find a reliable way to do it then... i can remove drops and create a new block in a desired location the problem is that i can't figure when is the falling block breaking OR trying to land...
     
  15. Create a class that extends FallingBlock en override die()
     
  16. Offline

    sintrinsic

    A fallingblock can do 2 different things upon impacting the ground: land and become a block, or break and become an item of its drop type. When it lands, it fires the EntityChangeBlock event just fine, but when it breaks, the only event fired is the ItemSpawnEvent for the resultant drop. In the case of a break, the falling block still exists at the time the item is spawned, so you can getNearbyEntities() around any spawned item of the correct type to track this (Dirty, I know, but I've used this with about 20 players throwing blocks around like crazy, and no noticeable bugs came up) :

    Code:java
    1.  
    2. @EventHandler
    3. public void onItemSpawn(ItemSpawnEvent event){
    4. List<Entity> ents = event.getEntity().getNearbyEntities(2, 2, 2);
    5. for(Entity e : ents){
    6. if(this.spawned.contains(e.getUniqueId())){
    7. event.getEntity().remove();
    8. this.spawned.remove(e);
    9. this.doManualBlockPlaceMethod(e);
    10. return;
    11. }
    12. }
    13. }


    This is just example code; be sure to start this with a conditional to check if if the spawned item is your desired block type(s) to avoid unnecessary load on the server. Also, you may be able to use a 1 block radius. I don't remember why I used 2. If your application wouldn't be able to easily track the FallingBlock entities upon their creation, you COULD just cycle through the nearby entities and test against their type, rather than testing against a saved list of entities.
     
    toropov023 and NathanWolf like this.
Thread Status:
Not open for further replies.

Share This Page