PrismarineJS / mineflayer

Create Minecraft bots with a powerful, stable, and high level JavaScript API.
https://prismarinejs.github.io/mineflayer/
MIT License
4.95k stars 904 forks source link

swingInterval in digging plugin does not stop #1736

Open SinanAkkoyun opened 3 years ago

SinanAkkoyun commented 3 years ago

Versions

Detailed description of a problem

When using the dig block, the bot often just keeps swinging its arm.

Happens in every example.

sefirosweb commented 3 years ago

In my case I saw that issue when bot is changing of target while is digging,

I think is a small issue of pathfinder

SinanAkkoyun commented 3 years ago

Oh thank you for the info! But it seems they even implemented a timeout for that, but somehow it apparently doesn't work

sefirosweb commented 3 years ago

Correct, I wanted to say that the bug is inside pathfinder, maybe you can't fix from you code =P

SinanAkkoyun commented 3 years ago

Correct, I wanted to say that the bug is inside pathfinder, maybe you can't fix from you code =P

I know, I will take a look inside the pathfinder and maybe do a PR of I figure out how to do one

SinanAkkoyun commented 3 years ago

I mean I think the bug pies within mineflayer, because as far as I know the pathfinder does not execute "swing", just "dig"

SinanAkkoyun commented 3 years ago

Why was this closed? This is still an issue, or did it get fixed?

rom1504 commented 3 years ago

this is something in pathfinder not mineflayer open an issue there if it still affects you

Karang commented 3 years ago

no its not, pathfinder calls mineflayer's dig.

SinanAkkoyun commented 3 years ago

I wanted to say, I looked at the source and this issue is at the right place

rom1504 commented 3 years ago

ok, to be clear: this is not an issue with mineflayer. And probably also not with pathfinder. Do you have an example that reproduces the problem ?

SinanAkkoyun commented 3 years ago

It probably does not cancel the swingArm interval

I tried many codes.

Just take the provided collect block example and let it collect >60 blocks and it should be swinging afterwards. If it doesn't (but it does for me), try to send another collect command while the bot is trying to collect the old ones.

rom1504 commented 3 years ago

that sounds like a bug with collect block. do you mean https://github.com/PrismarineJS/mineflayer-collectblock/blob/master/examples/collector.js ?

SinanAkkoyun commented 3 years ago

Well no, as far as I understood it the collectblock plugin just calls the dig function of mineflayer which has the swing interval inside of it, which doesn't stop.

rom1504 commented 3 years ago

most likely dig is called several time without waiting for the previous one to finish that's a bug in collect bog / your code / pathfinder

we could try to protect against such bug in user code in mineflayer

rom1504 commented 3 years ago

you can try to move this line https://github.com/PrismarineJS/mineflayer/blob/88bbca227386e4bef378eecd954233fa2ee1f933/lib/plugins/digging.js#L96 to there https://github.com/PrismarineJS/mineflayer/blob/88bbca227386e4bef378eecd954233fa2ee1f933/lib/plugins/digging.js#L27

and try again

however if you don't provide any specific code example to reproduce the issue, there's not much we can do for you here

SinanAkkoyun commented 3 years ago

I will, thank you so much

rom1504 commented 3 years ago

can you try again now ?

SinanAkkoyun commented 3 years ago

I am studying atm, in 3 weeks I can

flowl commented 3 years ago

I've had the same problem: https://github.com/PrismarineJS/mineflayer/issues/1631

IMO, that bug is in the dig() function. When you switch from digging to something else too fast, the swing interval does never get cleared.

The problem occurs very quickly when you combine pathfinder and digging, because pathfinder itself sometimes digs a block too on its way.

There should be a ghettolock in the dig function because even with async programing, it's not possible to dig two blocks at the same time. You can ever only dig one block after the other.

rom1504 commented 3 years ago

There already is a "lock" but would be useful to add tests for it so we know if it needs fixing