Check if redstone is on?

Discussion in 'Plugin Development' started by ServerfromMinecraft, Aug 13, 2012.

Thread Status:
Not open for further replies.
  1. Hi !

    How i can check i the redstone at given coords is powered?
    powered restone has a metadata for do that?
     
  2. Offline

    rjVapes

    There are data values for that. In the case of redstone wire, the data ranged from 0x0 to 0xF. You'll probably just want to consider 0x0 off, and anything else on, the range is due to the power drop off as it gets further from the power source. Actual blocks that are powered and unpowered have different states, so I don't think there's 1 single thing to check for. You probably just need to get what item is at the location, and go through a switch/case to determine if it's powered based on the item type.

    This should help you to form your cases:
    http://www.minecraftwiki.net/wiki/Data_values
     
  3. Thanks! but how i can check that in the code?

    because i will permanently check if a sign is powered... :/
     
  4. Offline

    tr4st

  5. thanks!!! i have search a thing like this :D

    hm... another stupid question... in what event i put this? in the BlockEvent the ispwered method not exist...

    edit:// solved.. i think

    Ok, its not work.
    If i power my sign, nothing spawn:

    Code:
        @EventHandler (priority = EventPriority.NORMAL)
        public void onPlayerInteract(BlockEvent event){
                EntityType t = null;
                Block Zustand = event.getBlock();
             
                if(Zustand instanceof Sign && Zustand.isBlockPowered()){
                 
                    final Sign Schild = (Sign)Zustand;
                    String line = Schild.getLine(0);
                    String linie = Schild.getLine(1);
                    if(linie.equalsIgnoreCase("Creeper")){
                        t = EntityType.CREEPER;
                     
                    }
                        if(line.equalsIgnoreCase("[Sign Spawn]")){
                         
                            Location loc = Zustand.getLocation();
                            World w = Zustand.getWorld();
                         
                         
                            w.spawnEntity(loc, t);
                        }
                     
                    }
                }
    "unable to find handler list fpor org. etc . blockevent"

    EDIT by Moderator: merged posts, please use the edit button instead of double posting.
     
    Last edited by a moderator: May 27, 2016
  6. Offline

    tr4st

  7. Ok, now i have changed it to a BlockRedstoneEvent, no error, but if i power the sign nothing happens :(
     
  8. Offline

    tr4st

    Code:
    @EventHandler
        public void onPlayerInteract(BlockRedstoneEvent event){
           
            EntityType t = null;
            Block Zustand = event.getBlock();
               
            if(Zustand.getType() == Material.SIGN_POST && Zustand.isBlockPowered()) {
                   
                Sign Schild = (Sign) Zustand.getState();
               
                if (Schild.getLine(1).equalsIgnoreCase("Creeper")){
                    t = EntityType.CREEPER;
                    if (Schild.getLine(0).equalsIgnoreCase("[Sign Spawn]")) {               
                    Location loc = Zustand.getLocation();
                    Zustand.getWorld().spawnEntity(loc, t);
                    }                           
                    }                       
                }           
          }
     
  9. Offline

    whitehooder

    BlockRedstoneEvent will NOT work in this case, since the sign is not a block that normally can be powered, you will need to use BlockPlysicEvent (something like that) and then check if the block is "isBlockPowered()" and "isBlockIndirectlyPowered()" for this to work.
     
  10. Offline

    tr4st

    It works perfectly my way ;)
    And if the Sign is a WallSign, you can easily check this with isWallSign().
     
  11. Offline

    whitehooder

    Maybe signs are also powerable then, cakes were not ;)
     
  12. Offline

    tr4st

    Here is the function included the possibility to use WallSigns.
    Code:
    @EventHandler
        public void onPlayerInteract(BlockRedstoneEvent event){
           
            EntityType t = null;
            Block Zustand = event.getBlock();
               
            if(Zustand.getType() == Material.SIGN_POST || Zustand.getType() == Material.WALL_SIGN) {
                if (Zustand.isBlockPowered()) {
                    Sign Schild = (Sign) Zustand.getState();
               
                if (Schild.getLine(1).equalsIgnoreCase("Creeper")){
                    t = EntityType.CREEPER;
                    if (Schild.getLine(0).equalsIgnoreCase("[Sign Spawn]")) {               
                    Location loc = Zustand.getLocation();
                    Zustand.getWorld().spawnEntity(loc, t);
                    }                           
                    }                       
                }
                }                       
          }
     
  13. Offline

    whitehooder

    Sounds cool if they have added the redstonevent on all blocks ;) Thanks tr4st
     
  14. Offline

    tr4st

    If you want to check a Block, you can always check the Block Material instead of.
     
Thread Status:
Not open for further replies.

Share This Page