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

Block mining updates #11

Open
deathcap opened this issue Mar 26, 2015 · 14 comments
Open

Block mining updates #11

deathcap opened this issue Mar 26, 2015 · 14 comments

Comments

@deathcap
Copy link
Member

Send mined blocks to the server

@deathcap
Copy link
Member Author

This probably requires GH-10 Client positioning, since the server won't let clients mine any arbitrary block (must be within a certain radius?)

@rom1504
Copy link

rom1504 commented Mar 27, 2015

I think the radius is 6 blocks.

@deathcap
Copy link
Member Author

yup, from http://wiki.vg/Protocol#Player_Digging:

Player Digging
Sent when the player mines a block. A Notchian server only accepts digging packets with coordinates within a 6-unit radius of the player's position.

for now, testing with /tp webuser-1 player to position the web client where it can legitimately mine blocks.

mineflayer has a digging API: https://github.com/andrewrk/mineflayer/blob/427eb934e0ccb391f7af01e3186a65be57fd10c7/lib/plugins/digging.js#L13 - implements dig(block,cb) and stopDigging(), experimenting with forwarding from voxel-reach 'stop mining' / 'stop mining' events.

@deathcap
Copy link
Member Author

Added showing server-side block destroy animations (from other players) as of 26891ae, some progress on client block digging. Calling from voxel-reach start mining event:

  self.digStart = function(event) {
    var block = self.bot.blockAt(vec3Object(event.position[0], event.position[1], event.position[2]));
    if (!block) return;
    self.bot.dig(block, function(err) {
      console.log('dig:',err);
    });

but the digging is interrupted:

start mining Object {voxel: Array[3], adjacent: Array[3], side: "top", sub: Array[2], normal: Array[3]…}
blob:http%3A//localhost%3A9966/27e26042-4e1b-4582-b0e2-66db7cc635e1:25987 blockUpdate Block {type: 3, metadata: 0, light: 0, skyLight: 15, biome: Biome…} Block {type: 3, metadata: 0, light: 0, skyLight: 15, biome: Biome…}
blob:http%3A//localhost%3A9966/27e26042-4e1b-4582-b0e2-66db7cc635e1:26207 dig: Error: digging interruption {code: "EDIGINTERRUPT", stack: (...), message: "digging interruption"}
clientmc.js:423 stop mining Object {voxel: Array[3], adjacent: Array[3], side: "top", sub: Array[2], normal: Array[3]…}
clientmc.js:417 start mining Object {voxel: Array[3], adjacent: Array[3], side: "top", sub: Array[2], normal: Array[3]…}
blob:http%3A//localhost%3A9966/27e26042-4e1b-4582-b0e2-66db7cc635e1:25987 blockUpdate Block {type: 3, metadata: 0, light: 0, skyLight: 15, biome: Biome…} Block {type: 3, metadata: 0, light: 0, skyLight: 15, biome: Biome…}
blob:http%3A//localhost%3A9966/27e26042-4e1b-4582-b0e2-66db7cc635e1:26207 dig: Error: digging interruption {code: "EDIGINTERRUPT", stack: (...), message: "digging interruption"}
clientmc.js:423 stop mining Object {voxel: Array[3], adjacent: Array[3], side: "top", sub: Array[2], normal: Array[3]…}
clientmc.js:423 stop mining Object {voxel: Array[3], adjacent: Array[3], side: "top", sub: Array[2], normal: Array[3]…}

deathcap added a commit that referenced this issue Mar 30, 2015
Updating voxel-use for usedBlock event
@rom1504
Copy link

rom1504 commented Apr 1, 2015

sounds like you are doing something before digging is over (it takes some time)

@deathcap
Copy link
Member Author

deathcap commented Apr 3, 2015

Yeah I have my own logic on the client-side for block 'hardness' = mining time, I think it is shorter than the server expects which may be causing these conflicts.

@rom1504
Copy link

rom1504 commented Apr 3, 2015

if you need that time, you may want to use that function https://github.com/andrewrk/mineflayer/blob/master/lib/plugins/digging.js#L91

@deathcap
Copy link
Member Author

deathcap commented Feb 7, 2016

Since have changed to use mineflayer dig() API:

  self.digStart = function(event) {
    var block = self.bot.blockAt(vec3Object(event.position[0], event.position[1], event.position[2]));
    if (!block) return;
    self.bot.dig(block, function(err) {
      console.log('dig:',err);
    });

I think this was working in ~1.8.3, but am encountering issues with 1.8.9 (after the nmp 0.16 update + various other updates #16), the client looks like it continues digging:

screen shot 2016-02-06 at 7 10 40 pm

the client (voxel.js side) logs start mining / stop mining events and shows the (client-side) block break animation, but something wrong with the interaction with mineflayer digging

@deathcap
Copy link
Member Author

deathcap commented Feb 7, 2016

start/stop mining (voxel.js, or more specifically voxel-mine events) is seemingly triggered repeatedly - this is for holding down the left mouse button once:

start mining Object {voxel: Array[3], adjacent: Array[3], side: "top", sub: Array[2], normal: Array[3]…}
clientmc.js:532 stop mining Object {voxel: Array[3], adjacent: Array[3], side: "top", sub: Array[2], normal: Array[3]…}
clientmc.js:526 start mining Object {voxel: Array[3], adjacent: Array[3], side: "top", sub: Array[2], normal: Array[3]…}
clientmc.js:532 stop mining Object {voxel: Array[3], adjacent: Array[3], side: "top", sub: Array[2], normal: Array[3]…}
clientmc.js:532 stop mining Object {voxel: Array[3], adjacent: Array[3], side: "top", sub: Array[2], normal: Array[3]…}

@deathcap
Copy link
Member Author

deathcap commented Feb 7, 2016

Actually this works (able to mine blocks, pickup the item drops, and place blocks), the failure I was seeing was caused by the client being located in the spawn area and not having permission to mine (fixed by /op webuser-1). Still could handle this failure case better.

@deathcap
Copy link
Member Author

deathcap commented Feb 7, 2016

Mining is implement as: start mining, causes mineflayer to dig(), which itself handles continuously mining until the block is broken. So you only need to tap left-click once on a block, and it will be mined (after waiting a while).

Should really switch to lower-level API, maybe using packets directly, to properly translate the start/stop mining events to MC.

@deathcap
Copy link
Member Author

deathcap commented Feb 8, 2016

http://wiki.vg/Protocol#Player_Digging packet: 0=started digging, 1=canceled, 2=finished

mineflayer digging: https://github.com/PrismarineJS/mineflayer/blob/master/lib/plugins/digging.js - sends block_dig with status=0 (start digging), arm_animation every 350 ms (seems to go on too long? at least here), then block_dig with status=2 (finished) after waiting block digTime

@deathcap
Copy link
Member Author

deathcap commented Feb 8, 2016

Bugs in current implementation (unclear if in mineflayer or voxel-clientmc): arm swings continuously, sometimes hits PrismarineJS/mineflayer#305 TypeError: Cannot read property 'position' of null in lib/plugins/digging.js:72 location: bot.targetDigBlock.position

@deathcap
Copy link
Member Author

Since block mining updates are sent, closing this issue as written, but new issue for improving the behavior: #51

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

2 participants