-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathcactus.js
189 lines (160 loc) · 8.81 KB
/
cactus.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
const mineflayer = require('mineflayer')
const vec3 = require('vec3')
const delay = require('util').promisify(setTimeout)
const bot = mineflayer.createBot({
host: "localhost",
port: 54823,
username: "CactusBuilder", //[email protected]
auth:"offline",
version: "1.18.2"
})
const cac = 9
const dirt = 20
const sand = 9
const fence = 6
bot.once('spawn', ()=>{
console.log('The bot is ready ....')
})
async function digLayer() {
await bot.dig(bot.blockAt(bot.entity.position.offset(2, -2, 0)), true);
await bot.dig(bot.blockAt(bot.entity.position.offset(2, -2, 2)), true);
await bot.dig(bot.blockAt(bot.entity.position.offset(0, -2, 2)), true);
await bot.dig(bot.blockAt(bot.entity.position.offset(-2, -2, 2)), true);
await bot.dig(bot.blockAt(bot.entity.position.offset(-2, -2, 0)), true);
await bot.dig(bot.blockAt(bot.entity.position.offset(-2, -2, -2)), true);
await bot.dig(bot.blockAt(bot.entity.position.offset(0, -2, -2)), true);
await bot.dig(bot.blockAt(bot.entity.position.offset(2, -2, -2)), true);
}
async function buildUp() {
await bot.equip(bot.inventory.items().find(item => item.name === 'dirt'), "hand")
const referenceBlock = bot.blockAt(bot.entity.position.offset(0, -1, 0))
const jumpY = Math.floor(bot.entity.position.y) + 1.0
bot.setControlState('jump', true)
bot.on('move', placeIfHighEnough)
let tryCount = 0
async function placeIfHighEnough() {
if (bot.entity.position.y > jumpY) {
try {
await bot.placeBlock(referenceBlock, vec3(0, 1, 0))
bot.setControlState('jump', false)
bot.removeListener('move', placeIfHighEnough)
//bot.chat('Placing a block was successful')
} catch (err) {
tryCount++
if (tryCount > 10) {
bot.chat(err.message)
bot.setControlState('jump', false)
bot.removeListener('move', placeIfHighEnough)
}
}
}
}
}
async function buildlayer() {
//Plaziert den Sand
await bot.equip(bot.inventory.items().find(item => item.name === 'sand'), "hand")
await bot.placeBlock(bot.blockAt(bot.entity.position.offset(2, -1, 0)), vec3(0, 1, 0))
await bot.placeBlock(bot.blockAt(bot.entity.position.offset(2, -1, 2)), vec3(0, 1, 0))
await bot.placeBlock(bot.blockAt(bot.entity.position.offset(0, -1, 2)), vec3(0, 1, 0))
await bot.placeBlock(bot.blockAt(bot.entity.position.offset(-2, -1, 2)), vec3(0, 1, 0))
await bot.placeBlock(bot.blockAt(bot.entity.position.offset(-2, -1, 0)), vec3(0, 1, 0))
await bot.placeBlock(bot.blockAt(bot.entity.position.offset(-2, -1, -2)), vec3(0, 1, 0))
await bot.placeBlock(bot.blockAt(bot.entity.position.offset(0, -1, -2)), vec3(0, 1, 0))
await bot.placeBlock(bot.blockAt(bot.entity.position.offset(2, -1, -2)), vec3(0, 1, 0))
//Plaziert den Kaktus
await bot.equip(bot.inventory.items().find(item => item.name === 'cactus'), "hand")
await bot.placeBlock(bot.blockAt(bot.entity.position.offset(2, 0, 0)), vec3(0, 1, 0))
await bot.placeBlock(bot.blockAt(bot.entity.position.offset(2, 0, 2)), vec3(0, 1, 0))
await bot.placeBlock(bot.blockAt(bot.entity.position.offset(0, 0, 2)), vec3(0, 1, 0))
await bot.placeBlock(bot.blockAt(bot.entity.position.offset(-2, 0, 2)), vec3(0, 1, 0))
await bot.placeBlock(bot.blockAt(bot.entity.position.offset(-2, 0, 0)), vec3(0, 1, 0))
await bot.placeBlock(bot.blockAt(bot.entity.position.offset(-2, 0, -2)), vec3(0, 1, 0))
await bot.placeBlock(bot.blockAt(bot.entity.position.offset(0, 0, -2)), vec3(0, 1, 0))
await bot.placeBlock(bot.blockAt(bot.entity.position.offset(2, 0, -2)), vec3(0, 1, 0))
}
async function buildFenceDirt() {
await bot.equip(bot.inventory.items().find(item => item.name === 'dirt'), "hand")
await bot.placeBlock(bot.blockAt(bot.entity.position.offset(2, -1, 2)), vec3(0, 1, 0))
await bot.equip(bot.inventory.items().find(item => item.name === 'iron_bars'), "hand")
await bot.placeBlock(bot.blockAt(bot.entity.position.offset(2, 0, 2)), vec3(0, 0, -1))
await bot.equip(bot.inventory.items().find(item => item.name === 'dirt'), "hand")
await bot.placeBlock(bot.blockAt(bot.entity.position.offset(0, -1, 2)), vec3(0, 1, 0))
await bot.equip(bot.inventory.items().find(item => item.name === 'iron_bars'), "hand")
await bot.placeBlock(bot.blockAt(bot.entity.position.offset(0, 0, 2)), vec3(0, 0, -1))
await bot.equip(bot.inventory.items().find(item => item.name === 'dirt'), "hand")
await bot.placeBlock(bot.blockAt(bot.entity.position.offset(-2, -1, 2)), vec3(0, 1, 0))
await bot.equip(bot.inventory.items().find(item => item.name === 'iron_bars'), "hand")
await bot.placeBlock(bot.blockAt(bot.entity.position.offset(-2, 0, 2)), vec3(0, 0, -1))
await bot.equip(bot.inventory.items().find(item => item.name === 'dirt'), "hand")
await bot.placeBlock(bot.blockAt(bot.entity.position.offset(-2, -1, -2)), vec3(0, 1, 0))
await bot.equip(bot.inventory.items().find(item => item.name === 'iron_bars'), "hand")
await bot.placeBlock(bot.blockAt(bot.entity.position.offset(-2, 0, -2)), vec3(0, 0, 1))
await bot.equip(bot.inventory.items().find(item => item.name === 'dirt'), "hand")
await bot.placeBlock(bot.blockAt(bot.entity.position.offset(0, -1, -2)), vec3(0, 1, 0))
await bot.equip(bot.inventory.items().find(item => item.name === 'iron_bars'), "hand")
await bot.placeBlock(bot.blockAt(bot.entity.position.offset(0, 0, -2)), vec3(0, 0, 1))
await bot.equip(bot.inventory.items().find(item => item.name === 'dirt'), "hand")
await bot.placeBlock(bot.blockAt(bot.entity.position.offset(2, -1, -2)), vec3(0, 1, 0))
await bot.equip(bot.inventory.items().find(item => item.name === 'iron_bars'), "hand")
await bot.placeBlock(bot.blockAt(bot.entity.position.offset(2, 0, -2)), vec3(0, 0, 1))
await bot.equip(bot.inventory.items().find(item => item.name === 'dirt'), "hand")
await bot.placeBlock(bot.blockAt(bot.entity.position.offset(2, -1, 0)), vec3(0, 1, 0))
await bot.placeBlock(bot.blockAt(bot.entity.position.offset(-2, -1, 0)), vec3(0, 1, 0))
}
async function placeDirtLayer() {
await bot.equip(bot.inventory.items().find(item => item.name === 'dirt'), "hand")
await bot.placeBlock(bot.blockAt(bot.entity.position.offset(2, -1, 0)), vec3(0, 1, 0))
await bot.placeBlock(bot.blockAt(bot.entity.position.offset(2, -1, 2)), vec3(0, 1, 0))
await bot.placeBlock(bot.blockAt(bot.entity.position.offset(0, -1, 2)), vec3(0, 1, 0))
await bot.placeBlock(bot.blockAt(bot.entity.position.offset(-2, -1, 2)), vec3(0, 1, 0))
await bot.placeBlock(bot.blockAt(bot.entity.position.offset(-2, -1, 0)), vec3(0, 1, 0))
await bot.placeBlock(bot.blockAt(bot.entity.position.offset(-2, -1, -2)), vec3(0, 1, 0))
await bot.placeBlock(bot.blockAt(bot.entity.position.offset(0, -1, -2)), vec3(0, 1, 0))
await bot.placeBlock(bot.blockAt(bot.entity.position.offset(2, -1, -2)), vec3(0, 1, 0))
//break
}
async function placeLastCactus(){
await bot.dig(bot.blockAt(bot.entity.position.offset(0, -2, 0)), true);
await bot.dig(bot.blockAt(bot.entity.position.offset(0, -3, 0)), true);
await bot.dig(bot.blockAt(bot.entity.position.offset(0, -4, 0)), true);
await delay(2000)
await bot.equip(bot.inventory.items().find(item => item.name === 'sand'), "hand")
await bot.placeBlock(bot.blockAt(bot.entity.position.offset(0, -5, 0)), vec3(0, 1, 0))
await bot.equip(bot.inventory.items().find(item => item.name === 'cactus'), "hand")
await delay(2000)
await bot.placeBlock(bot.blockAt(bot.entity.position.offset(0, -4, 0)), vec3(0, 1, 0))
}
async function cactus(x){
for(let layer =0; layer < x; layer++){
await buildlayer()
await delay(1000)
await buildUp()
await delay(1000)
await buildUp()
await delay(1000)
await buildFenceDirt()
await delay(1000)
await buildUp()
await delay(1000)
await placeDirtLayer()
await delay(1000)
await buildUp()
await delay(1000)
await digLayer()
await delay(1000)
await placeLastCactus()
delay(1000)
}
}
bot.on('chat', (username, message)=>{
if (username === bot.username)return
if (message.startsWith("cactus")){
const msg = message.split(" ")
cactus(msg[1])
}else if(message.startsWith("calculate")){
const calcu = message.split(" ")
bot.chat(`Du brauchst ${cac * calcu[1]} Kaktus, ${dirt * calcu[1]} Erde, ${sand * calcu[1]} Sand und ${fence * calcu[1]} Zäune!}` )
}
})
bot.on('kicked', console.log)
bot.on('error', console.log)