pyCraft icon indicating copy to clipboard operation
pyCraft copied to clipboard

Which packet to use to destroy blocks? And How?

Open AlexandrMilko opened this issue 4 years ago • 1 comments

Hi, I want my bot to be able to destroy blocks. I have tried BlockChangePacket, which is in minecraft.networking.packets.clientbound.play, but I haven't got it working. So, I would like to know 1) How do I make my bot destroy blocks, and idealy, 2) How to work with BlockChangePacket? Thanks! :)

AlexandrMilko avatar Jan 09 '21 22:01 AlexandrMilko

Yea! I got it! Here is the answer:

  1. Create a dig packet class:
class DigPacket(Packet):
    id = 0x1B
    packet_name = 'Player Digging'
    definition = [{'status': VarInt}, {'location': Position}, {'face': Byte}]
  1. Send this packet with status "started digging"(this and other parameters you can find here https://wiki.vg/Protocol#Player_Digging)(You can see a part from bot's class digging method below):
self.packet = DigPacket()
self.packet.status = 0
self.packet.location = Position(
                                x=block_coordinate_x, 
                                y=block_coordinate_y, 
                                z=block_coordinate_z
                                )
self.packet.face = 1
self.connection.write_packet(self.packet)
  1. Set a delay(i am not sure if this is needed, but it worked for me with a bot holding diamond shovel digging grass block)(AND DON'T FORGET TO IMPORT time MODULE!): time.sleep(0.2)
  2. Send the same packet, but with status "finished digging": self.packet.status = 2 self.connection.write_packet(self.packet)

Be OK to ask questions!

AlexandrMilko avatar Jan 11 '21 21:01 AlexandrMilko

That's good. But it is not an issue.

Cassy-Lee avatar Apr 22 '23 07:04 Cassy-Lee