FallingSandEntity Help

Discussion in 'Plugin Development' started by plobnob, Jun 14, 2014.

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


    Ok, so I currently have a set of code that will update a sponge to be replaced with a falling entity when it is replaced. This works fine, but as you may know, as soon as they stop, they become solid and never fall again. This means if a block breaks underneath it, it will not fall. This would be all fine if it was just a blockBreakEvent needed to make it fall, but I need it to respond to other ways of breaking blocks, like TNT explosions, TNT igniting underneath it, everything. Basically, give it the attributes of normal sand.

    Here is my current code:

    1. package com.plobnob.SpongeProjectiles;
    3. import org.bukkit.Bukkit;
    4. import org.bukkit.Material;
    5. import org.bukkit.event.EventHandler;
    6. import org.bukkit.event.Listener;
    7. import org.bukkit.event.block.BlockPlaceEvent;
    8. import org.bukkit.plugin.java.JavaPlugin;
    10. public class SpongeProjectiles extends JavaPlugin implements Listener
    11. {
    13. public void onEnable()
    14. {
    15. Bukkit.getPluginManager().registerEvents(this, this);
    16. }
    18. @SuppressWarnings("deprecation")
    19. @EventHandler
    20. public void blockPlace(BlockPlaceEvent event)
    21. {
    22. if(event.getBlock().getType().equals(Material.SPONGE))
    23. {
    24. event.getBlock().getWorld().spawnFallingBlock(event.getBlock().getLocation(), event.getBlock().getType(), (byte)0);
    25. event.getBlock().setType(Material.AIR);
    26. }
    27. }
    28. }

    Any help would be appreciated, thanks!

    Bump - Anyone got any ideas? :/

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


    think theres an event like BlockFormEvent which you can cancel to fix this. plobnob
  3. Offline



    BlockPhysicsEvent triggers whenever a block is updated. Blocks will begin falling when updated if there is an air block below them. Listen for the event, check if the block below is air using
    If it is, set the sponge to air and spawn your FallingSandEntity.

    Plo124 's comment

    This will result in a permanent non solid sponge block (entity really). Depends what you want. I get the feeling that the client side view of this method would be a glitchy sponge block that continually fell through the ground, however, this could probably be worked around using setVelocity().
  4. Offline


    This all works great so far! 2 more quick question. 1, the sponge falls slightly faster than the sand. Any way around this? 2, would it be possible to make the sponge remove water where it lands, like it does in bukkit, in a 5x5 area? When it stop from falling, it doesn't have this effect.

    Gunna just add this... Got the delay between the sand and sponge solved. it appears that by scheduling it on a 2 tick delay it goes at exactly the same time, so obviously sand has a 2 tick delay before it starts falling?

    Still stuck on this part though... When a sponge stops flying, how would you make it remove water, like in bucket?

    Hope someone has an idea, because I am certainly stumped! Thanks.

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


    You will have to check the blocks manually with a 3D for loop
  6. Offline


    I didn't understand thaaaat well what you mean, but you may can try something with EntityChangeBlockEvent...

    1. @EventHandler
    2. public void onFallingBlock(EntityChangeBlockEvent event){
    3. if(!event.getEntityType().equals(EntityType.FALLING_BLOCK)) return;
    4. // do some stuff here...
    5. }
  7. Code:Java
    2. FallingSand fb = event.getBlock().getWorld().spawnFallingBlock(event.getBlock().getLocation(), event.getBlock().getType(), (byte)0);
    3. fb.setVelocity(new Vector(0, 0.5, 0));
    4. event.getBlock().setType(Material.AIR);
Thread Status:
Not open for further replies.

Share This Page