slipers

"Go Home" turtle command

Jul 8th, 2021 (edited)
161
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 1.57 KB | None | 0 0
  1. # CC:Tweaked and Python 3
  2. # "Go Home" turtle command
  3. # Version 1.0 08.07.2021 12:24:00
  4. # (c) 2021, MCAP-2020 (mcap_nikita & mcap_slipers)
  5.  
  6. from cc import gps, turtle
  7.  
  8. t = turtle
  9. # Сoordinates of the Home
  10. x, y, z = 706, 74, -502
  11. # Item slot 2 - Wireless modem
  12. if (t.getItemDetail(2) != None):
  13.      t.select(2); t.equipLeft()
  14.  
  15. def move(item, direction, distance):
  16.      distance = abs(distance)
  17.      for s in range(distance):
  18.           if (direction == 'forward'):
  19.                while not item.forward():
  20.                     item.up()    
  21.           elif (direction == 'back'):
  22.                while not item.back():
  23.                     item.up()    
  24.           elif (direction == 'up'):
  25.                item.up()
  26.           elif (direction == 'down'):
  27.                item.down()
  28.  
  29. for i in 1, 2:
  30.      fd = ''
  31.      x1, y1, z1 = gps.locate()
  32.      dx = x - x1; dz = z - z1
  33.      t.forward(); x2, y2, z2 = gps.locate(); t.back()
  34.  
  35.      if (x2 != x1):
  36.           fd = 'x+' if (x2 > x1) else 'x-'
  37.      elif (z2 != z1):
  38.           fd = 'z+' if (z2 > z1) else 'z-'    
  39.  
  40.      if ((dx > 0) and (fd == 'x+')) or ((dx < 0) and (fd == 'x-')):
  41.           move(t, 'forward', dx)
  42.      elif ((dx < 0) and (fd == 'x+')) or ((dx > 0) and (fd == 'x-')):
  43.           move(t, 'back', dx)
  44.      elif ((dz > 0) and (fd == 'z+')) or ((dz < 0) and (fd == 'z-')):
  45.           move(t, 'forward', dz)
  46.      elif ((dz < 0) and (fd == 'z+')) or ((dz > 0) and (fd == 'z-')):
  47.           move(t, 'back', dz)
  48.      t.turnRight()
  49.  
  50. x1, y1, z1 = gps.locate(); dy = y - y1
  51. move(t, 'up' if (dy > 0) else 'down', dy)
Add Comment
Please, Sign In to add comment