RedstoneWire isPowered check

Discussion in 'Plugin Development' started by CevinWa, Jun 6, 2012.

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

    CevinWa

    Im having a hard time checking if an redstone wire is on it's powered state.
    When a redstone wire is powered over a certian block a certain thing will happen.
    So if this is possible im forever thankful for ur help :)
    i tried this but it aint working. Material.REDSTONE_WIRE.getData().isPowered();
     
  2. Offline

    wirher

    I haven't played around with blocks but I think you should get exact block state (eg. By location) and then do the checks.
     
  3. Offline

    Njol

    Of course it doesn't work, where can you see a reference to your block in that line?
    You have to get the data from the block: block.getState().getData().isPowered() (or faster: block.getData() > 0)
     
  4. Offline

    CevinWa

    It doesent work it just says that the method isPowered is undefined for materialdata.
    Sorry for this but im kinda of an noob to coding redstone shit.
     
  5. Offline

    Njol

    Ah I forgot that it has to be casted: ((RedstoneWire) block.getState().getData()).isPowered()
     
  6. Offline

    CevinWa

    Casted from what? Im a so big noob at this. Ive never learned casting. sorry for my stupidness.
     
  7. Offline

    Njol

    You have to cast the MaterialData to RedstoneWire to be able to use isPowered:
    Code:
    ((RedstoneWire) block.getState().getData()).isPowered()
    or you could simply use
    Code:
    block.getData() > 0
    It's shorter and more efficient, though if you use this you should add a comment why you check the data.
     
  8. Offline

    CevinWa

    I'm googling casting. Thank you very much for your help. :D

    Im googling casting. Thank you very much for your help. :D

    EDIT by Moderator: merged posts, please use the edit button instead of double posting.
     
    Last edited by a moderator: May 26, 2016
Thread Status:
Not open for further replies.

Share This Page