Advertisement
guitarplayer616

Turtle Schematic Builder 4 WORKING

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