Add packets for entity interaction and trade list

This commit is contained in:
2021-02-20 23:04:48 +00:00
parent af1db24cd5
commit b72c335ff7
4 changed files with 112 additions and 2 deletions
+26 -1
View File
@@ -20,7 +20,7 @@ from protocol.packets import (
ClickWindowPacket, CloseWindowPacket, ServerWindowConfirmationPacket,
ClientWindowConfirmationPacket, EntityMetadataPacket,
SpawnLivingEntityPacket, EntityPositionRotationPacket, DestroyEntitiesPacket,
EntityActionPacket, EntityTeleport,
EntityActionPacket, EntityTeleport, InteractEntityPacket, TradeListPacket
)
from protocol.types import Slot
@@ -338,6 +338,7 @@ class Game:
register(self.handle_entity_teleport, EntityTeleport)
register(self.handle_update_health, clientbound.play.UpdateHealthPacket)
#register(self.handle_entity_velocity, clientbound.play.EntityVelocityPacket)
register(self.handle_trade_list, TradeListPacket)
#register(self.handle_packet, Packet, early=True)
@@ -535,6 +536,16 @@ class Game:
print(str(k) + ':', v, mobs.MOB_NAMES[v.type])
reply = str(count) + ' monsters'
if command == 'villagers':
all_mobs = sorted(list(self.g.mobs.items()), key=lambda x: x[1].type)
count = 0
for k, v in all_mobs:
type_name = mobs.MOB_NAMES[v.type]
if type_name != 'villager' : continue
count += 1
print(str(k) + ':', v, type_name)
reply = str(count) + ' villagers'
if command == 'threats':
distance = int(data) if data else 20
p = utils.pint(self.g.pos)
@@ -757,6 +768,9 @@ class Game:
if command == 'use':
self.use_item(0)
if command == 'interact' and data:
self.interact(int(data))
if command == 'test':
reply = 'ok'
self.select_next_item()
@@ -1115,6 +1129,17 @@ class Game:
packet.hand = hand
self.g.connection.write_packet(packet)
def interact(self, eid):
packet = InteractEntityPacket()
packet.entity_id = eid
packet.type = 0
packet.hand = 0
packet.sneaking = False
self.g.connection.write_packet(packet)
def handle_trade_list(self, packet):
print(packet)
def tick(self):
if self.g.breaking:
self.animate()