Merge pull request #10 from TargetedEntropy/tab_error

Rolling back tab completion for now
This commit is contained in:
TargetedEntropy 2023-03-23 16:03:08 -04:00 committed by GitHub
commit 4a7276a149
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
9 changed files with 153 additions and 12 deletions

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,26 @@ 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,
QueryBlockNBTPacket
}
if context.protocol_later_eq(69):
packets |= {
@ -38,11 +43,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
@ -321,3 +327,15 @@ class ResourcePackStatusPacket(Packet):
definition = [
{"result": VarInt}
]
class QueryBlockNBTPacket(Packet):
@staticmethod
def get_id(context):
return 0x01
packet_name = "query block nbt"
definition = [
{"transaction_id": VarInt},
{"location": Position}
]

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')

View File

View File

@ -0,0 +1,14 @@
from minecraft.networking.packets.serverbound.play import PlayerBlockPlacementPacket
from minecraft.networking.types import Position
def place_block(connection, x: int, y: int, z: int):
packet = PlayerBlockPlacementPacket()
packet.location = Position(x=x, y=y, z=z)
packet.face = packet.Face.TOP # See networking.types.BlockFace.
packet.hand = packet.Hand.MAIN # See networking.types.RelativeHand.
packet.inside_block = False
packet.x = 0.5
packet.y = 0.5
packet.z = 0.5
connection.write_packet(packet)

View File

@ -0,0 +1,10 @@
from minecraft.networking.connection import Connection
from minecraft.networking.packets.serverbound.play import QueryBlockNBTPacket
from minecraft.networking.types import Position
def query_block(connection: Connection, location: list[3], transaction_id):
block_packet = QueryBlockNBTPacket()
block_packet.transaction_id = transaction_id
block_packet.location = Position(x=int(location[0]), y=int(location[1]), z=int(location[2]))
connection.write_packet(block_packet, force=True)

View File

@ -0,0 +1,7 @@
from minecraft.networking.packets.serverbound.play import ChatPacket
def send_message(connection, message):
message_packet = ChatPacket()
message_packet.message = message
connection.write_packet(message_packet, force=True)

View File

@ -0,0 +1,20 @@
from minecraft.networking.connection import Connection
from minecraft.networking.packets.serverbound.play import PositionAndLookPacket
def calculate_distance(start, end):
ans = 0
for i in range(3):
ans += (start[i] - float(end[i])) * (start[i] - float(end[i]))
return ans, [float(end[i]) - start[i] for i in range(3)]
def player_move(connection: Connection, destination, rotation):
pos_packet = PositionAndLookPacket()
pos_packet.x = float(destination[0])
pos_packet.feet_y = float(destination[1])
pos_packet.z = float(destination[2])
pos_packet.yaw = rotation[0]
pos_packet.pitch = rotation[1]
pos_packet.on_ground = True
connection.write_packet(pos_packet, force=True)