Power red Woll

Discussion in 'Plugin Development' started by Moon_werewolf, Jan 20, 2013.

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

    Moon_werewolf

    How do I check if red wool being powered, For it must be a better way than what i have so far.


    Code:
    public final static Integer[][] moveToAll =
        {
                {-1,-1,-1},{-1,-1,0},{-1,-1,1},
                {-1,0,-1},{-1,0,0},{-1,0,1},
                {-1,1,-1},{-1,1,0},{-1,1,1},
                {0,-1,-1},{0,-1,0},{0,-1,1},
                {0,0,-1},{0,0,1},{0,1,-1},
                {0,1,0},{0,1,1},{1,-1,-1},
                {1,-1,0},{1,-1,1},{1,0,-1},
                {1,0,0},{1,0,1},{1,1,-1},
                {1,1,0},{1,1,1}
        };


    Code:
    @EventHandler
        @EventHandler
        public void BlockRedstoneEvent(BlockRedstoneEvent event)
        {
            Block block = event.getBlock();
            for(Integer[] spead : moveToAll){
                Location l = block.getLocation().clone().add(spead[0], spead[1], spead[2]);
                Block scannedBlock = block.getWorld().getBlockAt(l);         
                if(block != null && !scannedBlock.isBlockPowered() && scannedBlock.getType() == Material.WOOL && scannedBlock.getData() == 14){
                    block.getWorld().playSound(scannedBlock.getLocation(), Sound.EXPLODE, 10.0f, 0.7f); //volume, pitch
                }
            }
        }
     
  2. Offline

    drtshock Retired Staff

  3. Offline

    gomeow

    As far as I know, block.getBlockPower() only works on normally power able blocks
     
  4. Offline

    Moon_werewolf

    Well the code works. But can i somehow remove the loop and get the same effect?
     
  5. Offline

    drtshock Retired Staff

    Does the event fire as long as the block is powered? Or just when the block is first powered? Because if the latter, then couldn't you just not use a loop at all.
     
  6. Offline

    Moon_werewolf

    I don't know how to explain it. Without the loop, all I'm getting event.getBlock() is redstone wire, button, and redstone torch on/off. No the block it powers.
     
Thread Status:
Not open for further replies.

Share This Page