Advertisement
Guest User

Untitled

a guest
Aug 19th, 2019
90
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Lua 3.03 KB | None | 0 0
  1. --STD addon for Turtles by Microeinstein
  2.  
  3. loadfile("std")()
  4.  
  5. __turtle = {}
  6.  
  7. if not turtle then
  8.     error("This is not a turtle.")
  9. end
  10.  
  11. turtle.faces = turtle.faces or {
  12.     N = 0,
  13.     E = 1,
  14.     S = 2,
  15.     W = 3,
  16.     U = 4,
  17.     D = 5
  18. }
  19. turtle.side = turtle.side or 0
  20. turtle.oldSlot = turtle.oldSlot or {x = 1, y = 1}
  21. turtle.slot = turtle.slot or {x = 1, y = 1}
  22.  
  23. function turtle.getSlotN(x, y)
  24.     return math.xyToNum(x, y, 4)
  25. end
  26. function turtle.getSlotXY(n)
  27.     return math.numToXY(n, 4)
  28. end
  29. function turtle.setSlot(x, y)
  30.     turtle.oldSlot = turtle.slot
  31.     turtle.slot = {x = x, y = y}
  32.     return turtle.select(turtle.getSlotN(x, y))
  33. end
  34. function turtle.setSlotTemp(x, y)
  35.     return turtle.select(turtle.getSlotN(x, y))
  36. end
  37. function turtle.getSelected()
  38.     return turtle.getSlotXY(turtle.getSelectedSlot())
  39. end
  40. function turtle.setSelected()
  41.     return turtle.setSlotTemp(turtle.slot.x, turtle.slot.y)
  42. end
  43. function turtle.selectOld()
  44.     local new = turtle.slot
  45.     turtle.slot = turtle.oldSlot
  46.     turtle.oldSlot = new
  47.     return turtle.select(turtle.getSlotN(turtle.slot.x, turtle.slot.y))
  48. end
  49.  
  50. function turtle.getItemDetailXY(x, y)
  51.     return turtle.getItemDetail(turtle.getSlotN(x, y))
  52. end
  53. function turtle.getItemCountXY(x, y)
  54.     return turtle.getItemCount(turtle.getSlotN(x, y))
  55. end
  56. function turtle.getItemSpaceXY(x, y)
  57.     return turtle.getItemSpace(turtle.getSlotN(x, y))
  58. end
  59. function turtle.moveSlot(x, y, amount)
  60.     if amount then
  61.         return turtle.transferTo(turtle.getSlotN(x, y), amount)
  62.     else
  63.         return turtle.transferTo(turtle.getSlotN(x, y))
  64.     end
  65. end
  66. function turtle.moveSlot(x1, y1, x2, y2, amount)
  67.     local r
  68.     turtle.setSlotTemp(x1, y1)
  69.     if amount then
  70.         r = turtle.transferTo(turtle.getSlotN(x2, y2), amount)
  71.     else
  72.         r = turtle.transferTo(turtle.getSlotN(x2, y2))
  73.     end
  74.     return r
  75. end
  76.  
  77. function turtle.turnSide(side)
  78.     side = side - math.floor(side / 4) * 4
  79.     if turtle.side - 3 == side then
  80.         turtle.turnRight()
  81.     elseif turtle.side < side then
  82.         for r = turtle.side, side, 1 do
  83.             turtle.turnRight()
  84.         end
  85.     elseif turtle.side > side then
  86.         for r = turtle.side, side, -1 do
  87.             turtle.turnLeft()
  88.         end
  89.     end
  90.     turtle.side = side
  91. end
  92.  
  93. function turtle.pull(x, y, face, amount)
  94.     local r
  95.     turtle.setSlotTemp(x, y)
  96.     if amount ~= nil then
  97.         if face == 4 then
  98.             r = turtle.suckUp(amount)
  99.         elseif face == 5 then
  100.             r = turtle.suckDown(amount)
  101.         else
  102.             turtle.turnSide(face)
  103.             r = turtle.suck(amount)
  104.         end
  105.     else
  106.         if face == 4 then
  107.             r = turtle.suckUp()
  108.         elseif face == 5 then
  109.             r = turtle.suckDown()
  110.         else
  111.             turtle.turnSide(face)
  112.             r = turtle.suck()
  113.         end
  114.     end
  115.     return r
  116. end
  117. function turtle.push(x, y, face, amount)
  118.     local r
  119.     turtle.setSlotTemp(x, y)
  120.     if amount ~= nil then
  121.         if face == 4 then
  122.             r = turtle.dropUp(amount)
  123.         elseif face == 5 then
  124.             r = turtle.dropDown(amount)
  125.         else
  126.             turtle.turnSide(face)
  127.             r = turtle.drop(amount)
  128.         end
  129.     else
  130.         if face == 4 then
  131.             r = turtle.dropUp()
  132.         elseif face == 5 then
  133.             r = turtle.dropDown()
  134.         else
  135.             turtle.turnSide(face)
  136.             r = turtle.drop()
  137.         end
  138.     end
  139.     return r
  140. end
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement