MCPcopy
hub / github.com/PrismarineJS/mineflayer / watchFurnace

Function watchFurnace

examples/chest.js:166–250  ·  view source on GitHub ↗
()

Source from the content-addressed store, hash-verified

164}
165
166async function watchFurnace () {
167 const furnaceBlock = bot.findBlock({
168 matching: ['furnace', 'lit_furnace'].filter(name => bot.registry.blocksByName[name] !== undefined).map(name => bot.registry.blocksByName[name].id),
169 maxDistance: 6
170 })
171 if (!furnaceBlock) {
172 bot.chat('no furnace found')
173 return
174 }
175 const furnace = await bot.openFurnace(furnaceBlock)
176 let output = ''
177 output += `input: ${itemToString(furnace.inputItem())}, `
178 output += `fuel: ${itemToString(furnace.fuelItem())}, `
179 output += `output: ${itemToString(furnace.outputItem())}`
180 bot.chat(output)
181
182 furnace.on('updateSlot', (slot, oldItem, newItem) => {
183 bot.chat(`furnace update: ${itemToString(oldItem)} -> ${itemToString(newItem)} (slot: ${slot})`)
184 })
185 furnace.on('close', () => {
186 bot.chat('furnace closed')
187 })
188 furnace.on('update', () => {
189 console.log(`fuel: ${Math.round(furnace.fuel * 100)}% progress: ${Math.round(furnace.progress * 100)}%`)
190 })
191
192 bot.on('chat', onChat)
193
194 function onChat (username, message) {
195 if (username === bot.username) return
196 const command = message.split(' ')
197 switch (true) {
198 case /^close$/.test(message):
199 closeFurnace()
200 break
201 case /^(input|fuel) \d+ \w+$/.test(message):
202 // input amount name
203 // ex: input 32 coal
204 putInFurnace(command[0], command[2], command[1])
205 break
206 case /^take (input|fuel|output)$/.test(message):
207 // take what
208 // ex: take output
209 takeFromFurnace(command[0])
210 break
211 }
212
213 function closeFurnace () {
214 furnace.close()
215 bot.removeListener('chat', onChat)
216 }
217
218 async function putInFurnace (where, name, amount) {
219 const item = itemByName(furnace.items(), name)
220 if (item) {
221 const fn = {
222 input: furnace.putInput,
223 fuel: furnace.putFuel

Callers 1

chest.jsFile · 0.85

Calls 1

itemToStringFunction · 0.70

Tested by

no test coverage detected

Used in the wild real call sites across dependent graphs

searching dependent graphs…