/
hoapbot.js
843 lines (792 loc) · 25.4 KB
/
hoapbot.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
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
/*
* แจกฟรี ห้ามนำไปขาย
* สำหรับเซิร์ฟเวอร์ mc-zero.net (GUI22)
* Hazuki-san (Hoap) 2021
* r0neko | Code Quality CHECK!
* Mxnuuel (Lemres) | Extra Help!
*/
// Packages
const async = require('async');
const math = require('mathjs');
const v = require('vec3');
const fs = require('fs')
// Config
let rawdata = fs.readFileSync('config.json');
let data = JSON.parse(rawdata);
const readFile = (fileName) => util.promisify(fs.readFile)(fileName, 'utf8')
// Setting stuff up
const host = data["ip"];
const port = data["port"];
const version = data["version"];
const authme = data["authme_pw"];
const botowner = data["botowner"]
//const events = require('events').EventEmitter.defaultMaxListeners = Infinity // Call me CRAZYCHAMP
// Mineflayer
const mineflayer = require('mineflayer')
const autoeat = require('mineflayer-auto-eat')
const pvp = require('mineflayer-pvp').plugin
const collectb = require('mineflayer-collectblock').plugin
const Item = require('prismarine-item')(version)
//const armorManager = require('mineflayer-armor-manager')
const {
pathfinder,
Movements,
goals: {
GoalBlock,
GoalNear,
GoalFollow
}
} = require('mineflayer-pathfinder')
const wrap = module.exports.wrap = cb => new Promise(resolve => cb(resolve));
const botName = process.argv[2]
makeBot(botName)
function makeBot(username) {
// Initialize bot
const bot = mineflayer.createBot({
username: username,
host: host,
port: port,
version: version
})
const mcData = require('minecraft-data')(bot.version)
const defaultMove = new Movements(bot, mcData)
console.log("Loaded: " + username)
// Plugins Load
//bot.loadPlugin(armorManager);
bot.loadPlugin(pathfinder)
bot.loadPlugin(autoeat)
bot.loadPlugin(pvp)
bot.loadPlugin(collectb)
bot.autoEat.enable()
bot.once('spawn', () => {
bot.chat('/login ' + authme)
bot.pathfinder.setMovements(defaultMove)
bot.pathfinder.setGoal(new GoalBlock(28, 68, 0))
bot.once('goal_reached', (goal) => {
// โดด เพราะเหมือนเซิร์ฟค้างหรือเปล่า? ไม่แน่ใจ
bot.setControlState('jump', true)
bot.setControlState('jump', false)
})
})
// Chat Pattern
bot.addChatPattern(
'nowplayingdetected',
/(ตอนนี้กำลังเล่นเพลง)/,
)
bot.addChatPattern(
"chatreactiondetected",
/CHATGAME » ใครพิมพ์คำว่า (.*) เสร็จก่อนชนะ!/, {
parse: true
}
)
bot.addChatPattern(
'clearlagged',
/ระบบได้ทำการลบเก็บขยะจำนวน (.*) ชิ้น/, {
parse: true
}
)
bot.addChatPattern(
'server',
/✭ (.*) ┇ (.*) ┇ \((.+)\) (.*) » (.*)/, {
parse: true
}
)
bot.addChatPattern(
'serverwhisper',
/\[\((.*)\) (.+) -» me\] (.+)/, {
parse: true
}
)
bot.addChatPattern(
'autosell_complete',
/ทั้งหมด ขายได้ราคา (.*) /, {
parse: true
}
)
// Initialize GUI to go to
function goGUI22() {
setTimeout(bot.activateItem, 500);
bot.once('windowOpen', async (window) => {
window.requiresConfirmation = false // fix
await bot.clickWindow(22, 0, 0)
})
}
const NowPlaying = () => {
// รู้แล้วว่าอยู่ในล็อบบี้ งั้นไปกันเลย!
setTimeout(goGUI22, 500);
}
bot.on('chat:nowplayingdetected', NowPlaying)
/*
* dumping
*/
var dumping = false;
var dumpAll = function(number) {
if (!dumping) return;
const excludedItems = data["excluded_items"]
const item = bot.inventory.items().find(item => !excludedItems.includes(item.name))
if (item) {
bot.tossStack(item).then(() => {
setTimeout(dumpAll)
}).catch(err => {
console.log(err)
setTimeout(dumpAll, 100)
})
} else {
dumping = false
botowner.forEach(function(ownerlist) {
bot.chat('/w ' + ownerlist + ' ' + 'เลิกโยนของแล้ว');
});
}
};
/*
* clickwindow
*/
var waitingwindow = false;
var checkwindow = function(number) {
if (!waitingwindow) return;
bot.once('windowOpen', async (window) => {
window.requiresConfirmation = false // fix
await bot.clickWindow(parseInt(number), 0, 0)
bot.closeWindow(window);
botowner.forEach(function(ownerlist) {
bot.chat('/w ' + ownerlist + ' ' + 'กดให้แล้วนะ แล้วก็ปิดหน้าต่างให้แล้ว');
});
waitingwindow = false
})
};
/*
* Mob Spawn
*/
var farmingmob = false;
var killingmob = function() {
if (!farmingmob) return;
bot.on('physicTick', () => {
var sword = bot.inventory.items().find(item => item.name.includes('sword'))
if (sword) bot.equip(sword, 'hand')
const filter = e => e.type === 'mob' && (e.mobType === 'Spider' || e.mobType === 'Cave Spider')
const entity = bot.nearestEntity(filter)
if (entity) {
bot.pvp.attack(entity)
}
})
}
/*
* SNIPER
*/
var sniping = false;
var snipe = function() {
if (!sniping) return;
bot.on('chatreactiondetected', matches => {
setTimeout(function() {
bot.chat(`${matches}`) // ตรงๆแม่นๆ แน่นอนจริงๆ
}, Math.floor(Math.random() * (Math.floor(data["rmax"]) - Math.ceil(data["rmin"])) + Math.ceil(data["rmin"])));
});
};
var farming = false;
var farm = function() {
if (!farming) return;
function collectPumpkin() {
// Find a nearby pumpkin block
const pumpkin = bot.findBlock({
matching: mcData.blocksByName.pumpkin.id,
maxDistance: 64
})
if (pumpkin) {
// If we found one, collect it.
bot.collectBlock.collect(pumpkin, err => {
if (err) // Handle errors, if any
console.log(err)
else
collectGrass() // Collect another pumpkin block
})
}
}
function blockToHarvest() {
return bot.findBlock({
point: bot.entity.position,
maxDistance: 3,
matching: (block) => {
return block && block.type === mcData.blocksByName.pumpkin.id
}
})
}
async function loop() {
try {
while (1) {
const toHarvest = blockToHarvest()
if (toHarvest) {
await bot.dig(toHarvest)
} else {
break
}
}
} catch (e) {
console.log(e)
}
// No block to harvest or sow. Postpone next loop a bit
setTimeout(function() {
loop()
collectPumpkin()
}, 1000)
}
loop()
}
/*
* โค้ตตกปลา
*/
var fishing = false;
var fish = function() {
// ClearLag Fix
if (!fishing) return;
bot.on('chat:clearlagged', matches => {
bot.activateItem();
fish();
});
let bobberId = 90
// 1.14+ Fix
if (bot.supportFeature('fishingBobberCorrectlyNamed')) {
bobberId = mcData.entitiesByName.fishing_bobber.id
}
let running = true;
(async () => {
while (running) {
await wrap(res => bot.equip(
bot.inventory.findInventoryItem(mcData.itemsByName.fishing_rod.id),
'hand',
res
));
let bobber = await wrap(res => {
let onSpawn = entity => {
if (entity.entityType !== bobberId) return;
bot.once('entitySpawn', onSpawn);
// Precise <= 0.3
// Default <= 1.23
// Rage <= 5
// MAD < Infinity
if (entity.position.z < 0) {
if ((entity.position.z - 1.23) <= bot.entity.position.z && (entity.position.z + 1.23) >= bot.entity.position.z) res(entity);
} else {
if ((entity.position.z + 1.23) >= bot.entity.position.z && (entity.position.z - 1.23) <= bot.entity.position.z) res(entity);
}
return;
}
bot.once('entitySpawn', onSpawn);
bot.activateItem();
});
await console.log(bot.username + ": I found a bobber!")
await console.log(bot.username + ": Here's some info about it!")
if (bobber.position.z < 0) {
await console.log(bot.username + "'s Bob Z: " + (bobber.position.z))
await console.log(bot.username + "'s Bot Z: " + bot.entity.position.z)
} else {
await console.log(bot.username + "'s Bob Z: " + (bobber.position.z))
await console.log(bot.username + "'s Bot Z: " + bot.entity.position.z)
}
if (!running) {
await bot.activateItem();
break;
}
// Soft <= 0.3
// Medium <= 1.23
// Rage <= 5
// MAD < Infinity
await wrap(res => {
let onParticles = packet => {
let pos = bobber.position
if (packet.particleId === 4 && packet.particles === 6 && pos.distanceTo(new v(packet.x, pos.y, packet.z)) <= 0.3) res();
bot._client.once('world_particles', onParticles);
}
bot._client.once('world_particles', onParticles)
});
await bot.activateItem();
await sleep(500)
}
})();
return () => {
running = false;
}
};
/*
* โค้ตแสดงข้อความในเซิรฺ์ฟ
*/
bot.on('message', (cm) => {
console.log(bot.username + ": " + cm.toString())
})
/*
* โค้ตแชท
*/
prefixes = ["!all", "!bot"]
bot.on('chat:server', async matches => command(matches, 0))
bot.on('chat:serverwhisper', async matches => command(matches, 1))
var command = async function(matches, mode) {
// Server Chat
if (mode == 0) {
var level = matches[0][0] // Level (+Marry)
var gang = matches[0][1] // Gang
var rank = matches[0][2] // Rank
var username = matches[0][3] // Username
var message = matches[0][4] // Message
} else if (mode == 1) {
var rank = matches[0][0] // Rank
var username = matches[0][1] // Username
var message = matches[0][2] // Message
}
if (username == bot.username) return; //ถ้าตรงกับชื่อตัวเอง อย่าสนใจ
if (!botowner.includes(username)) return; // ถ้าไม่ใช่เจ้าของบอท อย่าสนใจ
try {
var result = math.eval(message);
if (result != null && result != undefined)
bot.chat(result + '');
} catch (e) {}
var args = message.split(' ');
if (prefixes.includes(args[0].toLowerCase())) {
var command = args[1].toLowerCase();
switch (command) {
case 'sudo':
if (args.slice(2).join(" ") == "")
botowner.forEach(function(ownerlist) {
bot.chat('/w ' + ownerlist + ' ' + 'จะให้พิมพ์ว่าอะไรหรอ 555');
});
bot.chat(args.slice(2).join(" "))
break;
case 'clear_armor':
//ugly but hey it works?
await bot.unequip("head")
await bot.unequip("torso")
await bot.unequip("legs")
await bot.unequip("feet")
botowner.forEach(function(ownerlist) {
bot.chat('/w ' + ownerlist + ' ' + 'เอาออกหมดแล้ว');
});
break;
case 'gear_up':
var checkItemEquiped = function(itemArmor) {
let swordEquiped, isSword, bowEquiped, isBow
let slotID
switch (itemArmor) {
case 'helmet':
slotID = 5
break;
case 'chestplate':
slotID = 6
break
case 'leggings':
slotID = 7
break
case 'boots':
slotID = 8
break
case 'shield':
slotID = 45
break
case 'sword':
slotID = bot.getEquipmentDestSlot('hand')
swordEquiped = bot.inventory.slots[slotID]
if (swordEquiped === null) {
return false
}
isSword = swordEquiped.name.includes('sword')
return isSword
case 'bow':
slotID = bot.getEquipmentDestSlot('hand')
bowEquiped = bot.inventory.slots[slotID]
if (bowEquiped === null) {
return false
}
isBow = bowEquiped.name.includes('bow')
return isBow
default:
return false
}
return bot.inventory.slots[slotID] !== null
}
var equipItem = function(itemArmor) {
return new Promise((resolve, reject) => {
if (checkItemEquiped(itemArmor)) {
//console.log("checking checked")
resolve()
return
}
const armor = bot.inventory.items().find(item => item.name.includes(itemArmor))
if (!armor) {
//console.log("no armor checked")
resolve()
return
}
let location
switch (itemArmor) {
case 'helmet':
location = 'head'
break;
case 'chestplate':
location = 'torso'
break;
case 'leggings':
location = 'legs'
break;
case 'boots':
location = 'feet'
break;
case 'sword':
location = 'hand'
break;
case 'shield':
location = 'off-hand'
break;
}
bot.equip(armor, location, (error) => {
if (error === undefined) {
//console.log("equip checked")
resolve()
}
reject(error)
})
})
}
await equipItem("helmet");
await equipItem("chestplate");
await equipItem("leggings");
await equipItem("boots");
await equipItem("shield");
await equipItem("sword");
botowner.forEach(function(ownerlist) {
bot.chat('/w ' + ownerlist + ' ' + 'พร้อม!');
});
break;
case 'disconnect':
bot.quit();
break;
case 'drop':
try {
bot.toss(parseInt(args[2]), null, (args[3]) ? parseInt(args[3]) : 1, function(err) {
if (!err)
botowner.forEach(function(ownerlist) {
bot.chat('/w ' + ownerlist + ' ' + 'โยนของให้แล้วนะ');
});
else
botowner.forEach(function(ownerlist) {
console.log(err.message);
});
});
} catch (e) {
botowner.forEach(function(ownerlist) {
bot.chat('/w ' + ownerlist + ' ' + 'ไม่รู้จักสิ่งนี้อ่ะ');
});
}
break;
case 'dump':
var startDumping = function() {
dumping = true;
dumpAll();
botowner.forEach(function(ownerlist) {
bot.chat('/w ' + ownerlist + ' ' + 'กำลังโยนของทั้งหมดที่มี...');
});
};
var stopDumping = function() {
dumping = false;
botowner.forEach(function(ownerlist) {
bot.chat('/w ' + ownerlist + ' ' + 'เลิกโยนของแล้ว');
});
};
var toggleDumping = function() {
if (!dumping) startDumping();
else stopDumping();
};
if (args[2] == 'start') startDumping();
else if (args[2] == 'stop') stopDumping();
else toggleDumping();
break;
case 'equip':
var slot = (['hand', 'head', 'torso', 'legs', 'feed'].indexOf(args[3]) < 0) ? 'hand' : args[3];
bot.equip(bot.inventory.slots[parseInt(args[2])], slot, function(err) {
if (!err) botowner.forEach(function(ownerlist) {
bot.chat('/w ' + ownerlist + ' ' + 'ใส่ให้แล้วนะ');
});
else botowner.forEach(function(ownerlist) {
console.log(err.message);
});
})
case 'experience':
botowner.forEach(function(ownerlist) {
bot.chat('/w ' + ownerlist + ' ' + 'เลเวลตอนนี้: ' + bot.experience.level);
});
break;
case 'fish':
var startFishing = function() {
fishing = true;
fish();
botowner.forEach(function(ownerlist) {
bot.chat('/w ' + ownerlist + ' ' + 'เริ่มตกปลาแล้ว จะได้ปลาเยอะมั้ยนะ?');
});
};
var stopFishing = function() {
fishing = false;
bot.activateItem();
botowner.forEach(function(ownerlist) {
bot.chat('/w ' + ownerlist + ' ' + 'เลิกตกปลาแล้ว');
});
};
var toggleFishing = function() {
if (!fishing) startFishing();
else stopFishing();
};
if (args[2] == 'start') startFishing();
else if (args[2] == 'stop') stopFishing();
else toggleFishing();
break;
case 'farm':
var startFarming = function() {
farming = true;
farm();
botowner.forEach(function(ownerlist) {
bot.chat('/w ' + ownerlist + ' ' + 'เริ่มตกปลาแล้ว จะได้ปลาเยอะมั้ยนะ?');
});
};
var stopFarming = function() {
farming = false;
botowner.forEach(function(ownerlist) {
bot.chat('/w ' + ownerlist + ' ' + 'เลิกตกปลาแล้ว');
});
};
var toggleFarming = function() {
if (!fishing) startFarming();
else stopFarming();
};
if (args[2] == 'start') startFarming();
else if (args[2] == 'stop') stopFarming();
else toggleFarming();
break;
case 'mob_test':
var startMobFarm = function() {
farmingmob = true;
killingmob();
botowner.forEach(function(ownerlist) {
bot.chat('/w ' + ownerlist + ' ' + 'XXXXXXXX');
});
};
var stopMobFarm = function() {
farmingmob = false;
bot.pvp.stop();
botowner.forEach(function(ownerlist) {
bot.chat('/w ' + ownerlist + ' ' + 'DDDDDDDDD');
});
};
var toggleFarm = function() {
if (!farmingmob) startMobFarm();
else stopMobFarm();
};
if (args[2] == 'start') startMobFarm();
else if (args[2] == 'stop') stopMobFarm();
else toggleFarm();
break;
case 'snipe':
var startSniping = function() {
sniping = true;
snipe();
botowner.forEach(function(ownerlist) {
bot.chat('/w ' + ownerlist + ' ' + 'พวกมันพิมพ์ไม่ทันแน่ 5555');
});
};
var stopSniping = function() {
sniping = false;
botowner.forEach(function(ownerlist) {
bot.chat('/w ' + ownerlist + ' ' + 'อะไรอ่ะ กำลังสนุกอยู่เลย ปิดซะล่ะ :<');
});
};
var toggleSniping = function() {
if (!sniping) startSniping();
else stopSniping();
};
if (args[2] == 'start') startSniping();
else if (args[2] == 'stop') stopSniping();
else toggleSniping();
break;
case 'follow':
if (args[2] == 'me') {
try {
var target = bot.players[username].entity;
if (target != null && target != undefined)
bot.pathfinder.setMovements(defaultMove)
bot.pathfinder.setGoal(new GoalFollow(target, 1), true)
bot.lookAt(target.position.plus(v(0, 1.62, 0)));
} catch (e) {
botowner.forEach(function(ownerlist) {
bot.chat('/w ' + ownerlist + ' ' + 'เหมือนว่าจะไม่ได้อยู่ในระยะนี้นะ...');
});
return
}
} else {
try {
var target = bot.players[args[2]].entity;
if (target != null && target != undefined)
bot.pathfinder.setMovements(defaultMove)
bot.pathfinder.setGoal(new GoalFollow(target, 1), true)
bot.lookAt(target.position.plus(v(0, 1.62, 0)));
} catch (e) {
botowner.forEach(function(ownerlist) {
bot.chat('/w ' + ownerlist + ' ' + 'เหมือนว่าจะไม่ได้อยู่ในระยะนี้นะ...');
});
return
}
}
botowner.forEach(function(ownerlist) {
bot.chat('/w ' + ownerlist + ' ' + 'เรากำลังตามอยู่นะ นำทางเลย!');
});
break;
case 'fight':
if (args[2] == 'me') {
var fighter = bot.players[username]
if (!fighter) {
botowner.forEach(function(ownerlist) {
bot.chat('/w ' + ownerlist + ' ' + 'ไม่เจอนะ');
});
return
}
var sword = bot.inventory.items().find(item => item.name.includes('sword'))
if (sword) bot.equip(sword, 'hand')
bot.pvp.attack(fighter.entity)
} else {
var fighter = bot.players[args[2]]
if (!fighter) {
botowner.forEach(function(ownerlist) {
bot.chat('/w ' + ownerlist + ' ' + 'ไม่เจอนะ');
});
return
}
var sword = bot.inventory.items().find(item => item.name.includes('sword'))
if (sword) bot.equip(sword, 'hand')
bot.pvp.attack(fighter.entity)
};
botowner.forEach(function(ownerlist) {
bot.chat('/w ' + ownerlist + ' ' + 'ได้! เดียวจัดการให้!');
});
break;
case 'fight_stop':
bot.pvp.stop()
botowner.forEach(function(ownerlist) {
bot.chat('/w ' + ownerlist + ' ' + 'พอละๆ');
});
break;
case 'click_window':
var startClicking = function() {
waitingwindow = true;
checkwindow(args[3]);
botowner.forEach(function(ownerlist) {
bot.chat('/w ' + ownerlist + ' ' + 'กำลังรอ... หากพร้อมจะคลิกหมายเลข ' + args[3] + ' ทันที');
});
};
var stopClicking = function() {
waitingwindow = false;
botowner.forEach(function(ownerlist) {
bot.chat('/w ' + ownerlist + ' ' + 'ยกเลิกการคลิกแล้ว');
});
};
var toggleClicking = function() {
if (!fishing) startFishing();
else stopFishing();
};
if (args[2] == 'start') startClicking();
else if (args[2] == 'stop') stopClicking();
else toggleClicking();
break;
case 'follow_stop':
bot.pathfinder.setGoal(null)
break;
case 'food':
botowner.forEach(function(ownerlist) {
bot.chat('/w ' + ownerlist + ' ' + 'หลอดอาหาร: ' + bot.food + '/20');
});
break;
case 'health':
botowner.forEach(function(ownerlist) {
bot.chat('/w ' + ownerlist + ' ' + 'หลอดเลือด: ' + bot.health + '/20');
});
break;
case 'help':
botowner.forEach(function(ownerlist) {
bot.chat('/w ' + ownerlist + ' ' + 'คำสั่งทั้งหมด: [ sudo, disconnect, drop, dump, equip, experience, fish, snipe, food, health ]')
});
botowner.forEach(function(ownerlist) {
bot.chat('/w ' + ownerlist + ' ' + 'คำสั่งทั้งหมด (ต่อ): [ help, inventory, item_activate, item_deactivate, locate, look, ping ]')
});
botowner.forEach(function(ownerlist) {
bot.chat('/w ' + ownerlist + ' ' + 'คำสั่งทั้งหมด (ต่อ): [ route_to, route_stop ]')
});
break;
case 'inventory':
console.log(bot.username + ': ' + JSON.stringify(bot.inventory));
break;
case 'item_activate':
bot.activateItem();
break;
case 'item_deactivate':
bot.deactivateItem();
break;
case 'locate':
botowner.forEach(function(ownerlist) {
bot.chat('/w ' + ownerlist + ' ' + `ตอนนี้เราอยู่ที่: ${JSON.stringify(bot.entity.position)}`);
});
break;
case 'look':
var dir = {
yaw: parseFloat(args[2]),
pitch: parseFloat(args[3])
};
if (dir.yaw == null || dir.pitch == null || isNaN(dir.yaw) || isNaN(dir.pitch))
return botowner.forEach(function(ownerlist) {
bot.chat('/w ' + ownerlist + ' ' + 'ไม่รู้จักเลขนี้นะ');
});
bot.look(dir.yaw, dir.pitch, true, function() {
botowner.forEach(function(ownerlist) {
bot.chat('/w ' + ownerlist + ' ' + `ตอนนี้กำลังมองที่ ${JSON.stringify(dir)}`);
});
});
break;
case 'ping':
botowner.forEach(function(ownerlist) {
bot.chat('/w ' + ownerlist + ' ' + 'เรายังอยู่ดีจ้า!');
});
break;
case 'route_to':
if (args[2] == 'me' || args[2] == 'here') {
var target = bot.players[username].entity;
bot.pathfinder.setMovements(defaultMove)
bot.pathfinder.setGoal(new GoalNear(target.position.x, target.position.y, target.position.z, 1))
} else {
var dest = {
x: parseFloat(args[2]),
y: parseFloat(args[3]),
z: parseFloat(args[4])
};
if (dest.x == null || dest.y == null || dest.z == null || isNaN(dest.x) || isNaN(dest.y) || isNaN(dest.z))
return botowner.forEach(function(ownerlist) {
bot.chat('/w ' + ownerlist + ' ' + 'ที่นี่ที่ไหนหรอ?');
});
bot.pathfinder.setMovements(defaultMove)
bot.pathfinder.setGoal(new GoalBlock(dest.x, dest.y, dest.z))
}
break;
case 'route_stop':
bot.pathfinder.setGoal(null)
break;
default:
console.log(args)
botowner.forEach(function(ownerlist) {
bot.chat('/w ' + ownerlist + ' ' + 'ไม่รู้จักคำสั่งนี้');
});
}
}
}
bot.on('death', function() {
bot.emit("respawn")
bot.pvp.stop()
bot.pathfinder.setGoal(null)
});
bot.on('kicked', (reason, loggedIn) => console.log(reason, loggedIn))
bot.on('error', (err) => console.log(err))
}
function sleep(ms) {
return new Promise((resolve) => {
setTimeout(resolve, ms);
});
}