MrTJP / ProjectRed

Redstone Engineering
MIT License
471 stars 182 forks source link

Client Will Not Render (Some) Lamps With Optifine #1720

Closed WaterPasta closed 1 year ago

WaterPasta commented 2 years ago

Describe the bug When Optifine is installed with PR Illumination, it causes (some) lamps not to illuminate on the client-side. Bug found in the Create A&B pack.

To Reproduce Steps to reproduce the behavior:

  1. Install PR and Optifine
  2. Place a lamp
  3. Check light level

Some lamps placed prior to installing Optifine remain lit, but breaking and replacing them causes them to no longer illuminate client-side.

Expected behavior The client and server light levels should match.

Crash Log Required for crash. DO NOT paste the entire crash log here. Use pastebin or similar.

Versions Include versions of the dependencies. And since you're looking at it, make sure ProjectRed is up to date. Don't submit bugs for old versions, as they could have been fixed.

Screenshots/Videos If applicable, add screenshots or video links to help explain your problem.

2022-03-19_22 09 00

MrTJP commented 2 years ago

Can you confirm that this only happens with Optifine installed? Are there any cases where this bug appears without Optifine?

MrTJP commented 2 years ago

Bump. Any updates for this? Additionally, can you check if this happens with the full Lamp blocks as well?

AptGetGnome commented 2 years ago

This has happened to me too, originally the lamps worked fine with Optifine, placing them on my self-hosted server, after a restart when i went to play a few days later the lamps are now glowing, but not producing visible light on a client level, even the mod that shows light level is reading it as being no visible light. Attempted to break all the lamps, replace the colour, try the full blocks, even restarted both my server and client however nothing fixed the lamps short of removing Optifine. So yes this issue is Optifine related but thought I would share my experience too. image

Ocawesome101 commented 2 years ago

not exactly a solution but i recommend using Magnesium instead - it gives a significantly better performance boost.

it might still not be compatible but i'd at least try it.

ferreusveritas commented 2 years ago

Optifine Version: HD G8 Ultra PR Illumination Version: 1.16.5-4.12.0(issue tested on 4.11.0 as well with same result)

I hope this provided image helps diagnose the issue or at least answer your previous question:

2022-07-03_13 30 46

Full sized lamp blocks:

Fixture style blocks(microblock lamps):

Issue persists if Optifine is turned OFF(however still installed).

Vanilla Minecraft redstone lamps work as expected with redstone input.

I'm eager to help resolve this problem so please let me know if you need any additional information and I'll do what I can to provide it.

ferreusveritas commented 2 years ago

Addendum: 2022-07-03_13 51 04 Here's another related shot of two torches occupying the same block with the microblock system. Note how no block light is emmited.

MrTJP commented 2 years ago

My best guess based on these observations: Optifine is (incorrectly) assuming that light level does not change as long as the blockstate does not change.

Both PR lamps and all multipart-based tiles use the Tile Entity itself to determine light level, while keeping blockstate static. I could make that adjustment with lamps somewhat easily but it’s a little more difficult (maybe even out if the question) with multiparts.

Minecraft itself has no requirement for light level being tied to block state as far as I know.

MrFuzzihead commented 2 years ago

How do normal redstone lamps work when Optifine is installed then? I would have assumed they operate basically the same

ferreusveritas commented 2 years ago

A redstone lamp uses a blockstate to indicate the light level output. When a redstone lamp changes it's blockstate Optifine will detect the blockstate change and update the lighting in it's own way(Optifine overrides important Minecraft rendering code for one reason or another, likely for performance or for the data to become accessible to a shader program).

Conversely a microblock light(the non-full-block lights used by Project Red Illumination) uses a TileEntity to store the light data so when it's internally managed light value changes there's no blockstate change to be detected by Optifine. Normally the light would be available to Minecraft via the block's position sensitve method: getLightBlock(BlockState, IBlockReader, BlockPos). Somehow Optifine breaks this.

I'm assuming that @MrTJP has considered(or is indeed already) marking a block position in the world as dirty when it's internal state changes for lighting.

One possible workaround(hack) would be to have 2 identically functioning blockstates used for microblocks and just flip-flop between them when the state of a microblock tileEntity changes. This isn't ideal but might work.

MrTJP commented 2 years ago

@ferreusveritas Are you confirming that that is indeed the logic that Optifine is using, or just speculating?

If there is some fundamental Minecraft requirement for light levels to be bound to block state, then Multipart blocks should actually have a Light Level property. If it's just an Optifine assumption, I'd argue it is not correct.

Rayzeq commented 2 years ago

A solution to this problem could be to port ProjectRed to Fabric, which would allow the use of sodium, iris (which would allow the use of ProjectRed with shaders) and other optimization mods (I think they would work without any problems), and Fabric is lighter than Forge anyway. But depending on how the mod works, it could be a lot of work.

ferreusveritas commented 2 years ago

This was speculation about Optifine and how it might be optimizing. I agree with you that Optifine may be using blockstate changes as an event to recalc light and remesh chunks. This is new for 1.16.5(as opposed to 1.12.2 where Optifine worked fine with Project Red Illumination). Since 1.16.5 has focused maniacally on blockstates I think it has afforded tech like Optifine to make some assumptions it shouldn't be making. There are no TileEntity based lighting solutions in vanilla Minecraft.

Instead of guessing I'll do some research to get a better understanding of what's going on.

ferreusveritas commented 2 years ago

@MrTJP I did some research comparing Forge to Optifine code and tracing the calls for both. Here's what I have learned:

Therefor if the goal is to make Project Red Illumination work with Optifine then two alternatives are the most immediately obvious to me: