Advertisement
SirBaconBitz

Vendobot 9000

Jun 29th, 2014
353
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Lua 11.72 KB | None | 0 0
  1. --Beginning variables
  2. currpos = 0
  3. dir = "forward"
  4. found = nil
  5. crafted3 = "derp"
  6.  
  7. --end
  8. function turnaround()
  9.   turtle.turnRight()
  10.   turtle.turnRight()
  11. end
  12.  
  13. function forward()
  14.   if dir == "right" then
  15.     turtle.turnLeft()
  16.   elseif dir == "left" then
  17.     turtle.turnRight()
  18.   elseif dir == "backward" then
  19.     foodstuffs.turnaround()
  20.   end
  21. end
  22.  
  23. function backward()
  24.   if dir == "right" then
  25.     turtle.turnRight()
  26.   elseif dir == "left" then
  27.     turtle.turnLeft()
  28.   elseif dir == "forward" then
  29.     foodstuffs.turnaround()
  30.   end
  31. end
  32.  
  33. function right()
  34.   if dir == "left" then
  35.     foodstuffs.turnaround()
  36.   elseif dir == "forward" then
  37.     turtle.turnRight()
  38.   elseif dir == "backward" then
  39.     turtle.turnLeft()
  40.   end
  41. end
  42.  
  43. function left()
  44.   if dir == "right" then
  45.     foodstuffs.turnaround()
  46.   elseif dir == "forward" then
  47.     turtle.turnLeft()
  48.   elseif dir == "backward" then
  49.     turtle.turnRight()
  50.   end
  51. end
  52.    
  53. function sReturn()
  54.   if pos ~= 0 then
  55.     foodstuffs.backward()
  56.     dir = "backward"
  57.     for i = 1,currpos do
  58.       turtle.forward()
  59.     end
  60.     currpos = 0
  61.     foodstuffs.turnaround()
  62.     dir = "forward"
  63.   end
  64. end
  65.  
  66. function checkFuel()
  67.   refueled = false
  68.   am = 0
  69.   level = turtle.getFuelLevel()
  70.   if 500 >= level then
  71.     term.clear()
  72.     term.write("Refuelling...")
  73.     for i = 1,16 do
  74.       foodstuffs.getFood("Sugar", 1)
  75.     end
  76.     foodstuffs.sReturn()
  77.     sleep(1)
  78.     turtle.back()
  79.     turtle.turnRight()
  80.     turtle.up()
  81.     turtle.forward()
  82.     turtle.select(1)
  83.     turtle.dropDown()
  84.     turtle.back()
  85.     turtle.down()
  86.     turtle.down()
  87.     turtle.forward()
  88.     term.write()("Cooking...")
  89.     while refueled == false do
  90.       turtle.select(1)
  91.       if turtle.getItemCount() == 16 then
  92.         sleep(0.5)
  93.         refueled = true
  94.       end
  95.     end
  96.     turtle.refuel()
  97.     turtle.back()
  98.     turtle.turnLeft()
  99.     turtle.up()
  100.     turtle.forward()
  101.   end
  102. end
  103.  
  104. function getTool( sTool , sSlot )
  105.   handle = assert(fs.open("tools", "r"), "Couldn't load tools")
  106.   input = handle.readAll()
  107.   handle.close()
  108.   tdest = textutils.unserialize(input)
  109.     for k,v in pairs(tdest) do
  110.       if v.name == sTool then
  111.         found = k
  112.       end
  113.     end
  114.   destpos = tdest[found].pos
  115.   movement = destpos - currpos
  116.     if movement >= 0 then
  117.       foodstuffs.forward()
  118.       dir = "forward"
  119.       for i = 1,movement do
  120.         turtle.forward()
  121.         currpos = currpos + 1
  122.       end
  123.     elseif 0 >= movement then
  124.       newmov = movement * -1
  125.       foodstuffs.backward()
  126.       dir = "backward"
  127.         for i = 1,newmov do
  128.           turtle.forward()
  129.           currpos = currpos - 1
  130.         end
  131.     end
  132.     turtle.select( sSlot )
  133.     turtle.suckUp()
  134.     found = nil
  135. end
  136.  
  137. function repTool( sTool , sSlot )
  138.   handle = assert(fs.open("tools", "r"), "Couldn't load tools")
  139.   input = handle.readAll()
  140.   handle.close()
  141.   rdest = textutils.unserialize(input)
  142.     for k,v in pairs(rdest) do
  143.       if v.name == sTool then
  144.         found = k
  145.       end
  146.     end
  147.   destpos = rdest[found].pos
  148.   movement = destpos - currpos
  149.     if movement >= 0 then
  150.       foodstuffs.forward()
  151.       dir = "forward"
  152.       for i = 1,movement do
  153.         turtle.forward()
  154.         currpos = currpos + 1
  155.       end
  156.     elseif 0 >= movement then
  157.       newmov = movement * -1
  158.       foodstuffs.backward()
  159.       dir = "backward"
  160.         for i = 1,newmov do
  161.           turtle.forward()
  162.           currpos = currpos - 1
  163.         end
  164.     end
  165.     turtle.select( sSlot )
  166.     turtle.dropUp()
  167.     found = nil
  168. end
  169.  
  170. function getFood( sFood , sSlot )
  171.   handle = assert(fs.open("foods", "r"), "Couldn't load food list")
  172.   input = handle.readAll()
  173.   handle.close()
  174.   fdest = textutils.unserialize(input)
  175.     for k,v in pairs(fdest) do
  176.       if v.name == sFood then
  177.         found = k
  178.       end
  179.     end
  180.   destpos = fdest[found].pos
  181.   movement = destpos - currpos
  182.     if movement >= 0 then
  183.       foodstuffs.forward()
  184.       dir = "forward"
  185.       for i = 1,movement do
  186.         turtle.forward()
  187.         currpos = currpos + 1
  188.       end
  189.     elseif 0 >= movement then
  190.       newmov = movement * -1
  191.       foodstuffs.backward()
  192.       dir = "backward"
  193.         for i = 1,newmov do
  194.           turtle.forward()
  195.           currpos = currpos - 1
  196.         end
  197.     end
  198.   destdir = fdest[found].dir
  199.     if destdir == "right" then
  200.       foodstuffs.right()
  201.       turtle.select( sSlot )
  202.       turtle.suck(1)
  203.       dir = "right"
  204.     elseif destdir == "left" then
  205.       foodstuffs.left()
  206.       turtle.select( sSlot )
  207.       turtle.suck(1)
  208.       dir = "left"
  209.     elseif destdir == "down" then
  210.       turtle.select( sSlot )
  211.       turtle.suckDown(1)
  212.     end
  213.     found = nil
  214. end
  215.  
  216. function purge()
  217.   foodstuffs.sReturn()
  218.   for i = 1,16 do
  219.     turtle.select(i)
  220.     turtle.dropDown()
  221.   end
  222. end
  223.  
  224. function craft( sFood , sNum)
  225. for i = 1 , sNum do
  226.   foodstuffs.checkFuel()
  227.   noncon = {}
  228.   recipet = {}
  229.   craftables = {}
  230.   smeltables = {}
  231.   handle = assert(fs.open("recipes", "r"), "Couldn't load recipes")
  232.   output = handle.readAll()
  233.   cdest = textutils.unserialize(output)
  234.   handle.close()
  235.   for k,v in pairs(cdest) do
  236.     if v[1].name == sFood then
  237.       found = k
  238.     end
  239.   end
  240.    
  241.   recipet = cdest[found]
  242.   print(recipet[1].name)
  243.   for k,v in pairs(recipet) do
  244.     if k ~= 1 then
  245.       if v.type == "craftable" then
  246.         table.insert(craftables, { name = v.name })
  247.       end
  248.     end
  249.   end
  250.   for k,v in pairs(craftables) do
  251.       foodstuffs.craft2( v.name )
  252.   end
  253.   for k,v in pairs(recipet) do
  254.     if k ~= 1 then
  255.       if v.type == "smeltable" then
  256.         table.insert(smeltables, { name = v.name })
  257.       end
  258.     end
  259.   end
  260.   for k,v in pairs(smeltables) do
  261.     foodstuffs.craft2( v.name )
  262.   end
  263.   for i = 1,9 do
  264.   selected = i + 1
  265.  
  266.     if i == 4 then
  267.       selSlot = 5
  268.     elseif i == 5 then
  269.       selSlot = 6
  270.     elseif i == 6 then
  271.       selSlot =7
  272.     elseif i == 7 then
  273.       selSlot = 9
  274.     elseif i == 8 then
  275.       selSlot = 10
  276.     elseif i == 9 then
  277.       selSlot = 11
  278.     else
  279.       selSlot = i
  280.     end
  281.     if recipet[selected].type == "food" then
  282.       foodstuffs.getFood(recipet[selected].name, selSlot)
  283.     elseif recipet[selected].type == "tool" then
  284.       print(recipet[selected].name)
  285.       foodstuffs.getTool(recipet[selected].name, selSlot)
  286.       table.insert(noncon, { slot = selSlot, name = recipet[selected].name })
  287.     elseif recipet[selected].type == "craftable" then
  288.       foodstuffs.sReturn()
  289.       turtle.turnLeft()
  290.       dir = "left"
  291.       turtle.select(selSlot)
  292.       turtle.suck()
  293.       turtle.turnRight()
  294.       dir = "forward"
  295.     elseif recipet[selected].type == "smeltable" then
  296.       foodstuffs.sReturn()
  297.       turtle.turnLeft()
  298.       dir = "left"
  299.       turtle.select(selSlot)
  300.       turtle.suck()
  301.       turtle.turnRight()
  302.       dir = "forward"
  303.     end
  304.   end
  305.   foodstuffs.sReturn()
  306.  
  307.   if recipet[1].type == "smeltable" then
  308.     turtle.back()
  309.     turtle.turnRight()
  310.     turtle.up()
  311.     turtle.forward()
  312.     turtle.select(1)
  313.     turtle.dropDown()
  314.     turtle.back()
  315.     turtle.down()
  316.     turtle.down()
  317.     turtle.forward()
  318.     sleep(2.5)
  319.     turtle.suckUp()
  320.     turtle.back()
  321.     turtle.turnLeft()
  322.     turtle.up()
  323.     turtle.forward()
  324.     turtle.dropUp()
  325.   else
  326.     turtle.select(4)
  327.     turtle.craft()
  328.     turtle.dropUp()
  329.     for k,v in pairs(noncon) do
  330.       repTool(v.name, v.slot)
  331.     end
  332.     sReturn()
  333.   end
  334.   foodstuffs.purge()
  335. end
  336. end
  337.  
  338. function craft2( sFood2 )
  339.   noncon2 = {}
  340.   recipet2 = {}
  341.   craftables2 = {}
  342.   handle2 = assert(fs.open("recipes", "r"), "Couldn't load recipes")
  343.   output2 = handle.readAll()
  344.   cdest2 = textutils.unserialize(output)
  345.   handle.close()
  346.   for k,v in pairs(cdest2) do
  347.     if v[1].name == sFood2 then
  348.       found2 = k
  349.     end
  350.   end
  351.    
  352.   recipet2 = cdest2[found2]
  353.   print(recipet2[1].name)
  354.   for k,v in pairs(recipet2) do
  355.     if k ~= 1 then
  356.       if v.type == "craftable" then
  357.           table.insert(craftables2, { name = v.name })
  358.       end
  359.     end
  360.   end
  361.   for k,v in pairs(craftables2) do
  362.     foodstuffs.craft3( v.name )
  363.   end
  364.   for i = 1,9 do
  365.   selected2 = i + 1
  366.  
  367.     if i == 4 then
  368.       selSlot2 = 5
  369.     elseif i == 5 then
  370.       selSlot2 = 6
  371.     elseif i == 6 then
  372.       selSlot2 =7
  373.     elseif i == 7 then
  374.       selSlot2 = 9
  375.     elseif i == 8 then
  376.       selSlot2 = 10
  377.     elseif i == 9 then
  378.       selSlot2 = 11
  379.     else
  380.       selSlot2 = i
  381.     end
  382.     if recipet2[selected2].type == "food" then
  383.       foodstuffs.getFood(recipet2[selected2].name, selSlot2)
  384.     elseif recipet2[selected2].type == "tool" then
  385.       print(recipet2[selected2].name)
  386.       foodstuffs.getTool(recipet2[selected2].name, selSlot2)
  387.       table.insert(noncon2, { slot = selSlot2, name = recipet2[selected2].name })
  388.     elseif recipet2[selected2].type == "craftable" then
  389.       foodstuffs.sReturn()
  390.       turtle.turnRight()
  391.       dir = "right"
  392.       turtle.select(selSlot2)
  393.       turtle.suck()
  394.       turtle.turnLeft()
  395.       dir = "forward"
  396.     elseif recipet2[selected2].type == "smeltable" then
  397.       foodstuffs.sReturn()
  398.       turtle.turnLeft()
  399.       dir = "left"
  400.       turtle.select(selSlot2)
  401.       turtle.suck()
  402.       turtle.turnRight()
  403.       dir = "forward"
  404.     end
  405.   end
  406.   foodstuffs.sReturn()
  407.   if recipet2[1].type == "smeltable" then
  408.     turtle.back()
  409.     turtle.turnRight()
  410.     turtle.up()
  411.     turtle.forward()
  412.     turtle.select(1)
  413.     turtle.dropDown()
  414.     turtle.back()
  415.     turtle.down()
  416.     turtle.down()
  417.     turtle.forward()
  418.     sleep(2.5)
  419.     turtle.suckUp()
  420.     turtle.back()
  421.     turtle.turnLeft()
  422.     turtle.up()
  423.     turtle.forward()
  424.     turtle.turnLeft()
  425.     turtle.drop()
  426.     turtle.turnRight()
  427.   else
  428.     turtle.select(4)
  429.     turtle.craft()
  430.     turtle.turnLeft()
  431.     dir = "left"
  432.     turtle.drop()
  433.     turtle.turnRight()
  434.     dir = "forward"
  435.     for k,v in pairs(noncon2) do
  436.       repTool(v.name, v.slot)
  437.     end
  438.   end
  439.   foodstuffs.purge()
  440. end
  441.  
  442. function craft3( sFood3 )
  443.   noncon3 = {}
  444.   recipet3 = {}
  445.   handle3 = assert(fs.open("recipes", "r"), "Couldn't load recipes")
  446.   output3 = handle.readAll()
  447.   cdest3 = textutils.unserialize(output)
  448.   handle.close()
  449.   for k,v in pairs(cdest3) do
  450.     if v[1].name == sFood3 then
  451.       found3 = k
  452.     end
  453.   end
  454.    
  455.   recipet3 = cdest3[found3]
  456.   crafted3 = recipet3[1].name
  457.   print(recipet3[1].name)
  458.   for i = 1,9 do
  459.   selected3 = i + 1
  460.  
  461.     if i == 4 then
  462.       selSlot3 = 5
  463.     elseif i == 5 then
  464.       selSlot3 = 6
  465.     elseif i == 6 then
  466.       selSlot3 =7
  467.     elseif i == 7 then
  468.       selSlot3 = 9
  469.     elseif i == 8 then
  470.       selSlot3 = 10
  471.     elseif i == 9 then
  472.       selSlot3 = 11
  473.     else
  474.       selSlot3 = i
  475.     end
  476.     if recipet3[selected3].type == "food" then
  477.       foodstuffs.getFood(recipet3[selected3].name, selSlot3)
  478.     elseif recipet3[selected3].type == "tool" then
  479.       print(recipet3[selected3].name)
  480.       foodstuffs.getTool(recipet3[selected3].name, selSlot3)
  481.       table.insert(noncon3, { slot = selSlot3, name = recipet3[selected3].name })
  482.     end
  483.   end
  484.   foodstuffs.sReturn()
  485.   if recipet3[1].type == "smeltable" then
  486.     turtle.back()
  487.     turtle.turnRight()
  488.     turtle.up()
  489.     turtle.forward()
  490.     turtle.select(1)
  491.     turtle.dropDown()
  492.     turtle.back()
  493.     turtle.down()
  494.     turtle.down()
  495.     turtle.forward()
  496.     sleep(2.5)
  497.     turtle.suckUp()
  498.     turtle.back()
  499.     turtle.turnLeft()
  500.     turtle.up()
  501.     turtle.forward()
  502.     turtle.turnRight()
  503.     turtle.drop()
  504.     turtle.turnLeft()
  505.   else
  506.     turtle.select(4)
  507.     turtle.craft()
  508.     turtle.turnRight()
  509.     dir = "right"
  510.     turtle.drop()
  511.     turtle.turnLeft()
  512.     dir = "forward"
  513.     for k,v in pairs(noncon3) do
  514.       repTool(v.name, v.slot)
  515.     end
  516.   end
  517.   foodstuffs.purge()
  518. end
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement