[REDSTONE] Is block powered?

Discussion in 'Plugin Development' started by Mattie112, Jan 24, 2011.

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

    Mattie112

    Hi,

    Im working on a plugin (more learning) and i want to know if a block is receiving power.

    I've tried a lot of things but i can't get it to work

    Code:
    
      public void onBlockRedstoneChange(BlockFromToEvent event)
     {
      world = event.getBlock().getWorld();
      Block blockFrom = event.getBlock();
      Block blockTo = event.getToBlock();
      System.out.println("blockfrom: " + blockFrom.getType());
      System.out.println("blockTo: " + blockTo.getType());
     }
    
    
    
    Server output is:
    lever - redstone - redstone - block

    Ofcource this is not what i want... i want the block the redstone points to!

    How do i do that?

    Thanks in advance,

    Matthijs
     
  2. Offline

    mjmr89

  3. Offline

    Mattie112

    Ok i did something but the problem is: it keeps spamming when the redstone is not powered.

    Here is my code:
    http://mattie.pastebin.com/fCXRVVyc

    It's a redstone-sponge.
    If a sponge get's powered it converts into yellow cloth (for now) and it doesn't absorb water.
    If it get's unpowered it should convert back to sponge.

    Feel free to use my code in any other plugin but mention my name: "Mattie112/Matthijs" thanks!

    I hope someone can give me a little tip because i know i'm close to the solution!
     
  4. Offline

    eisental

    First of all, I've noticed that getBlock() and getToBlock() are always the same block in a redstone event. Maybe it'll change in the future. Second, the easiest way to do this, which I believe is not mentioned in the other thread is to do something like this:
    Code:
                public void onBlockRedstoneChange(BlockFromToEvent event) {
                    BlockRedstoneEvent r = (BlockRedstoneEvent)event;
                    int newCurrent = r.getNewCurrent();
                    int oldCurrent = r.getOldCurrent();
                }
    
    A current greater than 0 is powered.
     
  5. Offline

    Mattie112

Thread Status:
Not open for further replies.

Share This Page