Advertisement
markuszeller

Planter

May 25th, 2014 (edited)
188
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Lua 3.04 KB | None | 0 0
  1. -- Planter v1.0
  2.  
  3. local borderSlot = 1
  4. local digSlot = 2
  5.  
  6. local startFrom = "right"
  7. local facingForwardFromStartView = true
  8. local seeds = {}
  9.  
  10. local standardColor = colors.lime
  11. local specialColor = colors.pink
  12.  
  13. function cPrint(s)
  14.   term.clear()
  15.   term.setCursorPos(1,1)
  16.   for i = 1, string.len(s) do
  17.     c = string.sub(s, i, i)
  18.     if c == "[" then
  19.       term.setTextColor(specialColor)
  20.     elseif c == "]" then
  21.       term.setTextColor(standardColor)
  22.     else
  23.       write(c)
  24.     end
  25.   end
  26.   print()
  27. end
  28.  
  29. function turn()
  30.     if facingForwardFromStartView then
  31.       turtle.turnLeft()
  32.     else
  33.       turtle.turnRight()
  34.     end
  35. end
  36.  
  37. function invert()
  38.   facingForwardFromStartView = not facingForwardFromStartView
  39. end
  40.  
  41. function seed()
  42.   for i = 1, #seeds do
  43.     if turtle.getItemCount(seeds[i]) > 0 then
  44.       turtle.select(seeds[i])
  45.       turtle.placeDown()
  46.       if turtle.getItemCount(seeds[i]) < 1 then
  47.         table.remove(seeds, i)
  48.       end
  49.       return true
  50.     end
  51.   end
  52.   return false
  53. end
  54.  
  55. -- MAIN
  56.  
  57. term.setTextColor(standardColor)
  58.  
  59. local atom = true
  60. while turtle.getItemCount(borderSlot) < 1 do
  61.   if atom then
  62.     cPrint("Place a border [around] your field\nwith any material. Put at least 1 piece of that material into slot [" .. borderSlot .. "].")
  63.     atom = false
  64.   end
  65.   sleep(1)
  66. end
  67.  
  68. cPrint("Is your turtle positioned\n[L]eft or [R]ight?")
  69. while true do
  70.   local event, key = os.pullEvent("char")
  71.   if key == 'r' then
  72.     startFrom = "right"
  73.     facingForwardFromStartView = true
  74.     break
  75.   end
  76.   if key == 'l' then
  77.      startFrom = "left"
  78.      facingForwardFromStartView = false
  79.      break
  80.   end
  81. end
  82.  
  83. cPrint("If you want to [place seeds] after\nharvesting, then just put seeds in\nand press [enter] to start.")
  84. read()
  85.  
  86. for i = 2, 16 do
  87.   if turtle.getItemCount(i) > 0 then
  88.     table.insert(seeds, i)
  89.   end
  90. end
  91.  
  92. turtle.forward()
  93. turtle.digDown()
  94. turtle.down()
  95. local rows = 0
  96. local run1rows = 0
  97. local go = true
  98.  
  99. while go do
  100.   turtle.select(borderSlot)
  101.   if turtle.compare() then
  102.     turn()
  103.     turtle.select(borderSlot)
  104.     if turtle.compare() then
  105.       turtle.up()
  106.       run1rows = rows + 1
  107.       while rows > 0 do
  108.         turtle.back()
  109.         rows = rows - 1
  110.       end
  111.       invert()
  112.       turn()
  113.       turn()
  114.       turn()
  115.       turtle.back()
  116.       go = false
  117.       break
  118.     else
  119.       turtle.select(digSlot)
  120.       turtle.dig()
  121.       turtle.forward()
  122.     end
  123.     turn()
  124.     invert()
  125.     rows = rows + 1
  126.   end
  127.   turtle.select(digSlot)
  128.   turtle.dig()
  129.   turtle.forward()
  130. end
  131.  
  132. if #seeds < 1 then
  133.   return
  134. end
  135.  
  136. turtle.forward()
  137. seed()
  138. rows = run1rows
  139. while run1rows > 0 do
  140.   turtle.select(borderSlot)
  141.   if turtle.compareDown() then
  142.     if run1rows > 1 then
  143.       turn()
  144.       turtle.forward()
  145.       turn()
  146.       turtle.forward()
  147.       invert()
  148.       run1rows = run1rows - 1
  149.     else
  150.       turn()
  151.       while rows > 1 do
  152.         turtle.back()
  153.         rows = rows - 1
  154.       end
  155.       turn()
  156.       break
  157.     end
  158.   end
  159.   seed()
  160.   turtle.forward()
  161. end
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement