Advertisement
guitarplayer616

[LocationFinder] schem turtle

Nov 25th, 2016
244
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Lua 5.24 KB | None | 0 0
  1. function checkIfAir()
  2.     --finds the location to place the next block
  3.     while true do
  4.         iterate()
  5.         --makes the turtle build faster by having to travel less
  6.         blockID2 = getBlockId(x,y,z)    -- temporary variable
  7.         blockData2 = getData(x,y,z)     -- temporary variable
  8.         if slots[blockID2] then
  9.             -- makes sure the next block to place at location is not air
  10.             slot_2nd = slots[blockID2][blockData2]
  11.             if slot_2nd then
  12.                 if #slot_2nd > 0 then
  13.                     recordObj(x,y,z)
  14.                     break
  15.                 end
  16.             end
  17.         end
  18.     end
  19. end
  20.  
  21.  
  22. function checkIfAirBUILTIN(x,y,z,height,width,length)
  23.     --finds the location to place the next block
  24.     while true do
  25.         --makes the turtle build faster by having to travel less
  26.         blockID2 = getBlockId(x,y,z)    -- temporary variable
  27.         blockData2 = getData(x,y,z)     -- temporary variable
  28.         if slots[blockID2] then
  29.             -- makes sure the next block to place at location is not air
  30.             slot_2nd = slots[blockID2][blockData2]
  31.             if slot_2nd then
  32.                 if #slot_2nd > 0 then
  33.                     recordObj(x,y,z)
  34.                     break
  35.                 end
  36.             end
  37.         end
  38.         x,y,z = iterate(x,y,z,height,width,length)
  39.     end
  40. end
  41.  
  42.  
  43.  
  44. function checkIfAir2(slots,height,width,length)
  45.     local ObjectivesList = {}
  46.     x,y,z = 0,0,0
  47.     while x do
  48.         local id = getBlockId(x,y,z)
  49.         local data = getData(x,y,z)
  50.         if slots[id] and #slots[id][data] > 0 then
  51.             table.insert(ObjectivesList,{
  52.                 x = x,
  53.                 y = y,
  54.                 z = z,
  55.                 id = id,
  56.                 data = data,
  57.                 slotNums = slots[id][data],
  58.             })
  59.         end
  60.         print(x,y,z)
  61.         x,y,z = iterate(x,y,z,height,width,length)
  62.     end
  63.     return ObjectivesList
  64. end
  65.  
  66. --iterator api
  67.  
  68. function oldIterate()
  69.     --x,y,z = height,width,length
  70.     if z < length then
  71.         z = z + 1
  72.     elseif z == length then
  73.         z = 0
  74.         if y < width then
  75.             y = y + 1
  76.         elseif y == width then
  77.             y = 0
  78.             if x < height then
  79.                 x = x + 1
  80.             elseif x == height then
  81.                 --x = 'max'
  82.                 --y = 'max'
  83.                 --z = 'max'
  84.                 error()
  85.             end
  86.         end
  87.     end
  88.     recordObj(x,y,z)
  89. end
  90.  
  91. function checkInternal(x,y,z)
  92.     if x%2==0 then
  93.         evenx = true
  94.         if y%2==0 then
  95.             eveny = true
  96.         else
  97.             eveny = false
  98.         end
  99.     else
  100.         evenx = false
  101.         if y%2==0 then
  102.             eveny = false
  103.         else
  104.             eveny = true
  105.         end
  106.     end
  107.     return evenx,eveny
  108. end
  109.  
  110. function check()
  111.     if x%2==0 then
  112.         evenx = true
  113.         if y%2==0 then
  114.             eveny = true
  115.         else
  116.             eveny = false
  117.         end
  118.     else
  119.         evenx = false
  120.         if y%2==0 then
  121.             eveny = false
  122.         else
  123.             eveny = true
  124.         end
  125.     end
  126. end
  127.  
  128.  
  129. function Yiterate()
  130.     if evenx then
  131.         if y < width then
  132.             y = y + 1
  133.         elseif y == width then
  134.             if x < height then
  135.                 x = x + 1
  136.             elseif x == height then
  137.                 x,y,z = "max","max","max"
  138.             end
  139.         end
  140.     else
  141.         if y == 0 then
  142.             if x < height then
  143.                 x = x + 1
  144.             elseif x == height then
  145.                 x = "max"
  146.                 y = "max"
  147.                 z = "max"
  148.             end
  149.         else
  150.             y=y-1
  151.         end
  152.     end
  153. end
  154.  
  155. function iterate()
  156.     check()
  157.     if z == length and eveny then
  158.         Yiterate()
  159.     elseif z==length and (not eveny) then
  160.         z = z - 1
  161.     elseif z == 0 and eveny then
  162.         z = z + 1
  163.     elseif z == 0 and (not eveny) then
  164.         Yiterate()
  165.     elseif z < length then
  166.         if eveny then
  167.             z = z + 1
  168.         else
  169.             z = z - 1
  170.         end
  171.     end
  172. end
  173.  
  174. function YiterateInternal(x,y,z,length,width,height)
  175.     if evenx then
  176.         if y < width then
  177.             y = y + 1
  178.         elseif y == width then
  179.             if x < height then
  180.                 x = x + 1
  181.             elseif x == height then
  182.                 x,y,z = "max","max","max"
  183.             end
  184.         end
  185.     else
  186.         if y == 0 then
  187.             if x < height then
  188.                 x = x + 1
  189.             elseif x == height then
  190.                 x = "max"
  191.                 y = "max"
  192.                 z = "max"
  193.             end
  194.         else
  195.             y=y-1
  196.         end
  197.     end
  198.     return x,y,z
  199. end
  200.  
  201. function iterateInternal(x,y,z,length,width,height)
  202.     evenx,eveny = check(x,y,z)
  203.     if z == length and eveny then
  204.         x,y,z = Yiterate(x,y,z,length,width,height)
  205.     elseif z==length and (not eveny) then
  206.         z = z - 1
  207.     elseif z == 0 and eveny then
  208.         z = z + 1
  209.     elseif z == 0 and (not eveny) then
  210.         x,y,z = Yiterate(x,y,z,length,width,height)
  211.     elseif z < length then
  212.         if eveny then
  213.             z = z + 1
  214.         else
  215.             z = z - 1
  216.         end
  217.     end
  218.     return x,y,z
  219. end
  220.  
  221. function autorun()
  222.     --get the current coords
  223.     --get the iterater/goal block location
  224.     while true do
  225.         shell.run("position")
  226.         shell.run("objective")
  227.         goto(x,y,z)
  228.         findNextBlock(x,y,z)
  229.         checkIfAir()
  230.     end
  231.     shell.run("clr")
  232.     print("finished")
  233. end
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement