-
-
Notifications
You must be signed in to change notification settings - Fork 28
/
EntityCountingProfiler.java
52 lines (48 loc) · 1.87 KB
/
EntityCountingProfiler.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
package org.minimallycorrect.tickprofiler.minecraft.profiling;
import lombok.val;
import net.minecraft.world.WorldServer;
import net.minecraftforge.common.DimensionManager;
import org.minimallycorrect.tickprofiler.util.CollectionsUtil;
import java.util.*;
public class EntityCountingProfiler extends Profile {
private static <T> void increment(HashMap<T, Integer> counts, T t) {
val current = counts.get(t);
counts.put(t, current == null ? 1 : current + 1);
}
@Override
public void start() {
val elements = parameters.getInt("elements");
if (elements <= 0)
throw new IllegalArgumentException("elements must be > 0");
val entityCounts = new HashMap<Class, Integer>();
val tileEntityCounts = new HashMap<Class, Integer>();
val worlds = parameters.getString("worlds").toLowerCase();
val worldList = new ArrayList<WorldServer>();
if (worlds.equals("all")) {
Collections.addAll(worldList, DimensionManager.getWorlds());
worldList.removeIf(Objects::isNull);// #100 null world in world list?
} else {
//TODO: handle multiple entries, split by ','
worldList.add(DimensionManager.getWorld(Integer.parseInt(worlds)));
}
for (val world : worldList)
for (val entity : world.loadedEntityList)
increment(entityCounts, entity.getClass());
for (val world : worldList)
for (val entity : world.loadedTileEntityList)
increment(tileEntityCounts, entity.getClass());
targets.forEach(it -> {
val tf = it.getTableFormatter();
tf.heading("Class").heading("Count");
for (val key : CollectionsUtil.sortedKeys(entityCounts, elements))
tf.row(key.getSimpleName()).row(entityCounts.get(key));
tf.finishTable();
tf.sb.append('\n');
tf.heading("Class").heading("Count");
for (val key : CollectionsUtil.sortedKeys(tileEntityCounts, elements))
tf.row(key.getSimpleName()).row(tileEntityCounts.get(key));
tf.finishTable();
it.sendTables(tf);
});
}
}