Solved Proper way to check if block is powered

Discussion in 'Plugin Development' started by torpkev, Jan 16, 2019.

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

    torpkev

    What would be the proper way to detect if a block is powered, preferably when the redstone event changes (if a button is pressed or whatever). The block I want to check does not necessarily have the button on it, but is attached to the redstone circuit.

    If it helps - I have a list of blocks and their location that I need to check, so it doesn't need to check everything ever.

    Thanks

    Using this:

    Code:
    @EventHandler
        public void onBlockRedstoneEvent(BlockRedstoneEvent evt) {
            Location loc = new Location(evt.getBlock().getWorld(), -230, 80, -29); // This is nonsense, but I just happen to know my block is there.. will pull from my list
            Block b = loc.getBlock();
            if (b != null)
            {
                if (b.equals(evt.getBlock()))
                {
                    if (b.isBlockPowered())
                    {
                        System.out.println(b.getType().name() + " - Powered");
                    }
                    else
                    {
                        System.out.println(b.getType().name() + " - Not Powered");  
                    }
                }
            }
        }
    EDIT by Moderator: merged posts, please use the edit button instead of double posting.
     
    Last edited by a moderator: Jan 16, 2019
Thread Status:
Not open for further replies.

Share This Page