Compare commits
9 Commits
974d460061
...
cover
Author | SHA1 | Date | |
---|---|---|---|
|
6a1ab4dd91 | ||
|
2f88eedce9 | ||
|
a0893f2b29 | ||
|
b1a592dbbd | ||
|
f336e3d736 | ||
|
d953bd4cf6 | ||
|
fc43985337 | ||
|
6b1157147d | ||
|
e6d29576e7 |
@@ -217,6 +217,17 @@ function command(username, message) {
|
||||
subcommand("go follow once")
|
||||
}
|
||||
break;
|
||||
case "ride":
|
||||
case "mount":
|
||||
cfg.plugins.mover.command(message_parts)
|
||||
break
|
||||
case "unride":
|
||||
case "getoff":
|
||||
case "unmount":
|
||||
case "dismount":
|
||||
bot.dismount()
|
||||
bot.vehicle = void 0
|
||||
break
|
||||
case "move":
|
||||
case "go":
|
||||
cfg.plugins.mover.command(message_parts.slice(1), player)
|
||||
@@ -318,18 +329,6 @@ function command(username, message) {
|
||||
case "info":
|
||||
cfg.plugins.informer.command(message_parts.splice(1))
|
||||
break
|
||||
case "ride":
|
||||
case "mount":
|
||||
bot.mount(bot.nearestEntity())
|
||||
break
|
||||
case "getoff":
|
||||
case "unmount":
|
||||
case "dismount":
|
||||
bot.dismount()
|
||||
break
|
||||
case "go":
|
||||
bot.moveVehicle(0, 10)
|
||||
break
|
||||
// case "use":
|
||||
// bot.useOn(bot.nearestEntity())
|
||||
// break;
|
||||
|
@@ -67,12 +67,12 @@ function follow(entity, dynamic = true, distance = 3) {
|
||||
console.assert(entity)
|
||||
const { GoalFollow } = require('mineflayer-pathfinder').goals
|
||||
|
||||
cfg.quiet && console.log(entity)
|
||||
|| bot.chat(
|
||||
`following ${entity.type
|
||||
}: ${entity.username || entity.displayName
|
||||
}${dynamic ? "" : " once"}`
|
||||
)
|
||||
// console.log(entity)
|
||||
cfg.quiet || bot.chat(
|
||||
`following ${entity.type
|
||||
}: ${entity.username || entity.displayName
|
||||
}${dynamic ? "" : " once"}`
|
||||
)
|
||||
|
||||
entity = entity.entity ? entity.entity : entity
|
||||
|
||||
@@ -82,6 +82,38 @@ function follow(entity, dynamic = true, distance = 3) {
|
||||
bot.pathfinder.setGoal(new GoalFollow(entity, distance), dynamic)
|
||||
}
|
||||
|
||||
function ride(entity) {
|
||||
entity = entity?.entity || entity
|
||||
const ridableMobs = ["Horse", "Donkey", "Pig", "Strider"]
|
||||
const vehicle = entity && typeof entity !== "string" ? entity : bot.nearestEntity(e => {
|
||||
if (typeof entity === "string") return e.name === entity
|
||||
const maybeRidableMob = e.mobType?.split(" ")
|
||||
return e.kind == "Vehicles"
|
||||
|| ridableMobs.includes(e.mobType)
|
||||
|| maybeRidableMob && ridableMobs.includes(maybeRidableMob[maybeRidableMob.length - 1])
|
||||
})
|
||||
if (!vehicle) {
|
||||
return cfg.quiet || bot.chat(`nothing to ride!`)
|
||||
} else if ((dist = bot.entity.position.distanceSquared(vehicle.position)) > 36) {
|
||||
bot.lookAt(vehicle.position)
|
||||
follow(vehicle, false)
|
||||
bot.once('goal_reached', ride)
|
||||
return cfg.quiet || bot.chat(`${vehicle.name} bit far`)
|
||||
}
|
||||
console.log("vehicle:", vehicle)
|
||||
bot.mount(vehicle)
|
||||
}
|
||||
|
||||
function moveOrRide(turn = false, reverse = -1, directionLabel, message_parts2) {
|
||||
// bot.once("attach", state = "vehiccel")
|
||||
if (bot.vehicle) {
|
||||
const amount = parseInt(message_parts2[0]) || 10 * -reverse
|
||||
bot.moveVehicle(turn && amount || 0, !turn && amount || 0)
|
||||
} else {
|
||||
command([directionLabel].concat(message_parts2))
|
||||
}
|
||||
}
|
||||
|
||||
function hit(blockOrEntity) {
|
||||
bot.chat(`hitting ${entity.name || entity.type}`)
|
||||
}
|
||||
@@ -194,21 +226,25 @@ function command(message_parts, player) {
|
||||
break
|
||||
}
|
||||
break
|
||||
case "ride":
|
||||
case "mount":
|
||||
ride(message_parts2[0])
|
||||
break
|
||||
case "w":
|
||||
case "f":
|
||||
command(["forward"].concat(message_parts.slice(1)))
|
||||
moveOrRide(0, -1, "forward", message_parts2)
|
||||
break
|
||||
case "s":
|
||||
case "b":
|
||||
command(["back"].concat(message_parts.slice(1)))
|
||||
moveOrRide(0, 1, "back", message_parts2)
|
||||
break
|
||||
case "a":
|
||||
case "l":
|
||||
command(["right"].concat(message_parts.slice(1)))
|
||||
moveOrRide(1, -1, "right", message_parts2)
|
||||
break
|
||||
case "d":
|
||||
case "r":
|
||||
command(["left"].concat(message_parts.slice(1)))
|
||||
moveOrRide(1, 1, "left", message_parts2)
|
||||
break
|
||||
case "back":
|
||||
case "forward":
|
||||
@@ -220,7 +256,7 @@ function command(message_parts, player) {
|
||||
console.info(bot.controlState[message_parts[0]], bot.entity.position.floored())
|
||||
bot.setControlState(message_parts[0], true)
|
||||
console.info(bot.controlState[message_parts[0]])
|
||||
setTimeout(bot.setControlState, 200 * (message_parts[1] || 1), message_parts[0], false)
|
||||
setTimeout(bot.setControlState, 100 * (message_parts[1] || 2), message_parts[0], false)
|
||||
setTimeout(console.info, 5000, bot.controlState[message_parts[0]], bot.entity.position.floored())
|
||||
break
|
||||
case "stop":
|
||||
@@ -256,4 +292,9 @@ const unload = () => {
|
||||
bot.off('goal_reached', goalReached)
|
||||
}
|
||||
|
||||
module.exports = { load, unload, command, stop, initMoves, moveNear, moveXZ, moveY, follow }
|
||||
module.exports = {
|
||||
load, unload, command,
|
||||
stop, initMoves,
|
||||
moveNear, moveXZ, moveY, follow,
|
||||
ride
|
||||
}
|
217
lib/plugins/mycellium.js
Normal file
217
lib/plugins/mycellium.js
Normal file
@@ -0,0 +1,217 @@
|
||||
|
||||
// const mineflayer = require('mineflayer')
|
||||
// let pathfinder
|
||||
// const { pathfinder, Movements, goals } = require('mineflayer-pathfinder')
|
||||
const { Vec3 } = require('vec3')
|
||||
// const { GoalFollow, GoalNear } = goals
|
||||
let GoalFollow, GoalNear
|
||||
// const mcData = require('minecraft-data')('1.16.5')
|
||||
let mcData
|
||||
|
||||
// let bot = mineflayer.createBot()
|
||||
let bot
|
||||
let cfg = { bot: null }
|
||||
let timer
|
||||
let movements
|
||||
|
||||
/* let mcData
|
||||
bot.once('spawn', () => {
|
||||
mcData = require('minecraft-data')(bot.version)
|
||||
}) */
|
||||
|
||||
function stopCovering(quiet = cfg.quiet, resetGoal = true) { // This is a function to stop the cover() loop when called
|
||||
if (timer) {
|
||||
clearTimeout(timer);
|
||||
timer = null;
|
||||
}
|
||||
if (resetGoal) bot.pathfinder.setGoal(null)
|
||||
bot.stopDigging()
|
||||
quiet || bot.chat("stopped covering")
|
||||
}
|
||||
|
||||
function init() {
|
||||
const { Movements, goals } = require('mineflayer-pathfinder')
|
||||
GoalFollow = goals.GoalFollow
|
||||
GoalNear = goals.GoalNear
|
||||
movements = new Movements(bot, mcData)
|
||||
movements.canDig = true // Lets the bot dig
|
||||
bot.pathfinder.setMovements(movements)
|
||||
|
||||
console.info("mycelium start")
|
||||
stopCovering(true)
|
||||
bot.waitForChunksToLoad(cover)
|
||||
}
|
||||
|
||||
function cover(timeInt = 1000) {
|
||||
if (!Number.isSafeInteger(timeInt)) {
|
||||
console.log("cover int maybe goal?", timeInt)
|
||||
switch (timeInt.message) {
|
||||
case "No path to the goal!":
|
||||
console.info("Cover: can't reach")
|
||||
cfg.quiet || bot.chat("can't reach")
|
||||
break;
|
||||
|
||||
default:
|
||||
break;
|
||||
}
|
||||
if (timeInt) {
|
||||
timeInt = 5000
|
||||
}
|
||||
} else if (timeInt < 300) {
|
||||
timeInt = 1000
|
||||
}
|
||||
const wool = "white_wool"
|
||||
const wool_item = mcData.itemsByName[wool]
|
||||
const inventoryWool = bot.inventory.findInventoryItem(wool_item.id)
|
||||
// console.info(wool_item.id, inventoryWool)
|
||||
// if (!inventoryWool) return
|
||||
// bot.loadPlugin(pathfinder)
|
||||
|
||||
const myceliumClean = bot.findBlock({ // Const that is a brown_mushroom
|
||||
maxDistance: 6,
|
||||
matching: (block) => {
|
||||
// First check the type
|
||||
// lol
|
||||
// const { brown_mushroom, red_mushroom, white_wool } = mcData.blocksByName
|
||||
// if ([brown_mushroom.id, red_mushroom.id, white_wool.id].includes(block?.type)) {
|
||||
const { brown_mushroom, red_mushroom, } = mcData.blocksByName
|
||||
if ([brown_mushroom.id, red_mushroom.id,].includes(block?.type)) {
|
||||
// If position is defined, you can refine the search
|
||||
if (block.position) {
|
||||
const blockBelow = bot.blockAt(block.position.offset(0, -1, 0))
|
||||
return blockBelow?.type === mcData.blocksByName.mycelium.id || blockBelow?.type === mcData.blocksByName.spruce_fence.id // Makes sure there is mycelium below
|
||||
}
|
||||
return true // otherwise return always true (there is water in the section so it should be checked)
|
||||
}
|
||||
return false
|
||||
}
|
||||
})
|
||||
|
||||
function findMycelium(dist = 5) {
|
||||
return bot.findBlock({
|
||||
maxDistance: dist,
|
||||
matching: (block) => {
|
||||
// First check the type
|
||||
if (block?.type === mcData.blocksByName.mycelium.id) { // Const that is a mycelium block
|
||||
// If position is defined, you can refine the search
|
||||
if (block.position) {
|
||||
const blockAbove = bot.blockAt(block.position.offset(0, 1, 0))
|
||||
return !blockAbove || blockAbove?.type === mcData.blocksByName.air.id // Makes sure there is nothing above
|
||||
}
|
||||
return true // otherwise return always true (there is water in the section so it should be checked)
|
||||
}
|
||||
return false
|
||||
}
|
||||
})
|
||||
}
|
||||
let mycelium = findMycelium()
|
||||
|
||||
if (myceliumClean) {
|
||||
// bot.dig(myceliumClean, true)
|
||||
bot.dig(myceliumClean)
|
||||
}
|
||||
|
||||
if (mycelium) {
|
||||
timeInt = 500
|
||||
if (bot.heldItem?.type !== wool_item.id) { // Equips wool if not already
|
||||
if (!inventoryWool || inventoryWool.count < 10) { // Checks if there is less than 10 wool in the bots inventory
|
||||
timeInt = 5000
|
||||
console.warn("no wool")
|
||||
// const chestLocation = new Vec3(10614, 70, 5350) // Sets chest location
|
||||
const chestLocation = bot.findBlock({
|
||||
maxDistance: 100,
|
||||
matching: block => block && block.type === mcData.blocksByName.chest.id
|
||||
})?.position // Sets chest location
|
||||
const chestGoal = new GoalNear(chestLocation.x, chestLocation.y, chestLocation.z, 6) // Sets goal to chest location
|
||||
return bot.pathfinder.goto(chestGoal, () => { // Run code below when it gets to the chest
|
||||
bot.lookAt(chestLocation, true) // Looks at chest
|
||||
const chest = bot.openChest(bot.blockAt(chestLocation)) // Sets const to for opening chest
|
||||
chest.once('open', (err) => { // Opens chest
|
||||
if (err) {
|
||||
return console.error('Chest error', err)
|
||||
}
|
||||
const chest_item = chest.items().filter(item => item.type === wool_item.id)
|
||||
console.info(chest, chest_item)
|
||||
if (chest_item.length > 0) { // Checks that there is stuff in chest
|
||||
try {
|
||||
// Pulls out a chest (27 stack) of wool
|
||||
// chest.withdraw(chest_item[0].type, null, 64 * 27)
|
||||
chest.withdraw(chest_item[0].type, null, 64 * 3)
|
||||
} catch (error) {
|
||||
console.error('Chest withdraw error', error)
|
||||
}
|
||||
bot.once("close", cover)
|
||||
} else {
|
||||
console.log('Chest dont have', wool_item)
|
||||
cfg.quiet || bot.chat(`Not enough ${wool} in chest`)
|
||||
stopCovering()
|
||||
}
|
||||
setTimeout(chest.close, timeInt)
|
||||
})
|
||||
})
|
||||
} else {
|
||||
bot.equip(wool_item.id, "hand")
|
||||
}
|
||||
} else {
|
||||
const pos = mycelium.position
|
||||
bot.lookAt(pos, true)
|
||||
// let tryCount = 0
|
||||
const flooredPos = bot.entity.position.floored()
|
||||
if (flooredPos.offset(0, 1, 0).distanceTo(pos) <= 2) {
|
||||
bot.setControlState('jump', true)
|
||||
if (bot.entity.position.y > mycelium.position.y) {
|
||||
bot.placeBlock(mycelium, new Vec3(0, 1, 0), (err) => {
|
||||
setTimeout(bot.setControlState, 2000, 'jump', false)
|
||||
if (err) {
|
||||
console.error('Place (jumped)', err)
|
||||
}
|
||||
})
|
||||
}
|
||||
} else {
|
||||
bot.placeBlock(mycelium, new Vec3(0, 1, 0), (err) => {
|
||||
if (err) {
|
||||
if (err.message !== `No block has been placed : the block is still ${wool}`) {
|
||||
return console.error('Place (normal)', err)
|
||||
} else {
|
||||
return
|
||||
}
|
||||
}
|
||||
})
|
||||
}
|
||||
}
|
||||
} else {
|
||||
mycelium = findMycelium(100)
|
||||
if (mycelium) {
|
||||
const pos = mycelium.position
|
||||
const goal = new GoalNear(pos.x, pos.y, pos.z, 3)
|
||||
stopCovering(true)
|
||||
timeInt = 2000
|
||||
return bot.pathfinder.goto(goal, cover)
|
||||
} else {
|
||||
stopCovering(true)
|
||||
return cfg.quiet || bot.chat("no uncovered mycelium nearby")
|
||||
}
|
||||
}
|
||||
|
||||
timer = setTimeout(cover, timeInt, timeInt)
|
||||
}
|
||||
|
||||
function command(params) {
|
||||
stopCovering(true)
|
||||
cover()
|
||||
}
|
||||
|
||||
const load = (config) => {
|
||||
cfg = config
|
||||
bot = cfg.bot
|
||||
mcData = bot.mcData || (bot.mcData = require('minecraft-data')(bot.version))
|
||||
|
||||
pathfinder = bot.pathfinder || bot.loadPlugin(require('mineflayer-pathfinder').pathfinder)
|
||||
init()
|
||||
}
|
||||
|
||||
const unload = () => {
|
||||
stopCovering(true)
|
||||
}
|
||||
|
||||
module.exports = { load, unload, command, cover, stopCovering }
|
Reference in New Issue
Block a user