Advertisement
visiongaming43

Testing Methods

May 21st, 2022
742
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. -- Making Methods
  2. function move(amount)
  3.     if (amount < 0) then
  4.         turtle.turnRight()
  5.         turtle.turnRight()
  6.     end
  7.     amount = math.abs(amount)
  8.     while (amount > 0) do
  9.         turtle.forward()
  10.         amount = amount - 1
  11.     end
  12. end
  13.  
  14. -- DEFAULTS TO TURNING TURTLE NORTH ( Z - AXIS )
  15. function faceNorth()
  16.     local startX, startY, startZ = gps.locate()
  17.     turtle.dig()
  18.     turtle.forward()
  19.     local endX, endY, endZ = gps.locate()
  20.     turtle.back()
  21.     if(endX < startX) then turtle.turnLeft()
  22.     elseif (endX > startX) then turtle.turnRight()
  23.     elseif (endZ < startZ) then turtle.turnRight() turtle.turnRight()
  24.     end
  25. end
  26.  
  27. -- MOVES TO COORDINATES X, Y, Z
  28. function moveTo(x, y, z)
  29.     faceNorth()
  30.     local curX, curY, curZ = gps.locate()
  31.     local xDist = math.abs(x + curX)
  32.     local yDist = math.abs(y + curY)
  33.     local zDist = math.abs(z + curZ)
  34.     local xMethod
  35.     local yMethod
  36.     local zMethod
  37.     if (curX > x) then xMethod = turtle.forward else xMethod = turtle.back end
  38.     if (curY > y) then yMethod = turtle.down else yMethod = turtle.up end
  39.     if(curZ > z) then zMethod = turtle.forward else zMethod = turtle.back end
  40.  
  41.     while (xDist > 0) do
  42.         xMethod()
  43.         xDist = xDist - 1
  44.     end
  45.     while (yDist > 0) do
  46.         yMethod()
  47.         yDist = yDist - 1
  48.     end
  49.     while (zDist > 0) do
  50.         zMethod()
  51.         zDist = zDist - 1
  52.     end
  53. end
  54.  
  55. function getSeedIndex()
  56.     for slot = 1, 16, 1 do
  57.         local item = turtle.getItemDetail(slot)
  58.         if ( (item ~= nil) and ( (string.match(item.name, "seed") ) or (string.match(item.name, "potato") ) or (string.match(item.name, "carrot") ) ) ) then
  59.             return slot
  60.         end
  61.     end
  62. end
  63.  
  64. function getCrop()
  65.     local isBlock, data = turtle.inspectDown()
  66.     if(isBlock)then
  67.         if ( ( string.match(data.name, "croptopia:") or string.match(data.name, "wheat") or string.match(data.name, "potato") or string.match(data.name, "carrot")) and data['state']['age'] == 7) then
  68.             turtle.digDown()
  69.             seedIndex = getSeedIndex()
  70.             if(seedIndex ~= nil) then
  71.                 turtle.select(seedIndex)
  72.                 turtle.placeDown()
  73.             end
  74.         end
  75.     else
  76.         seedIndex = getSeedIndex()
  77.         if(seedIndex ~= nil) then
  78.             turtle.digDown()
  79.             turtle.select(seedIndex)
  80.             turtle.placeDown()
  81.         end
  82.     end
  83. end
  84.  
  85. function resetPos()
  86.     local file = fs.open("Settings", "r")
  87.     local startX = file.readLine()
  88.     local startY = file.readLine()
  89.     local startZ = file.readLine()
  90.     moveTo(startX, startY, startZ)
  91. end
Advertisement
RAW Paste Data Copied
Advertisement