voxel / voxel-clientmc

Minecraft client using WebSockets and voxel-engine (voxel.js plugin)
57 stars 13 forks source link

Block mining updates #11

Open deathcap opened 9 years ago

deathcap commented 9 years ago

Send mined blocks to the server

deathcap commented 9 years ago

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 commented 9 years ago

I think the radius is 6 blocks.

deathcap commented 9 years ago

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 commented 9 years ago

Added showing server-side block destroy animations (from other players) as of https://github.com/deathcap/voxel-clientmc/commit/26891ae3661bd0d3fb975528f9c47494c8a5a0b6, 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]…}

rom1504 commented 9 years ago

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

deathcap commented 9 years ago

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 commented 9 years ago

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 commented 8 years ago

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 https://github.com/voxel/voxel-clientmc/pull/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 commented 8 years ago

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 commented 8 years ago

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 commented 8 years ago

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 commented 8 years ago

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 commented 8 years ago

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

deathcap commented 8 years ago

Since block mining updates are sent, closing this issue as written, but new issue for improving the behavior: https://github.com/voxel/voxel-clientmc/issues/51