Bukkit change power of a block

Discussion in 'Plugin Development' started by giodamelio, May 26, 2011.

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

    giodamelio

    The block object has a method called getBlockPower();. After scouring bukkits java docs I have not been able to find a way to set a blocks power. I need to make a function that can do just that. Somthing like this would set the block to be a power source.
    Code:
    Block block = world.getBlockAt(0, 0, 0);
    block.setPower(true);
    
     
  2. Offline

    Shamebot

    One thing you can do is looking for redstonewire around your block, set the data to 0xF and set the data again for this block each time it changes with onRedstoneChange.
     
    giodamelio likes this.
  3. Offline

    giodamelio

    Cool, I'll look into that. But I hope there is some way to set power directly.

    As per your suggestion, I tried searching for nearby redstone, then setting the data to 0xF. I used this code but it diddent work. Can you give me a snippet of how I would set the data of a block.
    Code:
    Block redstone = block.getFace(BlockFace.NORTH);
    byte data = 0xF;
    redstone.setData(data);
    
    Thanks, giodamelio

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

    Shamebot

    Are there compile errors in your code or doesn't it have a effect?
    Did you listen for onRedstoneChange and set it to 15 or 0xF again?
     
  5. Offline

    giodamelio

    Yes I listened to the onRedstoneChange and set the data to 0xF. I know the rest of the code worked because I substituted in this code and i worked and made the redstone a cake block.
    Code:
    redstone.setType(Material.CAKE_BLOCK);
    
    Edit: I also now tried the code. It did not work either. :(
    Code:
    int data = 15;
    redstone.setData((byte) data);
    
     
  6. Offline

    Shamebot

    You probably didn't do BlockRedstoneEvent.setNewCurrent(...), sry didn't say this,
    but when testing it I noticed that the signal only is transmitted when you build the wire, not when it's there before, which makes it probably useless for you.
     
  7. Offline

    giodamelio

    T
    The only problem is, the block that the onRedstoneChange is called for is a different block then the one I need to set as a power source. I am making a kind of wireless redstone.
     
  8. Offline

    Shamebot

    So this solution isn't going to work for you, because only newly placed blocks will transmitt the current.
     
  9. Offline

    giodamelio

    Oh :( . There has got to be a way... Maybe I need to delete the redstone and replace it with a already powered redstone wire. Ill mess around and get back to you.
     
Thread Status:
Not open for further replies.

Share This Page