Compare commits
	
		
			16 Commits
		
	
	
		
			nogameplay
			...
			8e719d5ccf
		
	
	| Author | SHA1 | Date | |
|---|---|---|---|
| 
						 | 
					8e719d5ccf | ||
| 
						 | 
					112eb04a8d | ||
| 
						 | 
					ba7c53be0c | ||
| 
						 | 
					5b4718fa5d | ||
| 
						 | 
					902732c6dd | ||
| 
						 | 
					65d13a3379 | ||
| 
						 | 
					288b7045b6 | ||
| 
						 | 
					94574a4296 | ||
| 
						 | 
					68e60921b1 | ||
| 
						 | 
					f2281a7cb3 | ||
| 
						 | 
					e9f2080556 | ||
| 
						 | 
					086251bce6 | ||
| 
						 | 
					0ae961521f | ||
| 
						 | 
					eae4e95803 | ||
| 
						 | 
					fb066ee8a5 | ||
| 
						 | 
					f4445749e6 | 
							
								
								
									
										22
									
								
								lib/index.js
									
									
									
									
									
								
							
							
						
						
									
										22
									
								
								lib/index.js
									
									
									
									
									
								
							@@ -9,19 +9,22 @@ let cfg = {
 | 
				
			|||||||
const mineflayer = require("mineflayer");
 | 
					const mineflayer = require("mineflayer");
 | 
				
			||||||
// const { createGetAccessor } = require('typescript');
 | 
					// const { createGetAccessor } = require('typescript');
 | 
				
			||||||
 | 
					
 | 
				
			||||||
const bot =
 | 
					const options = !isNaN(parseInt(process.argv[3])) && parseInt(process.argv[3]) > 1e2 ?
 | 
				
			||||||
    !isNaN(parseInt(process.argv[3])) && parseInt(process.argv[3]) > 1e2 ?
 | 
					    {
 | 
				
			||||||
        mineflayer.createBot({
 | 
					 | 
				
			||||||
        host: process.argv[2] || process.env.MINECRAFT_HOST || env.MINECRAFT_HOST || 'localhost',  // Change this to the ip you want.
 | 
					        host: process.argv[2] || process.env.MINECRAFT_HOST || env.MINECRAFT_HOST || 'localhost',  // Change this to the ip you want.
 | 
				
			||||||
        port: parseInt(process.argv[3]) || process.env.MINECRAFT_PORT || env.MINECRAFT_PORT // || 58471,
 | 
					        port: parseInt(process.argv[3]) || process.env.MINECRAFT_PORT || env.MINECRAFT_PORT // || 58471,
 | 
				
			||||||
        })
 | 
					    }
 | 
				
			||||||
    :
 | 
					    :
 | 
				
			||||||
        mineflayer.createBot({
 | 
					    {
 | 
				
			||||||
        host: process.argv[2] || process.env.MINECRAFT_HOST || env.MINECRAFT_HOST || 'localhost',  // Change this to the ip you want.
 | 
					        host: process.argv[2] || process.env.MINECRAFT_HOST || env.MINECRAFT_HOST || 'localhost',  // Change this to the ip you want.
 | 
				
			||||||
        username: process.argv[3] || process.env.MINECRAFT_USER || env.MINECRAFT_USER,
 | 
					        username: process.argv[3] || process.env.MINECRAFT_USER || env.MINECRAFT_USER,
 | 
				
			||||||
        password: process.argv[4] || process.env.MINECRAFT_PASS || env.MINECRAFT_PASS,
 | 
					        password: process.argv[4] || process.env.MINECRAFT_PASS || env.MINECRAFT_PASS,
 | 
				
			||||||
        // port: process.argv[5] || process.env.MINECRAFT_PORT || 58471,
 | 
					        // port: process.argv[5] || process.env.MINECRAFT_PORT || 58471,
 | 
				
			||||||
        })
 | 
					    }
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					const bot = mineflayer.createBot(options)
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					cfg.botOptions = options
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					
 | 
				
			||||||
let plugins = {}
 | 
					let plugins = {}
 | 
				
			||||||
@@ -92,13 +95,14 @@ cfg.quiet = true
 | 
				
			|||||||
bot.once("spawn", () => {
 | 
					bot.once("spawn", () => {
 | 
				
			||||||
    plugins = {
 | 
					    plugins = {
 | 
				
			||||||
        command: require('./plugins/command'),
 | 
					        command: require('./plugins/command'),
 | 
				
			||||||
 | 
					        eater: require('./plugins/eater'),
 | 
				
			||||||
 | 
					        inventory: require('./plugins/inventory'),
 | 
				
			||||||
 | 
					        informer: require('./plugins/informer'),
 | 
				
			||||||
 | 
					        finder: require('./plugins/finder'),
 | 
				
			||||||
        sleeper: require('./plugins/sleeper'),
 | 
					        sleeper: require('./plugins/sleeper'),
 | 
				
			||||||
        armor: require('./plugins/armor'),
 | 
					        armor: require('./plugins/armor'),
 | 
				
			||||||
        mover: require('./plugins/mover'),
 | 
					        mover: require('./plugins/mover'),
 | 
				
			||||||
        guard: require('./plugins/guard'),
 | 
					        guard: require('./plugins/guard'),
 | 
				
			||||||
        inventory: require('./plugins/inventory'),
 | 
					 | 
				
			||||||
        eater: require('./plugins/eater'),
 | 
					 | 
				
			||||||
        finder: require('./plugins/finder'),
 | 
					 | 
				
			||||||
        // miner: require('./plugins/miner.js'),
 | 
					        // miner: require('./plugins/miner.js'),
 | 
				
			||||||
        // statemachine: require('./plugins/statemachine'),
 | 
					        // statemachine: require('./plugins/statemachine'),
 | 
				
			||||||
    }
 | 
					    }
 | 
				
			||||||
 
 | 
				
			|||||||
@@ -1,5 +1,5 @@
 | 
				
			|||||||
const v = require('vec3')
 | 
					const v = require('vec3')
 | 
				
			||||||
let mcData = require('minecraft-data')
 | 
					let mcData
 | 
				
			||||||
 | 
					
 | 
				
			||||||
let cfg = {}
 | 
					let cfg = {}
 | 
				
			||||||
let bot = {}
 | 
					let bot = {}
 | 
				
			||||||
@@ -46,7 +46,17 @@ const events = {
 | 
				
			|||||||
        }
 | 
					        }
 | 
				
			||||||
    }
 | 
					    }
 | 
				
			||||||
    , chat: command
 | 
					    , chat: command
 | 
				
			||||||
    , kicked: (reason, loggedIn) => console.warn(reason, loggedIn)
 | 
					    , kicked: function rejoin(reason, loggedIn) {
 | 
				
			||||||
 | 
					        console.warn(reason, loggedIn && "logged_in")
 | 
				
			||||||
 | 
					        if (reason.extra && reason.extra[0].text === "Server closed") {
 | 
				
			||||||
 | 
					            bot.quit()
 | 
				
			||||||
 | 
					            bot.end()
 | 
				
			||||||
 | 
					            // TODO implement all startup features (maybe refactor all into a single function / module?)
 | 
				
			||||||
 | 
					            setTimeout((bot, cfg) => {
 | 
				
			||||||
 | 
					                bot = mineflayer.createBot(cfg.botOptions)
 | 
				
			||||||
 | 
					            }, 15 * 60 * 1000, bot, cfg);
 | 
				
			||||||
 | 
					        }
 | 
				
			||||||
 | 
					    }
 | 
				
			||||||
}
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
const events_registered = []
 | 
					const events_registered = []
 | 
				
			||||||
@@ -183,7 +193,7 @@ function command(username, message) {
 | 
				
			|||||||
                    break;
 | 
					                    break;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
                case "follow":
 | 
					                case "follow":
 | 
				
			||||||
                    subcommand("go follow me")
 | 
					                    subcommand("go follow " + message_parts.slice(2).join(" "))
 | 
				
			||||||
                    break;
 | 
					                    break;
 | 
				
			||||||
                case "come":
 | 
					                case "come":
 | 
				
			||||||
                    subcommand("go follow once")
 | 
					                    subcommand("go follow once")
 | 
				
			||||||
@@ -416,29 +426,52 @@ function command(username, message) {
 | 
				
			|||||||
                // case "take":
 | 
					                // case "take":
 | 
				
			||||||
                //     // TODO take only what's requested, then throw all the rest
 | 
					                //     // TODO take only what's requested, then throw all the rest
 | 
				
			||||||
                //     // TODO take all
 | 
					                //     // TODO take all
 | 
				
			||||||
                // case "toss":
 | 
					
 | 
				
			||||||
                // case "drop":
 | 
					                // TODO move subcommands to cfg.plugins.inventory.itemByName
 | 
				
			||||||
                //     if (!message_parts[1]) { return false } // FIXME, works but ugly
 | 
					                case "toss":
 | 
				
			||||||
                //     if (!checkItemExists(message_parts[1])) { return false }
 | 
					                case "drop":
 | 
				
			||||||
                //     switch (message_parts.length) {
 | 
					                    if (!message_parts[1]) { return false } // FIXME, works but ugly
 | 
				
			||||||
                //         case 2:
 | 
					                    if (!mcData.findItemOrBlockByName(message_parts[1])) {
 | 
				
			||||||
                //             bot.toss(mcData.blocksByName[message_parts[1]].id)
 | 
					                        console.log("doesn't exist:", message_parts[1])
 | 
				
			||||||
                //             break
 | 
					                        cfg.quiet || bot.chat(`item doesn't exist: ${message_parts[1]}`)
 | 
				
			||||||
                //         case 3:
 | 
					                        return false
 | 
				
			||||||
                //             bot.tossStack(
 | 
					                    }
 | 
				
			||||||
                //                 mcData.itemsByName[message_parts[1]].id,
 | 
					                    const item = cfg.plugins.inventory.itemByName(message_parts[1])
 | 
				
			||||||
                //                 (err) => {
 | 
					                    if (!item) {
 | 
				
			||||||
                //                     if (err) {
 | 
					                        console.log("don't have:", message_parts[1])
 | 
				
			||||||
                //                         console.log(err)
 | 
					                        cfg.quiet || bot.chat(`don't have item: ${message_parts[1]}`)
 | 
				
			||||||
                //                         bot.chat(err)
 | 
					                        return false
 | 
				
			||||||
                //                     }
 | 
					                    }
 | 
				
			||||||
                //                 }
 | 
					                    switch (message_parts.length) {
 | 
				
			||||||
                //             )
 | 
					                        case 2:
 | 
				
			||||||
                //             break
 | 
					                            bot.tossStack(
 | 
				
			||||||
                //         default:
 | 
					                                item,
 | 
				
			||||||
                //             break
 | 
					                                (err) => {
 | 
				
			||||||
                //     }
 | 
					                                    if (err) {
 | 
				
			||||||
                //     break;
 | 
					                                        console.error(err)
 | 
				
			||||||
 | 
					                                        cfg.quiet || bot.chat(err.message)
 | 
				
			||||||
 | 
					                                    }
 | 
				
			||||||
 | 
					                                }
 | 
				
			||||||
 | 
					                            )
 | 
				
			||||||
 | 
					                            break
 | 
				
			||||||
 | 
					                        case 3:
 | 
				
			||||||
 | 
					                            const amount = parseInt(message_parts[2])
 | 
				
			||||||
 | 
					                            bot.toss(
 | 
				
			||||||
 | 
					                                item.type,
 | 
				
			||||||
 | 
					                                null, //metadata
 | 
				
			||||||
 | 
					                                amount,
 | 
				
			||||||
 | 
					                                (err) => {
 | 
				
			||||||
 | 
					                                    if (err) {
 | 
				
			||||||
 | 
					                                        console.error(err)
 | 
				
			||||||
 | 
					                                        cfg.quiet || bot.chat(err.message)
 | 
				
			||||||
 | 
					                                    }
 | 
				
			||||||
 | 
					                                }
 | 
				
			||||||
 | 
					                            )
 | 
				
			||||||
 | 
					                            break
 | 
				
			||||||
 | 
					                        default:
 | 
				
			||||||
 | 
					                            break
 | 
				
			||||||
 | 
					                    }
 | 
				
			||||||
 | 
					                    break;
 | 
				
			||||||
                case "location":
 | 
					                case "location":
 | 
				
			||||||
                    // TODO put in /lib/location
 | 
					                    // TODO put in /lib/location
 | 
				
			||||||
                    switch (message_parts[1]) {
 | 
					                    switch (message_parts[1]) {
 | 
				
			||||||
@@ -537,13 +570,12 @@ const load = (config) => {
 | 
				
			|||||||
    cfg = config
 | 
					    cfg = config
 | 
				
			||||||
    bot = cfg.bot
 | 
					    bot = cfg.bot
 | 
				
			||||||
 | 
					
 | 
				
			||||||
    mcData = mcData(bot.version)
 | 
					    mcData = bot.mcData || (bot.mcData = require('minecraft-data')(bot.version))
 | 
				
			||||||
    for (const [key, fn] of Object.entries(events)) {
 | 
					    for (const [key, fn] of Object.entries(events)) {
 | 
				
			||||||
        events_registered.push(
 | 
					        events_registered.push(
 | 
				
			||||||
            bot.on(key, fn)
 | 
					            bot.on(key, fn)
 | 
				
			||||||
        )
 | 
					        )
 | 
				
			||||||
    }
 | 
					    }
 | 
				
			||||||
    mcData = require('minecraft-data')(bot.version)
 | 
					 | 
				
			||||||
}
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
const unload = () => {
 | 
					const unload = () => {
 | 
				
			||||||
 
 | 
				
			|||||||
							
								
								
									
										22
									
								
								lib/plugins/informer.js
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										22
									
								
								lib/plugins/informer.js
									
									
									
									
									
										Normal file
									
								
							@@ -0,0 +1,22 @@
 | 
				
			|||||||
 | 
					let cfg
 | 
				
			||||||
 | 
					let bot
 | 
				
			||||||
 | 
					let mcData
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					function info() {
 | 
				
			||||||
 | 
					    const block = bot.blockAtCursor()
 | 
				
			||||||
 | 
					    console.log(block)
 | 
				
			||||||
 | 
					    cfg.quiet || bot.chat([block.id, block.name])
 | 
				
			||||||
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					const load = (config) => {
 | 
				
			||||||
 | 
					    cfg = config
 | 
				
			||||||
 | 
					    bot = cfg.bot
 | 
				
			||||||
 | 
					    cfg.info = {
 | 
				
			||||||
 | 
					        quiet: cfg.quiet,
 | 
				
			||||||
 | 
					    }
 | 
				
			||||||
 | 
					    mcData = bot.mcData || (bot.mcData = require('minecraft-data')(bot.version))
 | 
				
			||||||
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					const unload = () => {}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					module.exports = { load, unload, info }
 | 
				
			||||||
@@ -225,4 +225,4 @@ const unload = () => {
 | 
				
			|||||||
    bot.off('chat', inventory)
 | 
					    bot.off('chat', inventory)
 | 
				
			||||||
}
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
module.exports = { load, unload, equipItem, craftItem }
 | 
					module.exports = { load, unload, equipItem, craftItem, itemByName }
 | 
				
			||||||
@@ -1,27 +1,28 @@
 | 
				
			|||||||
// import { EntityFilters } from "mineflayer-statemachine"
 | 
					 | 
				
			||||||
// import v from "vec3"
 | 
					 | 
				
			||||||
 | 
					
 | 
				
			||||||
// import { Movements } from "mineflayer-pathfinder"
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
// const mineflayer = require('mineflayer')
 | 
					 | 
				
			||||||
const { Movements } = require('mineflayer-pathfinder')
 | 
					const { Movements } = require('mineflayer-pathfinder')
 | 
				
			||||||
// const { GoalBLah } = require('mineflayer-pathfinder').goals
 | 
					 | 
				
			||||||
const v = require('vec3')
 | 
					const v = require('vec3')
 | 
				
			||||||
 | 
					
 | 
				
			||||||
let cfg = {}
 | 
					let cfg = {}
 | 
				
			||||||
let bot = {}
 | 
					let bot = {}
 | 
				
			||||||
// let moving
 | 
					// let moving
 | 
				
			||||||
let pathfinder
 | 
					let pathfinder
 | 
				
			||||||
 | 
					let mcData
 | 
				
			||||||
let movements = []
 | 
					let movements = []
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					
 | 
				
			||||||
function initMoves(bot = bot, mcData = require('minecraft-data')(bot.version)) {
 | 
					function initMoves(bot = bot, mcData = bot.mcData) {
 | 
				
			||||||
 | 
					    console.info(movements)
 | 
				
			||||||
 | 
					    if (movements.length > 0) {
 | 
				
			||||||
 | 
					        bot.pathfinder.setMovements(movements.defaultMove)
 | 
				
			||||||
 | 
					        return console.warn("movements already initialized!")
 | 
				
			||||||
 | 
					    }
 | 
				
			||||||
    let defaultMove = new Movements(bot, mcData)
 | 
					    let defaultMove = new Movements(bot, mcData)
 | 
				
			||||||
    defaultMove.canDig = false
 | 
					    defaultMove.canDig = false
 | 
				
			||||||
    defaultMove.scafoldingBlocks.push(mcData.blocksByName.slime_block.id)
 | 
					    defaultMove.scafoldingBlocks.push(mcData.blocksByName.slime_block.id)
 | 
				
			||||||
    // defaultMove.blocksCantBreak.add(mcData.blocksByName.glass.id)
 | 
					    defaultMove.blocksCantBreak.add(mcData.blocksByName.glass.id)
 | 
				
			||||||
    // defaultMove.blocksToAvoid.add(mcData.blocksByName.magma.id)
 | 
					    defaultMove.blocksToAvoid.add(mcData.blocksByName.magma_block.id)
 | 
				
			||||||
    movements.defaultMove = defaultMove
 | 
					    movements.push(defaultMove)
 | 
				
			||||||
 | 
					    movements.defaultMove = movements[0]
 | 
				
			||||||
 | 
					
 | 
				
			||||||
    bot.pathfinder.setMovements(defaultMove)
 | 
					    bot.pathfinder.setMovements(defaultMove)
 | 
				
			||||||
}
 | 
					}
 | 
				
			||||||
@@ -40,8 +41,6 @@ function follow(entity, dynamic = true) {
 | 
				
			|||||||
    console.assert(entity)
 | 
					    console.assert(entity)
 | 
				
			||||||
    const { GoalFollow } = require('mineflayer-pathfinder').goals
 | 
					    const { GoalFollow } = require('mineflayer-pathfinder').goals
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
    cfg.quiet && console.log(entity)
 | 
					    cfg.quiet && console.log(entity)
 | 
				
			||||||
        || bot.chat(
 | 
					        || bot.chat(
 | 
				
			||||||
            `following ${entity.type
 | 
					            `following ${entity.type
 | 
				
			||||||
@@ -77,19 +76,16 @@ const load = (config) => {
 | 
				
			|||||||
        movements: []
 | 
					        movements: []
 | 
				
			||||||
    }
 | 
					    }
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					    mcData = bot.mcData || (bot.mcData = require('minecraft-data')(bot.version))
 | 
				
			||||||
    pathfinder = bot.pathfinder || bot.loadPlugin(require('mineflayer-pathfinder').pathfinder)
 | 
					    pathfinder = bot.pathfinder || bot.loadPlugin(require('mineflayer-pathfinder').pathfinder)
 | 
				
			||||||
 | 
					
 | 
				
			||||||
    // initMoves(bot, mcData)
 | 
					    // initMoves(bot, mcData)
 | 
				
			||||||
    setTimeout(initMoves, 500, bot)
 | 
					    setTimeout(initMoves, 500, bot, mcData)
 | 
				
			||||||
 | 
					 | 
				
			||||||
    // bot.loadPlugin(pathfinder)
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
    // bot.on('time', hello)
 | 
					 | 
				
			||||||
 | 
					
 | 
				
			||||||
}
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
const unload = () => {
 | 
					const unload = () => {
 | 
				
			||||||
    // TODO stop pathfinding maybe?
 | 
					    stop()
 | 
				
			||||||
}
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
module.exports = { load, unload, stop, initMoves, moveNear, follow }
 | 
					module.exports = { load, unload, stop, initMoves, moveNear, follow }
 | 
				
			||||||
@@ -7,27 +7,32 @@ let bot = {}
 | 
				
			|||||||
let inv
 | 
					let inv
 | 
				
			||||||
// cfg.autosleep = false
 | 
					// cfg.autosleep = false
 | 
				
			||||||
 | 
					
 | 
				
			||||||
function sleep(quiet) {
 | 
					function sleep(quiet = cfg.sleep.quiet) {
 | 
				
			||||||
    quiet = quiet !== undefined ? quiet : cfg.sleep.quiet
 | 
					 | 
				
			||||||
    if(bot.game.dimension !== "minecraft:overworld" || cfg.sleep.force){
 | 
					    if(bot.game.dimension !== "minecraft:overworld" || cfg.sleep.force){
 | 
				
			||||||
        !quiet && bot.chat("can't sleep, not in overworld now")
 | 
					        !quiet && bot.chat("can't sleep, not in overworld now")
 | 
				
			||||||
        return
 | 
					        return
 | 
				
			||||||
    }
 | 
					    }
 | 
				
			||||||
 | 
					    if (bot.isSleeping && !cfg.sleep.force) {
 | 
				
			||||||
 | 
					        !quiet && bot.chat("already in bed!")
 | 
				
			||||||
 | 
					        return
 | 
				
			||||||
 | 
					    }
 | 
				
			||||||
    let bed = bot.findBlock({
 | 
					    let bed = bot.findBlock({
 | 
				
			||||||
        matching: block => bot.isABed(block)
 | 
					        matching: block => bot.isABed(block)
 | 
				
			||||||
    })
 | 
					    })
 | 
				
			||||||
    let bedstatus = bed && bot.parseBedMetadata(bed).occupied ? "n unoccupied" : ""
 | 
					    let bed_occupied = bed && bot.parseBedMetadata(bed).occupied
 | 
				
			||||||
    if(bed && bedstatus == "n unoccupied"){
 | 
					    if (bed && bed_occupied) {
 | 
				
			||||||
        bot.lookAt(bed.position)
 | 
					        bot.lookAt(bed.position)
 | 
				
			||||||
        bed = bot.findBlock({
 | 
					        bed = bot.findBlock({
 | 
				
			||||||
            matching: block => bot.isABed(block) && !bot.parseBedMetadata(block).occupied
 | 
					            matching: block => bot.isABed(block) && !bot.parseBedMetadata(block).occupied
 | 
				
			||||||
        }) || bed
 | 
					        }) || bed
 | 
				
			||||||
        bedstatus = bot.parseBedMetadata(bed).occupied ? "n unoccupied" : ""
 | 
					        bed_occupied = bot.parseBedMetadata(bed).occupied
 | 
				
			||||||
    }
 | 
					    }
 | 
				
			||||||
    if (bed && bedstatus == "") {
 | 
					    if (bed && !bed_occupied) {
 | 
				
			||||||
        bot.lookAt(bed.position)
 | 
					        bot.lookAt(bed.position)
 | 
				
			||||||
        bot.waitForChunksToLoad(() => {
 | 
					        bot.waitForChunksToLoad(() => {
 | 
				
			||||||
            cfg.plugins.moveNear(bed.position)
 | 
					            cfg.plugins.mover && cfg.plugins.mover.moveNear(bed.position, 2)
 | 
				
			||||||
 | 
					            bot.once('goal_reached', (goal) => {
 | 
				
			||||||
 | 
					                console.info(goal)
 | 
				
			||||||
                bot.sleep(bed, (err) => {
 | 
					                bot.sleep(bed, (err) => {
 | 
				
			||||||
                    if (err) {
 | 
					                    if (err) {
 | 
				
			||||||
                        !quiet && bot.chat(`can't sleep: ${err.message}`)
 | 
					                        !quiet && bot.chat(`can't sleep: ${err.message}`)
 | 
				
			||||||
@@ -35,21 +40,42 @@ function sleep(quiet) {
 | 
				
			|||||||
                        !quiet && bot.chat("zzz")
 | 
					                        !quiet && bot.chat("zzz")
 | 
				
			||||||
                        console.log("sleeping? ", bot.isSleeping)
 | 
					                        console.log("sleeping? ", bot.isSleeping)
 | 
				
			||||||
                        // hack until this is fixed
 | 
					                        // hack until this is fixed
 | 
				
			||||||
                    // bot.isSleeping = bot.isSleeping ? bot.isSleeping : true
 | 
					                        // TODO confirm this is fixed
 | 
				
			||||||
                    bot.isSleeping = true
 | 
					                        // bot.isSleeping = true
 | 
				
			||||||
                    }
 | 
					                    }
 | 
				
			||||||
                })
 | 
					                })
 | 
				
			||||||
            })
 | 
					            })
 | 
				
			||||||
    } else if (inv && inv.equipItem("red_bed", "hand", true)) {
 | 
					        })
 | 
				
			||||||
        // doesn't work fortunately
 | 
					    } else if (bed = bot.inventory.items().filter(bot.isABed)[0]) {
 | 
				
			||||||
        // FIXME: DONT IMPLEMENT until it is detected as NOT NETHER
 | 
					        const v = require('vec3')
 | 
				
			||||||
        // bot.placeBlock()
 | 
					        bot.equip(bed, "hand", (err) => { if (err) console.error(err) })
 | 
				
			||||||
 | 
					        bot.waitForChunksToLoad(() => {
 | 
				
			||||||
 | 
					            let refBlock =
 | 
				
			||||||
 | 
					                // FIXME hack to get around findBlock returning null
 | 
				
			||||||
 | 
					                bot.blockAt(bot.entity.position.offset(1, 0, 1), false)
 | 
				
			||||||
 | 
					            // bot.findBlock({
 | 
				
			||||||
 | 
					            //     matching: (block) => {
 | 
				
			||||||
 | 
					            //         // if (block && block.type !== 0 && block.position) {
 | 
				
			||||||
 | 
					            //         if (block && block.position) {
 | 
				
			||||||
 | 
					            //             console.info("found", block)
 | 
				
			||||||
 | 
					            //             const blockAbove = bot.blockAt(block.position.offset(0, 1, 0))
 | 
				
			||||||
 | 
					            //             return !blockAbove || blockAbove.type === 0
 | 
				
			||||||
 | 
					            //         }
 | 
				
			||||||
 | 
					            //         // console.info("not found", block)
 | 
				
			||||||
 | 
					            //         return false
 | 
				
			||||||
 | 
					            //     }
 | 
				
			||||||
 | 
					            //     , maxDistance: 10
 | 
				
			||||||
 | 
					            // })
 | 
				
			||||||
 | 
					            console.log(refBlock)
 | 
				
			||||||
 | 
					            bot.placeBlock(refBlock, new v.Vec3(0, 1, 0), console.error)
 | 
				
			||||||
 | 
					            setTimeout(sleep, 3000, true)
 | 
				
			||||||
 | 
					        })
 | 
				
			||||||
    } else {
 | 
					    } else {
 | 
				
			||||||
        // TODO: use mover
 | 
					        // TODO: use mover
 | 
				
			||||||
        // bot.gameplay.solveFor(
 | 
					        // bot.gameplay.solveFor(
 | 
				
			||||||
        //     new ObtainItem("bed"), (err) => {
 | 
					        //     new ObtainItem("bed"), (err) => {
 | 
				
			||||||
        //         if (err) {
 | 
					        //         if (err) {
 | 
				
			||||||
        //             !quiet && bot.chat(`need a${bedstatus} bed: may not see if just placed`)
 | 
					        !quiet && bot.chat(`need a${bed_occupied ? "n unoccupied" : ""} bed: may not see if just placed`)
 | 
				
			||||||
        //         }
 | 
					        //         }
 | 
				
			||||||
        //     }
 | 
					        //     }
 | 
				
			||||||
        // )
 | 
					        // )
 | 
				
			||||||
@@ -72,7 +98,7 @@ function autoSleep() {
 | 
				
			|||||||
    if (!bot.time.isDay && !cfg.sleep.timeoutFn && cfg.sleep.auto && !bot.isSleeping) {
 | 
					    if (!bot.time.isDay && !cfg.sleep.timeoutFn && cfg.sleep.auto && !bot.isSleeping) {
 | 
				
			||||||
        sleep()
 | 
					        sleep()
 | 
				
			||||||
        cfg.sleep.timeoutFn = setTimeout(() => { cfg.sleep.timeoutFn = null }, cfg.sleep.timeout)
 | 
					        cfg.sleep.timeoutFn = setTimeout(() => { cfg.sleep.timeoutFn = null }, cfg.sleep.timeout)
 | 
				
			||||||
        console.log("sleeping?", bot.isSleeping, bot.time)
 | 
					        console.log("sleeping?", bot.isSleeping, bot.time.isDay, bot.time.timeOfDay)
 | 
				
			||||||
    }
 | 
					    }
 | 
				
			||||||
}
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 
 | 
				
			|||||||
							
								
								
									
										22
									
								
								package.json
									
									
									
									
									
								
							
							
						
						
									
										22
									
								
								package.json
									
									
									
									
									
								
							@@ -34,20 +34,20 @@
 | 
				
			|||||||
    "require-self": "^0.2.3"
 | 
					    "require-self": "^0.2.3"
 | 
				
			||||||
  },
 | 
					  },
 | 
				
			||||||
  "dependencies": {
 | 
					  "dependencies": {
 | 
				
			||||||
 | 
					    "dotenv-packed": "^1.2.1",
 | 
				
			||||||
    "minecraft-data": "^2.70.2",
 | 
					    "minecraft-data": "^2.70.2",
 | 
				
			||||||
    "mineflayer": "^2.34.0",
 | 
					    "mineflayer": "^2.39.2",
 | 
				
			||||||
    "mineflayer-armor-manager": "^1.3",
 | 
					    "mineflayer-armor-manager": "^1.3.0",
 | 
				
			||||||
    "mineflayer-pathfinder": "^1.1",
 | 
					    "mineflayer-pathfinder": "^1.2.3",
 | 
				
			||||||
    "mineflayer-pvp": "^1",
 | 
					    "mineflayer-pvp": "^1.0.2",
 | 
				
			||||||
    "prismarine-block": "^1",
 | 
					    "prismarine-block": "^1.7.2",
 | 
				
			||||||
    "prismarine-chat": "^1",
 | 
					    "prismarine-chat": "^1.0.3",
 | 
				
			||||||
    "prismarine-entity": "^1.1.0",
 | 
					    "prismarine-entity": "^1.1.0",
 | 
				
			||||||
    "prismarine-item": "^1.5.0",
 | 
					    "prismarine-item": "^1.5.0",
 | 
				
			||||||
    "prismarine-nbt": "^1.3",
 | 
					    "prismarine-nbt": "^1.3.0",
 | 
				
			||||||
    "prismarine-recipe": "^1",
 | 
					    "prismarine-recipe": "^1.1.0",
 | 
				
			||||||
    "typescript": "^4",
 | 
					    "typescript": "^4.1.3",
 | 
				
			||||||
    "vec3": "^0.1",
 | 
					    "vec3": "^0.1.7"
 | 
				
			||||||
    "dotenv-packed": "^1.2"
 | 
					 | 
				
			||||||
  },
 | 
					  },
 | 
				
			||||||
  "files": [
 | 
					  "files": [
 | 
				
			||||||
    "lib/**/*"
 | 
					    "lib/**/*"
 | 
				
			||||||
 
 | 
				
			|||||||
		Reference in New Issue
	
	Block a user