Fix vanilla lighting
This commit is contained in:
@@ -8,7 +8,7 @@ yarn_mappings=1.20.4+build.1
|
|||||||
loader_version=0.15.1
|
loader_version=0.15.1
|
||||||
|
|
||||||
# Mod Properties
|
# Mod Properties
|
||||||
mod_version = 0.1.2-alpha
|
mod_version = 0.1.3-alpha
|
||||||
maven_group = me.cortex
|
maven_group = me.cortex
|
||||||
archives_base_name = voxy
|
archives_base_name = voxy
|
||||||
|
|
||||||
|
|||||||
@@ -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<Long, Pair<ChunkNibbleArray, ChunkNibbleArray>> 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<Long, Pair<ChunkNibbleArray, ChunkNibbleArray>> 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<Long, Pair<ChunkNibbleArray, ChunkNibbleArray>> out, WorldChunk chunk) {
|
|
||||||
if (STARLIGHT_INSTALLED) {
|
|
||||||
fetchLightingDataStarlight(out, chunk);
|
|
||||||
} else {
|
|
||||||
fetchLightingDataVanilla(out, chunk);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
@@ -4,13 +4,13 @@ import it.unimi.dsi.fastutil.Pair;
|
|||||||
import me.cortex.voxy.common.voxelization.VoxelizedSection;
|
import me.cortex.voxy.common.voxelization.VoxelizedSection;
|
||||||
import me.cortex.voxy.common.voxelization.WorldConversionFactory;
|
import me.cortex.voxy.common.voxelization.WorldConversionFactory;
|
||||||
import me.cortex.voxy.common.world.WorldEngine;
|
import me.cortex.voxy.common.world.WorldEngine;
|
||||||
import me.cortex.voxy.common.world.other.LightingFetcher;
|
|
||||||
import net.minecraft.util.math.ChunkSectionPos;
|
import net.minecraft.util.math.ChunkSectionPos;
|
||||||
import net.minecraft.world.LightType;
|
import net.minecraft.world.LightType;
|
||||||
import net.minecraft.world.chunk.ChunkNibbleArray;
|
import net.minecraft.world.chunk.ChunkNibbleArray;
|
||||||
import net.minecraft.world.chunk.WorldChunk;
|
import net.minecraft.world.chunk.WorldChunk;
|
||||||
import net.minecraft.world.chunk.light.LightStorage;
|
import net.minecraft.world.chunk.light.LightStorage;
|
||||||
|
|
||||||
|
import java.util.Map;
|
||||||
import java.util.concurrent.ConcurrentHashMap;
|
import java.util.concurrent.ConcurrentHashMap;
|
||||||
import java.util.concurrent.ConcurrentLinkedDeque;
|
import java.util.concurrent.ConcurrentLinkedDeque;
|
||||||
import java.util.concurrent.Semaphore;
|
import java.util.concurrent.Semaphore;
|
||||||
@@ -79,8 +79,38 @@ public class VoxelIngestService {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private static void fetchLightingData(Map<Long, Pair<ChunkNibbleArray, ChunkNibbleArray>> 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) {
|
public void enqueueIngest(WorldChunk chunk) {
|
||||||
LightingFetcher.fetchLightingData(this.captureLightMap, chunk);
|
fetchLightingData(this.captureLightMap, chunk);
|
||||||
this.ingestQueue.add(chunk);
|
this.ingestQueue.add(chunk);
|
||||||
this.ingestCounter.release();
|
this.ingestCounter.release();
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user