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

Bot does not actually activate button #841

Closed FoamyTheFag closed 4 years ago

FoamyTheFag commented 5 years ago

I am trying to make a bot so that when whispered "press" in game, it presses the nearest button.

My code: https://pastebin.com/mGGCSTCS

Everything seems to work well, the bot will look at the nearest button and swing, but the button itself does not depress/activate. This would make the bot pointless, as without the button depressing there's no redstone current caused by it etc etc.

rom1504 commented 5 years ago

Try to identify the correct packet that should be sent using node-minecraft-protocol proxy and doing the same action within the vanilla client. Then you can use that packet for your bot.

On Fri, Aug 2, 2019, 22:26 FoamyTheFag notifications@github.com wrote:

I am trying to make a bot so that when whispered "press" in game, it presses the nearest button.

My code: https://pastebin.com/mGGCSTCS

Everything seems to work well, the bot will look at the nearest button and swing, but the button itself does not depress/activate. This would make the bot pointless, as without the button depressing there's no redstone current caused by it etc etc.

— You are receiving this because you are subscribed to this thread. Reply to this email directly, view it on GitHub https://github.com/PrismarineJS/mineflayer/issues/841?email_source=notifications&email_token=AAR437UYUA5FPHANTRTA7KTQCSKA7A5CNFSM4IJAZVXKYY3PNVWWK3TUL52HS4DFUVEXG43VMWVGG33NNVSW45C7NFSM4HDENQPA, or mute the thread https://github.com/notifications/unsubscribe-auth/AAR437TCS25GXXCECBNZAALQCSKA7ANCNFSM4IJAZVXA .

FoamyTheFag commented 5 years ago

client<-server: play.block_change :{"location":{"x":832,"y":53,"z":58},"type":1244} client<-server: play.block_change :{"location":{"x":832,"y":53,"z":57},"type":0} client<-server: play.block_change :{"location":{"x":832,"y":53,"z":58},"type":1244} client<-server: play.block_change :{"location":{"x":832,"y":53,"z":58},"type":1236} These 4 packets always get sent when a button is pressed, and I believe type 1244 is the one I need to use for my bot. I tried doing a quick look around, and I couldn't find any decent examples for how to implement packets into bots.

rom1504 commented 5 years ago

Those are packets sent from the server, to the client as indicated by client<-server notation You need to find the packets sent by the client for this.

If you send a packet you can use bot._client.write({the packet})

On Tue, Aug 20, 2019, 00:01 FoamyTheFag notifications@github.com wrote:

client<-server: play.block_change :{"location":{"x":832,"y":53,"z":58},"type":1244} client<-server: play.block_change :{"location":{"x":832,"y":53,"z":57},"type":0} client<-server: play.block_change :{"location":{"x":832,"y":53,"z":58},"type":1244} client<-server: play.block_change :{"location":{"x":832,"y":53,"z":58},"type":1236} These 4 packets always get sent when a button is pressed, and I believe type 1244 is the one I need to use for my bot. I tried doing a quick look around, and I couldn't find any decent examples for how to implement packets into bots.

— You are receiving this because you commented. Reply to this email directly, view it on GitHub https://github.com/PrismarineJS/mineflayer/issues/841?email_source=notifications&email_token=AAR437W5VB55SWSEDFQPRLDQFMJ4BA5CNFSM4IJAZVXKYY3PNVWWK3TUL52HS4DFVREXG43VMVBW63LNMVXHJKTDN5WW2ZLOORPWSZGOD4UNVGY#issuecomment-522771099, or mute the thread https://github.com/notifications/unsubscribe-auth/AAR437WRPCTJ4NOGFT44ITLQFMJ4BANCNFSM4IJAZVXA .

FoamyTheFag commented 5 years ago

Is there something I have to do with my proxy, as I only saw client<-server packets.

Edit: Nevermind I'm just blind

rom1504 commented 5 years ago

0 client to server packet ? Can you paste the log ?

On Tue, Aug 20, 2019, 17:20 FoamyTheFag notifications@github.com wrote:

Is there something I have to do with my proxy, as I only saw client<-server packets.

— You are receiving this because you commented. Reply to this email directly, view it on GitHub https://github.com/PrismarineJS/mineflayer/issues/841?email_source=notifications&email_token=AAR437U3YZEW3SGBOGR2GYLQFQDTVA5CNFSM4IJAZVXKYY3PNVWWK3TUL52HS4DFVREXG43VMVBW63LNMVXHJKTDN5WW2ZLOORPWSZGOD4WVFSA#issuecomment-523064008, or mute the thread https://github.com/notifications/unsubscribe-auth/AAR437WQRDXUH2HF5QFCD3DQFQDTVANCNFSM4IJAZVXA .

FoamyTheFag commented 5 years ago

I just misread, I've identified 2 packets that get sent when a player presses a button that my bot does not send, those 2 being: client->server: play block_place : {"location":{"x":830,"y":53,"z":62},"direction":3,"heldItem":{"blockId":-1},"cursorX":6,"cursorY":7,"cursorZ":2} and client->server: play arm_animation : {}

I understand that the arm_animation packet isn't necessary, but it seems like a good packet for my to try to send as it doesn't seem complicated.

I added bot._client.write(packet.arm_animation) to my code, but whenever it gets run, the bot just crashes.

rom1504 commented 5 years ago

Well if you look at the code activateBlock sends exactly these 2 packets. Check if your bot is really calling that function. To send a packet, you have the wrong syntax. Look at node-minecraft-protocol examples or mineflayer code to see what's the right syntax Here is an example : bot._client.write('some_packet', {field1: "some value"})

On Tue, Aug 20, 2019, 19:22 FoamyTheFag notifications@github.com wrote:

I just misread, I've identified 2 packets that get sent when a player presses a button that my bot does not send, those 2 being: client->server: play block_place : {"location":{"x":830,"y":53,"z":62},"direction":3,"heldItem":{"blockId":-1},"cursorX":6,"cursorY":7,"cursorZ":2} and client->server: play arm_animation : {}

I understand that the arm_animation packet isn't necessary, but it seems like a good packet for my to try to send as it doesn't seem complicated.

I added bot._client.write(packet.arm_animation) to my code, but whenever it gets run, the bot just crashes.

— You are receiving this because you commented. Reply to this email directly, view it on GitHub https://github.com/PrismarineJS/mineflayer/issues/841?email_source=notifications&email_token=AAR437RCP66Q6XOGFNUVHSDQFQR4XA5CNFSM4IJAZVXKYY3PNVWWK3TUL52HS4DFVREXG43VMVBW63LNMVXHJKTDN5WW2ZLOORPWSZGOD4XBDXY#issuecomment-523112927, or mute the thread https://github.com/notifications/unsubscribe-auth/AAR437W7OOMEFGPH5O6Q3QTQFQR4XANCNFSM4IJAZVXA .

FoamyTheFag commented 5 years ago

Ok so I found the source for activateBlock, so I decided to to stop using activateBlock and just write in the packets into my code for testing purposes. I stood in the same position as my bot, pressed a button, and got this packet:

client->server: play block_place : {"location":{"x":830,"y":53,"z":65},"direction":1,"heldItem":{"blockId":-1},"cursorX":9,"cursorY":10,"cursorZ":14}

So I decided to try to get my bot to replicate and send that packet as well.

My code:

`function press () { const button = bot.findBlock({ matching: 77 })

if (!button) {
    return bot.chat('There are no nearby buttons!')
}

bot.lookAt(button.position.offset(0.5, 0.5, 0.5), false,function(){
    bot._client.write('arm_animation', {});
    bot._client.write('block_place', {
        location: button.position,
        direction: 1,
        heldItem: Item.toNotch(bot.heldItem),
        cursorX: 9,
        cursorY: 10,
        cursorZ: 14
    });
});

}`

And the packet sent by press() being called is exactly the same as the one sent by me just pressing the button, but the button still does not depress and redstone still does not activate when press() is called.

node proxy.js --dump-all -x keep_alive -x update_time -x entity_velocity -x rel_entity_move -x entity_look -x entity_move_look -x entity_teleport -x entity_head_rotation -x position -x flying -x look -x player_info -x position_look -x spawn_entity_living -x map_chunk_bulk -x custom_payload -x map_chunk -x update_attributes -x chat -x multi_block_change -x entity_metadata -x named_sound_effect -x entity_equipment -x entity_destroy localhost 1.8

The above is my proxy run command, and I don't believe any of the options leave out packets important to this. Only reason I include it is because I see no other packets sent from the client to the server besides block_place, and obviously swing_arm.

rom1504 commented 5 years ago

What is bot.heldItem value ? The packet you see with the proxy seems to be sending -1

You cannot test this on a normal vanilla server right ?

It's possible that some of the packets you excluded have some influence, I'm not sure what the plugins this server has are doing

On Tue, Aug 20, 2019, 21:39 FoamyTheFag notifications@github.com wrote:

Ok so I found the source for activateBlock, so I decided to to stop using activateBlock and just write in the packets into my code for testing purposes. I stood in the same position as my bot, pressed a button, and got this packet:

client->server: play block_place : {"location":{"x":830,"y":53,"z":65},"direction":1,"heldItem":{"blockId":-1},"cursorX":9,"cursorY":10,"cursorZ":14}

So I decided to try to get my bot to replicate and send that packet as well.

My code:

`function press () { const button = bot.findBlock({ matching: 77 })

if (!button) { return bot.chat(There are no nearby buttons!) }

bot.lookAt(button.position.offset(0.5, 0.5, 0.5), false,function(){ bot._client.write('arm_animation', {}); bot._client.write('block_place', { location: button.position, direction: 1, heldItem: Item.toNotch(bot.heldItem), cursorX: 9, cursorY: 10, cursorZ: 14 }); });

}`

And the packet sent by press() being called is exactly the same as the one sent by me just pressing the button, but the button still does not depress and redstone still does not activate when press() is called.

node proxy.js --dump-all -x keep_alive -x update_time -x entity_velocity -x rel_entity_move -x entity_look -x entity_move_look -x entity_teleport -x entity_head_rotation -x position -x flying -x look -x player_info -x position_look -x spawn_entity_living -x map_chunk_bulk -x custom_payload -x map_chunk -x update_attributes -x chat -x multi_block_change -x entity_metadata -x named_sound_effect -x entity_equipment -x entity_destroy localhost 1.8

The above is my proxy run command, and I don't believe any of the options leave out packets important to this. Only reason I include it is because I see no other packets sent from the client to the server besides block_place, and obviously swing_arm.

— You are receiving this because you commented. Reply to this email directly, view it on GitHub https://github.com/PrismarineJS/mineflayer/issues/841?email_source=notifications&email_token=AAR437VWGNCJ6CIGMB64NPLQFRCATA5CNFSM4IJAZVXKYY3PNVWWK3TUL52HS4DFVREXG43VMVBW63LNMVXHJKTDN5WW2ZLOORPWSZGOD4XNX4Y#issuecomment-523164659, or mute the thread https://github.com/notifications/unsubscribe-auth/AAR437VG36K6IPE3TMVCVSDQFRCATANCNFSM4IJAZVXA .

FoamyTheFag commented 5 years ago

This is on a completely vanilla, localhost, server. All I did was double click server.jar, and enable EULA, nothing else.

I believe the value is -1 because the hand is empty, the value was 77 when I did tests holding a button, which has an item id of 77.

rom1504 commented 5 years ago

can you share your last code reproducing the issue ?

FoamyTheFag commented 5 years ago

https://pastebin.com/z6cA6HaS

FoamyTheFag commented 5 years ago

Bump

rom1504 commented 5 years ago

Try to compare with what the vanilla client is doing (use node-minecraft-protocol proxy for that)

On Sat, Aug 31, 2019, 08:15 FoamyTheFag notifications@github.com wrote:

Bump

— You are receiving this because you commented. Reply to this email directly, view it on GitHub https://github.com/PrismarineJS/mineflayer/issues/841?email_source=notifications&email_token=AAR437TH6TAEQDJ5NPTWNFTQHIEA5A5CNFSM4IJAZVXKYY3PNVWWK3TUL52HS4DFVREXG43VMVBW63LNMVXHJKTDN5WW2ZLOORPWSZGOD5TGMKI#issuecomment-526804521, or mute the thread https://github.com/notifications/unsubscribe-auth/AAR437QCXCZCOSQKAAZGPBTQHIEA5ANCNFSM4IJAZVXA .

FoamyTheFag commented 5 years ago

I did, the packets getting sent are exactly the same as from the vanilla client.

rom1504 commented 5 years ago

not possible, you must have missed something. Can you post both logs please ? (vanilla and mineflayer using debug mode)

On Sat, Aug 31, 2019 at 4:42 PM FoamyTheFag notifications@github.com wrote:

I did, the packets getting sent are exactly the same as from the vanilla client.

— You are receiving this because you commented. Reply to this email directly, view it on GitHub https://github.com/PrismarineJS/mineflayer/issues/841?email_source=notifications&email_token=AAR437SPHGLLMEQY23FRHEDQHJ7LTA5CNFSM4IJAZVXKYY3PNVWWK3TUL52HS4DFVREXG43VMVBW63LNMVXHJKTDN5WW2ZLOORPWSZGOD5TOBIY#issuecomment-526835875, or mute the thread https://github.com/notifications/unsubscribe-auth/AAR437STUOMPESXQFHEOIW3QHJ7LTANCNFSM4IJAZVXA .

1by commented 4 years ago

Is this still an issue? I can help if needed.