From 0ce18262d0ebcd622444ecc48a36418409b85b93 Mon Sep 17 00:00:00 2001 From: Aeiou <3160746+AeiouEnigma@users.noreply.github.com> Date: Fri, 24 Dec 2021 19:10:46 -0500 Subject: [PATCH] Add check in LevelLightEngineMixin::construct for whether chunkProvider::getLevel returns a Level. Avoids a possible ClassCastException in StarLightInterface's constructor if a custom LightChunkGetter which does not return a Level from its getLevel is passed as an argument to the LevelLightEngine constructor. --- .../mixin/common/lightengine/LevelLightEngineMixin.java | 8 +++++++- 1 file changed, 7 insertions(+), 1 deletion(-) diff --git a/src/main/java/ca/spottedleaf/starlight/mixin/common/lightengine/LevelLightEngineMixin.java b/src/main/java/ca/spottedleaf/starlight/mixin/common/lightengine/LevelLightEngineMixin.java index e66710cd..3ff0d239 100644 --- a/src/main/java/ca/spottedleaf/starlight/mixin/common/lightengine/LevelLightEngineMixin.java +++ b/src/main/java/ca/spottedleaf/starlight/mixin/common/lightengine/LevelLightEngineMixin.java @@ -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; @@ -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); + } // intentionally destroy mods hooking into old light engine state this.blockEngine = null; this.skyEngine = null;