package net.minecraft.server.level.progress;

import javax.annotation.Nullable;
import net.minecraft.world.level.chunk.ChunkStatus;
import net.minecraft.world.level.ChunkPos;
import java.util.concurrent.Executor;
import net.minecraft.util.thread.ProcessorMailbox;

public class ProcessorChunkProgressListener implements ChunkProgressListener {
    private final ChunkProgressListener delegate;
    private final ProcessorMailbox<Runnable> mailbox;
    
    public ProcessorChunkProgressListener(final ChunkProgressListener zm, final Executor executor) {
        this.delegate = zm;
        this.mailbox = ProcessorMailbox.create(executor, "progressListener");
    }
    
    @Override
    public void updateSpawnPos(final ChunkPos bph) {
        this.mailbox.tell(() -> this.delegate.updateSpawnPos(bph));
    }
    
    @Override
    public void onStatusChange(final ChunkPos bph, @Nullable final ChunkStatus chc) {
        this.mailbox.tell(() -> this.delegate.onStatusChange(bph, chc));
    }
    
    @Override
    public void stop() {
        this.mailbox.tell(this.delegate::stop);
    }
}
