From af9d4065a09c29929f14062f5f16161d01e525bf Mon Sep 17 00:00:00 2001 From: mcrcortex <18544518+MCRcortex@users.noreply.github.com> Date: Thu, 22 Feb 2024 10:34:22 +1000 Subject: [PATCH] Fix vanilla lighting --- gradle.properties | 2 +- .../common/world/other/LightingFetcher.java | 79 ------------------- .../world/service/VoxelIngestService.java | 34 +++++++- 3 files changed, 33 insertions(+), 82 deletions(-) delete mode 100644 src/main/java/me/cortex/voxy/common/world/other/LightingFetcher.java diff --git a/gradle.properties b/gradle.properties index 500969dc..deb4ffaf 100644 --- a/gradle.properties +++ b/gradle.properties @@ -8,7 +8,7 @@ yarn_mappings=1.20.4+build.1 loader_version=0.15.1 # Mod Properties -mod_version = 0.1.2-alpha +mod_version = 0.1.3-alpha maven_group = me.cortex archives_base_name = voxy diff --git a/src/main/java/me/cortex/voxy/common/world/other/LightingFetcher.java b/src/main/java/me/cortex/voxy/common/world/other/LightingFetcher.java deleted file mode 100644 index e3ec5912..00000000 --- a/src/main/java/me/cortex/voxy/common/world/other/LightingFetcher.java +++ /dev/null @@ -1,79 +0,0 @@ -package me.cortex.voxy.common.world.other; - -import ca.spottedleaf.starlight.common.light.StarLightEngine; -import ca.spottedleaf.starlight.common.light.StarLightInterface; -import ca.spottedleaf.starlight.common.light.StarLightLightingProvider; -import it.unimi.dsi.fastutil.Pair; -import net.fabricmc.loader.api.FabricLoader; -import net.minecraft.client.MinecraftClient; -import net.minecraft.util.math.ChunkPos; -import net.minecraft.util.math.ChunkSectionPos; -import net.minecraft.world.LightType; -import net.minecraft.world.chunk.ChunkNibbleArray; -import net.minecraft.world.chunk.WorldChunk; - -import java.util.Map; - -public class LightingFetcher { - //TODO: FIXME: I dont think the 2 codepaths are needed, just do what you do for starlight for vanilla and it should work just fine - - private static final boolean STARLIGHT_INSTALLED = FabricLoader.getInstance().isModLoaded("starlight"); - private static void fetchLightingDataVanilla(Map> out, WorldChunk chunk) { - var lp = chunk.getWorld().getLightingProvider(); - var blockLight = lp.get(LightType.BLOCK); - var skyLight = lp.get(LightType.SKY); - int i = chunk.getBottomSectionCoord() - 1; - for (var section : chunk.getSectionArray()) { - i++; - if (section == null) continue; - if (section.isEmpty()) continue; - var pos = ChunkSectionPos.from(chunk.getPos(), i); - if (blockLight.getLightSection(pos).isUninitialized()) - continue; - var bl = blockLight.getLightSection(pos); - var sl = skyLight.getLightSection(pos); - if (bl == null && sl == null) continue; - bl = bl==null?null:bl.copy(); - sl = sl==null?null:sl.copy(); - out.put(pos.asLong(), Pair.of(bl, sl)); - } - } - - private static void fetchLightingDataStarlight(Map> out, WorldChunk chunk) { - var starlight = ((StarLightLightingProvider)chunk.getWorld().getLightingProvider()); - var blp = starlight.getLightEngine().getBlockReader(); - var slp = starlight.getLightEngine().getSkyReader(); - - int i = chunk.getBottomSectionCoord() - 1; - for (var section : chunk.getSectionArray()) { - i++; - if (section == null) continue; - if (section.isEmpty()) continue; - var pos = ChunkSectionPos.from(chunk.getPos(), i); - var bl = blp.getLightSection(pos); - if (!(bl == null || bl.isUninitialized())) { - bl = bl.copy(); - } else { - bl = null; - } - var sl = slp.getLightSection(pos); - if (!(sl == null || sl.isUninitialized())) { - sl = sl.copy(); - } else { - sl = null; - } - if (bl == null && sl == null) { - continue; - } - out.put(pos.asLong(), Pair.of(bl, sl)); - } - } - - public static void fetchLightingData(Map> out, WorldChunk chunk) { - if (STARLIGHT_INSTALLED) { - fetchLightingDataStarlight(out, chunk); - } else { - fetchLightingDataVanilla(out, chunk); - } - } -} diff --git a/src/main/java/me/cortex/voxy/common/world/service/VoxelIngestService.java b/src/main/java/me/cortex/voxy/common/world/service/VoxelIngestService.java index 1e99783f..b903b061 100644 --- a/src/main/java/me/cortex/voxy/common/world/service/VoxelIngestService.java +++ b/src/main/java/me/cortex/voxy/common/world/service/VoxelIngestService.java @@ -4,13 +4,13 @@ import it.unimi.dsi.fastutil.Pair; import me.cortex.voxy.common.voxelization.VoxelizedSection; import me.cortex.voxy.common.voxelization.WorldConversionFactory; import me.cortex.voxy.common.world.WorldEngine; -import me.cortex.voxy.common.world.other.LightingFetcher; import net.minecraft.util.math.ChunkSectionPos; import net.minecraft.world.LightType; import net.minecraft.world.chunk.ChunkNibbleArray; import net.minecraft.world.chunk.WorldChunk; import net.minecraft.world.chunk.light.LightStorage; +import java.util.Map; import java.util.concurrent.ConcurrentHashMap; import java.util.concurrent.ConcurrentLinkedDeque; import java.util.concurrent.Semaphore; @@ -79,8 +79,38 @@ public class VoxelIngestService { } } + private static void fetchLightingData(Map> out, WorldChunk chunk) { + var lightingProvider = chunk.getWorld().getLightingProvider(); + var blp = lightingProvider.get(LightType.BLOCK); + var slp = lightingProvider.get(LightType.SKY); + + int i = chunk.getBottomSectionCoord() - 1; + for (var section : chunk.getSectionArray()) { + i++; + if (section == null) continue; + if (section.isEmpty()) continue; + var pos = ChunkSectionPos.from(chunk.getPos(), i); + var bl = blp.getLightSection(pos); + if (!(bl == null || bl.isUninitialized())) { + bl = bl.copy(); + } else { + bl = null; + } + var sl = slp.getLightSection(pos); + if (!(sl == null || sl.isUninitialized())) { + sl = sl.copy(); + } else { + sl = null; + } + if (bl == null && sl == null) { + continue; + } + out.put(pos.asLong(), Pair.of(bl, sl)); + } + } + public void enqueueIngest(WorldChunk chunk) { - LightingFetcher.fetchLightingData(this.captureLightMap, chunk); + fetchLightingData(this.captureLightMap, chunk); this.ingestQueue.add(chunk); this.ingestCounter.release(); }