diff --git a/src/main/java/com/simibubi/create/compat/Mods.java b/src/main/java/com/simibubi/create/compat/Mods.java index b32960505..6f6684554 100644 --- a/src/main/java/com/simibubi/create/compat/Mods.java +++ b/src/main/java/com/simibubi/create/compat/Mods.java @@ -12,6 +12,7 @@ import net.minecraftforge.fml.ModList; */ public enum Mods { DYNAMICTREES, + STARLIGHT, TCONSTRUCT; /** @@ -38,4 +39,14 @@ public enum Mods { return Optional.of(toRun.get().get()); return Optional.empty(); } + + /** + * Simple hook to execute code if a mod is installed + * @param toExecute will be executed only if the mod is loaded + */ + public void executeIfInstalled(Supplier toExecute) { + if (isLoaded()) { + toExecute.get().run(); + } + } } diff --git a/src/main/java/com/simibubi/create/foundation/utility/worldWrappers/chunk/WrappedChunk.java b/src/main/java/com/simibubi/create/foundation/utility/worldWrappers/chunk/WrappedChunk.java index 60dbcd16b..cb12d4c83 100644 --- a/src/main/java/com/simibubi/create/foundation/utility/worldWrappers/chunk/WrappedChunk.java +++ b/src/main/java/com/simibubi/create/foundation/utility/worldWrappers/chunk/WrappedChunk.java @@ -11,6 +11,7 @@ import ca.spottedleaf.starlight.common.chunk.ExtendedChunk; import ca.spottedleaf.starlight.common.light.StarLightEngine; +import com.simibubi.create.compat.Mods; import com.simibubi.create.foundation.utility.worldWrappers.PlacementSimulationWorld; import it.unimi.dsi.fastutil.longs.LongSet; @@ -34,7 +35,6 @@ import net.minecraft.world.level.material.Fluid; import net.minecraft.world.level.material.FluidState; import net.minecraft.world.ticks.BlackholeTickAccess; import net.minecraft.world.ticks.TickContainerAccess; -import net.minecraftforge.fml.ModList; public class WrappedChunk extends ChunkAccess { @@ -61,11 +61,12 @@ public class WrappedChunk extends ChunkAccess { for (int i = 0; i < this.sections.length; i++) { sections[i] = new WrappedChunkSection(this, i << 4); } + // If Starlight is loaded, initialize its NibbleArrays for this chunk to default values - if (ModList.get().isLoaded("starlight")) { + Mods.STARLIGHT.executeIfInstalled(() -> () -> { ((ExtendedChunk)this).setBlockNibbles(StarLightEngine.getFilledEmptyLight(this)); ((ExtendedChunk)this).setSkyNibbles(StarLightEngine.getFilledEmptyLight(this)); - } + }); } @Override