-
-
Notifications
You must be signed in to change notification settings - Fork 44
/
PatchFMLCommonHandler.java
59 lines (51 loc) · 1.9 KB
/
PatchFMLCommonHandler.java
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
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
package me.nallar.tickthreading.minecraft.patched;
import java.util.EnumSet;
import java.util.List;
import com.google.common.base.Objects;
import cpw.mods.fml.common.FMLCommonHandler;
import cpw.mods.fml.common.IScheduledTickHandler;
import cpw.mods.fml.common.TickType;
import cpw.mods.fml.relauncher.Side;
import net.minecraft.profiler.Profiler;
public abstract class PatchFMLCommonHandler extends FMLCommonHandler {
public Profiler theProfiler = null;
@Override
public void tickStart(EnumSet<TickType> ticks, Side side, Object... data) {
if (theProfiler == null) {
theProfiler = getMinecraftServerInstance().theProfiler;
}
List<IScheduledTickHandler> scheduledTicks = side.isClient() ? scheduledClientTicks : scheduledServerTicks;
if (scheduledTicks.size() == 0) {
return;
}
for (IScheduledTickHandler ticker : scheduledTicks) {
EnumSet<TickType> ticksToRun = EnumSet.copyOf(Objects.firstNonNull(ticker.ticks(), EnumSet.noneOf(TickType.class)));
ticksToRun.retainAll(ticks);
if (!ticksToRun.isEmpty()) {
theProfiler.startSection(ticker.getClass().toString());
synchronized (ticker) {
ticker.tickStart(ticksToRun, data);
}
theProfiler.endSection();
}
}
}
@Override
public void tickEnd(EnumSet<TickType> ticks, Side side, Object... data) {
List<IScheduledTickHandler> scheduledTicks = side.isClient() ? scheduledClientTicks : scheduledServerTicks;
if (scheduledTicks.size() == 0) {
return;
}
for (IScheduledTickHandler ticker : scheduledTicks) {
EnumSet<TickType> ticksToRun = EnumSet.copyOf(Objects.firstNonNull(ticker.ticks(), EnumSet.noneOf(TickType.class)));
ticksToRun.retainAll(ticks);
if (!ticksToRun.isEmpty()) {
theProfiler.startSection(ticker.getClass().toString());
synchronized (ticker) {
ticker.tickEnd(ticksToRun, data);
}
theProfiler.endSection();
}
}
}
}