Rewrite regenerateChunkRegion
This commit is contained in:
1 parent
b9f2e68ddb
commit
0c1dba0157
19 files changed
+876
-208
No files matched your search
@@ -1,54 +1,84 @@
|
||||
package carpet.mixins;
|
||||
|
||||
import carpet.fakes.ServerLightingProviderInterface;
|
||||
import it.unimi.dsi.fastutil.objects.ObjectList;
|
||||
import net.minecraft.server.world.ServerLightingProvider;
|
||||
import net.minecraft.util.math.ChunkPos;
|
||||
import java.util.concurrent.CompletableFuture;
|
||||
import java.util.function.IntSupplier;
|
||||
|
||||
import org.spongepowered.asm.mixin.Final;
|
||||
import org.spongepowered.asm.mixin.Mixin;
|
||||
import org.spongepowered.asm.mixin.Shadow;
|
||||
import org.spongepowered.asm.mixin.gen.Invoker;
|
||||
|
||||
import java.util.concurrent.atomic.AtomicBoolean;
|
||||
|
||||
import static java.lang.Thread.yield;
|
||||
import carpet.fakes.Lighting_scarpetChunkCreationInterface;
|
||||
import carpet.fakes.ServerLightingProviderInterface;
|
||||
import carpet.fakes.ThreadedAnvilChunkStorageInterface;
|
||||
import net.minecraft.server.world.ServerLightingProvider;
|
||||
import net.minecraft.server.world.ServerLightingProvider.Stage;
|
||||
import net.minecraft.server.world.ThreadedAnvilChunkStorage;
|
||||
import net.minecraft.util.Util;
|
||||
import net.minecraft.util.math.ChunkPos;
|
||||
import net.minecraft.util.math.ChunkSectionPos;
|
||||
import net.minecraft.world.chunk.Chunk;
|
||||
import net.minecraft.world.chunk.ChunkProvider;
|
||||
import net.minecraft.world.chunk.light.LightingProvider;
|
||||
|
||||
@Mixin(ServerLightingProvider.class)
|
||||
public abstract class ServerLightingProvider_scarpetChunkCreationMixin implements ServerLightingProviderInterface
|
||||
public abstract class ServerLightingProvider_scarpetChunkCreationMixin extends LightingProvider implements ServerLightingProviderInterface
|
||||
{
|
||||
private ServerLightingProvider_scarpetChunkCreationMixin(final ChunkProvider chunkProvider, final boolean hasBlockLight, final boolean hasSkyLight)
|
||||
{
|
||||
super(chunkProvider, hasBlockLight, hasSkyLight);
|
||||
}
|
||||
|
||||
@Shadow protected abstract void updateChunkStatus(ChunkPos pos);
|
||||
@Shadow
|
||||
protected abstract void enqueue(final int x, final int z, final IntSupplier completedLevelSupplier, final Stage stage, final Runnable task);
|
||||
|
||||
@Shadow private volatile int taskBatchSize;
|
||||
|
||||
@Shadow public abstract void setTaskBatchSize(int taskBatchSize);
|
||||
|
||||
@Shadow @Final private AtomicBoolean field_18812;
|
||||
|
||||
@Shadow @Final private ObjectList pendingTasks;
|
||||
|
||||
@Shadow protected abstract void runTasks();
|
||||
@Shadow
|
||||
@Final
|
||||
private ThreadedAnvilChunkStorage chunkStorage;
|
||||
|
||||
@Override
|
||||
public void publicUpdateChunkStatus(ChunkPos pos)
|
||||
@Invoker("updateChunkStatus")
|
||||
public abstract void invokeUpdateChunkStatus(ChunkPos pos);
|
||||
|
||||
@Override
|
||||
public void removeLightData(final Chunk chunk)
|
||||
{
|
||||
updateChunkStatus(pos);
|
||||
final ChunkPos pos = chunk.getPos();
|
||||
chunk.setLightOn(false);
|
||||
|
||||
this.enqueue(pos.x, pos.z, () -> 0, ServerLightingProvider.Stage.PRE_UPDATE, Util.debugRunnable(() -> {
|
||||
super.setLightEnabled(pos, false);
|
||||
((Lighting_scarpetChunkCreationInterface) this).removeLightData(ChunkSectionPos.withZeroZ(ChunkSectionPos.asLong(pos.x, 0, pos.z)));
|
||||
},
|
||||
() -> "Remove light data " + pos
|
||||
));
|
||||
}
|
||||
|
||||
@Override
|
||||
public void flush()
|
||||
public CompletableFuture<Void> relight(final Chunk chunk)
|
||||
{
|
||||
try
|
||||
{
|
||||
while (!field_18812.compareAndSet(false, true)) yield();
|
||||
if (pendingTasks.size() == 0) return;
|
||||
int prevTaskBatchSize = taskBatchSize;
|
||||
setTaskBatchSize(pendingTasks.size());
|
||||
runTasks();
|
||||
setTaskBatchSize(prevTaskBatchSize);
|
||||
}
|
||||
finally
|
||||
{
|
||||
this.field_18812.set(false);
|
||||
}
|
||||
final ChunkPos pos = chunk.getPos();
|
||||
|
||||
this.enqueue(pos.x, pos.z, () -> 0, ServerLightingProvider.Stage.PRE_UPDATE, Util.debugRunnable(() -> {
|
||||
super.setLightEnabled(pos, true);
|
||||
|
||||
chunk.getLightSourcesStream().forEach(
|
||||
blockPos -> super.addLightSource(blockPos, chunk.getLuminance(blockPos))
|
||||
);
|
||||
|
||||
((Lighting_scarpetChunkCreationInterface) this).relight(ChunkSectionPos.withZeroZ(ChunkSectionPos.asLong(pos.x, 0, pos.z)));
|
||||
},
|
||||
() -> "Relight chunk " + pos
|
||||
));
|
||||
|
||||
return CompletableFuture.runAsync(
|
||||
Util.debugRunnable(() -> {
|
||||
chunk.setLightOn(true);
|
||||
((ThreadedAnvilChunkStorageInterface) this.chunkStorage).releaseRelightTicket(pos);
|
||||
},
|
||||
() -> "Release relight ticket " + pos
|
||||
),
|
||||
runnable -> this.enqueue(pos.x, pos.z, () -> 0, ServerLightingProvider.Stage.POST_UPDATE, runnable)
|
||||
);
|
||||
}
|
||||
}
|
||||
Reference in new issue
Block a user