guitarplayer616

Turtle Schematic Builder 3 Backup

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