Control Block Lighting Levels ?

Discussion in 'Plugin Development' started by Jacek, Jul 23, 2011.

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

    Jacek

    I am working on my first plugin, and actually the first thing I ever made in Java. The idea is that powered wool blocks will be illuminated, not emit light like a torch, but lit up so light level 15 on all surrounding blocks. So people can make glow in the dark pixel art, hot air balloons that look realistic at night etc.

    I got this working pretty well using a method found by decompiling a plugin called PortableTorch, and rapidly toggling the power works fine causing no server lag. What does cause server lag is placing a block that is gravity affected next to some glowing wool. Because it causes a lighting update and it looks like Minecraft doesn't know what to do with the unnatural light distribution. What happens is that all of the light around the glowing blocks in the area spreads out and fades away (moving east to west), after that the repeating task from my plugin resets the light because it detected that it changed from being lit. Then the block falls, and when it lands the whole thing happens again. all of these updates cause the stars to move backwards quite a lot ! I had a similar problem before when turning some wool off which was easily solved by manually setting the light level to the average of the area around the wool instead of just letting the game work it out.

    So that is the situation as it stands now, and I have two questions. First, what is the best way to set the light level for a block ? And second, how best to reduce the lag when blocks are placed, could I reasonably use the block place event to see if the block is in a lit area and manually light it as before ? And if so, is the block place event fired when a gravity affected block lands ?

    Okay that was three questions ;)
     
  2. Offline

    Shamebot

  3. Offline

    Jacek

    Thanks for the reply. I found that topic before but didn't want to grave dig, replied now anyway.

    Turns out he cheated a bit and retextured glowstone for the demo ;)

    I have a few things to try to reduce the lag a bit, but I think a big contributor may be that the server I am testing on is pretty underpowered.

    So as it stands now, I would like to know if there is a way to cancel a lighting update (I guess there isn't, but I found a few topics saying there was no way to add light too) ?

    Also, are the any things that can be done to pinpoint the cause of the lag a bit more, so I could find out if it is the weird blending that happens or my plugin putting the light back that causes it ? I would guess it's the blending, because just toggling ~50 blocks causes no problems at all.

    Don't want to be that guy who keeps posting in a topic that is going nowhere, but here is a video of my progress so far.



    It does (sort of) work.

    EDIT: I have smooth lighting off because it makes the recording a bit better and is easier to see which blocks are being lit for debugging, obviously works with it on too.

    EDIT2: Fixed the last bug that makes this useless



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

Share This Page