Fabricators-of-Create / Create

[Fabric Mod] Building Tools and Aesthetic Technology
MIT License
871 stars 198 forks source link

Phosphor causes Redstone Links to break chunk lighting #318

Closed TropheusJ closed 6 months ago

TropheusJ commented 2 years ago

Describe the Bug

When Phosphor is installed, Redstone Links, when 2 are placed in a chunk together, break that chunk's lighting. Phosphor issue: https://github.com/CaffeineMC/phosphor-fabric/issues/82

Reproduction Steps

  1. Install Phosphor and Create
  2. Place 2 Redstone links in 1 chunk
  3. Relog
  4. See broken light

Expected Result

Correct light

Screenshots and Videos

image

Crash Report or Log

No response

Operating System

Windows 10

Mod Version

0.4.1

Minecraft Version

1.18.2

Other Mods

Phosphor

Additional Context

Pretty sure this cannot be fixed on our side. For now, Starlight can be safely used instead.

TropheusJ commented 2 years ago

forgot to link forge issue

PhiProven commented 2 years ago

The issue is actually caused by Create and only made visible by Phosphor. Create can reload chunks in the middle of the unloading process within ThreadedAnvilChunkStorage.tryUnloadChunk(...). There we have the following sequence of operations

...
this.save((Chunk)chunk);
if (this.loadedChunks.remove(pos) && chunk instanceof WorldChunk) {
  WorldChunk worldChunk = (WorldChunk)chunk;
  this.world.unloadEntities(worldChunk);
}
this.lightingProvider.updateChunkStatus(chunk.getPos());
this.lightingProvider.tick();
...

At this point, the chunk is already out of reach for the chunk manager and a query will need to reload it. Now, World.unloadEntities(...) contains a call to RedstoneLinkNetworkHandler.removeFromNetwork(...) which in turn queries all remaining block entities and hence queries their chunks. In particular, if there are two redstone links in the same chunk, unloading the first will reload the chunk by querying the block entity for the second. The light data will only be unloaded afterwards via lightingProvider.updateChunkStatus(...) in the remainder of the unloading process, despite the chunk already being fully reloaded at that point. Since light data is stored separately from chunks, this will not only affect the old copy of the chunk but also the new one. Subsequently saving the chunk will hence not have any light data available. The reason this does not cause lighting glitches for Vanilla is that Phosphor unloads lightmaps more aggressively.

TropheusJ commented 2 years ago

Very useful info, thanks!

ardissaps commented 2 years ago

Starlight can be safely used instead

It worked.

TropheusJ commented 6 months ago

Issues that occur on Forge as well are no longer being tracked on this repo. Please follow the respective issue on the Forge repo instead: https://github.com/Creators-of-Create/Create/issues/3068