Spawn a falling block

Discussion in 'Resources' started by PxlPanda, Aug 14, 2012.

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

    PxlPanda

    Since the latest Bukkit snapshot build which has been submitted today, there's a way to spawn falling blocks. This means you can make almost every block in Minecraft fall like sand or gravel. Here's the code snippet, it's really easy:

    Code:
    Byte blockData = 0x0;
     
    location.getWorld().spawnFallingBlock(location, Material.Bedrock, blockData);
     
  2. Offline

    Icyene

    Cool! A new way to grief players: raining bedrock! But in all honesty, this would be pretty cool for a volcano plugin. Can the direction be reversed, to have the block, say, fly up, or to the right?
     
  3. Offline

    WarmakerT

    Code:java
    1. @EventHandler
    2. public void onInteract(PlayerInteractEvent event){
    3. if(event.getAction().equals(Action.LEFT_CLICK_AIR)){
    4. FallingBlock block = event.getPlayer().getWorld().spawnFallingBlock(event.getPlayer().getLocation(), Material.LAVA, (byte) 0);
    5. float x = (float) -1 + (float) (Math.random() * ((1 - -1) + 1));
    6. float y = (float) -5 + (float)(Math.random() * ((5 - -5) + 1));
    7. float z = (float) -0.3 + (float)(Math.random() * ((0.3 - -0.3) + 1));
    8. Bukkit.broadcastMessage("§c" + x + ", §a" + y + ", §d" + z);
    9. block.setVelocity(new Vector(x, y, z));
    10. }
    11. }
     
    xtreameprogram, jorisk322 and Icyene like this.
  4. Offline

    Icyene

    Ohhhh, so now block has a .setVelocity! Nice! Thanks!
     
  5. Offline

    WarmakerT

    Nono, setVelocity is for FallingBlock's.
     
  6. Offline

    Icyene

    Yea, thats what I meant :p

    So how does this sound: get a location on ground, get a random assortments around them, and throw them up. Then do the same, but with location y -1, and so on... Then start filling with lava... OHOHO

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

    Taco

    They finally added a supported way to implement falling blocks. I've been waiting ages for this.
     
    WarmakerT likes this.
  8. Offline

    lol768

    Is there a way I can figure out where the block lands? Or when it will land (for a simple schedule)?
     
  9. Offline

    dvdbrander

    I think blocks that hit the ground will change to normal blocks again instead of falling ones? This could be used to make some sort of advanced gravity system so you have to strengthen your structures, seems pretty cool to me.
     
    WarmakerT likes this.
  10. Offline

    Icyene

    Or, since falling blocks don't correspond to the grid, maybe building off the grid if you have the permission?
     
  11. Offline

    dvdbrander

    Oooh, great idea, or at least a smaller grid. No grid at all will make it very difficult to build walls. But, how are you going to do the roof then? XD And you can fall/walk through falling blocks if I'm right.
     
  12. Offline

    Icyene

    Then I can go into NMS.FallingBlock and change the a() (the function that is called when a player collides with it) to halt the velocity of the player touching it.
     
  13. Offline

    dvdbrander

    Are you sure that get's called with falling blocks?
     
  14. Offline

    Icyene

    If they are blocks, yes. But now I realize they are entities. No matter, doesn't change much. MCP:

    Code:
      public void onCollideWithPlayer(EntityPlayer entityplayer)
        {
        }
    
     
  15. Is there a way to send a block update of a falling block ?
     
  16. Offline

    codename_B

    Hmm.. Someone needs to make a plugin to make configurable blocks fall when placed :D

    Call it "stickyblock" or something...
    Make building a whole new challenge :O
     
    WarmakerT likes this.
  17. Offline

    Ne0nx3r0

    Urge to replace all explosions with flying blocks rising...

    Code:
    @EventHandler(priority = EventPriority.MONITOR,ignoreCancelled = true)
        public void onEntityExplode(EntityExplodeEvent e){
            e.setCancelled(true);
            
            for(Block b : e.blockList())
            {
                bounceBlock(b);
            }
        }
     
        public void bounceBlock(Block b)
        {
            if(b == null) return;
            
            FallingBlock fb = b.getWorld()
                    .spawnFallingBlock(b.getLocation(), b.getType(), b.getData());
            
            b.setType(Material.AIR);
            
            float x = (float) -1 + (float) (Math.random() * ((1 - -1) + 1));
            float y = 2;//(float) -5 + (float)(Math.random() * ((5 - -5) + 1));
            float z = (float) -0.3 + (float)(Math.random() * ((0.3 - -0.3) + 1));
            
            fb.setVelocity(new Vector(x, y, z));
        }
    
    http://www.modevs.net/stuff/BouncyBooms.jar

    The lag, and the griefed houses say no... but the hilarious flying block explosions, say oh yeaah.
     
    chasechocolate likes this.
  18. Offline

    PxlPanda

    Here's a short video showing falling blocks



    Sorry for the bad quality, I have no idea what happened :O
     
  19. Offline

    WarmakerT

    This opens up so many possibilities: raining, volcanoes, rainbows, etc.
     
  20. Offline

    The_Coder

    PxlPanda
    can you post the code for making it rain
    thanks
     
  21. Offline

    dvdbrander

    It's also possible with older versions, I've got:
    Code:
    Location loc = player.getLocation().getBlock().getRelative(BlockFace.UP,20).getLocation().add(0.5, 0, 0.5);
                    EntityFallingBlock entity = new EntityFallingBlock(((CraftWorld) loc.getWorld()).getHandle(), loc.getX(), loc.getY(), loc.getZ(), Material.DIAMOND_BLOCK.getId(), 0x0);
                    entity.c = 1; // ticksLived
                    ((CraftWorld) loc.getWorld()).getHandle().addEntity(entity, SpawnReason.CUSTOM);
    this works with 1.3.1 R1.0
     
  22. Offline

    chaseoes

    Done! However before I release it, I need a way to get the location where the falling block lands. Without it I can't call a BlockPlaceEvent, which allows logging plugins to log that the player placed it, region protection plugins to check if they can place it there, etc.

    Any ideas?
     
  23. Offline

    WarmakerT

    Owned, dev.bukkit.org/server-mods/stickyblocks <3
     
  24. Offline

    chaseoes

    Well yours has the same problem as mine! :p
    I wait to release plugins with security risks. ;)
     
    kaiser_czar likes this.
  25. Offline

    WarmakerT

    That's not what the plugin should do, it should be another plugin. As the same thing applies for normal sand :p
     
  26. Offline

    codename_B

    Calling a blockFromTo event would make more sense ;)
     
  27. Offline

    chaseoes

    Either way I need it's location. :p
     
  28. Offline

    dvdbrander

    Block block = location.getBlock();
    While (block.getRelative(BlockFace.down).getType().equals(Material.AIR)){
    block = block.getRelative(BlockFace.down);
    }
    or so?
     
  29. Offline

    Icyene

    /me forgot. Is this 1.2.5 or 1.3.1?
     
  30. Offline

    dvdbrander

    It's also possible with older versions, I've got:
    That's 1.3.1, and that's before the working version of this, this code might work with 1.2.5
     
Thread Status:
Not open for further replies.

Share This Page