-
Notifications
You must be signed in to change notification settings - Fork 497
/
BCStatCollector.java
72 lines (56 loc) · 2.73 KB
/
BCStatCollector.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
package buildcraft.core;
import java.util.IdentityHashMap;
import java.util.Map;
import java.util.Map.Entry;
import net.minecraft.block.Block;
import net.minecraft.item.Item;
import net.minecraft.item.ItemBlock;
import net.minecraft.item.ItemStack;
import net.minecraft.stats.StatCrafting;
import net.minecraft.stats.StatList;
import net.minecraft.util.ChatComponentTranslation;
import net.minecraft.util.ResourceLocation;
public enum BCStatCollector {
INSTANCE;
private final Map<Block, StatCrafting> blockMined = new IdentityHashMap<>();
private final Map<Item, StatCrafting> itemCrafted = new IdentityHashMap<>();
private final Map<Item, StatCrafting> itemUsed = new IdentityHashMap<>();
public static void registerStats(Block block) {
if (!block.getEnableStats()) return;
Item item = Item.getItemFromBlock(block);
if (item == null) return;
String statName = toStatName(item);
Object[] translation = { (new ItemStack(block)).getChatComponent() };
StatCrafting mineBlock = new StatCrafting("stat.mineBlock.", statName, new ChatComponentTranslation("stat.mineBlock", translation), item);
mineBlock.registerStat();
StatList.objectMineStats.add(mineBlock);
INSTANCE.blockMined.put(block, mineBlock);
registerStats(item);
}
public static void registerStats(Item item) {
String statName = toStatName(item);
Object[] translation = { (new ItemStack(item)).getChatComponent() };
StatCrafting used = new StatCrafting("stat.useItem.", statName, new ChatComponentTranslation("stat.useItem", translation), item);
StatCrafting craft = new StatCrafting("stat.craftItem.", statName, new ChatComponentTranslation("stat.craftItem", translation), item);
used.registerStat();
craft.registerStat();
if (!(item instanceof ItemBlock)) {
StatList.itemStats.add(used);
}
INSTANCE.itemUsed.put(item, used);
INSTANCE.itemCrafted.put(item, craft);
}
private static String toStatName(Item item) {
ResourceLocation resourcelocation = Item.itemRegistry.getNameForObject(item);
return resourcelocation != null ? resourcelocation.toString().replace(':', '.') : null;
}
public void serverStarting() {
/* We know that the registry has been frozen at this point so it is safe to fill up the arrays */
for (Entry<Item, StatCrafting> crafted : itemUsed.entrySet()) {
StatList.objectUseStats[Item.getIdFromItem(crafted.getKey())] = crafted.getValue();
}
for (Entry<Item, StatCrafting> crafted : itemCrafted.entrySet()) {
StatList.objectCraftStats[Item.getIdFromItem(crafted.getKey())] = crafted.getValue();
}
}
}