Track player positions and add !here
This commit is contained in:
parent
beb4c31f5e
commit
93c1ab7c0a
63
game.py
63
game.py
|
@ -327,6 +327,7 @@ class Game:
|
|||
register(self.handle_destroy_entities, DestroyEntitiesPacket)
|
||||
register(self.handle_spawn_player, SpawnPlayerPacket)
|
||||
register(self.handle_respawn, clientbound.play.RespawnPacket)
|
||||
register(self.handle_player_list, clientbound.play.PlayerListItemPacket)
|
||||
#register(self.handle_entity_velocity, clientbound.play.EntityVelocityPacket)
|
||||
|
||||
#register(self.handle_packet, Packet, early=True)
|
||||
|
@ -454,7 +455,7 @@ class Game:
|
|||
reply = data
|
||||
|
||||
if command == 'pos':
|
||||
reply = str(utils.pint(self.g.pos))[1:-1]
|
||||
reply = str(utils.pint(self.g.pos))[1:-1] + ', ' + self.g.dimension
|
||||
|
||||
if command == 'afk':
|
||||
if not self.g.afk:
|
||||
|
@ -512,6 +513,14 @@ class Game:
|
|||
if command == 'loaded':
|
||||
reply = str(self.g.chunks.get_loaded_area())
|
||||
|
||||
if command == 'players':
|
||||
if data == 'clear':
|
||||
self.g.players = {}
|
||||
reply = 'ok'
|
||||
else:
|
||||
for k, v in self.g.players.items():
|
||||
print(str(k) + ':', v, self.g.player_names[v.player_uuid])
|
||||
|
||||
if command == 'objects':
|
||||
if data == 'clear':
|
||||
self.g.objects = {}
|
||||
|
@ -672,6 +681,37 @@ class Game:
|
|||
self.g.job.state = self.g.job.fill_blocks
|
||||
reply = 'filling ' + str(utils.pvolume(coord1, coord2)) + ' with ' + blocks.BLOCKS[block]
|
||||
|
||||
if command == 'here':
|
||||
try:
|
||||
sender_uuid = self.g.player_names[sender]
|
||||
except KeyError:
|
||||
reply = 'can\'t find your uuid'
|
||||
|
||||
if not reply:
|
||||
for p in self.g.players.values():
|
||||
if p.player_uuid == sender_uuid:
|
||||
player = p
|
||||
break
|
||||
else: # for
|
||||
reply = 'can\'t find you'
|
||||
|
||||
if not reply:
|
||||
pos = utils.pint(self.g.pos)
|
||||
goal = utils.pint((p.x, p.y, p.z))
|
||||
start = time.time()
|
||||
navpath = self.g.world.path_to_place(pos, goal)
|
||||
|
||||
if navpath:
|
||||
self.g.path = navpath
|
||||
if self.g.job:
|
||||
self.g.job.stop()
|
||||
print(len(navpath))
|
||||
print(navpath)
|
||||
print(round(time.time() - start, 3), 'seconds')
|
||||
reply = 'ok'
|
||||
else:
|
||||
reply = 'no path'
|
||||
|
||||
|
||||
################# Authorized commands ##########################
|
||||
if authed:
|
||||
|
@ -936,6 +976,14 @@ class Game:
|
|||
mob.y += packet.delta_y / 4096.0
|
||||
mob.z += packet.delta_z / 4096.0
|
||||
|
||||
player = self.g.players.get(packet.entity_id, None)
|
||||
if player:
|
||||
player.x += packet.delta_x / 4096.0
|
||||
player.y += packet.delta_y / 4096.0
|
||||
player.z += packet.delta_z / 4096.0
|
||||
|
||||
if player.player_uuid == '0c123cfa-1697-4427-9413-4b645dee7ec0': print(packet)
|
||||
|
||||
def handle_entity_position_rotation(self, packet):
|
||||
mob = self.g.mobs.get(packet.entity_id, None)
|
||||
if mob:
|
||||
|
@ -943,6 +991,14 @@ class Game:
|
|||
mob.y += packet.delta_y / 4096.0
|
||||
mob.z += packet.delta_z / 4096.0
|
||||
|
||||
player = self.g.players.get(packet.entity_id, None)
|
||||
if player:
|
||||
player.x += packet.delta_x / 4096.0
|
||||
player.y += packet.delta_y / 4096.0
|
||||
player.z += packet.delta_z / 4096.0
|
||||
|
||||
if player.player_uuid == '0c123cfa-1697-4427-9413-4b645dee7ec0': print(packet)
|
||||
|
||||
def handle_entity_velocity(self, packet):
|
||||
obj = self.g.objects.get(packet.entity_id, None)
|
||||
if obj:
|
||||
|
@ -969,6 +1025,11 @@ class Game:
|
|||
print(packet)
|
||||
self.g.dimension = packet.world_name.replace('minecraft:', '')
|
||||
|
||||
def handle_player_list(self, packet):
|
||||
for action in packet.actions:
|
||||
if isinstance(action, packet.AddPlayerAction):
|
||||
self.g.player_names[action.uuid] = action.name
|
||||
self.g.player_names[action.name] = action.uuid # porque no los dos?
|
||||
|
||||
def tick(self):
|
||||
if self.g.breaking:
|
||||
|
|
Loading…
Reference in New Issue
Block a user