Advertisement
YK7942

Potion Turtle v1.1

Nov 8th, 2013
473
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Lua 20.08 KB | None | 0 0
  1. --[[TODO LIST
  2. 1. make prompts blink to make them stand out to the user
  3. 2. modify FindHome() to prevent turtle from running away
  4. 3. modify RunMenu() so that the printing code is more compact
  5. 4. modify menu routine to have +duration/+effect/splash sub menus for each of the primary potions
  6. 5. allow for 'n' dispensers to be used ( n > 2 )
  7. 6. modify menu to indicate what potions were selected for inactive shelves
  8. ]]
  9.  
  10. function Main() --Control center for the program DONE
  11.     --construction
  12.     if DoYouWantTheBuilder() == true then
  13.         WaitForInventory()
  14.         SurveySite()
  15.         AutoBuilder()
  16.     end
  17.     --potion selection
  18.     if DoesOldSaveExist() == true then
  19.         if ChooseANewSet() == true then
  20.             potionList = RunMenu()
  21.             SaveFile(potionList)
  22.         else
  23.             potionList = LoadFile()
  24.         end
  25.     else
  26.         potionList = RunMenu()
  27.         SaveFile(potionList)
  28.     end
  29.     inventory, reservedSlots = DefineInventory(potionList)
  30.     --potion brewing
  31.     FindHome()
  32.     CleanUp(reservedSlots)
  33.     shelfNo = 1
  34.     while true do
  35.         if IsShelfFull(shelfNo,reservedSlots) == true then
  36.             --Do nothing
  37.         else
  38.             if IsEnoughIngredients(potionList[shelfNo],inventory) == true then
  39.                 FillBottles(reservedSlots)
  40.                 BrewPotion(potionList[shelfNo],inventory)
  41.                 RestockShelf(shelfNo)
  42.             else
  43.                 RestockTurtle(reservedSlots)
  44.             end
  45.         end
  46.        
  47.         if shelfNo == 4 then
  48.             Rest(10,"sleep","Cycle complete.")
  49.             shelfNo = 1
  50.         else
  51.             shelfNo = shelfNo + 1
  52.         end
  53.     end
  54. end
  55.  
  56. function DoYouWantTheBuilder() --Ask the user if they require instructions DONE
  57.     term.clear() term.setCursorPos(1,1)
  58.     print("Would you like to use the builder program? (Y/N)")
  59.     local timer = os.startTimer(10) --#The interval that you would like to wait
  60.     while true do
  61.         local event, result = os.pullEvent()
  62.         if event=="timer" then --#If a timer event is pulled and its ID matches the one returned by startTimer
  63.             return false
  64.         elseif event == "key" then
  65.             if result == keys.enter or result == keys.y then return true
  66.             elseif result == keys.n then return false              
  67.             end
  68.         end
  69.     end
  70. end
  71.  
  72. function WaitForInventory() --Waits for the required building materials DONE
  73.     repeat
  74.         term.clear() term.setCursorPos(1,1)
  75.         local inventory = "good"
  76.         turtle.select(1)  --building material
  77.         if turtle.getItemCount(1) < 23 then
  78.             print(" - Put exactly 23 blocks of a building material in slot 1")
  79.             inventory = "bad"
  80.         end
  81.         turtle.select(2)  --dispensers
  82.         if turtle.getItemCount(2) < 4 then
  83.             print(" - Put exactly 4 dispensers or droppers in slot 2")
  84.             inventory = "bad"
  85.         end
  86.         turtle.select(3)  --chest
  87.         if turtle.getItemCount(3) < 2 then
  88.             print(" - Put exactly 2 chests in slot 3")
  89.             inventory = "bad"
  90.         end
  91.         turtle.select(4)  --brewing stand
  92.         if turtle.getItemCount(4) < 1 then
  93.             print(" - Put exactly one brewing stand in slot 4")
  94.             inventory = "bad"
  95.         end
  96.         turtle.select(5)  --fuel
  97.         turtle.refuel()
  98.         if turtle.getFuelLevel() < 90 then
  99.             print(" - Put at least 2 coal worth of fuel in slot 5")
  100.             inventory = "bad"
  101.         end
  102.         sleep(3)
  103.     until inventory == "good"
  104. end
  105.  
  106. function SurveySite() --Ensures the area is ready for construction DONE
  107.     term.clear() term.setCursorPos(1,1)
  108.     print("Surveying site.  Stand well back.")
  109.     for layer = 1,2 do
  110.         for section = 1,6 do
  111.             while turtle.detect() == true do
  112.                 print("Remove this block. TimeStamp = " ..os.clock())
  113.                 sleep(5)
  114.             end
  115.             turtle.turnLeft()
  116.             while turtle.detect() == true do
  117.                 print("Remove this block. TimeStamp = " ..os.clock())
  118.                 sleep(5)
  119.             end
  120.             TurnAround()
  121.             while turtle.detect() == true do
  122.                 print("Remove this block. TimeStamp = " ..os.clock())
  123.                 sleep(5)
  124.             end
  125.             turtle.turnLeft()
  126.             turtle.forward()
  127.         end
  128.         if layer == 1 then
  129.             while turtle.detectUp() == true do
  130.                 print("Remove this block. TimeStamp = " ..os.clock())
  131.                 sleep(5)
  132.             end
  133.             turtle.up()
  134.         end
  135.         TurnAround()
  136.         turtle.forward()
  137.     end
  138.     turtle.down()
  139.    
  140.     for i = 1,3 do turtle.forward() end
  141.     while turtle.detectDown() == true do
  142.         print("Remove the block below and fill it with water. TimeStamp = " ..os.clock())
  143.         sleep(5)
  144.     end
  145.     for i = 1,3 do turtle.back() end
  146.     print("Survey complete.  Area is clear.")
  147. end
  148.  
  149. function AutoBuilder() --Constructs the setup DONE
  150.     print("Laying first layer")
  151.     turtle.select(1)
  152.     for i = 1,6 do   --build the left and right sides
  153.         turtle.turnLeft()
  154.         turtle.place()
  155.         TurnAround()
  156.         turtle.place()
  157.         turtle.turnLeft()
  158.         turtle.forward()
  159.     end
  160.     turtle.back()  --place the end block
  161.     turtle.back()
  162.     turtle.place()
  163.     turtle.select(4) --place the brewing stand
  164.     turtle.back()
  165.     turtle.place()
  166.     turtle.select(3) --place the chest
  167.     for i = 1,3 do turtle.back() end
  168.     turtle.place()
  169.     turtle.select(1) --place the last block
  170.     turtle.back()
  171.     turtle.place()
  172.     --turtle is now outside the apothecary facing the righthand end
  173.    
  174.     print("Laying top layer")
  175.     turtle.up()
  176.     turtle.forward()
  177.     turtle.select(1) --BM
  178.     turtle.turnLeft()
  179.     turtle.place()
  180.     TurnAround()
  181.     turtle.place()
  182.     turtle.turnRight()
  183.     turtle.back()
  184.     turtle.select(3) --chests
  185.     turtle.place()
  186.     TurnAround()
  187.     for i = 1,4 do --laying the 'shelves'
  188.         turtle.turnLeft()
  189.         turtle.select(2) --dispensers
  190.         turtle.place()
  191.         TurnAround()
  192.         turtle.select(1) --Building material
  193.         turtle.place()
  194.         turtle.turnLeft()
  195.         turtle.forward()
  196.     end
  197.     turtle.turnLeft()  --place the blocks around 'home'
  198.     turtle.place()
  199.     TurnAround()
  200.     turtle.place()
  201.     turtle.turnLeft()
  202.     turtle.back()
  203.     turtle.select(1) --BM
  204.     turtle.place()
  205.     --turtle is now in home position
  206. end
  207.  
  208. function DoesOldSaveExist() --Is there an old save file existing? DONE
  209.     print("Searching for existing save file..")
  210.     local fileName = os.getComputerID()..".potions" --computer ID with the extension .potions
  211.     local file = io.open(fileName,"r")
  212.     if file == nil then
  213.         return false
  214.     else
  215.         --[[if file:readLine() == nil then
  216.             file:close()
  217.             return false
  218.         else
  219.             file:close()
  220.             return true
  221.         end]]
  222.         return true
  223.     end
  224. end
  225.  
  226. function ChooseANewSet() --do you need to choose a new potion set? DONE
  227.     term.clear() term.setCursorPos(1,1)
  228.     print("Would you like to select a new set of potions?? (Y/N)")
  229.     local timer = os.startTimer(20) --#The interval that you would like to wait
  230.     while true do
  231.         local event, result = os.pullEvent()
  232.         if event=="timer" then --#If a timer event is pulled and its ID matches the one returned by startTimer
  233.             return false
  234.         elseif event == "key" then
  235.             if result == keys.enter or result == keys.y then return true
  236.             elseif result == keys.n then return false              
  237.             end
  238.         end
  239.     end
  240. end
  241.  
  242. function RunMenu() --run the menu program to read a users selection DONE
  243.     local potion = {}
  244.     potion[01] = {"N.V.  3:00","g.carrot "}  --Night Vision
  245.     potion[02] = {"N.V.  8:00","g.carrot ","redstone "}  --Night Vision
  246.     potion[03] = {"Inv.  3:00","g.carrot ","f.s.eye  "}  --Invisibility
  247.     potion[04] = {"Inv.  8:00","g.carrot ","f.s.eye  ","redstone "}  --Invisibility
  248.     potion[05] = {"F.R.  3:00","m. cream "}  --Fire Resist
  249.     potion[06] = {"F.R.  8:00","m. cream ","redstone "}  --Fire Resist
  250.     potion[07] = {"Sl(s) 1:30","m. cream ","f.s.eye  ","gunpowder"}  --Slowness
  251.     potion[08] = {"Sl(s) 4:00","m. cream ","f.s.eye  ","redstone ","gunpowder"}  --Slowness
  252.     potion[09] = {"Sw I  3:00","sugar    "}  --Swiftness
  253.     potion[10] = {"Sw I  8:00","sugar    ","redstone "}  --Swiftness
  254.     potion[11] = {"Sw II 1:30","sugar    ","gl.stone "}  --Swiftness
  255.     potion[12] = {"Hp I  +6  ","gl.melon "}  --Healing
  256.     potion[13] = {"Hp II +12 ","gl.melon ","gl.stone "}  --Healing
  257.     potion[14] = {"Hm1(s)-6  ","spidereye","f.s.eye  ","gunpowder"}  --Harming
  258.     potion[15] = {"Hm2(s)-12 ","spidereye","f.s.eye  ","glowstone","gunpowder"} --Harming
  259.     potion[16] = {"Ps1(s)0:45","spidereye","redstone ","gunpowder"}  --Poison
  260.     potion[17] = {"Ps1(s)2:00","spidereye","glowstone","gunpowder"}  --Poison
  261.     potion[18] = {"Ps2(s)0:22","spidereye","glowstone","f.s.eye  ","gunpowder"}
  262.     potion[19] = {"RgnI  0:45","ghastTear"}
  263.     potion[20] = {"RgnI  2:00","ghastTear","redstone "}
  264.     potion[21] = {"RgnII 0.22","ghastTear","glowstone"}
  265.     potion[22] = {"Weak  1:30","f.s.eye  ","gunpowder"}
  266.     potion[23] = {"Weak  4:00","f.s.eye  ","redstone ","gunpowder"}
  267.     potion[24] = {"St I  3:00","blz.pwdr "}
  268.     potion[25] = {"St I  8:00","blz.pwdr ","glowstone"}
  269.     potion[26] = {"St II 1:30","blz.pwdr ","redstone "}
  270.  
  271.     local choice={1,1,1,1}
  272.     local itemspp = 9
  273.     local column = 1
  274.     local pagestart = 4
  275.  
  276.     repeat
  277.         term.clear() term.setCursorPos(1,1)
  278.         --Print the headings
  279.         print("Select potions from the choice: (UDLR)")
  280.         print("          <<< Shelf "..column.." of 4 >>>         ")
  281.        
  282.         --Print the potions
  283.         --todo - rebuild this section much shorter
  284.         for ID = 1,itemspp do
  285.             term.setCursorPos(1,pagestart + ID - 1)
  286.             if choice[column] == ID then
  287.                 print(">>"..potion[ID][1])
  288.             else
  289.                 print("  "..potion[ID][1])
  290.             end
  291.         end
  292.         for ID = itemspp+1,itemspp*2 do
  293.             term.setCursorPos(14,pagestart + ID - itemspp - 1)
  294.             if choice[column] == ID then
  295.                 print(">>"..potion[ID][1])
  296.             else
  297.                 print("  "..potion[ID][1])
  298.             end
  299.         end
  300.         for ID = itemspp*2+1,#potion do
  301.             term.setCursorPos(27,pagestart + ID - itemspp*2 - 1)
  302.             if choice[column] == ID then
  303.                 print(">>"..potion[ID][1])
  304.             else
  305.                 print("  "..potion[ID][1])
  306.             end
  307.         end
  308.        
  309.         --Recieve and process keyboard input
  310.         local eventtype, key = os.pullEvent()  --get keyboard input
  311.         if key == 200 and choice[column] == 1 then choice[column] = #potion  --up
  312.             elseif key == 200 then choice[column] = choice[column] - 1 --up
  313.             elseif key == 208 and choice[column] == #potion then choice[column] = 1  --down
  314.             elseif key == 208 then choice[column] = choice[column] + 1 --down
  315.             elseif key == 205 and column == 4 then column = 1 --right
  316.             elseif key == 205 then column = column + 1 --right
  317.             elseif key == 203 and column == 1 then column = 4 --left
  318.             elseif key == 203 then column = column - 1 --left
  319.         end
  320.     until key == 28  --if keypress = 'enter' then continue the program
  321.  
  322.     --print the user choice
  323.     term.clear() term.setCursorPos(1,1)
  324.     print("You have selected:\n") --print the user choice
  325.     print("Shelf 1      Shelf 2")
  326.     print(potion[choice[1]][1].."   "..potion[choice[2]][1].."\n")
  327.     print("      Shelf 3      Shelf 4")
  328.     print("      "..potion[choice[3]][1].."   "..potion[choice[4]][1].."\n")
  329.    
  330.     print("Are you happy with this selection? (Y/N)")
  331.     local input = read()
  332.     if input == "n" then
  333.         return RunMenu()
  334.     else
  335.         --reduce the potionlist to just the 4 choices stored in a 2D array
  336.         local potionShortList = {}
  337.         for i = 1,4 do
  338.             potionShortList[i] = potion[choice[i]]
  339.         end
  340.        
  341.         term.clear() term.setCursorPos(1,1)
  342.         return potionShortList
  343.     end
  344. end
  345.  
  346. function SaveFile(potionShortList) --saves the potion list as an 8 bit number in a file DONE
  347.     print("Saving potion set to file..")
  348.     local fileName = os.getComputerID()..".potions" --computer ID with the extension .potions
  349.     local file = fs.open(fileName,"w")
  350.     for potionNo = 1,4 do
  351.         local potionString = ""
  352.         for potionItem = 1,#potionShortList[potionNo],1 do
  353.             potionString = potionString..potionShortList[potionNo][potionItem]
  354.         end
  355.         file.writeLine(potionString)
  356.     end
  357.     file:close()
  358. end
  359.  
  360. function LoadFile() --loads the data from file and returns the potion list DONE
  361.     print("Loading potions set from existing file..")
  362.     local fileName = os.getComputerID()..".potions" --computer ID with the extension .potions
  363.     local file = fs.open(fileName,"r")
  364.     local potionShortList = {}
  365.     potionShortList[1] = {"",""} --possibly unnecessary code
  366.     potionShortList[2] = {"",""}
  367.     potionShortList[3] = {"",""}
  368.     potionShortList[4] = {"",""}
  369.     for potionNo = 1,4,1 do
  370.         local potionString = file.readLine()
  371.         potionShortList[potionNo][1] = potionString:sub(1,10) --record the potion name
  372.         for potionItem = 1,(potionString:len()-10)/9 do
  373.             local startChar = (potionItem-1)*9 + 1 + 10
  374.             local endChar = (potionItem) * 9 + 10
  375.             --local ingredient = potionString:sub(startChar,endChar)
  376.             --potionShortList[potionNo][potionItem] = ingredient
  377.             potionShortList[potionNo][potionItem+1] = potionString:sub(startChar,endChar)
  378.         end
  379.     end
  380.     file:close()
  381.     return potionShortList
  382. end
  383.  
  384. function DefineInventory(potionShortList) --gives instruction on inventory layout and returns the inventory array DONE
  385.     local inventory = {"bottles  ","n. wart  "} --establish the inventory
  386.     for potID = 1,4 do --loop through all 4 potions
  387.         for ingredient = 2,#potionShortList[potID] do --loop through all the ingredients
  388.             local listed = false  --assume the current ingredient not in the inventory array
  389.             for slot = 1,#inventory do
  390.                 if inventory[slot] == potionShortList[potID][ingredient] then
  391.                     listed = true
  392.                 end
  393.             end
  394.             if listed == false then
  395.                 inventory[#inventory+1] = potionShortList[potID][ingredient] --append the array
  396.             end
  397.         end
  398.     end
  399.     local resSlotNum = #inventory --calculates the number of reserved slots
  400.     for slot = resSlotNum+1,16 do inventory[slot] = "[empty]  " end --mark the empty slots
  401.  
  402.     --prints the inventory and scans the inventory ensuring it is at least minimally stocked
  403.     local stocked
  404.     repeat
  405.         term.clear() term.setCursorPos(1,1)
  406.         print("Stock the inventory to continue.  \n\n")
  407.         for x = 0,3 do
  408.             print(inventory[x*4+1].." "..inventory[x*4+2].." "..inventory[x*4+3].." "..inventory[x*4+4].."")
  409.         end
  410.         sleep(1)
  411.         stocked = true
  412.         for slot = 1,resSlotNum do
  413.             turtle.select(slot)
  414.             if turtle.getItemCount(slot) == 0 then
  415.                 stocked = false
  416.             end
  417.         end
  418.     until stocked
  419.     term.clear() term.setCursorPos(1,1)
  420.    
  421.     return inventory, resSlotNum
  422. end
  423.  
  424. function FindHome() --Navigates to home base DONE (needs to prevent breakouts)
  425.     print("\nGetting my bearings...")
  426.     repeat
  427.         turtle.forward()
  428.         turtle.turnLeft()
  429.     until (turtle.detect() == false) and (turtle.detectDown() == false) --nothing forwards or down (narrows it down to 3 blocks, 5 orientations)
  430.     if turtle.back() == true then
  431.         turtle.forward()
  432.         turtle.down()
  433.         repeat
  434.             turtle.forward()
  435.             turtle.turnLeft()
  436.         until (turtle.detect() == false) and (turtle.detectDown() == false) --nothing forwards or down
  437.     end
  438.     turtle.turnLeft()
  439.     turtle.turnLeft()
  440.     turtle.up()
  441.     turtle.forward()
  442. end
  443.  
  444. function CleanUp(reservedSlotCount) --Clears away any leftovers from the previous run DONE
  445.     print("Cleaning up from last time")
  446.     turtle.suckDown()
  447.     turtle.back()
  448.     turtle.down()
  449.     for i = 1,3 do turtle.suck() end
  450.     TurnAround()
  451.     turtle.forward()
  452.     for slot = reservedSlotCount+1,16 do
  453.         turtle.select(slot)
  454.         turtle.drop(64)
  455.     end
  456.     TurnAround()
  457.     turtle.up()
  458.     turtle.forward() turtle.forward() turtle.forward()
  459.     term.clear() term.setCursorPos(1,1)
  460. end
  461.  
  462. function IsShelfFull(shelfID,reservedSlotCount) --counts the contents of a shelf and returns true or false DONE
  463.     print("Inspecting shelf #"..shelfID.."..")
  464.     --move into position and face the shelf
  465.     while shelfID > 1 do
  466.         turtle.back()
  467.         shelfID = shelfID - 1
  468.     end
  469.     turtle.turnLeft()
  470.     --attempt to withdraw as many potions as possible
  471.     turtle.select(reservedSlotCount+1)
  472.     for slot = reservedSlotCount+1,16 do
  473.         turtle.suck()
  474.     end
  475.     --count the potions and put them back
  476.     local potionCount = 0
  477.     for slot = reservedSlotCount+1,16 do
  478.         turtle.select(slot)
  479.         if turtle.getItemCount(slot) == 1 then
  480.             potionCount = potionCount + 1
  481.         elseif turtle.getItemCount(slot) == 0 then
  482.             break
  483.         end
  484.         turtle.drop()
  485.     end
  486.     --go home
  487.     turtle.turnRight()
  488.     while turtle.forward() == true do
  489.         turtle.forward()
  490.     end
  491.     --return a result
  492.     if potionCount < 16-reservedSlotCount then
  493.         if potionCount > 6 then
  494.             return true
  495.         else
  496.             return false
  497.         end
  498.     else
  499.         return true
  500.     end
  501. end
  502.  
  503. function IsEnoughIngredients(potionRecipe, inventoryList) --ensures engough supply of raw materials for brewing DONE
  504.     print("Checking internal storage..")
  505.     turtle.select(1) --contains bottles
  506.     if turtle.getItemCount(1) <= 3 then return false end
  507.     turtle.select(2)
  508.     if turtle.getItemCount(2) <= 1 then return false end
  509.     for slot = 3,16 do
  510.         turtle.select(slot)
  511.         if turtle.getItemCount(slot) <= 1 then --check item count first.  more likely to be false.  saves time
  512.             for ingredient = 2,#potionRecipe do
  513.                 if inventoryList[slot] == potionRecipe[ingredient] then
  514.                      return false
  515.                 end
  516.             end
  517.         end
  518.     end
  519.     return true
  520. end
  521.  
  522. function FillBottles(reservedSlotCount) --DONE
  523.     print("Filling bottles..")
  524.     turtle.back()
  525.     turtle.down()
  526.     for i = 1,3 do
  527.         turtle.select(1) --slot 1 contains empty bottles
  528.         turtle.placeDown()
  529.         turtle.select(reservedSlotCount + 1)
  530.         turtle.drop()
  531.     end
  532.     turtle.up()
  533.     turtle.forward()
  534. end
  535.    
  536. function BrewPotion(potionRecipe, inventoryList) --brews the potion corresponding to the shelfID DONE
  537.     local potionSize = #potionRecipe
  538.     turtle.select(2) --this slot contains netherwart
  539.     turtle.dropDown(1)
  540.     term.clear() term.setCursorPos(1,1)
  541.     Rest(20,"brew","Brewing step 1 of "..potionSize)
  542.     --find the next ingredient in the recipe in the inventory and put it in the stand
  543.     for ingredient = 2,potionSize do
  544.         for slot = 1,16 do
  545.             if inventoryList[slot] == potionRecipe[ingredient] then
  546.                 turtle.select(slot)
  547.                 turtle.dropDown(1)
  548.                 term.clear() term.setCursorPos(1,1)
  549.                 Rest(20,"brew","Brewing step "..ingredient.." of "..potionSize)
  550.             end
  551.         end
  552.     end
  553. end
  554.  
  555. function RestockShelf(shelfID)  --puts freshly brewed potions on the shelf DONE
  556.     print("Restocking Shelves...")
  557.     --move to the brewing stand
  558.     turtle.back()
  559.     turtle.down()
  560.     --extract potions
  561.     for i = 1,3 do
  562.         turtle.suck()
  563.     end
  564.     --move to home
  565.     turtle.up()
  566.     turtle.forward()
  567.     --move to shelf
  568.     while shelfID > 1 do
  569.         turtle.back()
  570.         shelfID = shelfID - 1
  571.     end
  572.     turtle.turnLeft()
  573.     --identify which slots the potions are stored in
  574.     local slot = 16
  575.     turtle.select(slot)
  576.     while turtle.getItemCount(slot) == 0 do
  577.         slot = slot - 1
  578.         turtle.select(slot)
  579.     end
  580.     --put the potions away
  581.     for i = 1,3 do
  582.         turtle.drop()
  583.         slot = slot - 1
  584.         turtle.select(slot)
  585.     end
  586.     --move to home
  587.     turtle.turnRight()
  588.     while turtle.forward() == true do
  589.         turtle.forward()
  590.     end
  591. end
  592.  
  593. function RestockTurtle(reservedSlotCount) --restocks the turtle from the storage chests DONE
  594.     print("Restocking turtle...")
  595.     TurnAround()
  596.     while turtle.forward() == true do turtle.forward() end   --go to the chests
  597.    
  598.     turtle.select(reservedSlotCount+1)
  599.     while turtle.suck() == true do --get a stack of items
  600.         for slot = 1,reservedSlotCount do turtle.transferTo(slot) end  --shove it in the working inventory
  601.         turtle.refuel()   --attempt to refuel with the item
  602.         turtle.dropDown()  --dump the item in the temp chest
  603.     end
  604.     while turtle.suckDown() == true do  --move items from temp to perm chest
  605.       turtle.drop()
  606.     end
  607.    
  608.     TurnAround()
  609.     while turtle.forward() == true do turtle.forward() end   --go home
  610.     if turtle.getFuelLevel() < 50 then
  611.         Rest(300,"sleep","Low on fuel.  Slowing down work rate..")
  612.     elseif turtle.getFuelLevel() < 100 then
  613.         Rest(100,"sleep","Low on fuel.  Slowing down work rate..")
  614.     end
  615. end
  616.  
  617. function Rest(restTime, restType, heading) --makes the turtle sleep for a time with animations DONE
  618.     term.clear() term.setCursorPos(1,1)
  619.     print(heading)
  620.     local restStep
  621.     while restTime > 0 do
  622.         term.setCursorPos(1,2)
  623.         if restType == "brew" then
  624.             restStep = 1 --must be an odd number
  625.             print("Brewing for "..restTime.."s  \n")
  626.             if math.fmod(restTime,2) == 0 then
  627.                 print[[
  628.                   \      
  629.                  } \   {
  630.                 |O  \o  |
  631.                 |  o \  |
  632.                  \_____/
  633.                 ]]
  634.             else
  635.                 print[[
  636.                       /  
  637.                  }   / {
  638.                 | o / O |
  639.                 |  / o  |
  640.                  \_____/
  641.                 ]]
  642.             end
  643.         elseif restType == "sleep" then
  644.             restStep = 1 --must be an odd number
  645.             print("Sleeping for "..restTime.."s   \n")
  646.             if math.fmod(restTime,2) == 0 then
  647.                 print[[
  648.                 ==== ====          
  649.                   //   // ===  ===  
  650.                  //   //   //   //  
  651.                 ==== ====  ===  ===
  652.                 ]]
  653.             else
  654.                 print[[
  655.                 ==== ====  ===  ===
  656.                   //   //   //   //
  657.                  //   //    ===  ===
  658.                 ==== ====          
  659.                 ]]
  660.             end
  661.         end
  662.         restTime = restTime - restStep
  663.         sleep(restStep)
  664.     end
  665.     term.clear() term.setCursorPos(1,1)
  666. end
  667.  
  668. function TurnAround()  --turtle performs a 180 leftwise DONE
  669.     turtle.turnLeft() turtle.turnLeft()
  670. end
  671.  
  672. term.clear() term.setCursorPos(1,1)
  673. print("\nStarting program 'Potion Robot v1.2' by YardKing42 aka YK7942")
  674. Main()
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement