pyCraft
pyCraft copied to clipboard
cant send position pakets
i am working a a bot when i run
` def crot(self, x, y):
pos_look = PositionAndLook()
pos_look.look = x, y
self.connection.write_packet(serverbound.play.PositionAndLookPacket(
position_and_look=pos_look, on_ground=True,
))`
i get
Traceback (most recent call last): File "C:\Users\username\Desktop\server\sjoin.py", line 26, in <module> pla.crot(random.randrange(1, 180), random.randrange(1, 180)) File "C:\Users\username\Desktop\server\test1.py", line 86, in crot self.connection.write_packet(serverbound.play.PositionAndLookPacket( File "C:\Users\username\Desktop\server\minecraft\networking\packets\packet.py", line 37, in __init__ self.set_values(**kwargs) File "C:\Users\username\Desktop\server\minecraft\networking\packets\packet.py", line 58, in set_values setattr(self, key, value) File "C:\Users\username\Desktop\server\minecraft\networking\types\utility.py", line 134, in alias for name, value in zip(arg_names, values): File "C:\Users\username\Desktop\server\minecraft\networking\types\utility.py", line 83, in <genexpr> return iter(getattr(self, a) for a in self._all_slots()) AttributeError: x
i cant send PositionAndLookPacket with out getting this error
It is the x and z coordinates that correspond to the horizontal axis. The y axis is vertical, and in terms of this packet is called feet_y
, not y
. This is because it refers to your player's y position at their feet. Absolute feet position, normally Head Y - 1.62
. In the second line, you are setting the PositionAndLook's pitch+yaw (look) and not the position part. You would need to change this to pos_look.position
instead, and set the look attribute to another intended value
In the last line, you go to write a PositionAndLookPacket
to the connection's packet buffer. That's great, but an AttributeError occurs, because the packet you are ultimately trying to send does not have the required 'x' attribute set. This seems like it could be a common error, and I do believe this should be made a bit clearer, potentially through raising a custom error.
However, do note that you are also missing several other required attributes for the packet to be written to the server, or else this error would continue to persist. https://github.com/ammaraskar/pyCraft/blob/ff9a0813b64a0afdf3cd089ad9000350bb4122bc/minecraft/networking/packets/serverbound/play/init.py#L94-L100
An example of what you could do to fix this:
def send_position_and_look_packet(x, feet_y, z, yaw, pitch, on_ground):
packet = serverbound.play.PositionAndLookPacket()
packet.position = x, feet_y, z
packet.look = yaw, pitch
packet.on_ground = on_ground
connection.write_packet(packet)