Solved Falling block breaking

Discussion in 'Plugin Development' started by hayhaycrusher, May 13, 2013.

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

    hayhaycrusher

    so im maing a block fall in this case its a piston moving piece, it falls perfectly fine but it then brakes into an item when it hits the floor.

    Code:
    FallingBlock block = player.getPlayer().getWorld().spawnFallingBlock(player.getPlayer().getLocation(), Material.PISTON_MOVING_PIECE, (byte) 0);
    Extra Help:

    im trying to create something similar to the crate in the hive SG.
     
  2. Offline

    Rprrr

  3. Offline

    Garris0n

    It's trying to place but since it's a piston head updating and deleting I guess...unless it's landing on a half slab or something of the sort?
     
  4. Offline

    hayhaycrusher

    Last edited by a moderator: Jun 1, 2016
  5. Offline

    Polaris29

    Try this: falllingBlock.setDropItem(false);
     
  6. Offline

    hayhaycrusher

    done that. Nothing happend
     
  7. Offline

    Polaris29

    Well when a FallingBlock lands, EntityChangeBlockEvent is the event that is triggered so try something similar to this:

    Code:
    @EventHandler
    public void onEntityChangeBlockEvent(EntityChangeBlockEvent event) {
        if (event.getEntityType() == EntityType.FALLING_BLOCK) {
            FallingBlock fallingBlock = (FallingBlock) event.getEntity();
            if (fallingBlock.getMaterial() == Material.PISTON_MOVING_PIECE) {
                event.getBlock().setType(Material.PISTON_MOVING_PIECE);
            }
        }
    }
    
    If you want to make sure the falling block entity is one of the falling blocks your plugin spawned then save the falling block's entity id to an ArrayList when you spawn it. When the event is triggered, check if the entity's id is in the ArrayList and if it's in the arraylist, do your stuff and remove the entity id from the arraylist.
    Make sure you don't remove anything while iterating through the list or else you'll get a ConcurrentModificationException
     
  8. Offline

    hayhaycrusher

    I'll try it out now, And thanks!

    Bump

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

    Garris0n

    Why?
     
  10. Offline

    chasechocolate

  11. Offline

    hayhaycrusher

    chasechocolate i tried it and it still dosnt work, i think its because i dont have to set the material Material.PISTON_MOVING_PIECE i have to set it with the block id 33 and sub id 6
     
  12. Offline

    Steffion

  13. Offline

    hayhaycrusher

    chasechocolate nope dosnt work alltogether Polaris29


    i tried
    Code:
    event.getBlock().setTypeIdAndData(33, (byte) 6, false);
    its not even executing the code

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

    Aqua

    Code:
        @EventHandler
        public void onEntityChangeBlockEvent(EntityChangeBlockEvent event) {
            Bukkit.broadcastMessage("Found a blockchange");
            if (event.getEntityType() == EntityType.FALLING_BLOCK) {
                Bukkit.broadcastMessage("Its a falling block");
                FallingBlock fallingBlock = (FallingBlock) event.getEntity();
                if (fallingBlock.getMaterial() == Material.PISTON_MOVING_PIECE) {
                    Bukkit.broadcastMessage("and its piston moving piece");
                    event.getBlock().setType(Material.PISTON_MOVING_PIECE);
                }
            }
        }
    I also tested this event, but it seems it's not being fired:
    The first Message is not send to server.
     
  15. Offline

    Steffion

  16. Offline

    Aqua

    Steffion Yes I did.
    Code:
            Bukkit.getPluginManager().registerEvents(this, this);
     
  17. Offline

    Steffion

    Wierd? I have this:
    Code:java
    1. @EventHandler(priority = EventPriority.NORMAL)
    2. public void EntityChangeBlockEvent (final EntityChangeBlockEvent event) {
    3. if (event.getEntityType() == EntityType.FALLING_BLOCK) {
    4. event.setCancelled(true);
    5. }
    6. }
    7.  


    This does work, also registered event like you.
    Aqua
     
  18. Offline

    Aqua

    Steffion I just noticed, the event is working since I get spammed out of nowhere with blockchanges, but it just doesn't work on those piston parts.

    EDIT: The event does work on sand, with second message. So I am sure it doesnt work on piston.

    If I make a stoneblock drop the EventChangeBlockEvent is fired... But why isn't it when I drop a moving piston piece?

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

    hayhaycrusher

    im not sure but the actual id of the block ingam is 33:6 and i thinks its actaully a different block. so if there is a way of dropping a falling block by id it might work.
     
  20. Offline

    Aqua

    Found a solution;
    Code:
    Bukkit.getWorld("world").spawnFallingBlock(LOCATION, Material.PISTON_MOVING_PIECE, (byte) 6).setDropItem(false);
    Will not work. Use:
    Code:
    Bukkit.getWorld("world").spawnFallingBlock(LOCATION, 33, (byte) 6).setDropItem(false);
    instead.
     
  21. Offline

    hayhaycrusher

    Aqua that dosnt seem to work
     
  22. Offline

    Aqua

    hayhaycrusher change LOCATION to the desired location, if you place it in a command replace LOCATION with:
    Code:
    Bukkit.getPlayer(sender.getName()).getLocation().add(0, 20, 0)
    Make sure to stand somewhere without roof :p and then look up.
     
  23. Offline

    hayhaycrusher

    Aqua Thanks that works fine!
     
  24. Offline

    kyledag500

    I didn't scroll down after the one guys code...and then I did after trying it out...and I love how we had the exact same debug messages xD
     
Thread Status:
Not open for further replies.

Share This Page