-
Notifications
You must be signed in to change notification settings - Fork 0
/
获取粘液配方_v1.1.js
215 lines (184 loc) · 5.7 KB
/
获取粘液配方_v1.1.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
function wait_next_container() {
while(Player.openInventory().getCurrentSyncId() == LastSyncId || Player.openInventory().getCurrentSyncId() == 0){
// 等待打开容器
Client.waitTick(1)
}
LastSyncId = Player.openInventory().getCurrentSyncId()
Client.waitTick(1)
}
function getItemInfo() {
var item_id = getItemIdBySlot(16)
var data = {
"item_name":getItemNameBySlot(16),
"output_times":Player.openInventory().getSlot(16).getCount(),
// "craft_id":getItemIdBySlot(10),
"method":getItemNameBySlot(10),
"materials":[]
}
var tabel = [3,4,5,12,13,14,21,22,23]
for (let i = 0; i < 9; i++) {
let material_id = getItemIdBySlot(tabel[i])
let material_name = getItemNameBySlot(tabel[i])
let material_count = Player.openInventory().getSlot(tabel[i]).getCount()
if (material_id!="minecraft:air"){
data["materials"].push({
// "material_id":material_id,
"name":material_name,
"count":material_count,
"position":i
})
}
}
return [item_id, data]
}
function close_inventory() {
Player.openInventory().close()
while (Player.openInventory().getCurrentSyncId()!=0) {
Client.waitTick(1)
}
}
function back_to_last_menu() {
var state = findItemById("slimefun:_UI_BACK","container")
enter_into_slot_menu(state['slot'][0][0])
}
function back_to_main_menu() {
var state
while((state = findItemById("slimefun:_UI_BACK","container"))) {
if (state['count'] == 0)
break
enter_into_slot_menu(state['slot'][0][0])
}
}
function enter_into_slot_menu(slot) {
Player.openInventory().click(slot)
wait_next_container()
}
function loads(s) {
return eval('('+s+')');
}
function dumps(o) {
return JSON.stringify(o)
}
function getItemNameBySlot(Index) {
return Player.openInventory().getSlot(Index).getName().getString()
}
function getItemNbtBySlot(Index) {
Item = Player.openInventory().getSlot(Index), Nbt = Item.getNBT()
return Nbt
}
function getItemIdBySlot(Index) {
var Item = Player.openInventory().getSlot(Index)
var Nbt = Item.getNBT()
if (Nbt==null) {
return Item.getItemId()
}
else {
if (Nbt.has("PublicBukkitValues")) {
let PublicBukkitValues = Nbt.get("PublicBukkitValues")
if(PublicBukkitValues.has("slimefun:slimefun_item")) {
return "slimefun:"+PublicBukkitValues.get("slimefun:slimefun_item").asString()
}
else{
return PublicBukkitValues.asString()
}
}
else{
return Item.getItemId()
}
}
}
function findItemById(id,map_identifiers) {
let correct_slot = []
let item_count = 0
if (typeof(map_identifiers)=="string"){
for (let slot = 0; slot < Player.openInventory().getTotalSlots() ; slot++) {
let map_loc = Player.openInventory().getLocation(slot)
if (map_loc != map_identifiers)
continue
let item = Player.openInventory().getSlot(slot)
// Chat.log(slot);
let item_id = getItemIdBySlot(slot)
if (item_id == id) {
correct_slot.push([slot, item.getCount()])
item_count += item.getCount()
}
}
}
else if(typeof(map_identifiers)=="object"){
for (let slot = 0; slot < Player.openInventory().getTotalSlots() ; slot++) {
let map_loc = Player.openInventory().getLocation(slot)
if (!map_identifiers.includes(map_loc))
continue
let item = Player.openInventory().getSlot(slot)
let item_id = getItemIdBySlot(slot)
if (item_id == id) {
correct_slot.push([slot, item.getCount()])
item_count += item.getCount()
}
}
}
return {"slot":correct_slot.sort(function(a,b){return a[1]-b[1]}), "count":item_count}
}
function nextPage() {
var state = findItemById('slimefun:_UI_NEXT_ACTIVE','container')
if (state['count'] == 0 ) {
return false
}
else{
enter_into_slot_menu(state['slot'][0][0])
return true
}
}
function method(o) {
for (const m in o) {
Chat.log(m)
}
}
function merge(a,b) {
for (const k in a) {
if (!(k in b)) {
b[k] = a[k]
}
}
return b
}
var LastSyncId = 0
var me = Player.getPlayer()
me.interact()
wait_next_container()
back_to_main_menu()
var file = FS.open('./config/type_list.txt').readLines()
var class_list = []
while(file.hasNext()) {
line = file.next().split(',').map(str => parseInt(str));
class_list.push(line)
}
current_data = {}
for (let index = 0; index < class_list.length; index++) {
for (let deep = 0; deep < class_list[index].length; deep++) {
enter_into_slot_menu(class_list[index][deep])
}
do {
for (let slot = 9; slot < 45 && getItemIdBySlot(slot) != "minecraft:air"; slot++) {
Chat.log(getItemNameBySlot(slot))
enter_into_slot_menu(slot)
info = getItemInfo()
current_data[info[1]['item_name']] = info[1]
back_to_last_menu()
}
} while (nextPage());
back_to_main_menu()
}
if (FS.exists('./config/craft_formula.json') ) {
f = FS.open('./config/craft_formula.json')
previous_data = loads(f.read())
data = merge(previous_data,current_data)
s = dumps(data)
f.write(s)
}
else{
FS.createFile('./config/', 'craft_formula.json')
f = FS.open('./config/craft_formula.json')
s = dumps(current_data)
f.write(s)
}