Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Mining under gravity block fix #239

Merged
merged 4 commits into from
Jan 11, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions index.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -179,6 +179,7 @@ declare module 'mineflayer-pathfinder' {

public canDig: boolean;
public dontCreateFlow: boolean;
public dontMineUnderFallingBlock: boolean;
public allow1by1towers: boolean;
public allowFreeMotion: boolean;
public allowParkour: boolean;
Expand All @@ -187,6 +188,7 @@ declare module 'mineflayer-pathfinder' {
public blocksCantBreak: Set<number>;
public blocksToAvoid: Set<number>;
public liquids: Set<number>;
public gravityBlocks: Set<number>;
public scafoldingBlocks: number[];

public maxDropDown: number;
Expand Down
13 changes: 13 additions & 0 deletions lib/movements.js
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,7 @@ class Movements {
this.allowFreeMotion = false
this.allowParkour = true
this.allowSprinting = true
this.dontMineUnderFallingBlock = true

this.blocksCantBreak = new Set()
this.blocksCantBreak.add(mcData.blocksByName.chest.id)
Expand All @@ -53,6 +54,10 @@ class Movements {
this.liquids.add(mcData.blocksByName.water.id)
this.liquids.add(mcData.blocksByName.lava.id)

this.gravityBlocks = new Set()
this.gravityBlocks.add(mcData.blocksByName.sand.id)
this.gravityBlocks.add(mcData.blocksByName.gravel.id)

this.climbables = new Set()
this.climbables.add(mcData.blocksByName.ladder.id)
// this.climbables.add(mcData.blocksByName.vine.id)
Expand Down Expand Up @@ -121,6 +126,7 @@ class Movements {
if (!b) {
return {
replaceable: false,
canFall: false,
safe: false,
physical: false,
liquid: false,
Expand All @@ -135,7 +141,9 @@ class Movements {
b.replaceable = this.replaceables.has(b.type) && !b.physical
b.liquid = this.liquids.has(b.type)
b.height = pos.y + dy
b.canFall = this.gravityBlocks.has(b.type)
b.openable = this.openable.has(b.type)

for (const shape of b.shapes) {
b.height = Math.max(b.height, pos.y + dy + shape[4])
}
Expand All @@ -155,6 +163,11 @@ class Movements {
if (this.getBlock(block.position, 0, 0, -1).liquid) return false
if (this.getBlock(block.position, 0, 0, 1).liquid) return false
}

if (this.dontMineUnderFallingBlock) {
if (this.getBlock(block.position, 0, 1, 0).canFall) return false
}

return block.type && !this.blocksCantBreak.has(block.type)
// TODO: break exclusion areas
}
Expand Down
8 changes: 8 additions & 0 deletions readme.md
Original file line number Diff line number Diff line change
Expand Up @@ -176,6 +176,10 @@ Additional cost for interacting with liquids.
Do not break blocks that touch liquid blocks.
* Default - `true`

### dontMineUnderFallingBlock
Do not break blocks that have gravityBlock above.
* Default - `true`

### allow1by1towers
Allow pillaring up on 1x1 towers.
* Default - `true`
Expand Down Expand Up @@ -216,6 +220,10 @@ Set of block id's that can be replaced when placing blocks.
Array of item id's that can be used as scaffolding blocks.
* Default - `[<scaffoldingItems>]`

### gravityBlocks
Set of block id's that can fall on bot's head.
* instance of `Set`

### fences
Set of block id's that are fences or blocks that have a collision box taler then 1 block.
* instance of `Set`
Expand Down