1.16.5 disable anvil gravity

Discussion in 'Spigot Plugin Development' started by KaboomRoads, Jul 7, 2021.

  1. So as shown in the video i found out that when breaking the block under the anvil the cause of the event is AIR
    but when using a piston the anvil still falls and when updated it falls same thing when placed, so it only doesent fall when the bottom block removed.
    The log in chat shows
    Code (Java):
    event.getBlock().getType()
    as the first message and
    Code (Java):
    event.getSourceBlock().getType()
    as the second message

    how can i detect if the block falling is stored in a hashmap and also disable the block falling with the use of pistons and right after it is placed?



    Here is the listener
    Code (Java):

    @EventHandler
        public void onForgeNoDontFall(BlockPhysicsEvent event)
        {
            if(event.getBlock().getType() == Material.AIR)
            {
                event.setCancelled(true);
                Bukkit.broadcastMessage(ChatColor.GREEN + "" + event.getBlock().getType() + "\n" + event.getSourceBlock().getType() + " \n \n");
            }
        }
     
     
  2. Try removing the block type = air check and see which combinations make the anvil fall
     
  3. i tried that and i realized that sometimes the cause is the air sometimes the anvil and sometimes the piston head
     
  4. Oh, so sometimes the cause of the anvil falling is a piston head? Didn't expect that, try then something like this:

    Code (Java):
    @EventHandler
        public void onForgeNoDontFall(BlockPhysicsEvent event)
        {
            if(event.getBlock().getType() == Material.ANVIL || event.getSourceBlock().getType() == Material.ANVIL){
                event.setCancelled(true);
            }
            Bukkit.broadcastMessage("block1: "+event.getBlock().getType()+", source: "+event.getSourceBlock().getType()+". cancelled: "+event.isCancelled());
        }
    and let me know what is the output