-
Notifications
You must be signed in to change notification settings - Fork 0
/
index.js
49 lines (46 loc) · 1.51 KB
/
index.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
const mineflayer = require("mineflayer")
const mc = require("minecraft-data")
const {WebSocketServer} = require("ws")
const express = require("express")
let web = express()
web.use(express.static("./public"))
let bot = mineflayer.createBot({
username:"ozo"
})
let ws = new WebSocketServer({
port:5555
})
ws.on("connection",e=>{
console.log("client connected")
e.on("message",c=>{
let state = JSON.parse(c.toString())
if(state.event == "mov"){
bot.controlState.forward = state.value == "forward"
bot.controlState.back = state.value == "back"
bot.controlState.left = state.value == "left"
bot.controlState.right = state.value == "right"
bot.controlState.jump = state.value == "jump"
bot.controlState.sneak = state.value == "sneak"
}
if(state.event == "msg"){
bot.chat(state.value)
}
if(state.event == "mouse"){
let {px,py} = state.value
bot.entity.pitch -= py/250
bot.entity.yaw -= px/400
}
if(state.event == "attack"){
let bac = bot.blockAtCursor()
if(bac)bot.dig(bac)
}
if(state.event == "use"){
// idk ¯\_(ツ)_/¯
// let refblock = bot.blockAtCursor()
// bot.placeBlock(refblock,refblock.position)
}
})
})
web.listen(8888,e=>{
console.log("server started at http://localhost:8888")
})