Compare commits
9 Commits
aded1e4193
...
1b21fcb096
Author | SHA1 | Date | |
---|---|---|---|
|
1b21fcb096 | ||
|
4b3e58ceb3 | ||
|
8e854a0a2f | ||
|
c42a3a2304 | ||
|
b453b7d6bd | ||
|
6b79f1fc60 | ||
|
6e1ef5aada | ||
|
e2ae7e5ad2 | ||
|
42138a421b |
|
@ -96,13 +96,13 @@ 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'),
|
informer: require('./plugins/informer'),
|
||||||
|
inventory: require('./plugins/inventory'),
|
||||||
finder: require('./plugins/finder'),
|
finder: require('./plugins/finder'),
|
||||||
sleeper: require('./plugins/sleeper'),
|
|
||||||
armor: require('./plugins/armor'),
|
|
||||||
mover: require('./plugins/mover'),
|
mover: require('./plugins/mover'),
|
||||||
|
sleeper: require('./plugins/sleeper'),
|
||||||
|
eater: require('./plugins/eater'),
|
||||||
|
armor: require('./plugins/armor'),
|
||||||
guard: require('./plugins/guard'),
|
guard: require('./plugins/guard'),
|
||||||
// miner: require('./plugins/miner.js'),
|
// miner: require('./plugins/miner.js'),
|
||||||
statemachine: require('./plugins/statemachine'),
|
statemachine: require('./plugins/statemachine'),
|
||||||
|
|
|
@ -11,17 +11,16 @@ let movements = []
|
||||||
|
|
||||||
|
|
||||||
function initMoves(bot = bot, mcData = bot.mcData) {
|
function initMoves(bot = bot, mcData = bot.mcData) {
|
||||||
console.info(movements)
|
|
||||||
if (movements.length > 0) {
|
if (movements.length > 0) {
|
||||||
bot.pathfinder.setMovements(movements.defaultMove)
|
bot.pathfinder.setMovements(movements.defaultMove)
|
||||||
return console.warn("movements already initialized!")
|
return console.warn("go init: movements already initialized!", movements)
|
||||||
}
|
}
|
||||||
let defaultMove = new Movements(bot, mcData)
|
const normalMove = new Movements(bot, mcData)
|
||||||
defaultMove.canDig = false
|
normalMove.canDig = false
|
||||||
defaultMove.scafoldingBlocks.push(mcData.blocksByName.slime_block.id)
|
normalMove.scafoldingBlocks.push(mcData.blocksByName.slime_block.id)
|
||||||
defaultMove.blocksCantBreak.add(mcData.blocksByName.glass.id)
|
normalMove.blocksCantBreak.add(mcData.blocksByName.glass.id)
|
||||||
defaultMove.blocksToAvoid.add(mcData.blocksByName.magma_block.id)
|
normalMove.blocksToAvoid.add(mcData.blocksByName.magma_block.id)
|
||||||
movements.push(defaultMove)
|
movements.push(normalMove)
|
||||||
movements.defaultMove = movements[0]
|
movements.defaultMove = movements[0]
|
||||||
|
|
||||||
bot.pathfinder.setMovements(defaultMove)
|
bot.pathfinder.setMovements(defaultMove)
|
||||||
|
@ -82,6 +81,66 @@ function follow(entity, dynamic = true, distance = 3) {
|
||||||
bot.pathfinder.setGoal(new GoalFollow(entity, distance), dynamic)
|
bot.pathfinder.setGoal(new GoalFollow(entity, distance), dynamic)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
function away(entity = bot.nearestEntity(), invertInvert = true, dynamic = true, distance = 10) {
|
||||||
|
const currentGoal = bot.pathfinder.goal
|
||||||
|
console.assert(currentGoal || entity)
|
||||||
|
const { GoalInvert } = require('mineflayer-pathfinder').goals
|
||||||
|
|
||||||
|
bot.pathfinder.setMovements(movements.defaultMove)
|
||||||
|
|
||||||
|
if (!currentGoal) {
|
||||||
|
const { GoalFollow } = require('mineflayer-pathfinder').goals
|
||||||
|
|
||||||
|
if (entity.entity) {
|
||||||
|
console.log("go away entity:", entity, entity.entity)
|
||||||
|
entity = entity.entity
|
||||||
|
}
|
||||||
|
|
||||||
|
cfg.quiet || bot.chat(
|
||||||
|
`going away from ${entity?.type
|
||||||
|
}: ${entity?.username || entity?.displayName
|
||||||
|
}${dynamic ? "" : " once"}`
|
||||||
|
)
|
||||||
|
// alternative implementation
|
||||||
|
// follow(entity, dynamic, distance)
|
||||||
|
// bot.pathfinder.setGoal(new GoalInvert(bot.pathfinder.goal), dynamic)
|
||||||
|
return bot.pathfinder.setGoal(new GoalInvert(
|
||||||
|
new GoalFollow(entity, distance)
|
||||||
|
), dynamic)
|
||||||
|
}
|
||||||
|
|
||||||
|
if (currentGoal instanceof GoalInvert) {
|
||||||
|
const currEntity = currentGoal.goal.entity
|
||||||
|
console.log("go away inverse goal:", currentGoal.goal)
|
||||||
|
if (invertInvert) {
|
||||||
|
cfg.quiet || bot.chat(
|
||||||
|
`switching towards ${currentGoal.goal?.constructor.name
|
||||||
|
}: ${currEntity?.type
|
||||||
|
}: ${currEntity?.username || currEntity?.displayName
|
||||||
|
}${dynamic ? "" : " once"}`
|
||||||
|
)
|
||||||
|
bot.pathfinder.setGoal(currentGoal.goal, dynamic)
|
||||||
|
} else {
|
||||||
|
cfg.quiet || bot.chat(
|
||||||
|
`already going away from ${currentGoal.goal?.constructor.name
|
||||||
|
}; not switching`
|
||||||
|
)
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
const currEntity = currentGoal.entity
|
||||||
|
console.log("go away goal:", currentGoal)
|
||||||
|
cfg.quiet || bot.chat(
|
||||||
|
`going away from ${currentGoal?.constructor.name
|
||||||
|
}: ${currEntity?.type
|
||||||
|
}: ${currEntity?.username || currEntity?.displayName
|
||||||
|
}${dynamic ? "" : " once"}`
|
||||||
|
)
|
||||||
|
bot.pathfinder.setGoal(new GoalInvert(currentGoal), dynamic)
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
function ride(entity) {
|
function ride(entity) {
|
||||||
entity = entity?.entity || entity
|
entity = entity?.entity || entity
|
||||||
const ridableMobs = ["Horse", "Donkey", "Pig", "Strider"]
|
const ridableMobs = ["Horse", "Donkey", "Pig", "Strider"]
|
||||||
|
@ -107,7 +166,8 @@ function ride(entity) {
|
||||||
function moveOrRide(turn = false, reverse = -1, directionLabel, message_parts2) {
|
function moveOrRide(turn = false, reverse = -1, directionLabel, message_parts2) {
|
||||||
// bot.once("attach", state = "vehiccel")
|
// bot.once("attach", state = "vehiccel")
|
||||||
if (bot.vehicle) {
|
if (bot.vehicle) {
|
||||||
const amount = parseInt(message_parts2[0]) || 10 * -reverse
|
// FIXME moveVehicle should be +-1 or 0?
|
||||||
|
const amount = Math.sign(parseInt(message_parts2[0]) || -reverse)
|
||||||
bot.moveVehicle(turn && amount || 0, !turn && amount || 0)
|
bot.moveVehicle(turn && amount || 0, !turn && amount || 0)
|
||||||
} else {
|
} else {
|
||||||
command([directionLabel].concat(message_parts2))
|
command([directionLabel].concat(message_parts2))
|
||||||
|
@ -230,6 +290,11 @@ function command(message_parts, player) {
|
||||||
case "mount":
|
case "mount":
|
||||||
ride(message_parts2[0])
|
ride(message_parts2[0])
|
||||||
break
|
break
|
||||||
|
case "away":
|
||||||
|
case "run":
|
||||||
|
case "runaway":
|
||||||
|
away()
|
||||||
|
break
|
||||||
case "w":
|
case "w":
|
||||||
case "f":
|
case "f":
|
||||||
moveOrRide(0, -1, "forward", message_parts2)
|
moveOrRide(0, -1, "forward", message_parts2)
|
||||||
|
@ -246,6 +311,11 @@ function command(message_parts, player) {
|
||||||
case "r":
|
case "r":
|
||||||
moveOrRide(1, 1, "left", message_parts2)
|
moveOrRide(1, 1, "left", message_parts2)
|
||||||
break
|
break
|
||||||
|
case "up":
|
||||||
|
case "u":
|
||||||
|
case "j":
|
||||||
|
moveOrRide(1, 1, "left", message_parts2)
|
||||||
|
break
|
||||||
case "back":
|
case "back":
|
||||||
case "forward":
|
case "forward":
|
||||||
case "jump":
|
case "jump":
|
||||||
|
|
|
@ -78,8 +78,9 @@ function init(smName = "dummy", webserver) {
|
||||||
actions: {
|
actions: {
|
||||||
// action implementation
|
// action implementation
|
||||||
lookAtPlayerOnce: (context, event) => {
|
lookAtPlayerOnce: (context, event) => {
|
||||||
const player = context?.player || bot.nearestEntity(entity => entity.type === 'player');
|
const player = context?.player && (context?.player?.isValid || context?.player?.entity?.isValid)
|
||||||
if (player.position || player.entity) {
|
|| bot.nearestEntity(entity => entity.type === 'player');
|
||||||
|
if (player?.position || player?.entity) {
|
||||||
context.player = player;
|
context.player = player;
|
||||||
bot.lookAt((player.entity || player).position.offset(0, 1, 0));
|
bot.lookAt((player.entity || player).position.offset(0, 1, 0));
|
||||||
}
|
}
|
||||||
|
@ -87,9 +88,10 @@ function init(smName = "dummy", webserver) {
|
||||||
},
|
},
|
||||||
activities: {
|
activities: {
|
||||||
lookAtPlayer: (context, event) => {
|
lookAtPlayer: (context, event) => {
|
||||||
const player = context?.player || bot.nearestEntity(entity => entity.type === 'player');
|
const player = (context?.player?.isValid || context?.player?.entity?.isValid) && context?.player
|
||||||
// TODO check every event?
|
|| bot.nearestEntity(entity => entity.type === 'player' && entity.isValid);
|
||||||
if (player.position || player.entity) {
|
// TODO check pos every event?
|
||||||
|
if (player?.position || player?.entity) {
|
||||||
context.player = player;
|
context.player = player;
|
||||||
function looks() {
|
function looks() {
|
||||||
bot.lookAt((player.entity || player).position.offset(0, 1, 0));
|
bot.lookAt((player.entity || player).position.offset(0, 1, 0));
|
||||||
|
@ -97,6 +99,11 @@ function init(smName = "dummy", webserver) {
|
||||||
bot.on("time", looks);
|
bot.on("time", looks);
|
||||||
return () => bot.off("time", looks);
|
return () => bot.off("time", looks);
|
||||||
}
|
}
|
||||||
|
else {
|
||||||
|
quiet || bot.chat("look: no valid players");
|
||||||
|
// TODO use xstate logger
|
||||||
|
context.debug && console.log("sm: no valid player", this, context, player);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
delays: {
|
delays: {
|
||||||
|
@ -255,9 +262,6 @@ function runSM(name = getSM(undefined, undefined, true), player // or supervisor
|
||||||
cfg.statemachine.running[machine.id] = service;
|
cfg.statemachine.running[machine.id] = service;
|
||||||
cfg.statemachine.recent = machine;
|
cfg.statemachine.recent = machine;
|
||||||
service.start();
|
service.start();
|
||||||
// // TODO check if idle state is different (maybe?)
|
|
||||||
console.log("sm run", service.state.value === machine.initialState.value, service.state);
|
|
||||||
console.log("sm run", service.state !== machine.initialState, machine.initialState);
|
|
||||||
// return machine
|
// return machine
|
||||||
return service;
|
return service;
|
||||||
}
|
}
|
||||||
|
@ -291,7 +295,7 @@ function actionSM(action, name = getSM()) {
|
||||||
if (service.status !== InterpreterStatus.Running)
|
if (service.status !== InterpreterStatus.Running)
|
||||||
return;
|
return;
|
||||||
// const machine = service.machine
|
// const machine = service.machine
|
||||||
service.send(action.toLowerCase());
|
service.send(action.toUpperCase());
|
||||||
}
|
}
|
||||||
function stepSM(command = "", ...message_parts) {
|
function stepSM(command = "", ...message_parts) {
|
||||||
let service = getSM(undefined, true);
|
let service = getSM(undefined, true);
|
||||||
|
|
Loading…
Reference in New Issue
Block a user