Skip to content

Commit

Permalink
continuing to work on porting baritone movements
Browse files Browse the repository at this point in the history
  • Loading branch information
GenerelSchwerz committed Apr 9, 2024
1 parent 1a13037 commit 100a360
Show file tree
Hide file tree
Showing 8 changed files with 202 additions and 128 deletions.
41 changes: 25 additions & 16 deletions src/ThePathfinder.ts
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,12 @@ import {
StraightUp
} from './mineflayer-specific/movements/movementProviders'


import {
MovementAscend,
MovementDescend
} from './mineflayer-specific/movements/baritone/baritoneProviders'

import {
ParkourForwardExecutor,
ForwardDropDownExecutor,
Expand Down Expand Up @@ -62,13 +68,15 @@ const EMPTY_VEC = new Vec3(0, 0, 0)
* These are the default movement types and their respective executors.
*/
const DEFAULT_PROVIDER_EXECUTORS = [
[Forward, NewForwardExecutor],
[ForwardJump, NewForwardJumpExecutor],
[ForwardDropDown, ForwardDropDownExecutor],
[Diagonal, NewForwardExecutor],
[StraightDown, StraightDownExecutor],
[StraightUp, StraightUpExecutor],
[ParkourForward, ParkourForwardExecutor]
// [Forward, NewForwardExecutor],
// [ForwardJump, NewForwardJumpExecutor],
// [ForwardDropDown, ForwardDropDownExecutor],
// [Diagonal, NewForwardExecutor],
// [StraightDown, StraightDownExecutor],
// [StraightUp, StraightUpExecutor],
// [ParkourForward, ParkourForwardExecutor]
[MovementAscend, StraightUpExecutor],
[MovementDescend, StraightDownExecutor]
] as Array<[BuildableMoveProvider, BuildableMoveExecutor]>

/**
Expand Down Expand Up @@ -579,9 +587,9 @@ export class ThePathfinder {
}
}

do {
outer0: do {
let madeIt = false
do {
outer1: do {
setupWait()

console.log('reset I believe', doForever)
Expand All @@ -592,7 +600,7 @@ export class ThePathfinder {
if (res.result.status !== 'success') {
if (res.result.status === 'noPath' || res.result.status === 'timeout' || res.result.status === 'canceled') {
if (task !== null && res1 !== null) res1.path.length = 0
break
break outer1
}

if (res.result.status === 'partialSuccess') {
Expand Down Expand Up @@ -665,16 +673,17 @@ export class ThePathfinder {
}

private async postProcess (pathInfo: Path): Promise<Path> {
const optimizer = new Optimizer(this.bot, this.world, this.optimizers)
return pathInfo
// const optimizer = new Optimizer(this.bot, this.world, this.optimizers)

optimizer.loadPath(pathInfo.path)
// optimizer.loadPath(pathInfo.path)

const res = await optimizer.compute()
// const res = await optimizer.compute()

const ret = { ...pathInfo }
// const ret = { ...pathInfo }

ret.path = res
return ret
// ret.path = res
// return ret
}

private check (): void {
Expand Down
20 changes: 10 additions & 10 deletions src/customHashmap/Int64Map/src/Int64Map.ts
Original file line number Diff line number Diff line change
@@ -1,33 +1,33 @@

type primitive = boolean | number | string | bigint | symbol | object | null

interface Node {
interface Node<P extends primitive = primitive> {
intLow: number
intHigh: number
value: primitive
next?: Node
value: P
next?: Node<P>
}

interface Bucket {
head?: Node
interface Bucket<P extends primitive> {
head?: Node<P>
}

const DEFAULT_SIZE = 1024
const LOAD_FACTOR = 0.5

console.log('running with load factor', LOAD_FACTOR)

class Int64Map {
class Int64Map<P extends primitive> {
constructor (initialSize = DEFAULT_SIZE) {
this.values = new Array<Bucket>(initialSize)
this.values = new Array<Bucket<P>>(initialSize)
for (let i = 0; i < initialSize; i++) {
this.values[i] = { }
}
this.INTIAL_SIZE = initialSize
this.size = initialSize
}

private readonly values: Bucket[]
private readonly values: Bucket<P>[]

private readonly INTIAL_SIZE: number = DEFAULT_SIZE

Expand All @@ -43,7 +43,7 @@ class Int64Map {
return this.length
}

get (intLow: number, intHigh: number): primitive {
get (intLow: number, intHigh: number): P | null {
const index = intLow & (this.size - 1)
const bucket = this.values[index]
let node = bucket.head
Expand All @@ -56,7 +56,7 @@ class Int64Map {
return null
}

set (intLow: number, intHigh: number, value: primitive): primitive {
set (intLow: number, intHigh: number, value: P): P | boolean {
if (this.length > this.size * LOAD_FACTOR) {
this.grow()
}
Expand Down
3 changes: 3 additions & 0 deletions src/mineflayer-specific/move.ts
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,9 @@ export class Move implements PathData {

this.cachedVec = new Vec3(this.x, this.y, this.z)
Object.freeze(this.cachedVec)

Object.freeze(toBreak)
Object.freeze(toPlace)
// this.x = x;
// this.y = y;
// this.z = z;
Expand Down
Loading

0 comments on commit 100a360

Please sign in to comment.