relight cleanup - think it works now. Little higher level, but that's what's needed.

This commit is contained in:
gnembon committed 2023-05-12 22:04:19 +02:00
1 parent 2cfedc733e
commit 755ec1daa8
11 files changed
+75 -365

No files matched your search

@@ -6,29 +6,19 @@ import carpet.fakes.Lighting_scarpetChunkCreationInterface;
import net.minecraft.core.SectionPos;
import net.minecraft.world.level.chunk.DataLayer;
import net.minecraft.world.level.lighting.DataLayerStorageMap;
import net.minecraft.world.level.lighting.LightEngine;
import net.minecraft.world.level.lighting.LayerLightSectionStorage;
import org.spongepowered.asm.mixin.Final;
import org.spongepowered.asm.mixin.Mixin;
import org.spongepowered.asm.mixin.Shadow;
import org.spongepowered.asm.mixin.Unique;
import org.spongepowered.asm.mixin.injection.At;
import org.spongepowered.asm.mixin.injection.Inject;
import org.spongepowered.asm.mixin.injection.callback.CallbackInfo;
import carpet.fakes.LightStorageInterface;
import it.unimi.dsi.fastutil.longs.Long2ObjectMap;
import it.unimi.dsi.fastutil.longs.LongOpenHashSet;
import it.unimi.dsi.fastutil.longs.LongSet;
@Mixin(LayerLightSectionStorage.class)
public abstract class LayerLightSectionStorage_scarpetChunkCreationMixin implements LightStorageInterface
public abstract class LayerLightSectionStorage_scarpetChunkCreationMixin implements Lighting_scarpetChunkCreationInterface
{
@Shadow
protected abstract DataLayer getDataLayer(final long sectionPos, final boolean cached);
//@Shadow
//protected abstract void clearQueuedSectionBlocks(final LightEngine<?, ?> storage, final long blockChunkPos);
protected abstract DataLayer getDataLayer(long sectionPos, boolean cached);
@Shadow
@Final
@@ -38,79 +28,29 @@ public abstract class LayerLightSectionStorage_scarpetChunkCreationMixin impleme
@Final
protected DataLayerStorageMap<?> updatingSectionData;
@Shadow protected abstract boolean storingLightForSection(final long sectionPos);
@Shadow protected abstract boolean storingLightForSection(long sectionPos);
@Shadow
@Final
protected Long2ObjectMap<DataLayer> queuedSections;
//@Shadow protected abstract void enableLightSources(final long l, final boolean bl);
@Unique
private final LongSet removedChunks = new LongOpenHashSet();
@Unique
private final LongSet relightChunks = new LongOpenHashSet();
@Override
public void removeLightData(final long pos)
public void removeLightData(long cPos)
{
this.removedChunks.add(pos);
}
@Override
public void relight(final long pos)
{
this.relightChunks.add(pos);
}
@Inject(
method = "markNewInconsistencies",
at = @At("HEAD")
)
private void processData(final LightEngine<?, ?> lightProvider, final CallbackInfo ci)
{
// Process light removal
for (final long cPos : this.removedChunks)
for (int y = -1; y < 17; ++y)
{
for (int y = -1; y < 17; ++y)
long sectionPos = SectionPos.asLong(SectionPos.x(cPos), y, SectionPos.z(cPos));
this.queuedSections.remove(sectionPos);
if (this.storingLightForSection(sectionPos))
{
final long sectionPos = SectionPos.asLong(SectionPos.x(cPos), y, SectionPos.z(cPos));
if (this.changedSections.add(sectionPos))
this.updatingSectionData.copyDataLayer(sectionPos);
this.queuedSections.remove(sectionPos);
if (this.storingLightForSection(sectionPos))
{
//((Lighting_scarpetChunkCreationInterface)lightProvider).clearQueuedSectionBlocksPublicAccess(sectionPos);
if (this.changedSections.add(sectionPos))
this.updatingSectionData.copyDataLayer(sectionPos);
Arrays.fill(this.getDataLayer(sectionPos, true).getData(), (byte) 0);
}
Arrays.fill(this.getDataLayer(sectionPos, true).getData(), (byte) 0);
}
this.processRemoveLightData(cPos);
}
this.removedChunks.clear();
// Process relighting
for (final long cPos : this.relightChunks)
this.processRelight(lightProvider, cPos);
this.relightChunks.clear();
}
@Override
public void processRemoveLightData(final long pos)
{
}
@Override
public void processRelight(final LightEngine<?, ?> lightProvider, final long pos)
{
}
}