Skip to content

Commit

Permalink
Upgrading package versions
Browse files Browse the repository at this point in the history
  • Loading branch information
sefirosweb committed Oct 28, 2023
1 parent 11aa9e9 commit 4a66a13
Show file tree
Hide file tree
Showing 24 changed files with 4,609 additions and 3,029 deletions.
2,460 changes: 1,506 additions & 954 deletions core/package-lock.json

Large diffs are not rendered by default.

48 changes: 24 additions & 24 deletions core/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -20,46 +20,46 @@
"dependencies": {
"async": "^3.2.4",
"base-types": "file:../base-types/base-types-1.0.0.tgz",
"dotenv": "^16.0.3",
"dotenv": "^16.3.1",
"express": "4.18.2",
"lowdb": "1.0.0",
"minecraft-data": "3.31.0",
"minecraft-data": "3.47.0",
"minecrafthawkeye": "1.3.5",
"mineflayer": "4.8.1",
"mineflayer-pathfinder": "2.4.2",
"mineflayer": "4.14.0",
"mineflayer-pathfinder": "2.4.5",
"mineflayer-statemachine": "1.7.0",
"mineflayer-web-inventory": "1.8.4",
"prismarine-viewer": "1.25.0",
"socket.io-client": "4.6.1",
"uuid": "^9.0.0",
"socket.io-client": "4.7.2",
"uuid": "^9.0.1",
"vec3": "0.1.8"
},
"devDependencies": {
"@babel/cli": "^7.21.0",
"@babel/core": "^7.21.4",
"@babel/node": "^7.20.7",
"@babel/preset-env": "^7.21.4",
"@babel/preset-typescript": "^7.21.4",
"@types/async": "^3.2.18",
"@types/chai": "^4.3.4",
"@types/events": "^3.0.0",
"@types/lodash": "^4.14.194",
"@types/mocha": "^10.0.1",
"@types/uuid": "^9.0.1",
"@babel/cli": "^7.23.0",
"@babel/core": "^7.23.2",
"@babel/node": "^7.22.19",
"@babel/preset-env": "^7.23.2",
"@babel/preset-typescript": "^7.23.2",
"@types/async": "^3.2.22",
"@types/chai": "^4.3.9",
"@types/events": "^3.0.2",
"@types/lodash": "^4.14.200",
"@types/mocha": "^10.0.3",
"@types/uuid": "^9.0.6",
"babel-plugin-module-resolver": "^5.0.0",
"chai": "^4.3.7",
"chai": "^4.3.10",
"events": "^3.3.0",
"lodash": "^4.17.21",
"mocha": "^10.2.0",
"nodemon": "2.0.22",
"prismarine-block": "^1.16.3",
"prismarine-entity": "^2.2.0",
"prismarine-windows": "^2.6.1",
"nodemon": "3.0.1",
"prismarine-block": "^1.17.1",
"prismarine-entity": "^2.3.1",
"prismarine-windows": "^2.8.0",
"swc": "^1.0.11",
"ts-node": "^10.9.1",
"tsconfig-paths": "^4.2.0",
"tslint": "^6.1.3",
"typescript": "^5.0.4"
"typescript": "^5.2.2"
},
"repository": {
"type": "git",
Expand All @@ -71,4 +71,4 @@
"url": "https://github.com/sefirosweb/minecraftLegion/issues"
},
"homepage": "https://github.com/sefirosweb/minecraftLegion#readme"
}
}
2 changes: 1 addition & 1 deletion core/src/BehaviorModules/BehaviorFertilize.ts
Original file line number Diff line number Diff line change
Expand Up @@ -57,7 +57,7 @@ export default class BehaviorFertilize implements StateBehavior {
const targetPosition = new Vec3(this.targets.position.x, this.targets.position.y, this.targets.position.z)

const slotID = this.bot.getEquipmentDestSlot('hand')
if (this.bot.inventory.slots[slotID] === null || !this.bot.inventory.slots[slotID].name.includes('hoe')) {
if (this.bot.inventory.slots[slotID] === null || !this.bot.inventory.slots[slotID]?.name.includes('hoe')) {
const hoe = this.bot.inventory.items().find(item => item.name.includes('hoe'))

if (!hoe) {
Expand Down
2 changes: 1 addition & 1 deletion core/src/BehaviorModules/BehaviorFindItems.ts
Original file line number Diff line number Diff line change
Expand Up @@ -60,7 +60,7 @@ export default class BehaviorFindItems implements StateBehavior {
!this.isOnFloor ||
Math.abs(entity.position.y - this.bot.entity.position.y) <= 1
)) {
if (entity.objectType === 'Item' /* || entity.objectType === 'Arrow' */) {
if (entity.displayName === 'Item' /* || entity.displayName === 'Arrow' */) {
entity.distance = disatanceToObject
itemsFound.push(entity as EntityWithDistance)
}
Expand Down
5 changes: 1 addition & 4 deletions core/src/BehaviorModules/BehaviorMoveTo.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
import mineflayerPathfinder, { Movements } from 'mineflayer-pathfinder'
import botWebsocket from '@/modules/botWebsocket'
import { LegionStateMachineTargets, Vec3WithDimension } from 'base-types'
import mcDataLoader from 'minecraft-data'
import movementModule from '@/modules/movementModule'
import { StateBehavior } from 'mineflayer-statemachine'
import { Bot, Dimension, Dimension_V2 } from 'mineflayer'
Expand All @@ -10,7 +9,6 @@ export default class BehaviorMoveTo implements StateBehavior {
active: boolean
readonly bot: Bot
readonly targets: LegionStateMachineTargets
readonly mcData: mcDataLoader.IndexedData
stateName: string
x?: number
y?: number
Expand All @@ -34,8 +32,7 @@ export default class BehaviorMoveTo implements StateBehavior {
this.distance = 0
this.bot = bot
this.targets = targets
this.mcData = mcDataLoader(bot.version)
this.movements = new mineflayerPathfinder.Movements(bot, this.mcData)
this.movements = new mineflayerPathfinder.Movements(bot)

this.movementModule = movementModule(bot, targets)
}
Expand Down
5 changes: 1 addition & 4 deletions core/src/BehaviorModules/BehaviorMoveToArray.ts
Original file line number Diff line number Diff line change
@@ -1,15 +1,13 @@
import mineflayerPathfinder, { Movements } from 'mineflayer-pathfinder'
import botWebsocket from '@/modules/botWebsocket'
import { LegionStateMachineTargets } from 'base-types'
import mcDataLoader from 'minecraft-data'
import { Vec3 } from 'vec3'
import { StateBehavior } from 'mineflayer-statemachine'
import { Bot } from 'mineflayer'

export default class BehaviorMoveToArray implements StateBehavior {
readonly bot: Bot
readonly targets: LegionStateMachineTargets
readonly mcData: mcDataLoader.IndexedData
stateName: string
x?: number
y?: number
Expand Down Expand Up @@ -37,8 +35,7 @@ export default class BehaviorMoveToArray implements StateBehavior {
this.endPatrol = false
this.active = false

this.mcData = mcDataLoader(bot.version)
this.movements = new mineflayerPathfinder.Movements(this.bot, this.mcData)
this.movements = new mineflayerPathfinder.Movements(this.bot)

if (this.startNearestPoint === true && this.patrol !== undefined) {
this.sortPatrol()
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -56,6 +56,7 @@ export default class BehaviorcCheckItemsInChest implements StateBehavior {

if (chestIndex) {

// @ts-ignore
this.targets.chests[chestIndex[0]].slots = slots
this.targets.chests[chestIndex[0]].lastTimeOpen = Date.now()

Expand All @@ -64,6 +65,7 @@ export default class BehaviorcCheckItemsInChest implements StateBehavior {
const newChest: ChestBlock = {
dimension: this.bot.game.dimension as Dimension_V2,
position: chest.position,
// @ts-ignore
slots,
lastTimeOpen: Date.now()
}
Expand Down
20 changes: 9 additions & 11 deletions core/src/NestedStateModules/combat/combatFunction.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@ import BehaviorAttack from '@/BehaviorModules/combat/BehaviorAttack'
import BehaviorLongAttack from '@/BehaviorModules/combat/BehaviorLongAttack'
import { fakeVec3, LegionStateMachineTargets } from 'base-types'
import { Entity } from 'prismarine-entity'
import mcDataLoader from 'minecraft-data'
import inventoryModule from '@/modules/inventoryModule'
import getClosestEnemy from '@/modules/getClosestEnemy'
import botWebsocket from '@/modules/botWebsocket'
Expand All @@ -16,10 +15,9 @@ function combatFunction(bot: Bot, targets: LegionStateMachineTargets) {
const inventory = inventoryModule(bot)
const { ignoreMobs, flyingMobs } = getClosestEnemy(bot, targets)

const mcData = mcDataLoader(bot.version)
const movements = new mineflayerPathfinder.Movements(bot, mcData)
const movements = new mineflayerPathfinder.Movements(bot)

const movementsForFliyingMobs = new mineflayerPathfinder.Movements(bot, mcData)
const movementsForFliyingMobs = new mineflayerPathfinder.Movements(bot)
movementsForFliyingMobs.canDig = false
movementsForFliyingMobs.allow1by1towers = false
movementsForFliyingMobs.scafoldingBlocks = []
Expand Down Expand Up @@ -64,20 +62,20 @@ function combatFunction(bot: Bot, targets: LegionStateMachineTargets) {
let newTargetColdDown = Date.now()

const filter = (e: Entity) =>
e.mobType !== undefined &&
e.type === 'mob' &&
e.displayName !== undefined &&
(e.type === 'hostile' || e.kind === 'Hostile mobs') &&
e.position.distanceTo(bot.entity.position) < 10 &&
e.mobType !== 'Armor Stand' &&
e.displayName !== 'Armor Stand' &&
e.kind !== 'Passive mobs' &&
e.isValid &&
!ignoreMobs.includes(e.mobType)
!ignoreMobs.includes(e.displayName)

const getGrades = function () {
// Of other enemies aproax, change target (Ex clipper)
if (Date.now() - newTargetColdDown > 1000) {
const entity = bot.nearestEntity(filter)
if (entity) {
botWebsocket.log('Change Target => ' + entity.mobType + ' ' + JSON.stringify(entity.position))
botWebsocket.log('Change Target => ' + entity.displayName + ' ' + JSON.stringify(entity.position))
targets.entity = entity
newTargetColdDown = Date.now()
}
Expand Down Expand Up @@ -201,7 +199,7 @@ function combatFunction(bot: Bot, targets: LegionStateMachineTargets) {
child: attack,
onTransition: () => {
botWebsocket.emitCombat(true)
botWebsocket.log('Start combat ' + targets.entity?.mobType + ' ' + JSON.stringify(targets.entity?.position))
botWebsocket.log('Start combat ' + targets.entity?.displayName + ' ' + JSON.stringify(targets.entity?.position))
startGrades()
},
name: 'start -> followMob',
Expand Down Expand Up @@ -274,7 +272,7 @@ function combatFunction(bot: Bot, targets: LegionStateMachineTargets) {
(longRangeAttack.checkBowAndArrow() === false && targets.entity.isValid) ||
(followMob.distanceToTarget() > rangoBow && targets.entity.isValid) ||
(followMob.distanceToTarget() < rangeFollowToShortAttack && targets.entity.isValid) ||
(targets.entity.mobType === 'Enderman' && targets.entity.isValid) ||
(targets.entity.displayName === 'Enderman' && targets.entity.isValid) ||
(targetGrade === undefined && targets.entity.isValid)
)
}
Expand Down
2 changes: 1 addition & 1 deletion core/src/NestedStateModules/commandsFunction.ts
Original file line number Diff line number Diff line change
Expand Up @@ -102,7 +102,7 @@ function commandsFunction(bot: Bot, targets: LegionStateMachineTargets) {

const filter = (e: Entity) => e.type === 'player' &&
e.username === master &&
e.mobType !== 'Armor Stand'
e.displayName !== 'Armor Stand'

const entity = bot.nearestEntity(filter)

Expand Down
6 changes: 2 additions & 4 deletions core/src/NestedStateModules/startStateMachine.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@ import { LegionStateMachineTargets, BotwebsocketAction } from "base-types"
import { Bot, BotEvents } from "mineflayer"
import { Vec3 } from "vec3"
import config from '@/config'
import mcDataLoader from 'minecraft-data'
import movementModule from '@/modules/movementModule'
import botWebsocket from '@/modules/botWebsocket'
import mineflayerPathfinder from 'mineflayer-pathfinder'
Expand All @@ -17,7 +16,6 @@ import inventoryViewer from 'mineflayer-web-inventory'
const startStateMachine = (bot: Bot) => {
const botConfig = botConfigLoader(bot.username)
const { debugMode } = config
const mcData = mcDataLoader(bot.version)

// const targets: LegionStateMachineTargets = {
// aListener: function (object, val) {
Expand Down Expand Up @@ -50,7 +48,7 @@ const startStateMachine = (bot: Bot) => {
// }
// }

const movements = new mineflayerPathfinder.Movements(bot, mcData)
const movements = new mineflayerPathfinder.Movements(bot)

const targets: LegionStateMachineTargets = {
config: botConfig.defaultConfig,
Expand Down Expand Up @@ -191,7 +189,7 @@ const startStateMachine = (bot: Bot) => {
checkPortalsOnSpawn()
})

bot.on('physicTick', () => {
bot.on('physicsTick', () => {
bot.emit('customEventPhysicTick')
})

Expand Down
4 changes: 2 additions & 2 deletions core/src/modules/botWebsocket.ts
Original file line number Diff line number Diff line change
Expand Up @@ -214,7 +214,7 @@ const connect = async () => {
(e) =>
e.type === 'player' &&
e.username === value &&
e.mobType !== 'Armor Stand'
e.displayName !== 'Armor Stand'
)
if (!findMaster) {
return
Expand Down Expand Up @@ -258,7 +258,7 @@ const connect = async () => {
(e) =>
e.type === 'player' &&
e.username === value &&
e.mobType !== 'Armor Stand'
e.displayName !== 'Armor Stand'
)
if (!findMaster) {
return
Expand Down
29 changes: 14 additions & 15 deletions core/src/modules/getClosestEnemy.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@
import { CustomEntity, LegionStateMachineTargets } from 'base-types'
import botWebsocket from '@/modules/botWebsocket'
import { Entity } from 'prismarine-entity'
import mcDataLoader from 'minecraft-data'
import mineflayerPathfinder from 'mineflayer-pathfinder'
import { Bot } from 'mineflayer'

Expand Down Expand Up @@ -40,8 +39,7 @@ const getClosestEnemy = (bot: Bot, targets: LegionStateMachineTargets) => {
'Wither'
]

const mcData = mcDataLoader(bot.version)
const movements = new mineflayerPathfinder.Movements(bot, mcData)
const movements = new mineflayerPathfinder.Movements(bot)
movements.canDig = false

// const movementsForFliyingMobs = new mineflayerPathfinder.Movements(bot, mcData)
Expand Down Expand Up @@ -75,9 +73,9 @@ const getClosestEnemy = (bot: Bot, targets: LegionStateMachineTargets) => {

const getValidPath = (entity: Entity) => { // UNUSED FOR A NOW
if (entity.type === 'mob' && (
entity.mobType === 'Phantom' ||
entity.mobType === 'Blaze' ||
entity.mobType === 'Ender Dragon'
entity.displayName === 'Phantom' ||
entity.displayName === 'Blaze' ||
entity.displayName === 'Ender Dragon'
)) { return true }

const goal = new mineflayerPathfinder.goals.GoalNear(entity.position.x, entity.position.y, entity.position.z, 2)
Expand Down Expand Up @@ -116,11 +114,11 @@ const getClosestEnemy = (bot: Bot, targets: LegionStateMachineTargets) => {
if (targets.config.mode === 'pvp') {
if (
(entity.position.distanceTo(bot.player.entity.position) <= targets.config.distance) &&
(entity.type === 'mob' || entity.type === 'player') &&
(entity.kind !== 'Passive mobs') &&
entity.mobType &&
!ignoreMobs.includes(entity.mobType) &&
(entity.isValid)
(entity.type === 'hostile' || entity.kind === 'Hostile mobs' || entity.type === 'player') &&
// entity.kind !== 'Passive mobs' &&
entity.displayName &&
!ignoreMobs.includes(entity.displayName) &&
entity.isValid
) {
const botFriends = botWebsocket.getFriends()
const bFriend = botFriends.find(b => b.name === entity.username)
Expand All @@ -141,11 +139,12 @@ const getClosestEnemy = (bot: Bot, targets: LegionStateMachineTargets) => {
}

if (targets.config.mode === 'pve') {
// console.log(`${entity.displayName} + ${entity.type} + ${entity.kind}`)
return (entity.position.distanceTo(bot.player.entity.position) <= targets.config.distance) &&
(entity.type === 'mob') &&
(entity.kind !== 'Passive mobs') &&
entity.mobType &&
!ignoreMobs.includes(entity.mobType) &&
(entity.type === 'hostile' || entity.kind === 'Hostile mobs') &&
// (entity.kind !== 'Passive mobs') &&
entity.displayName &&
!ignoreMobs.includes(entity.displayName) &&
(entity.isValid)
}

Expand Down
3 changes: 1 addition & 2 deletions core/src/modules/inventoryModule.ts
Original file line number Diff line number Diff line change
Expand Up @@ -158,15 +158,14 @@ const inventoryModule = (bot: Bot) => {
let block: BlockChest | null | undefined
let secondBlock: Vec3
let secondBlockIndex: number
let props: Record<string, string | number>

while (block = blocksFound.shift()) {

if (chests.length >= count) {
break
}

props = block.getProperties()
const props = block.getProperties()
const facing: Facing = props.facing as Facing
const type: ChestPosition = props.type as ChestPosition
const offset = getSecondBlockPosition(facing, type)
Expand Down
2 changes: 2 additions & 0 deletions core/src/modules/refreshChests.ts
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@ const refreshChest = (chestToOpen: Block, container: Chest, bot: Bot, targets: L
if (!chest) {
const chestOpened: ChestBlock = {
dimension: bot.game.dimension as Dimension_V2,
// @ts-ignore
slots,
position: chestToOpen.position,
position_2: position2,
Expand All @@ -38,6 +39,7 @@ const refreshChest = (chestToOpen: Block, container: Chest, bot: Bot, targets: L

chest.position = chestToOpen.position,
chest.position_2 = position2
// @ts-ignore
chest.slots = slots
chest.lastTimeOpen = Date.now()
}
Expand Down
Loading

0 comments on commit 4a66a13

Please sign in to comment.