-
Notifications
You must be signed in to change notification settings - Fork 3
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
04a438c
commit d2bee9d
Showing
16 changed files
with
441 additions
and
133 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -2,6 +2,5 @@ node_modules/ | |
dist/ | ||
yarn-* | ||
package-lock.json | ||
*.log | ||
vscode-profile-* | ||
flamegraph.htm |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
157 changes: 157 additions & 0 deletions
157
src/mineflayer-specific/movements/baritone/baritoneProviders.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,157 @@ | ||
import { Vec3 } from "vec3"; | ||
import { Move } from "../../move"; | ||
import { MovementProvider } from "../movementProvider"; | ||
import { Goal } from "../../goals"; | ||
import { canUseFrostWalker, canWalkOn, canWalkThrough, findPlaceOpts, getMiningDurationTicks, isBottomSlab } from "./movementHelper"; | ||
import { BreakHandler, PlaceHandler } from "../interactionUtils"; | ||
import { CENTER_AFTER_FALL_COST, COST_INF, FALL_N_BLOCKS_COST, JUMP_ONE_BLOCK_COST, WALK_OFF_BLOCK_COST, WALK_ONE_BLOCK_COST, WALK_ONE_OVER_SOUL_SAND_COST } from "../costs"; | ||
import { BlockInfo } from "../../world/cacheWorld"; | ||
|
||
export class IdleMovement extends MovementProvider { | ||
movementDirs: Vec3[] = []; | ||
provideMovements(start: Move, storage: Move[]): void {} | ||
async performInit(thisMove: Move, currentIndex: number, path: Move[]): Promise<void> {} | ||
async performPerTick(thisMove: Move, tickCount: number, currentIndex: number, path: Move[]): Promise<boolean> { | ||
return true; | ||
} | ||
} | ||
|
||
// base all code in this file off of: | ||
// https://github.com/cabaletta/baritone/blob/1.19.4/src/main/java/baritone/pathing/movement/movements/MovementAscend.java | ||
|
||
export class MovementAscend extends MovementProvider { | ||
movementDirs = [new Vec3(0, 1, 0)]; | ||
provideMovements(start: Move, storage: Move[], goal: Goal, closed: Set<string>): void { | ||
for (const dir of this.movementDirs) { | ||
const off = start.cachedVec.plus(dir); | ||
if (closed.has(off.toString())) return; | ||
this.provideAscend(start, dir, storage, closed); | ||
} | ||
} | ||
|
||
provideAscend(node: Move, dir: Vec3, storage: Move[], closed: Set<string>): void { | ||
const blPlace = this.getBlockInfo(node, dir.x, 0, dir.y); | ||
|
||
if (blPlace.isInvalid) return; | ||
|
||
// potentially get rid of these, as we don't actually need them for the time being. | ||
const toPlace: PlaceHandler[] = []; | ||
const toBreak: BreakHandler[] = []; | ||
|
||
let cost = 0; | ||
if (!blPlace.physical) { | ||
if (!blPlace.replaceable) { | ||
if ((cost += this.safeOrBreak(blPlace, toBreak)) >= COST_INF) return; | ||
} | ||
if ((cost += this.safeOrPlace(blPlace, toPlace)) >= COST_INF) return; | ||
if (findPlaceOpts(this, node, blPlace.position) == null) return; | ||
} | ||
|
||
const srcUp1 = this.getBlockInfo(node, 0, 1, 0); | ||
const srcUp2 = this.getBlockInfo(node, 0, 2, 0); | ||
const srcUp3 = this.getBlockInfo(node, 0, 3, 0); | ||
// translate below to typescript | ||
// if (context.get(x, y + 3, z).getBlock() instanceof FallingBlock && (MovementHelper.canWalkThrough(context, x, y + 1, z) || !(srcUp2.getBlock() instanceof FallingBlock))) {//it would fall on us and possibly suffocate us | ||
|
||
if (srcUp3.canFall && (canWalkThrough(srcUp1) || !srcUp2.canFall)) { | ||
return; | ||
} | ||
|
||
const srcDown1 = this.getBlockInfo(node, 0, -1, 0); | ||
if (srcDown1.climbable) return; | ||
|
||
const jumpFromBottomSlab = isBottomSlab(srcDown1); | ||
const jumpToBottomSlab = isBottomSlab(blPlace); | ||
|
||
if (jumpFromBottomSlab && !jumpToBottomSlab) { | ||
return; | ||
} | ||
|
||
let walk = 0; | ||
if (jumpToBottomSlab) { | ||
if (jumpFromBottomSlab) { | ||
walk = Math.max(JUMP_ONE_BLOCK_COST, WALK_ONE_BLOCK_COST); // we hit space immediately on entering this action | ||
walk += this.settings.jumpCost; | ||
} else { | ||
walk = WALK_ONE_BLOCK_COST; | ||
} | ||
} else { | ||
if (blPlace.block!.type === BlockInfo.soulsandId) { | ||
walk = WALK_ONE_OVER_SOUL_SAND_COST; | ||
} else { | ||
walk = Math.max(JUMP_ONE_BLOCK_COST, WALK_ONE_BLOCK_COST); | ||
} | ||
walk += this.settings.jumpCost; | ||
} | ||
|
||
if ((cost += walk) >= COST_INF) return; | ||
if ((cost += getMiningDurationTicks(this, srcUp2)) >= COST_INF) return; | ||
|
||
const target1 = this.getBlockInfo(node, dir.x, 1, dir.z); | ||
if ((cost += getMiningDurationTicks(this, target1)) >= COST_INF) return; | ||
|
||
const target2 = this.getBlockInfo(node, dir.x, 2, dir.z); | ||
if ((cost += getMiningDurationTicks(this, target2)) >= COST_INF) return; | ||
} | ||
} | ||
|
||
|
||
export class MovementDescend extends MovementProvider { | ||
movementDirs = [new Vec3(0, -1, 0)]; | ||
provideMovements(start: Move, storage: Move[], goal: Goal, closed: Set<string>): void { | ||
for (const dir of this.movementDirs) { | ||
this.provideDescend(start, dir, storage, closed); | ||
} | ||
} | ||
|
||
provideDescend(node: Move, dir: Vec3, storage: Move[], closed: Set<string>): void { | ||
|
||
const srcN1 = this.getBlockInfo(node, dir.x, -1, dir.z); | ||
if (srcN1.climbable) return; | ||
|
||
|
||
const srcN2 = this.getBlockInfo(node, dir.x, -2, dir.z); | ||
if (!canWalkOn(srcN2)) { | ||
return // for now, do not calculate this movement as it will be handled by movementFall. | ||
// this.dynamicFallCosts(srcN2, cost); | ||
} | ||
|
||
if (canUseFrostWalker(this, srcN2)) { | ||
return; | ||
} | ||
|
||
let cost = 0; | ||
|
||
const destN1 = this.getBlockInfo(node, dir.x, -1, dir.z); | ||
if ((cost+=getMiningDurationTicks(this, destN1)) >= COST_INF) return; | ||
|
||
const dest = this.getBlockInfo(node, dir.x, 0, dir.z); | ||
if ((cost+=getMiningDurationTicks(this, dest)) >= COST_INF) return; | ||
|
||
const dest1 = this.getBlockInfo(node, dir.x, 1, dir.z); | ||
if ((cost+=getMiningDurationTicks(this, dest1, true)) >= COST_INF) return; | ||
|
||
|
||
let walk = WALK_OFF_BLOCK_COST | ||
if (srcN1.block!.type === BlockInfo.soulsandId) { | ||
walk = WALK_ONE_OVER_SOUL_SAND_COST / WALK_ONE_BLOCK_COST | ||
} | ||
|
||
cost += walk; | ||
cost + Math.max(FALL_N_BLOCKS_COST[1], CENTER_AFTER_FALL_COST); | ||
} | ||
|
||
|
||
// TODO: implement mutables | ||
dynamicFallCosts(info: BlockInfo, cost: number): void { | ||
|
||
} | ||
} | ||
|
||
export class MovementDiagonal extends MovementProvider { | ||
movementDirs = MovementProvider.diagonalDirs; | ||
provideMovements(start: Move, storage: Move[], goal: Goal, closed: Set<string>): void { | ||
|
||
} | ||
|
||
} |
58 changes: 58 additions & 0 deletions
58
src/mineflayer-specific/movements/baritone/movementHelper.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,58 @@ | ||
import { Vec3 } from "vec3"; | ||
import { BlockInfo } from "../../world/cacheWorld"; | ||
import { World } from "../../world/worldInterface"; | ||
import { Movement } from "../movement"; | ||
import { Vec3Properties } from "../../../types"; | ||
|
||
export function canWalkOn(info: BlockInfo): boolean { | ||
if (info.block == null) return false | ||
return info.block.boundingBox === "block" || info.safe | ||
} | ||
|
||
export function canWalkThrough(info: BlockInfo): boolean { | ||
if (info.block == null) return false | ||
return info.block.boundingBox === "empty" || info.safe | ||
} | ||
|
||
const ALL_DIRS_BUT_UP = [ | ||
new Vec3(1, 0, 0), | ||
new Vec3(-1, 0, 0), | ||
new Vec3(0, 0, 1), | ||
new Vec3(0, 0, -1), | ||
new Vec3(0, -1, 0), | ||
] | ||
export function findPlaceOpts(move: Movement, orgPos: Vec3Properties, pos: Vec3Properties): BlockInfo | null { | ||
for (const dir of ALL_DIRS_BUT_UP) { | ||
const nX = pos.x + dir.x | ||
const nZ = pos.z + dir.z | ||
if (nX === orgPos.x && nZ === orgPos.z) continue | ||
const info = move.getBlockInfo(pos, dir.x, dir.y, dir.z) | ||
if (canPlaceAgainst(info)) return info | ||
} | ||
|
||
return null; | ||
|
||
} | ||
|
||
export function canPlaceAgainst(info: BlockInfo): boolean { | ||
return info.physical | ||
} | ||
|
||
export function isBottomSlab(info: BlockInfo): boolean { | ||
return info.dY === 0.5 | ||
} | ||
|
||
export function getMiningDurationTicks(move: Movement, info: BlockInfo, includeFalling=false): number { | ||
if (!includeFalling) return move.breakCost(info); | ||
|
||
const above = move.getBlockInfo(info.position, 0, 1, 0); | ||
return move.breakCost(info) + getMiningDurationTicks(move, above, true); // recurse upwards. potentially slow. | ||
} | ||
|
||
export function getMiningDurationTicksCoords(move: Movement, pos: Vec3, includeFalling=false): number { | ||
return getMiningDurationTicks(move, move.getBlockInfoRaw(pos), includeFalling); | ||
} | ||
|
||
export function canUseFrostWalker(move: Movement, info: BlockInfo): boolean { | ||
return info.liquid && false; // TODO: frostwalker. | ||
} |
Oops, something went wrong.