Advertisement
guitarplayer616

Turtle Schematic Builder hopeItUpd8s

Dec 17th, 2015
185
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Lua 21.22 KB | None | 0 0
  1. --[[function saveVarsToConsole(name)
  2.     local h = fs.open(name,'w')
  3.     local env = getfenv()
  4.     for i,v in pairs(env) do
  5.         if i then
  6.             h.write(i)
  7.             if v then
  8.                 --h.write("("..tostring(type(v))..")")
  9.                 h.write(': ')
  10.                 h.writeLine(v)
  11.             end
  12.         end
  13.     end
  14.     h.close()
  15. end]]
  16.  
  17. function openRednet()
  18.     for _,v in ipairs(peripheral.getNames()) do
  19.             if peripheral.getType(v)=="modem" then
  20.                     rednet.open(v)
  21.             end
  22.     end
  23. end
  24.  
  25. function checkIfRefill()
  26.     local _,inFront = turtle.inspect()
  27.     local _,below = turtle.inspectDown()
  28.     local mem = turtle.getSelectedSlot()
  29.     turtle.select(16)
  30.     local check = turtle.getItemDetail()
  31.     if check and check.name ~= "EnderStorage:enderChest" then
  32.         if not turtle.dropDown() then
  33.             if not turtle.drop() then
  34.                 turtle.dropUp()
  35.             end
  36.         end  
  37.     end
  38.     if inFront or below then
  39.         if inFront.name == "EnderStorage:enderChest" then
  40.             turtle.select(enderchest1)
  41.             turtle.dig()
  42.         end
  43.         if below.name == "EnderStorage:enderChest" then
  44.             turtle.select(enderchest2)
  45.             turtle.digDown()
  46.         end
  47.     end
  48.     turtle.select(mem)
  49. end
  50.  
  51. function calibrateDir()
  52.     if gpsi then
  53.         local dir
  54.         local h,k,l = gps.locate()
  55.         while not turtle.forward() do
  56.             turtle.dig()
  57.         end
  58.         local h2,k2,l2 = gps.locate()
  59.         turtle.back()
  60.         if h2>h then
  61.             dir = "east"
  62.         elseif h2<h then
  63.             dir = "west"
  64.         elseif l2>l then
  65.             dir = "south"
  66.         elseif l2<l then
  67.             dir = "north"
  68.         end
  69.         return dir
  70.     end
  71. end
  72.  
  73. function recalibratePos()
  74.     local h,k,l = gps.locate() 
  75.     local ytemp,xtemp,ztemp  = h - Hoff, k - Koff, l - Loff
  76.  
  77.     if origDir == "south" then
  78.         xnew = 0 + xtemp   
  79.         ynew = ytemp
  80.         znew = 0 + ztemp
  81.     elseif origDir == "north" then
  82.         xnew = 0 - xtemp
  83.         ynew = ytemp
  84.         znew = 0 - ztemp
  85.     elseif origDir == "east" then
  86.         xnew = 0  - ztemp
  87.         ynew = ytemp
  88.         znew = 0  + xtemp
  89.     elseif origDir == "west" then
  90.         xnew = 0 + ztemp
  91.         ynew = ytemp
  92.         znew = 0 - xtemp
  93.     end
  94.  
  95.     widthPos,heightPos,lengthPos = xnew,ynew,znew
  96. end
  97.  
  98. function recalibrateFace() 
  99.     if origDir ~= "south" then
  100.         if origDir == "north" then
  101.             update("right")
  102.             update("right")
  103.         elseif origDir == "east" then
  104.             update("right")
  105.         elseif origDir == "west" then
  106.             update("left")
  107.         end
  108.     end
  109. end
  110.  
  111. function resynchronize()
  112.     recalibratePos()
  113.     face = calibrateDir()
  114.     recalibrateFace()
  115. end
  116.  
  117. function saveVarsToFile()
  118.     local h = fs.open("currentVars",'w')
  119.     local env = getfenv()
  120.     for i,v in pairs(env) do
  121.         if type(v) == "string" then
  122.             h.write(tostring(i))
  123.             h.write(" = ")
  124.             h.write([["]]..tostring(v)..[["]])
  125.         elseif type(v) == "table" then
  126.             h.write(i)
  127.             h.write(" = ")
  128.             h.write(textutils.serialize(v))
  129.         end
  130.     end
  131.     h.close()
  132. end
  133.  
  134. function loadVars()
  135.     local h = fs.open("currentVars",'r')
  136. end
  137.  
  138. function recordPos(heightPos,widthPos,lengthPos,face)
  139.     local h = fs.open("position","w")
  140.     h.writeLine("heightPos = "..tostring(heightPos))
  141.     h.writeLine("widthPos = "..tostring(widthPos))
  142.     h.writeLine("lengthPos = "..tostring(lengthPos))
  143.     h.writeLine("face = ".."\""..tostring(face).."\"")
  144.     h.close()
  145. end
  146.  
  147. function recordObj(x,y,z)
  148.     local h = fs.open("objective",'w')
  149.     h.writeLine("x = "..tostring(x))
  150.     h.writeLine("y = "..tostring(y))
  151.     h.writeLine("z = "..tostring(z))
  152.     h.close()
  153. end
  154.  
  155. block_id = {}
  156. block_id[0] = "Air"
  157. block_id[1] = "Stone"
  158. block_id[2] = "Grass"
  159. block_id[3] = "Dirt"
  160. block_id[4] = "Cobblestone"
  161. block_id[5] = "Wooden Plank"
  162. block_id[6] = "Sapling"
  163. block_id[7] = "Bedrock"
  164. block_id[8] = "Water"
  165. block_id[9] = "Stationary water"
  166. block_id[10] = "Lava"
  167. block_id[11] = "Stationary lava"
  168. block_id[12] = "Sand"
  169. block_id[13] = "Gravel"
  170. block_id[14] = "Gold Ore"
  171. block_id[15] = "Iron (Ore)"
  172. block_id[16] = "Coal Ore"
  173. block_id[17] = "Log"
  174. block_id[18] = "Leaves"
  175. block_id[19] = "Sponge"
  176. block_id[20] = "Glass"
  177. block_id[21] = "Lapis Lazuli (Ore)"
  178. block_id[22] = "Lapis Lazuli (Block)"
  179. block_id[23] = "Dispenser"
  180. block_id[24] = "Sandstone"
  181. block_id[25] = "Note Block Tile entity"
  182. block_id[26] = "Bed"
  183. block_id[27] = "Powered Rail "
  184. block_id[28] = "Detector Rail "
  185. block_id[29] = "Sticky Piston"
  186. block_id[30] = "Cobweb"
  187. block_id[31] = "Tall Grass"
  188. block_id[32] = "Dead Bush"
  189. block_id[33] = "Piston"
  190. block_id[34] = "Piston Extension"
  191. block_id[35] = "Wool"
  192. block_id[36] = "Block moved by Piston"
  193. block_id[37] = "Dandelionandelion"
  194. block_id[38] = "Rose"
  195. block_id[39] = "Brown Mushroom"
  196. block_id[40] = "Red Mushroom"
  197. block_id[41] = "Block of Gold"
  198. block_id[42] = "Block of Iron"
  199. block_id[43] = "Double Slabs"
  200. block_id[44] = "Slabs"
  201. block_id[45] = "Brick Block"
  202. block_id[46] = "TNT"
  203. block_id[47] = "Bookshelf"
  204. block_id[48] = "Moss Stone"
  205. block_id[49] = "Obsidian"
  206. block_id[50] = "Torch"
  207. block_id[51] = "Fire"
  208. block_id[52] = "Monster Spawner"
  209. block_id[53] = "Wooden Stairs"
  210. block_id[54] = "Chest"
  211. block_id[55] = "Redstone (Wire)"
  212. block_id[56] = "Diamond (Ore)"
  213. block_id[57] = "Block of Diamond"
  214. block_id[58] = "Crafting Table"
  215. block_id[59] = "Seeds"
  216. block_id[60] = "Farland"
  217. block_id[61] = "Furnace"
  218. block_id[62] = "Burning Furnace"
  219. block_id[63] = "Sign Post"
  220. block_id[64] = "Wooden Door"
  221. block_id[65] = "Ladders"
  222. block_id[66] = "Rails"
  223. block_id[67] = "Cobblestone Stairs"
  224. block_id[68] = "Wall Sign"
  225. block_id[69] = "Lever"
  226. block_id[70] = "Stone Pressure Plate"
  227. block_id[71] = "Iron Door"
  228. block_id[72] = "Wooden Pressure Plates"
  229. block_id[73] = "Redstone Ore"
  230. block_id[74] = "Glowing Redstone Ore"
  231. block_id[75] = "Redstone Torch"
  232. block_id[76] = "Redstone Torch"
  233. block_id[77] = "Stone Button "
  234. block_id[78] = "Snow"
  235. block_id[79] = "Ice"
  236. block_id[80] = "Snow Block"
  237. block_id[81] = "Cactus"
  238. block_id[82] = "Clay (Block)"
  239. block_id[83] = "Sugar Cane"
  240. block_id[84] = "Jukebox"
  241. block_id[85] = "Fence"
  242. block_id[86] = "Pumpkin"
  243. block_id[87] = "Netherrack"
  244. block_id[88] = "Soul Sand"
  245. block_id[89] = "Glowstone"
  246. block_id[90] = "Portal"
  247. block_id[91] = "Jack-O-Lantern"
  248. block_id[92] = "Cake Block"
  249. block_id[93] = "Redstone Repeater"
  250. block_id[94] = "Redstone Repeater"
  251. block_id[95] = "Locked Chest"
  252. block_id[96] = "Trapdoors"
  253. block_id[97] = "Hidden Silverfish"
  254. block_id[98] = "Stone Brick"
  255. block_id[99] = "Huge brown and red mushroom"
  256. block_id[100] = "Huge brown and red mushroom"
  257. block_id[101] = "Iron Bars"
  258. block_id[102] = "Glass Pane"
  259. block_id[103] = "Melon"
  260. block_id[104] = "Pumpkin Stem"
  261. block_id[105] = "Melon Stem"
  262. block_id[106] = "Vines"
  263. block_id[107] = "Fence Gate"
  264. block_id[108] = "Brick Stairs"
  265. block_id[109] = "Stone Brick Stairs"
  266. block_id[110] = "Mycelium"
  267. block_id[111] = "Lily Pad"
  268. block_id[112] = "Nether Brick"
  269. block_id[113] = "Nether Brick Fence"
  270. block_id[114] = "Nether Brick Stairs"
  271. block_id[115] = "Nether Wart"
  272. block_id[116] = "Enchantment Table"
  273. block_id[117] = "Brewing Stand"
  274. block_id[118] = "Cauldron"
  275. block_id[119] = "End Portal"
  276. block_id[120] = "End Portal Frame"
  277. block_id[121] = "End Stone "
  278. block_id[256] = "Iron Ingotron Shovel"
  279. block_id[257] = "Iron Pickaxe"
  280. block_id[258] = "Iron Axe"
  281. block_id[259] = "Flint and Steel"
  282. block_id[260] = "Red Apple"
  283. block_id[261] = "Bow"
  284. block_id[262] = "Arrow"
  285. block_id[263] = "Coal"
  286.  
  287. woolColors = {}
  288. woolColors[0] = "White"
  289. woolColors[1] = "Orange"
  290. woolColors[2] = "Magenta"
  291. woolColors[3] = "Light Blue"
  292. woolColors[4] = "Yellow"
  293. woolColors[5] = "Lime"
  294. woolColors[6] = "Pink"
  295. woolColors[7] = "Gray"
  296. woolColors[8] = "Light Gray"
  297. woolColors[9] = "Cyan"
  298. woolColors[10] = "Purple"
  299. woolColors[11] = "Blue"
  300. woolColors[12] = "Brown"
  301. woolColors[13] = "Green"
  302. woolColors[14] = "Red"
  303. woolColors[15] = "Black"
  304.  
  305. --[[Navigation Functions]]--
  306.  
  307. function goto(heightGoal,widthGoal,lengthGoal)
  308.     shell.run("position")
  309.     if turtle.getFuelLevel() < 200 then
  310.         refill()
  311.     end
  312.     if heightGoal > heightPos then
  313.         while heightGoal > heightPos do
  314.             up()
  315.         end
  316.     elseif heightGoal < heightPos then
  317.         while heightGoal < heightPos do
  318.             down()
  319.         end
  320.     end
  321.     if widthGoal > widthPos then
  322.         turn("east")
  323.         while widthGoal > widthPos do
  324.             forward()
  325.         end
  326.     elseif widthGoal < widthPos then
  327.         turn("west")
  328.         while widthGoal < widthPos do
  329.             forward()
  330.         end
  331.     end
  332.     if lengthGoal > lengthPos then
  333.         turn("south")
  334.         while lengthGoal > lengthPos do
  335.             forward()
  336.         end
  337.     elseif lengthGoal < lengthPos then
  338.         turn("north")
  339.         while lengthGoal < lengthPos do
  340.             forward()
  341.         end
  342.     end
  343. end
  344.  
  345. function update(dir)
  346.         if dir == "forward" then
  347.             if face == "north" then
  348.                 lengthPos = lengthPos - 1
  349.             elseif face == "south" then
  350.                 lengthPos = lengthPos + 1
  351.             elseif face == "west" then
  352.                 widthPos = widthPos - 1
  353.             elseif face == "east" then
  354.                 widthPos = widthPos + 1
  355.             end
  356.         elseif dir == "backward" then
  357.                 if face == "north" then
  358.                         lengthPos = lengthPos + 1
  359.                 elseif face == "south" then
  360.                         lengthPos = lengthPos - 1
  361.                 elseif face == "west" then
  362.                         widthPos = widthPos + 1
  363.                 elseif face == "east" then
  364.                         widthPos = widthPos - 1
  365.                 end
  366.         elseif dir == "up" then
  367.                 heightPos = heightPos + 1
  368.         elseif dir == "down" then
  369.                 heightPos = heightPos - 1
  370.         elseif dir == "right" then
  371.                 if face == "north" then
  372.                         face = "east"
  373.                 elseif face == "east" then
  374.                         face = "south"
  375.                 elseif face == "south" then
  376.                         face = "west"
  377.                 elseif face == "west" then
  378.                         face = "north"
  379.                 end
  380.         elseif dir == "left" then
  381.                 if face == "north" then
  382.                         face = "west"
  383.                 elseif face == "west" then
  384.                         face = "south"
  385.                 elseif face == "south" then
  386.                         face = "east"
  387.                 elseif face == "east" then
  388.                         face = "north"
  389.                 end
  390.         end
  391.         recordPos(heightPos,widthPos,lengthPos,face)
  392. end
  393.  
  394. --[[Refill Functions]]--
  395.  
  396. function scanInv()
  397.         local invList = {}
  398.         for i = 1,16 do
  399.                 turtle.select(i)
  400.                 local item = turtle.getItemDetail()
  401.                 if item then
  402.                         invList[i] = {}
  403.             invList[i][item.name] = item.damage
  404.                 end
  405.         end
  406.         return invList
  407. end
  408.  
  409. function ParseInv()
  410.         turtle.select(16)
  411.         turtle.dropUp()
  412.         while turtle.suck() do
  413.                 local item = turtle.getItemDetail()
  414.                 for i =1,16 do
  415.                         if invList[i][item.name] then
  416.                 if invList[i][item.name] == item.damage then
  417.                                     turtle.transferTo(i)
  418.                                     break
  419.                 end
  420.                         end
  421.                         if item.name == "minecraft:lava_bucket" or item.name == "minecraft:coal" then
  422.                                 turtle.refuel(64)
  423.                         end
  424.                 end
  425.                 turtle.dropUp()
  426.         end
  427. end
  428.  
  429. function refill()
  430.     local mem = turtle.getSelectedSlot()
  431.     chester("set")
  432.         ParseInv()
  433.         chester("gather")
  434.     turtle.select(mem)
  435. end
  436.  
  437. function chester(action)
  438.         --action = 'set' or 'gather'
  439.         if action == "set" then
  440.                 turtle.select(tonumber(enderchest1))
  441.                 turtle.place()
  442.                 turtle.select(tonumber(enderchest2))
  443.                 turtle.placeUp()
  444.         elseif action == "gather" then
  445.                 if tonumber(chestOrder) == 1 then
  446.                         turtle.select(tonumber(enderchest1))
  447.                         turtle.digUp()
  448.                         turtle.select(tonumber(enderchest2))
  449.                         turtle.dig()
  450.                         chestOrder = 2
  451.                 elseif tonumber(chestOrder) == 2 then
  452.                         turtle.select(tonumber(enderchest1))
  453.                         turtle.dig()
  454.                         turtle.select(tonumber(enderchest2))
  455.                         turtle.digUp()
  456.                         chestOrder = 1
  457.                 end
  458.         end
  459. end
  460.  
  461. function getBlockName(id, blockData)
  462.   blockData = blockData or nil
  463.   if(block_id[id] == nil) then
  464.     return "ID: "..tostring(id)..", Data: "..tostring(blockData)
  465.   else
  466.     if(blockData) then
  467.       if(id == 35) then
  468.         str = woolColors[blockData] .. " " .. block_id[id]
  469.         return str
  470.       end
  471.     end
  472.     return block_id[id]
  473.   end
  474. end
  475.  
  476. function getBlockId(x,y,z)
  477.   return blocks[y + z*width + x*length*width + 1]
  478. end
  479.  
  480. function getData(x,y,z)
  481.   return data[y + z*width + x*length*width + 1]
  482. end
  483.  
  484. function readbytes(handle, n)
  485.   for i=1,n do
  486.     handle.read()
  487.   end
  488. end
  489.  
  490. function readname(handle)  
  491.   n1 = handle.read()
  492.   n2 = handle.read()
  493.  
  494.   if(n1 == nil or n2 == nil) then
  495.     return ""
  496.   end
  497.  
  498.   n = n1*256 + n2
  499.  
  500.   str = ""
  501.   for i=1,n do
  502.     c = handle.read()
  503.     if c == nil then
  504.       return
  505.     end  
  506.     str = str .. string.char(c)
  507.   end
  508.   return str
  509. end
  510.  
  511. function parse(a, handle, containsName)
  512.   containsName = containsName or true
  513.   if a==0 then
  514.     return
  515.   end
  516.   if containsName then
  517.     name = readname(handle)
  518.   end
  519.    
  520.   if a==1 then
  521.     readbytes(handle,1)  
  522.   elseif a==2 then
  523.     i1 = handle.read()
  524.     i2 = handle.read()
  525.     i = i1*256 + i2
  526.     if(name=="Height") then
  527.       height = i
  528.     elseif (name=="Length") then
  529.       length = i
  530.     elseif (name=="Width") then
  531.       width = i
  532.     end
  533.   elseif a==3 then
  534.     readbytes(handle,4)
  535.   elseif a==4 then
  536.     readbytes(handle,8)
  537.   elseif a==5 then
  538.     readbytes(handle,4)
  539.   elseif a==6 then
  540.     readbytes(handle,8)
  541.   elseif a==7 then
  542.     i1 = handle.read()
  543.     i2 = handle.read()
  544.     i3 = handle.read()
  545.     i4 = handle.read()
  546.     i = i1*256*256*256 + i2*256*256 + i3*256 + i4
  547.     if name == "Blocks" then
  548.       for i=1,i do
  549.         table.insert(blocks, handle.read())
  550.       end
  551.     elseif name == "Data" then
  552.       for i=1,i do
  553.         table.insert(data, handle.read())
  554.       end
  555.     else
  556.       readbytes(handle,i)
  557.     end
  558.   elseif a==8 then
  559.     i1 = handle.read()
  560.     i2 = handle.read()
  561.     i = i1*256 + i2
  562.     readbytes(handle,i)
  563.   elseif a==9 then
  564.         --readbytes(handle,5)
  565.         type = handle.read()
  566.         i1 = handle.read()
  567.     i2 = handle.read()
  568.     i3 = handle.read()
  569.     i4 = handle.read()
  570.     i = i1*256*256*256 + i2*256*256 + i3*256 + i4
  571.     for j=1,i do
  572.       parse(handle.read(), handle, false)
  573.     end
  574.   end
  575. end
  576.  
  577. --[[Movement Functions]]--
  578.  
  579. function forward()
  580.   update("forward")
  581.   while not turtle.forward() do
  582.     turtle.dig()
  583.   end
  584. end
  585.  
  586. function up()
  587.   update("up")
  588.   while not turtle.up() do
  589.     turtle.digUp()
  590.   end
  591. end
  592.  
  593. function down()
  594.   update("down")
  595.   while not turtle.down() do
  596.     turtle.digDown()
  597.   end
  598. end
  599.  
  600. function right()
  601.   update("right")
  602.   turtle.turnRight()
  603. end
  604.    
  605. function left()
  606.   update("left")
  607.   turtle.turnLeft()
  608. end
  609.  
  610. function turn(dir)
  611.     if face == "north" then
  612.         if dir == "east" then
  613.             while face ~= dir do
  614.                 right()
  615.             end
  616.         else
  617.             while face ~= dir do
  618.                 left()
  619.             end
  620.         end
  621.    elseif face == "east" then
  622.         if dir == "south" then
  623.             while face ~= dir do
  624.                 right()
  625.             end
  626.         else
  627.             while face ~= dir do
  628.                 left()
  629.             end
  630.         end
  631.     elseif face == "south" then
  632.         if dir == "west" then
  633.             while face ~= dir do
  634.                 right()
  635.             end
  636.         else
  637.             while face ~= dir do
  638.                 left()
  639.             end
  640.         end
  641.     elseif face == "west" then
  642.         if dir == "north" then
  643.             while face ~= dir do
  644.                 right()
  645.             end
  646.         else
  647.             while face ~= dir do
  648.                 left()
  649.             end
  650.         end
  651.     end
  652. end
  653.  
  654. function place()
  655.   while not turtle.placeDown() do
  656.     turtle.digDown()
  657.   end
  658.   return true
  659. end
  660.  
  661. --[[Working Functions]]--
  662.  
  663. function setup()
  664.     a = 0
  665.     while (a ~= nil) do
  666.         a = handle.read()
  667.         parse(a, handle)
  668.     end
  669.  
  670.     write("length: " .. length)
  671.     write("   width: " .. width)
  672.     write("   height: " .. height .. "\n")
  673.  
  674.     uniqueblocks={}
  675.     for i,v in ipairs(blocks) do
  676.         found = false
  677.         for j,w in ipairs(uniqueblocks) do
  678.             -- for now, data is only accounted for when the block is wool
  679.                 if (w.blockID==v and (w.data==data[i] or w.blockID ~= 35)) then
  680.                     found = true
  681.                     w.amount = w.amount + 1
  682.                     break
  683.             end
  684.         end
  685.  
  686.         if found==false then
  687.             uniqueblocks[#uniqueblocks+1] = {}
  688.             uniqueblocks[#uniqueblocks].blockID = v
  689.             uniqueblocks[#uniqueblocks].data = data[i]
  690.             uniqueblocks[#uniqueblocks].amount = 1
  691.         end
  692.     end
  693.  
  694.     print("number of block types: " .. #uniqueblocks)
  695.     for i,v in ipairs(uniqueblocks) do
  696.         if (i%9)==0 then
  697.             read()
  698.         end
  699.         print(" -" .. getBlockName(v.blockID, v.data) .. ": " .. v.amount)
  700.     end
  701.  
  702.     read()
  703.  
  704.     print("Give the numbers of all slots containing the specified block type:")
  705.  
  706.     slots={}
  707.     for i,block in ipairs(uniqueblocks) do
  708.         blockData = block.data
  709.         print(" -in which slots is " .. getBlockName(block.blockID, blockData) .. "?")
  710.         if not slots[block.blockID] then
  711.             slots[block.blockID] = {}
  712.         end
  713.         slots[block.blockID][blockData] = {}
  714.         write("   ")
  715.         str = read()
  716.         for i = 1, #str do
  717.                 local c = str:sub(i,i)
  718.                 n = tonumber(c)
  719.                 if(n) then
  720.                     if(n>0 and n<10) then
  721.                         table.insert(slots[block.blockID][blockData], n)
  722.                     end
  723.             end
  724.         end
  725.     end
  726.     invList = scanInv()
  727.  end
  728.  
  729. function run()
  730.     print("Press key to start building...")
  731.     read()
  732.     --invList = scanInv()
  733.  
  734.     up()
  735.     n = 1
  736.     turtle.select(n)
  737.  
  738.     for x=1,height do
  739.         for y=1,width do
  740.             for z=1,length do
  741.                 blockID = getBlockId(x-1,y-1,z-1)
  742.                     blockData = getData(x-1,y-1,z-1)
  743.                     forward()
  744.                 turtle.digDown()
  745.                     slot_lst = slots[blockID][blockData]
  746.                     if(slot_lst ~= nil) then
  747.                         if(#slot_lst > 0) then
  748.                             local found=false
  749.                             for i,v in ipairs(slot_lst) do
  750.                                 if(turtle.getItemCount(v) > 0) then
  751.                                     found=true
  752.                                     turtle.select(v)
  753.                                     break
  754.                                 end
  755.                             end
  756.                             if not found then
  757.                                 print("Not enough " .. getBlockName(blockID, blockData) .. ". Please refill...")
  758.                             refill()
  759.                             end
  760.                             while turtle.getItemCount() == 0 do
  761.                             refill()
  762.                         end
  763.                         if turtle.getFuelLevel() < 200 then
  764.                             refill()
  765.                         end
  766.                         end
  767.                     end
  768.                 end
  769.                 left()
  770.                 forward()
  771.             left()
  772.             for i=1,length do
  773.                 forward()
  774.             end
  775.             right()
  776.             right()
  777.         end
  778.         right()
  779.         for i=1,width do
  780.             forward()
  781.         end
  782.         left()
  783.         up()
  784.     end
  785.  
  786.     for i=1,height+1 do
  787.         down()
  788.     end
  789. end
  790.  
  791. function findNextBlock(x,y,z)
  792.     blockID = getBlockId(x,y,z)
  793.     blockData = getData(x,y,z)
  794.     if blockID then
  795.         slot_lst = slots[blockID][blockData]
  796.         if(slot_lst ~= nil) then
  797.                 if(#slot_lst > 0) then
  798.                     local found=false
  799.                     for i,v in ipairs(slot_lst) do
  800.                         if(turtle.getItemCount(v) > 0) then
  801.                             found=true
  802.                             turtle.select(v)
  803.                             break
  804.                         end
  805.                     end
  806.                     if not found then
  807.                         print("Not enough " .. getBlockName(blockID, blockData) .. ". Please refill...")
  808.                     refill()
  809.                     end
  810.                                 while turtle.getItemCount() == 0 do
  811.                                     refill()
  812.                                 end
  813.                 local doubleCheck = turtle.getItemDetail()
  814.                 if doubleCheck.name ~= "EnderStorage:enderChest" then
  815.                     place()
  816.                 else
  817.                     findNextBlock(x,y,z)   
  818.                 end
  819.             end
  820.             if turtle.getFuelLevel() < 200 then
  821.                 refill()
  822.             end
  823.         end
  824.     end
  825. end
  826.  
  827. function oldIterate()
  828.     --x,y,z = height,width,length
  829.     if z < length then
  830.         z = z + 1
  831.     elseif z == length then
  832.         z = 0
  833.         if y < width then
  834.             y = y + 1
  835.         elseif y == width then
  836.             y = 0
  837.             if x < height then
  838.                 x = x + 1
  839.             elseif x == height then
  840.                 x = 'max'
  841.                 y = 'max'
  842.                 z = 'max'
  843.             end
  844.         end
  845.     end
  846.     recordObj(x,y,z)
  847. end
  848.  
  849. function check()
  850.     if x%2==0 then
  851.         evenx = true
  852.         if y%2==0 then
  853.             eveny = true
  854.         else
  855.             eveny = false
  856.         end
  857.     else
  858.         evenx = false
  859.         if y%2==0 then
  860.             eveny = false
  861.         else
  862.             eveny = true
  863.         end
  864.     end
  865. end
  866.  
  867. function iterate()
  868.     check()
  869.     if z == length and eveny then
  870.         Yiterate()
  871.     elseif z==length and (not eveny) then
  872.         z = z - 1
  873.     elseif z == 0 and eveny then
  874.         z = z + 1
  875.     elseif z == 0 and (not eveny) then
  876.         Yiterate()
  877.     elseif z < length then
  878.         if eveny then
  879.             z = z + 1
  880.         else
  881.             z = z - 1
  882.         end
  883.     end
  884. end
  885.  
  886. function Yiterate()
  887.     if evenx then
  888.         if y < width then
  889.             y = y + 1
  890.         elseif y == width then
  891.             if x < height then
  892.                 x = x + 1
  893.             end
  894.         end
  895.     else
  896.         if y == 0 then
  897.             if x < height then
  898.                 x = x + 1
  899.             end
  900.         else
  901.             y=y-1
  902.         end
  903.     end
  904. end
  905.  
  906. function checkIfAir()
  907.     while true do
  908.         iterate()
  909.         blockID2 = getBlockId(x,y,z)
  910.         blockData2 = getData(x,y,z)
  911.         slot_2nd = slots[blockID2][blockData2]
  912.         if slot_2nd then
  913.             if #slot_2nd > 0 then
  914.                 recordObj(x,y,z)
  915.                 break
  916.             end
  917.         end
  918.     end
  919. end
  920.  
  921. function autorun()
  922.     --get the current coords
  923.     --get the iterater/goal block location
  924.     while true do
  925.         shell.run("position")
  926.         shell.run("objective")
  927.         goto(x,y,z)
  928.         findNextBlock(x,y,z)
  929.         checkIfAir()
  930.     end
  931. end
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement