Dynamic Lights Improvements (#1319)

This commit is contained in:
Jason Mitchell authored and GitHub committed 2026-01-25 19:07:11 -08:00
1 parent dcea970a77
commit 63e9fa0df1
3 files changed
+24 -7

No files matched your search

@@ -52,6 +52,7 @@ public class DynamicLights {
private static final double MAX_RADIUS_SQUARED = MAX_RADIUS * MAX_RADIUS;
private final Set<IDynamicLightSource> dynamicLightSources = new ObjectOpenHashSet<>();
private final ReentrantReadWriteLock lightSourcesLock = new ReentrantReadWriteLock();
private volatile int lightSourceCount = 0;
private final ChunkRebuildManager chunkRebuildManager = new ChunkRebuildManager();
private long lastUpdate = System.currentTimeMillis();
private int lastUpdateCount = 0;
@@ -70,6 +71,10 @@ public class DynamicLights {
(ShaderForce || !IrisApi.getInstance().isShaderPackInUse());
}
public boolean hasLightSources() {
return lightSourceCount > 0;
}
public static IDynamicLightWorldRenderer getActiveRenderer() {
return activeRenderer;
}
@@ -142,7 +147,9 @@ public class DynamicLights {
public void addLightSource(IDynamicLightSource lightSource) {
this.lightSourcesLock.writeLock().lock();
this.dynamicLightSources.add(lightSource);
if (this.dynamicLightSources.add(lightSource)) {
this.lightSourceCount = this.dynamicLightSources.size();
}
this.lightSourcesLock.writeLock().unlock();
}
@@ -160,6 +167,7 @@ public class DynamicLights {
it = dynamicLightSources.next();
if (it.equals(lightSource)) {
dynamicLightSources.remove();
this.lightSourceCount = this.dynamicLightSources.size();
if (activeRenderer != null)
lightSource.angelica$scheduleTrackedChunksRebuild(activeRenderer);
break;
@@ -183,6 +191,7 @@ public class DynamicLights {
it = dynamicLightSources.next();
if (filter.test(it)) {
dynamicLightSources.remove();
this.lightSourceCount = this.dynamicLightSources.size();
if (activeRenderer != null) {
if (it.angelica$getLuminance() > 0)
it.angelica$resetDynamicLight();
@@ -212,6 +221,7 @@ public class DynamicLights {
it.angelica$scheduleTrackedChunksRebuild(activeRenderer);
}
}
this.lightSourceCount = 0;
this.lightSourcesLock.writeLock().unlock();
}
@@ -14,10 +14,15 @@ public class MixinItemRenderer {
@WrapOperation(method = "renderItemInFirstPerson", at = @At(value = "INVOKE", target = "Lnet/minecraft/client/multiplayer/WorldClient;getLightBrightnessForSkyBlocks(IIII)I"))
private int angelica$dynamiclights_renderItemInFirstPerson(WorldClient theWorld, int posX, int posY, int posZ, int p_72802_4_, Operation<Integer> original){
int lightmap = original.call(theWorld, posX, posY, posZ, p_72802_4_);
if (DynamicLights.isEnabled()){
lightmap = (int)DynamicLights.get().getLightmapWithDynamicLight(posX, posY, posZ, lightmap);
if (DynamicLights.isEnabled()) {
final DynamicLights dl = DynamicLights.get();
if (dl.hasLightSources()) {
final double dynamicLightLevel = dl.getDynamicLightLevel(posX, posY, posZ);
if (dynamicLightLevel > 0) {
lightmap = dl.getLightmapWithDynamicLight(dynamicLightLevel, lightmap);
}
}
}
return lightmap;
}
}
@@ -30,9 +30,11 @@ public abstract class MixinWorld {
@ModifyReturnValue(method = "getLightBrightnessForSkyBlocks", at = @At(value = "RETURN"))
private int angelica$dynamiclights_getLightBrightnessForSkyBlocks(int lightmap, int x, int y, int z, int p_72802_4_){
if (DynamicLights.isEnabled() && !getBlock(x, y, z).isOpaqueCube()){
return DynamicLights.get().getLightmapWithDynamicLight(x, y, z, lightmap);
}
if (!DynamicLights.isEnabled()) return lightmap;
final DynamicLights dl = DynamicLights.get();
if (!dl.hasLightSources()) return lightmap;
final double dynamicLightLevel = dl.getDynamicLightLevel(x, y, z);
if (dynamicLightLevel > 0 && !getBlock(x, y, z).isOpaqueCube()) return dl.getLightmapWithDynamicLight(dynamicLightLevel, lightmap);
return lightmap;
}