-
Notifications
You must be signed in to change notification settings - Fork 0
/
EntityCounter.js
216 lines (204 loc) · 7.2 KB
/
EntityCounter.js
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
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
// LiteLoaderScript Dev Helper
/// <reference path="../HelperLib/src/index.d.ts"/>
/* global mc ll PermType ParamType */
const entityNames = {
'minecraft:area_effect_cloud': '区域效果云',
'minecraft:armor_stand': '盔甲架',
'minecraft:arrow': '箭',
'minecraft:bat': '蝙蝠',
'minecraft:bee': '蜜蜂',
'minecraft:blaze': '烈焰人',
'minecraft:boat': '船',
'minecraft:cat': '猫',
'minecraft:cave_spider': '洞穴蜘蛛',
'minecraft:chicken': '鸡',
'minecraft:cow': '牛',
'minecraft:creeper': '苦力怕',
'minecraft:dolphin': '海豚',
'minecraft:goat': '山羊',
'minecraft:panda': '熊猫',
'minecraft:donkey': '驴',
'minecraft:dragon_fireball': '末影龙火球',
'minecraft:drowned': '溺尸',
'minecraft:egg': '鸡蛋',
'minecraft:elder_guardian': '远古守卫者',
'minecraft:ender_crystal': '末地水晶',
'minecraft:ender_dragon': '末影龙',
'minecraft:enderman': '末影人',
'minecraft:endermite': '末影螨',
'minecraft:ender_pearl': '末影珍珠',
'minecraft:evocation_illager': '唤魔者',
'minecraft:evocation_fang': '唤魔者尖牙',
'minecraft:eye_of_ender_signal': '末影之眼',
'minecraft:falling_block': '下落的方块',
'minecraft:fireball': '火球',
'minecraft:fireworks_rocket': '烟花火箭',
'minecraft:fishing_hook': '浮漂',
'minecraft:fox': '狐狸',
'minecraft:cod': '鳕鱼',
'minecraft:pufferfish': '河豚',
'minecraft:salmon': '鲑鱼',
'minecraft:tropicalfish': '热带鱼',
'minecraft:axolotl': '美西螈',
'minecraft:ghast': '恶魂',
'minecraft:glow_squid': '发光鱿鱼',
'minecraft:piglin_brute': '猪灵蛮兵',
'minecraft:guardian': '守卫者',
'minecraft:hoglin': '疣猪兽',
'minecraft:horse': '马',
'minecraft:husk': '尸壳',
'minecraft:ravager': '劫掠兽',
'minecraft:iron_golem': '铁傀儡',
'minecraft:item': '掉落物',
'minecraft:leash_knot': '拴绳结',
'minecraft:lightning_bolt': '闪电束',
'minecraft:lingering_potion': '滞留药水',
'minecraft:llama': '羊驼',
'minecraft:trader_llama': '行商羊驼',
'minecraft:llama_spit': '羊驼唾沫',
'minecraft:magma_cube': '岩浆怪',
'minecraft:minecart': '矿车',
'minecraft:chest_minecart': '运输矿车',
'minecraft:command_block_minecart': '命令方块矿车',
'minecraft:furnace_minecart': '动力矿车',
'minecraft:hopper_minecart': '漏斗矿车',
'minecraft:tnt_minecart': 'TNT矿车',
'minecraft:mule': '骡',
'minecraft:mooshroom': '哞菇',
'minecraft:moving_block': '移动中的方块',
'minecraft:ocelot': '豹猫',
'minecraft:painting': '画',
'minecraft:parrot': '鹦鹉',
'minecraft:phantom': '幻翼',
'minecraft:pig': '猪',
'minecraft:piglin': '猪灵',
'minecraft:pillager': '掠夺者',
'minecraft:polar_bear': '北极熊',
'minecraft:rabbit': '兔子',
'minecraft:sheep': '绵羊',
'minecraft:shulker': '潜影贝',
'minecraft:shulker_bullet': '潜影弹',
'minecraft:silverfish': '蠹虫',
'minecraft:skeleton': '骷髅',
'minecraft:skeleton_horse': '骷髅马',
'minecraft:stray': '流浪者',
'minecraft:slime': '史莱姆',
'minecraft:small_fireball': '小火球',
'minecraft:sniffer': '嗅探兽',
'minecraft:snowball': '雪球',
'minecraft:snow_golem': '雪傀儡',
'minecraft:spider': '蜘蛛',
'minecraft:splash_potion': '药水',
'minecraft:squid': '鱿鱼',
'minecraft:strider': '炽足兽',
'minecraft:tnt': 'TNT',
'minecraft:thrown_trident': '三叉戟',
'minecraft:tripod_camera': '相机',
'minecraft:turtle': '海龟',
'minecraft:unknown': '未知',
'minecraft:vex': '恼鬼',
'minecraft:villager': '村民',
'minecraft:villager_v2': '村民',
'minecraft:vindicator': '卫道士',
'minecraft:wandering_trader': '流浪商人',
'minecraft:witch': '女巫',
'minecraft:wither': '凋灵',
'minecraft:wither_skeleton': '凋灵骷髅',
'minecraft:wither_skull': '凋灵之首',
'minecraft:wither_skull_dangerous': '凋灵之首',
'minecraft:wolf': '狼',
'minecraft:xp_orb': '经验球',
'minecraft:xp_bottle': '附魔之瓶',
'minecraft:zoglin': '僵尸疣猪兽',
'minecraft:zombie': '僵尸',
'minecraft:zombie_horse': '僵尸马',
'minecraft:zombie_pigman': '僵尸猪灵',
'minecraft:zombie_villager': '僵尸村民',
'minecraft:zombie_villager_v2': '僵尸村民',
'minecraft:frog': '青蛙',
'minecraft:tadpole': '蝌蚪',
'minecraft:warden': '监守者',
'minecraft:allay': '悦灵',
'minecraft:chest_boat': '运输船',
'minecraft:camel': '骆驼',
'minecraft:chest_raft': '运输竹筏',
'minecraft:balloon': '气球',
'minecraft:ice_bomb': '冰弹',
'minecraft:breeze': '旋风人',
'minecraft:armadillo': '犰狳',
}
/**
* @param { { [type: string]: number } } obj
* @returns {string}
*/
function objectToStr(obj) {
/** @type {string[]} */
const tmpLi = []
Object.entries(obj)
.sort((x, y) => y[1] - x[1])
.forEach((x) => {
const [k, v] = x
tmpLi.push(`§a${k} §r* §6${v}§r`)
})
return tmpLi.join('\n')
}
mc.listen('onServerStarted', () => {
const cmdEntC = mc.newCommand('entc', '查看服务器当前实体数量', PermType.Any)
cmdEntC.optional('targets', ParamType.Actor)
cmdEntC.optional('showAnalytics', ParamType.Bool)
cmdEntC.overload(['showAnalytics', 'targets'])
cmdEntC.setCallback(
(_, origin, out, /** @type {{targets?:Entity[],showAnalytics?:boolean}} */ res) => {
let { targets } = res
const { showAnalytics } = res
const { player } = origin
let isSelector = true
if (!targets) {
targets = mc.getAllEntities()
isSelector = false
}
// if (showAnalytics === undefined) showAnalytics = true;
const count = targets.length
/** @type { { [type: string]: number } } */
const analytic = {}
/** @type { { [type: string]: number } } */
const itemAnalytic = {}
targets.forEach((e) => {
const { type, name } = e
// @ts-expect-error - type as keyof entityNames
const disName = entityNames[type] || name
const num = analytic[disName] || 0
analytic[disName] = num + 1
if (type === 'minecraft:item') {
const itNum = itemAnalytic[name] || 0
itemAnalytic[name] = itNum + 1
}
})
const targetTip = isSelector ? `§d目标选择器§r已选择` : '§d当前服务器§r已加载'
let analyticTip = ''
if (count !== 0 && showAnalytics) {
const tmpLi = [
`\n==============\n以下是已统计实体及数量:\n${objectToStr(analytic)}`,
]
if (Object.keys(itemAnalytic).length > 0) {
tmpLi.push(
`==============\n在这些实体中,§d掉落物§r的名称与数量:\n` +
`${objectToStr(itemAnalytic)}`,
)
}
analyticTip = tmpLi.join('\n')
}
const tip = `${targetTip} §l§6${count} §r个实体${analyticTip}`
if (player && showAnalytics) {
player.sendForm(
mc.newSimpleForm().setTitle('§b实体数量查看').setContent(tip),
() => {},
)
} else {
out.success(`§b[实体数量查看] ${tip}`)
}
},
)
cmdEntC.setup()
})
ll.registerPlugin('EntityCounter', '实体数量查看', [0, 0, 2], {})