pyCraft
pyCraft copied to clipboard
Which packet to use to destroy blocks? And How?
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! :)
Yea! I got it! Here is the answer:
- Create a dig packet class:
class DigPacket(Packet):
id = 0x1B
packet_name = 'Player Digging'
definition = [{'status': VarInt}, {'location': Position}, {'face': Byte}]
- 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)
- 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) - Send the same packet, but with status "finished digging":
self.packet.status = 2self.connection.write_packet(self.packet)
Be OK to ask questions!
That's good. But it is not an issue.