Skip to content
This repository has been archived by the owner on Mar 8, 2024. It is now read-only.

Add type check to LevelLightEngineMixin for compatibility with Create #111

Merged
merged 1 commit into from
Jan 1, 2022
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@
import net.minecraft.core.BlockPos;
import net.minecraft.core.SectionPos;
import net.minecraft.world.level.ChunkPos;
import net.minecraft.world.level.Level;
import net.minecraft.world.level.LightLayer;
import net.minecraft.world.level.chunk.ChunkAccess;
import net.minecraft.world.level.chunk.DataLayer;
Expand Down Expand Up @@ -57,7 +58,12 @@ public final StarLightInterface getLightEngine() {
)
public void construct(final LightChunkGetter chunkProvider, final boolean hasBlockLight, final boolean hasSkyLight,
final CallbackInfo ci) {
this.lightEngine = new StarLightInterface(chunkProvider, hasSkyLight, hasBlockLight, (LevelLightEngine)(Object)this);
// avoid ClassCastException in cases where custom LightChunkGetters do not return a Level from getLevel()
if (chunkProvider.getLevel() instanceof Level) {
this.lightEngine = new StarLightInterface(chunkProvider, hasSkyLight, hasBlockLight, (LevelLightEngine) (Object) this);
} else {
this.lightEngine = new StarLightInterface(null, hasSkyLight, hasBlockLight, (LevelLightEngine) (Object) this);
}
Comment on lines +61 to +66

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'd recommend moving the instanceof check into the StarLightInterface constructor.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

That was the first fix I attempted, which resulted in a hang on world load.
image

Performing the check in LeveLightEngineMixin fixed everything without issue.

// intentionally destroy mods hooking into old light engine state
this.blockEngine = null;
this.skyEngine = null;
Expand Down