Jump to content

[1.10.2] Preventing a lighting update at a certain block pos?


TheMasterGabriel

Recommended Posts

Hi,

I'm currently attempting to make a sort of anti-torch (as in it makes the surrounding blocks darker, not lighter), and I've run into a bit of a problem. I can successfully make the surrounding blocks darker, but it induces a bit of a performance penalty. Basically, Minecraft is set to update the light levels of blocks with the time of day (and if other light-emitting blocks are placed), which is something I'm trying to avoid. Right now, I have a system where any light changes made to any of the blocks being affected by my torch are reset, the process goes something like this:

 

Surronding light level changes --> block's light level changes --> torch recognizes light level change --> reset back to original light level

 

I've managed to prevent infinite looping with this system (by checking if the current light level of the block was the previous light level of the block). However, the main problem is that the entire process happens after the initial light level change, meaning that whenever someone places a block or the sky light level changes, I get a huge lag spike (because Minecraft recalculates the light level twice: once for the initial change and once for the reset).

 

That brings me to my question. Does anyone know if forge provides an event or something that I can use to prevent the light changes from happening in the first place? Preventing them entirely will bypass the whole reset system I described above. Perhaps there is an easier way that I am completely missing? Any help or info on the subject would be appreciated.

 

-TMG

Link to comment
Share on other sites

You might be able to adapt a method I used to speed up the generation of structures. I was working on a mod where I wanted to generate a castle way up in the clouds and found that due to lighting updates, blocks placed up high take a much longer (like minutes for full structure) to generate if you update lighting for each one. So after a bunch of work, I found a way to place blocks without lighting update.

 

This is only temporary of course, and I purposefully invoke some lighting updates when my structure is finished. But maybe I can give you an idea where to look.

 

The Chunk.enqueueRelightChecks() method seems to be one key. The comment for that method says:

 

    /**

    * Called once-per-chunk-per-tick, and advances the round-robin relight check index by up to 8 blocks at a time. In

    * a worst-case scenario, can potentially take up to 25.6 seconds, calculated via (4096/8)/20, to re-check all

    * blocks in a chunk, which may explain lagging light updates on initial world generation.

    */

 

 

 

This method works on a private field called queuedLightChecks which seems to simply count from 0 to 4095 to step 8 at a time through all the blocks in a chunk.

 

I think that by using Java Reflection you might be able to monitor and edit this queue. If you can edit it at the right time (you'd need to play around with various tick and render events to figure out the best place) you can probably prevent light updates in specific area. (You'll have to do some math to convert the block position (and surrounding area) to the figure out when you want to skip.

 

So a bit of work but I think it is possible.

 

 

Check out my tutorials here: http://jabelarminecraft.blogspot.com/

Link to comment
Share on other sites

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.
Note: Your post will require moderator approval before it will be visible.

Guest
Unfortunately, your content contains terms that we do not allow. Please edit your content to remove the highlighted words below.
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

Announcements



×
×
  • Create New...

Important Information

By using this site, you agree to our Terms of Use.