-
-
Notifications
You must be signed in to change notification settings - Fork 101
Expand file tree
/
Copy pathClientWorker.java
More file actions
34 lines (28 loc) · 1.09 KB
/
ClientWorker.java
File metadata and controls
34 lines (28 loc) · 1.09 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
package de.srendi.advancedperipherals.client;
import de.srendi.advancedperipherals.AdvancedPeripherals;
import net.minecraftforge.api.distmarker.Dist;
import net.minecraftforge.event.TickEvent;
import net.minecraftforge.eventbus.api.SubscribeEvent;
import net.minecraftforge.fml.common.Mod;
import java.util.Map;
import java.util.concurrent.ConcurrentHashMap;
@Mod.EventBusSubscriber(value = Dist.CLIENT, modid = AdvancedPeripherals.MOD_ID)
public class ClientWorker {
private static final Map<String, Runnable> tasks = new ConcurrentHashMap<>();
/**
* This method will put a task to current tick's end.
* If a task with given identifier is already exists, the task will be replaced.
*/
public static void put(final String id, final Runnable task) {
tasks.put(id, task);
}
@SubscribeEvent
public static void clientTick(TickEvent.ClientTickEvent event) {
if (event.phase == TickEvent.Phase.END) {
tasks.forEach((id, runnable) -> {
tasks.remove(id, runnable);
runnable.run();
});
}
}
}