Skip to content
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -5,23 +5,28 @@
import net.minecraftforge.eventbus.api.SubscribeEvent;
import net.minecraftforge.fml.common.Mod;

import java.util.ArrayDeque;
import java.util.Queue;
import java.util.concurrent.ConcurrentLinkedQueue;

@Mod.EventBusSubscriber(modid = AdvancedPeripherals.MOD_ID)
public class ServerWorker {

private static final Queue<Runnable> callQueue = new ArrayDeque<>();
private static final Queue<Runnable> callQueue = new ConcurrentLinkedQueue<>();

public static void add(final Runnable call) {
callQueue.add(call);
if (call != null) {
callQueue.add(call);
}
}

@SubscribeEvent
public static void serverTick(TickEvent.ServerTickEvent event) {
if (event.phase == TickEvent.Phase.END) {
while (!callQueue.isEmpty()) {
while (true) {
Comment thread
zyxkad marked this conversation as resolved.
final Runnable runnable = callQueue.poll();
if (runnable == null) {
return;
}
AdvancedPeripherals.debug("Running queued server worker call: " + runnable);
runnable.run();
}
Expand Down