NicolaosGreene

Seed Check

Jan 1st, 2019
180
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Lua 3.10 KB | None | 0 0
  1. -- =============VARIABLES===================
  2. note = peripheral.wrap("left")
  3. -- =============VARIABLES END===============
  4.  
  5. -- ============FUNCTIONS====================
  6. function NewLine(Str,Int)
  7.     local barLength = 40
  8.     local tempPercentage = 0
  9.     term.clear()
  10.     term.setCursorPos(1,2)
  11.     print("-------------[SeedBot v0.6]------------")
  12.     term.setCursorPos(11,5)
  13.     write("v {Current action} v")
  14.     term.setCursorPos(Int,8)
  15.     print(Str)
  16.     term.setCursorPos(12,12)
  17.     write("[Current Fuel %"..(math.floor(turtle.getFuelLevel())))
  18.     write("]")
  19.     term.setCursorPos(1,13)
  20.     barLength = turtle.getFuelLevel() / 100 * 40
  21.     if barLength > 40 then barLength = 40 end
  22.     if term.isColor() then
  23.       term.setBackgroundColor(colors.green)
  24.     else
  25.       term.setBackgroundColor(colors.white)
  26.     end
  27.     for i =1,(barLength) do
  28.       write(" ")
  29.     end
  30.     if barLength < 40 then
  31.         if term.isColor() then term.setBackgroundColor(colors.red) else term.setBackgroundColor(colors.gray) end
  32.         local remainingBarLength = (40 - barLength)
  33.         for i =1,(remainingBarLength) do
  34.           write(" ")
  35.         end
  36.     end
  37.     term.setBackgroundColor(colors.black)
  38. end
  39.  
  40. function CheckFuel(bool)
  41.   local fuel = turtle.getFuelLevel()
  42.   --Checking fuel level & fueling if low
  43.   if turtle.getFuelLevel() < 25 then
  44.     GetFuel()
  45.     return true
  46.   else
  47.     return false
  48.   end
  49. end
  50.  
  51. function GetFuel()
  52.   if not done then NewLine("Getting fuel",15) end
  53.   --print("Current Fuel Level: "..turtle.getFuelLevel())
  54.   turtle.select(16)
  55.   while turtle.getFuelLevel() <= 100 do
  56.     if not turtle.suckUp(1) and (turtle.getFuelLevel() <= 100) then
  57.       NewLine("No fuel in fuel chest!",10)
  58.       turtle.select(1)
  59.       done = true
  60.       break
  61.     end
  62.     turtle.refuel(1)
  63.     turtle.drop(turtle.getItemCount(16))
  64.     NewLine("Getting fuel",15)
  65.     --print("Current Fuel Level: "..turtle.getFuelLevel())
  66.   end
  67.   turtle.select(1)
  68. end
  69.  
  70. function CheckPosition()
  71.   if turtle.up() then
  72.     NewLine("Returning to start position",8)
  73.     turtle.down()
  74.     turtle.forward()
  75.     turtle.forward()
  76.     turtle.turnLeft()
  77.     turtle.back()
  78.     os.reboot()
  79.   end
  80. end
  81.  
  82. function GetSeed()
  83.   turtle.suck()
  84.   print("Getting seeds")  
  85. end
  86.  
  87. function AnalyzeSeed()
  88.   turtle.dropDown()
  89.   os.sleep(6)
  90.   turtle.suckDown()
  91.   print("Analyzing seeds")
  92. end
  93.  
  94. function DepositSeed()
  95.   turtle.turnRight()
  96.   print("Storing seeds")
  97.   os.sleep(1)
  98.   for i=1,4 do
  99.     turtle.drop()
  100.     turtle.select(i)
  101.   end
  102.   os.sleep(1)
  103.   turtle.select(1)
  104.   turtle.turnLeft()
  105. end
  106. -- ============FUNCTIONS END====================
  107.  
  108. -- ===========STARTUP SEQUENCE==========
  109. if turtle.getFuelLevel() > 4 then CheckPosition() end
  110. CheckFuel()
  111. -- ===========STARTUP SEQUENCE END======
  112.  
  113. -- ===========MAIN LOOP=================
  114. while not done do
  115.   GetSeed()
  116.   if turtle.compareTo(2) then
  117.     NewLine("No seeds left in the chest!",10)
  118.     for i=0,4 do
  119.       note.playNote(6, i)
  120.       os.sleep(.2)
  121.     end
  122.     break
  123.   end
  124.   AnalyzeSeed()
  125.   DepositSeed()
  126.   CheckFuel()
  127. end
  128. -- ===========MAIN LOOP END=================
Advertisement
Add Comment
Please, Sign In to add comment