Skip to content

Commit

Permalink
Merge pull request #581 from zyxkad/patch-2
Browse files Browse the repository at this point in the history
Fix NullPointerException when server ticking
  • Loading branch information
SirEndii authored Apr 22, 2024
2 parents eb35cd2 + ed6a478 commit 0ef4a8c
Showing 1 changed file with 9 additions and 4 deletions.
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) {
final Runnable runnable = callQueue.poll();
if (runnable == null) {
return;
}
AdvancedPeripherals.debug("Running queued server worker call: " + runnable);
runnable.run();
}
Expand Down

0 comments on commit 0ef4a8c

Please sign in to comment.