Compare commits
No commits in common. "6b2df0c27e0c5f24ab4c861e58c17455dd8467b0" and "43f4eb3517baa936b1bd2195d7d25fab8077b9e1" have entirely different histories.
6b2df0c27e
...
43f4eb3517
30
game.py
30
game.py
|
@ -10,17 +10,7 @@ from panda3d.core import LPoint3f
|
|||
from minecraft.networking.packets import Packet, clientbound, serverbound
|
||||
from minecraft.networking.types import BlockFace
|
||||
|
||||
from protocol.packets import (
|
||||
TimeUpdatePacket, SetSlotPacket, PlayerDiggingPacket,
|
||||
BlockBreakAnimationPacket, AcknowledgePlayerDiggingPacket,
|
||||
HeldItemChangePacket, PickItemPacket, OpenWindowPacket,
|
||||
ClickWindowPacket, CloseWindowPacket, ServerWindowConfirmationPacket,
|
||||
ClientWindowConfirmationPacket, EntityMetadataPacket,
|
||||
SpawnLivingEntityPacket, EntityPositionPacket,
|
||||
EntityPositionRotationPacket,
|
||||
|
||||
)
|
||||
|
||||
from protocol.packets import TimeUpdatePacket, SetSlotPacket, PlayerDiggingPacket, BlockBreakAnimationPacket, AcknowledgePlayerDiggingPacket, HeldItemChangePacket, PickItemPacket, OpenWindowPacket, ClickWindowPacket, CloseWindowPacket, ServerWindowConfirmationPacket, ClientWindowConfirmationPacket, EntityMetadataPacket
|
||||
from protocol.types import Slot
|
||||
|
||||
import utils
|
||||
|
@ -200,9 +190,6 @@ class Game:
|
|||
register(self.handle_window_confirmation, ClientWindowConfirmationPacket)
|
||||
register(self.handle_spawn_object, clientbound.play.SpawnObjectPacket)
|
||||
register(self.handle_entity_metadata, EntityMetadataPacket)
|
||||
register(self.handle_spawn_living, SpawnLivingEntityPacket)
|
||||
register(self.handle_entity_position, EntityPositionPacket)
|
||||
register(self.handle_entity_position_rotation, EntityPositionRotationPacket)
|
||||
|
||||
#register(self.handle_packet, Packet, early=True)
|
||||
|
||||
|
@ -510,24 +497,13 @@ class Game:
|
|||
self.g.connection.write_packet(packet2)
|
||||
|
||||
def handle_spawn_object(self, packet):
|
||||
if packet.type_id != 37: return
|
||||
print(packet)
|
||||
print(packet.type_id)
|
||||
|
||||
def handle_entity_metadata(self, packet):
|
||||
return
|
||||
if packet.metadata and packet.metadata[0].index != 7: return
|
||||
print(packet)
|
||||
|
||||
def handle_spawn_living(self, packet):
|
||||
return
|
||||
print(packet)
|
||||
|
||||
def handle_entity_position(self, packet):
|
||||
return
|
||||
print(packet)
|
||||
|
||||
def handle_entity_position_rotation(self, packet):
|
||||
return
|
||||
def handle_packet(self, packet):
|
||||
print(packet)
|
||||
|
||||
def tick(self):
|
||||
|
|
|
@ -21,9 +21,6 @@ def get_packets(old_get_packets):
|
|||
mc_packets.add(packets.ClientWindowConfirmationPacket)
|
||||
mc_packets.add(packets.ServerWindowConfirmationPacket)
|
||||
mc_packets.add(packets.EntityMetadataPacket)
|
||||
mc_packets.add(packets.SpawnLivingEntityPacket)
|
||||
mc_packets.add(packets.EntityPositionPacket)
|
||||
mc_packets.add(packets.EntityPositionRotationPacket)
|
||||
|
||||
return mc_packets
|
||||
return lambda x: wrapper(old_get_packets, x)
|
||||
|
|
|
@ -113,10 +113,7 @@ class ChatManager:
|
|||
elif 'text' in data:
|
||||
return data['text']
|
||||
elif 'with' in data:
|
||||
if len(data['with']) >= 2:
|
||||
return '<{}> {}'.format(*[self.translate_chat(x) for x in data['with']])
|
||||
else:
|
||||
return self.translate_chat(data['with'][0])
|
||||
return '<{}> {}'.format(*[self.translate_chat(x) for x in data['with']])
|
||||
elif 'translate' in data:
|
||||
return data['translate']
|
||||
else:
|
||||
|
@ -130,7 +127,6 @@ class ChatManager:
|
|||
print('[%s] %s'%(source, text))
|
||||
except Exception as ex:
|
||||
print('Exception %r on message (%s): %s' % (ex, chat_packet.field_string('position'), chat_packet.json_data))
|
||||
return
|
||||
|
||||
if self.handler:
|
||||
self.handler((source, text))
|
||||
|
|
|
@ -307,58 +307,3 @@ class EntityMetadataPacket(Packet):
|
|||
entry = Entry.read(file_object)
|
||||
if not entry: break
|
||||
self.metadata.append(entry)
|
||||
|
||||
|
||||
class SpawnLivingEntityPacket(Packet):
|
||||
# Sent by the server when a living entity is spawned
|
||||
# https://wiki.vg/Protocol#Spawn_Entity
|
||||
|
||||
id = 0x02
|
||||
packet_name = 'spawn living entity'
|
||||
|
||||
definition = [
|
||||
{'entity_id': VarInt},
|
||||
{'entity_uuid': UUID},
|
||||
{'type': VarInt},
|
||||
{'x': Double},
|
||||
{'y': Double},
|
||||
{'z': Double},
|
||||
{'yaw': Angle},
|
||||
{'pitch': Angle},
|
||||
{'head_pitch': Angle},
|
||||
{'x_velocity': Short},
|
||||
{'y_velocity': Short},
|
||||
{'z_velocity': Short},
|
||||
]
|
||||
|
||||
class EntityPositionPacket(Packet):
|
||||
# Sent by the server when an entity moves less then 8 blocks
|
||||
# https://wiki.vg/Protocol#Spawn_Entity
|
||||
|
||||
id = 0x27
|
||||
packet_name = 'entity position'
|
||||
|
||||
definition = [
|
||||
{'entity_id': VarInt},
|
||||
{'delta_x': Short},
|
||||
{'delta_y': Short},
|
||||
{'delta_z': Short},
|
||||
{'on_ground': Boolean},
|
||||
]
|
||||
|
||||
class EntityPositionRotationPacket(Packet):
|
||||
# Sent by the server when an entity rotates and moves
|
||||
# https://wiki.vg/Protocol#Entity_Position_and_Rotation
|
||||
|
||||
id = 0x28
|
||||
packet_name = 'entity position and rotation'
|
||||
|
||||
definition = [
|
||||
{'entity_id': VarInt},
|
||||
{'delta_x': Short},
|
||||
{'delta_y': Short},
|
||||
{'delta_z': Short},
|
||||
{'yaw': Angle},
|
||||
{'pitch': Angle},
|
||||
{'on_ground': Boolean},
|
||||
]
|
||||
|
|
|
@ -40,9 +40,10 @@ class Nbt(Type):
|
|||
@staticmethod
|
||||
def read(file_object):
|
||||
type_id = Byte.read(file_object)
|
||||
if type_id != TAG_Compound:
|
||||
#raise Exception("Invalid NBT header")
|
||||
if type_id == TAG_End:
|
||||
return None
|
||||
if type_id != TAG_Compound:
|
||||
raise Exception("Invalid NBT header")
|
||||
name = ShortPrefixedByteArray.read(file_object).decode('utf-8')
|
||||
a = Nbt.decode_tag(file_object, TAG_Compound)
|
||||
a['_name'] = name
|
||||
|
@ -118,14 +119,10 @@ class Slot(Type):
|
|||
@staticmethod
|
||||
def read(file_object):
|
||||
present = Boolean.read(file_object)
|
||||
if present:
|
||||
item_id = VarInt.read(file_object)
|
||||
item_count = Byte.read(file_object)
|
||||
nbt = Nbt.read(file_object)
|
||||
else:
|
||||
item_id = None
|
||||
item_count = None
|
||||
nbt = None
|
||||
item_id = VarInt.read(file_object) if present else None
|
||||
item_count = Byte.read(file_object) if present else None
|
||||
print('slot read', present, item_id, item_count)
|
||||
nbt = Nbt.read(file_object) if present else None
|
||||
return Slot(present, item_id, item_count, nbt)
|
||||
|
||||
@staticmethod
|
||||
|
@ -142,11 +139,9 @@ class Entry(Type):
|
|||
1: VarInt,
|
||||
2: Float,
|
||||
3: String,
|
||||
5: Boolean,
|
||||
6: Slot,
|
||||
7: Boolean,
|
||||
9: Position,
|
||||
18: VarInt,
|
||||
}
|
||||
|
||||
def __init__(self, index, type, value):
|
||||
|
|
Loading…
Reference in New Issue
Block a user