Packet fix work and moving char

This commit is contained in:
Brian Merriam 2023-03-22 03:10:07 +00:00
parent 93a0b69221
commit 52bc61a361
5 changed files with 128 additions and 17 deletions

View File

@ -9,6 +9,7 @@ from minecraft import authentication
from minecraft.exceptions import YggdrasilError
from minecraft.networking.connection import Connection
from minecraft.networking.packets import Packet, clientbound, serverbound
from minecraft.networking.types import Vector
def get_options():
@ -182,17 +183,50 @@ def main():
connection.register_packet_listener(
print_chat, clientbound.play.ChatMessagePacket)
def print_location(location_packet):
print(
"MapPacket (%s): %s"
% (location_packet.field_string("position"), location_packet.json_data)
)
connection.register_packet_listener(
print_location, clientbound.play.MapPacket)
current_x_pos = float(-7.5)
def print_postion(postion_packet):
global current_x_pos
current_x_pos = postion_packet.x
print(
"PositionPacket (%s): %s"
% (postion_packet.field_string("position"), postion_packet.x)
)
connection.register_packet_listener(
print_postion, clientbound.play.PlayerPositionAndLookPacket
)
connection.connect()
count = 0
while True:
try:
text = input()
if text == "/respawn":
print("respawning...")
packet = serverbound.play.ClientStatusPacket()
packet.action_id = serverbound.play.ClientStatusPacket.RESPAWN
connection.write_packet(packet)
if text == "test":
print(f"Testing, currentpos: {current_x_pos}")
new_x = float(current_x_pos + 0.5)
pos_packet = serverbound.play.PositionAndLookPacket()
pos_packet.x = new_x
pos_packet.feet_y = float(68.0)
pos_packet.z = float(-1.5)
pos_packet.yaw = 0.0
pos_packet.pitch = 0.0
pos_packet.on_ground = False
connection.write_packet(pos_packet, force=True)
current_x_pos = new_x
else:
print(f"Count2: {count}")
packet = serverbound.play.ChatPacket()
packet.message = text
connection.write_packet(packet)

View File

@ -87,11 +87,11 @@ def get_packets(context):
packets |= {
FacePlayerPacket,
}
if context.protocol_later_eq(345) or \
context.protocol_earlier_eq(342):
packets |= {
TabCompletePacket,
}
# if context.protocol_later_eq(345) or \
# context.protocol_earlier_eq(342):
# packets |= {
# TabCompletePacket,
# }
return packets

View File

@ -9,21 +9,25 @@ from minecraft.networking.types import (
)
from .client_settings_packet import ClientSettingsPacket
from .tab_complete_packet import TabCompletePacket
# from .tab_complete_packet import TabCompletePacket
from .use_entity_packet import UseEntityPacket
from .vehicle_move_packet import VehicleMovePacket
from .player_position_packet import PlayerPositionPacket
# Formerly known as state_playing_serverbound.
def get_packets(context):
packets = {
KeepAlivePacket,
ChatPacket,
PlayerPositionPacket,
PositionAndLookPacket,
AnimationPacket,
ClientStatusPacket,
ClientSettingsPacket,
PluginMessagePacket,
PlayerBlockPlacementPacket,
UseEntityPacket
UseEntityPacket,
VehicleMovePacket
}
if context.protocol_later_eq(69):
packets |= {
@ -38,11 +42,12 @@ def get_packets(context):
TeleportConfirmPacket,
}
# For some reason this packet did not exist on protocols 343 & 344.
if context.protocol_later_eq(345) or \
context.protocol_earlier_eq(342):
packets |= {
TabCompletePacket,
}
# if context.protocol_later_eq(345) or \
# context.protocol_earlier_eq(342):
# packets |= {
# TabCompletePacket,
# }
return packets

View File

@ -0,0 +1,33 @@
from minecraft.networking.packets import Packet
from minecraft.networking.types import (
Double, Float, Boolean, Vector, multi_attribute_alias
)
class PlayerPositionPacket(Packet):
@staticmethod
def get_id(context):
return 0x11 if context.protocol_version >= 471 else \
0x12 if context.protocol_version >= 464 else \
0x10 if context.protocol_version >= 389 else \
0x0E if context.protocol_version >= 386 else \
0x0D if context.protocol_version >= 345 else \
0x0C if context.protocol_version >= 343 else \
0x0D if context.protocol_version >= 336 else \
0x0E if context.protocol_version >= 332 else \
0x0D if context.protocol_version >= 318 else \
0x0C if context.protocol_version >= 94 else \
0x0B if context.protocol_version >= 70 else \
0x04
packet_name = "player position"
definition = [
{'x': Double},
{'feet_y': Double},
{'z': Double},
{'on_ground': Boolean}
]
# The code under this line was copied from the packets/clientbound/play/player_position_and_look_packet.py
# Access the 'x', 'y', 'z' fields as a Vector tuple.
position = multi_attribute_alias(Vector, 'x', 'feet_y', 'z')

View File

@ -0,0 +1,39 @@
from minecraft.networking.packets import Packet
from minecraft.networking.types import (
Double, Float, Vector, multi_attribute_alias, Direction, PositionAndLook
)
class VehicleMovePacket(Packet):
@staticmethod
def get_id(context):
return 0x15 if context.protocol_version >= 464 else \
0x13 if context.protocol_version >= 389 else \
0x11 if context.protocol_version >= 386 else \
0x10 if context.protocol_version >= 345 else \
0x0F if context.protocol_version >= 343 else \
0x10 if context.protocol_version >= 336 else \
0x11 if context.protocol_version >= 318 else \
0x10
packet_name = "vehicle move"
definition = [
{'x': Double},
{'y': Double},
{'z': Double},
{'yaw': Float},
{'pitch': Float}
]
# The code under this line was copied from the packets/clientbound/play/player_position_and_look_packet.py
# Access the 'x', 'y', 'z' fields as a Vector tuple.
position = multi_attribute_alias(Vector, 'x', 'y', 'z')
# Access the 'yaw', 'pitch' fields as a Direction tuple.
look = multi_attribute_alias(Direction, 'yaw', 'pitch')
# Access the 'x', 'y', 'z', 'yaw', 'pitch' fields as a PositionAndLook.
# NOTE: modifying the object retrieved from this property will not change
# the packet; it can only be changed by attribute or property assignment.
position_and_look = multi_attribute_alias(
PositionAndLook, 'x', 'y', 'z', 'yaw', 'pitch')