Solved BlockRedstoneEvent, automatically update state?

Discussion in 'Plugin Development' started by TerraVale, Apr 24, 2013.

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

    TerraVale

    Hi, I'm currently developing something for my own use and have run into a problem. I've created an item with the name "Sensor Lamp" which will, when placed, turn off during the day and on at night.

    Thus far, everything is working just fine except for the fact that the event I'm using (BlockRedstoneEvent) only fires when the block receives a redstone update of sorts.

    http://pastebin.com/8cbgtv05

    For instance, if I place one down during the day, set it to night time, then manually update the block, it will change from its prior OFF state and lock in an ON state (because the block updates immediately when placed -- if placed during the day, it will turn off and at night, it will stay on when placed).

    Just wondering what I should change or add to have it actually update the blocks efficiently without -- you know -- having to run around in a frenzy at nightfall/sunrise and manually toggle the event on every Sensor Lamp in my world.

    Thanks!
     
  2. Offline

    Phoenix1123

    No, you don't need to update the state, you can just modify the block so that it turns on, and ignore physics.
    Example code:
    Code:
    Location l = player.getLocation();
    l.getBlock().setTypeIdAndData(124, (byte) 0, false);
    Sets the block at location "l" to Redstone Lamp on, with no data and ignores physics.
    Replace "l" with whatever location you would like, in this case I used a players location.
     
  3. Offline

    TerraVale

    I'll try it out, however I also do use the data value of the block to determine if it's my custom made block, as metadata isn't saved when you place it on the ground.

    Hm, it seems even setting the block physics to false ".setTypeIdAndData(124, (byte) 0, false);" did not accomplish anything as far as keeping a redstone lamp in the on state.

    I also believe that my question was read incorrectly (to a small extent), so I will re-state it.

    Is there an optimal event I could use instead of BlockRedstoneEvent that will always be checking the time, instead of my current code where it only checks the time when the event is fired? I ask this because the BlockRedstoneEvent can only be fired by manually updating the redstone current next to the block(s) being effected by the code.

    Oh well, I don't really need it regardless; just thought it'd be cool!

    Solved, but not solved.

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

Share This Page