-
-
Notifications
You must be signed in to change notification settings - Fork 44
/
PatchMinecraftServer.java
125 lines (101 loc) · 3.77 KB
/
PatchMinecraftServer.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
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
package me.nallar.tickthreading.minecraft.patched;
import java.io.File;
import cpw.mods.fml.common.FMLCommonHandler;
import me.nallar.tickthreading.minecraft.ThreadManager;
import me.nallar.tickthreading.minecraft.TickThreading;
import me.nallar.tickthreading.patcher.Declare;
import net.minecraft.crash.CrashReport;
import net.minecraft.network.packet.Packet4UpdateTime;
import net.minecraft.server.MinecraftServer;
import net.minecraft.server.gui.IUpdatePlayerListBox;
import net.minecraft.util.ReportedException;
import net.minecraft.world.WorldServer;
import net.minecraftforge.common.DimensionManager;
public abstract class PatchMinecraftServer extends MinecraftServer {
public ThreadManager threadManager;
public PatchMinecraftServer(File par1File) {
super(par1File);
}
@Override
public void updateTimeLightAndEntities() {
this.theProfiler.startSection("levels");
int var1;
Integer[] ids = DimensionManager.getIDs();
if (threadManager == null) {
threadManager = new ThreadManager(8, "World Tick");
}
for (int x = 0; x < ids.length; x++) {
final int id = ids[x];
if (theProfiler.profilingEnabled || !TickThreading.instance().enableWorldTickThreading) {
tickWorld(id);
} else {
threadManager.run(new TickRunnable(id));
}
}
threadManager.waitForCompletion();
this.theProfiler.endStartSection("dim_unloading");
DimensionManager.unloadWorlds(worldTickTimes);
this.theProfiler.endStartSection("connection");
this.getNetworkThread().networkTick();
this.theProfiler.endStartSection("players");
this.serverConfigManager.sendPlayerInfoToAllPlayers();
this.theProfiler.endStartSection("tickables");
for (var1 = 0; var1 < this.tickables.size(); ++var1) {
((IUpdatePlayerListBox) this.tickables.get(var1)).update();
}
this.theProfiler.endSection();
}
@Declare
public void tickWorld(int id) {
long var2 = System.nanoTime();
if (id == 0 || this.getAllowNether()) {
WorldServer var4 = DimensionManager.getWorld(id);
this.theProfiler.startSection(var4.getWorldInfo().getWorldName());
this.theProfiler.startSection("pools");
var4.getWorldVec3Pool().clear();
this.theProfiler.endSection();
if (this.tickCounter % 60 == 0) {
this.theProfiler.startSection("timeSync");
this.serverConfigManager.sendPacketToAllPlayersInDimension(new Packet4UpdateTime(var4.getTotalWorldTime(), var4.getWorldTime()), var4.provider.dimensionId);
this.theProfiler.endSection();
}
this.theProfiler.startSection("forgeTick");
FMLCommonHandler.instance().onPreWorldTick(var4);
CrashReport var6;
this.theProfiler.endStartSection("worldTick");
try {
var4.tick();
} catch (Throwable var8) {
var6 = CrashReport.makeCrashReport(var8, "Exception ticking world");
var4.addWorldInfoToCrashReport(var6);
throw new ReportedException(var6);
}
this.theProfiler.endStartSection("entityTick");
try {
var4.updateEntities();
} catch (Throwable var7) {
var6 = CrashReport.makeCrashReport(var7, "Exception ticking world entities");
var4.addWorldInfoToCrashReport(var6);
throw new ReportedException(var6);
}
this.theProfiler.endStartSection("postForgeTick");
FMLCommonHandler.instance().onPostWorldTick(var4);
this.theProfiler.endSection();
this.theProfiler.startSection("tracker");
var4.getEntityTracker().updateTrackedEntities();
this.theProfiler.endSection();
this.theProfiler.endSection();
}
worldTickTimes.get(id)[this.tickCounter % 100] = System.nanoTime() - var2;
}
public static class TickRunnable implements Runnable {
final int id;
public TickRunnable(int id) {
this.id = id;
}
@Override
public void run() {
mcServer.tickWorld(id);
}
}
}