AgriCraft

AgriCraft

30M Downloads

Client thread can not get correct light levels at night

CodesCubesAndCrashes opened this issue ยท 3 comments

commented

Summary

While debugging the "plants won't grow after spreading" bug, I noticed that magnifying glass would report some very weird results. Basically, it would always give the day-time brightness value, even if it was night. This affected the growth requirements check as well, since those depend on the current light level.

agricraft growth after spreading - 04
Notice that the chat is incorrect about the current fertility of all three plants, while WAILA reports it correctly.

Cause

It turns out that in the client thread, world#getLightFromNeighbors doesn't reflect the time of day. This is true even during singleplayer.

agricraft magnifying glass bug
Here I modified the code for the magnifying glass so that it would report on both the client and server threads. This is a single player session, for reference.

Fixes

  • The immediate solution is to make the magnifying glass only report the server side data.
  • But to do it right, the code for displaying information (which is used by the magnifying glass) is going to need rewriting, to account for the sided-ness of the situation.
  • It also will probably be a good idea to review any code that checks the light levels, to make sure it's all happening server side only. All of the game logic and mechanics should already be purely on the server, but it's better to be sure.
  • The magnifying glass (and other items) will need to be switched from onItemFirstUse to onItemUse instead. The former is never called on the server, and it potentially will be removed entirely at some point. [Ref] I've seen LexManos saying the same thing elsewhere, but now it's more immediately salient to AgriCraft.
  • In that case, the glass can be added to the BlockCrop#ITEM_EXCLUDES list, to let it continue its existing behavior. The method doesSneakBypassUse lets the target block take control, and not the other way around.
commented

After adding a new light testing mode to the debugger, it looks like very few of the light level functions are synchronized between server and client. We might have to make a custom packet for waila/the magnifying glass to get them to report correctly. Or we could try to use getLightLevel, given that that was the only method that seemed to be consistent across both server and client.

commented

I have at least fixed the Magnifying Glass, so that it reports from the server side thread, instead of the client one. This will make the item more useful for debugging, and avoid some confusion.

commented

Closing since we are moving to 1.16.