[SOLVED]If a block is powered by redstone...

Discussion in 'Plugin Development' started by Kohle, Jul 15, 2011.

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

    Kohle

    I know I need to use the isPowered() method, but can someone give me a code snippet of what I would use to see if a block is powered by redstone, and then do X.

    So:
    If Block A powered by redstone
    Do X action.

    Im not sure how to do this exactly... please help.

    -Kohle ;)
     
  2. Offline

    LaLa

    Code:
            Block block = event.getPlayer().getLocation().getBlock(); // probably air
            if (block.isBlockPowered()){
                block.setTypeId(50);
            }
    
    This will just set the block the player is in to a torch if powered, this is probably difficult to do though. Just for an example.
     
  3. Offline

    Kohle

    @LaLa thanks for that example. I was looking more into something like if a lapis block is powered, spawn a mob, for example. The example you gave is only for the block they are on, correct?
     
  4. Offline

    bleachisback

    No, it's the block that their legs are in
     
  5. Offline

    LaLa

    Correct.
    Same thing to check if it's not powered, but add == false
    Code:
    if (block.isBlockPowered() == false){}
    
     
  6. Offline

    bleachisback

    if you're using booleans in a conditional, you can use the NOT operator !
    Code:
    if (!block.isBlockPowered()){}
    
     
  7. Offline

    Telgar

    This is a tough one for ideal practicality. There is an event for redstone change at which point you can check for lapis lazuli or whatever, but it is only called when redstone wire or other redstone driven blocks change their powered state. You have to check around the wire for a lapis block, then check its power state with block.isBlockPowered(). What I ended up doing was creating a scheduled task to run through my blocks to test for power, but that is not all that feasible for lapis lazuli blocks because you dont have a Collection of them all stored. Does anyone else have a better solution?
     
  8. Offline

    Kohle

    I really need help on this yam... -,-
     
  9. Offline

    Telgar

    What?
     
  10. Offline

    Kohle

    I used to use 'lol' a lot so now I use 'yam'....

    yam.
     
    EdTheLoon and DrBoweNur like this.
  11. Offline

    Kohle

    Someone please give me another example...
     
  12. Offline

    Kohle

    Solved! Thanks to a few people, specifically @tyzoid.
     
  13. Offline

    tyzoid

    Your welcome :)
     
Thread Status:
Not open for further replies.

Share This Page