Add goto command

This commit is contained in:
Isaia 2021-03-26 16:20:50 -06:00
parent afa588d843
commit e4b51aa2d6

29
game.py
View File

@ -454,7 +454,7 @@ class Game:
elif text == 'You are no longer AFK.':
self.g.afk = False
match1 = re.match(r'<(\w+)> (.*)', text)
match1 = re.match(r'<?(\w+)> (.*)', text)
match2 = re.match(r'\[(\w+) -> me] (.*)', text)
if match1:
sender, text = match1.groups()
@ -780,6 +780,33 @@ class Game:
else:
reply = 'no path'
if command == 'goto':
try:
data = data.replace('(', ' ').replace(')', ' ').replace(',', ' ')
x2, y2, z2 = [int(x) for x in data.split()]
except (AttributeError, ValueError):
reply = 'usage: !goto x y z'
if not reply:
pos = utils.pint(self.g.pos)
goal = utils.pint((x2, y2, z2))
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')
if self.g.job:
self.g.job.stop()
self.g.look_at = None
reply = 'ok'
else:
reply = 'no path'
if command == 'break':
self.break_block(blocks.TEST_BLOCK)
reply = 'ok'