pson

SimpleLivingTurtle.lua

Jul 1st, 2020 (edited)
1,138
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Lua 2.48 KB | None | 0 0
  1. function refill(slot)
  2.     turtle.select(slot)
  3.     if turtle.getItemCount() < 8 then
  4.         for i=4,16 do
  5.             -- print("Comparing (", i, ") to (", slot, "): ", turtle.compareTo(i))
  6.             if turtle.compareTo(i) then
  7.                 turtle.select(i)
  8.                 turtle.transferTo(slot)
  9.                 if turtle.getItemCount(slot) > 7 then
  10.                     return true
  11.                 end -- if 9
  12.                 turtle.select(slot)
  13.             end -- if 6
  14.         end -- for 4
  15.         -- print("for loop")
  16.         return false
  17.     else -- if 3
  18.         return true
  19.     end -- if 3
  20. end -- function 1
  21.  
  22. function reFuelFill()
  23.     -- Refuel
  24.     while turtle.getFuelLevel() < 20 do
  25.         turtle.select(1)
  26.         if turtle.getItemCount(1) == 0 then
  27.             return false
  28.         end
  29.         turtle.refuel(1)
  30.     end
  31.     return refill(2) and refill(3)
  32. end
  33.  
  34. function odd(offset)
  35.     turtle.select(2+offset)
  36.     if not turtle.compareDown() then
  37.         turtle.digDown()
  38.         turtle.placeDown()
  39.     end  
  40.     turtle.forward()
  41. end
  42.  
  43. function even(offset)
  44.     local i
  45.     if offset == 1 then i = 2 else i = 3 end
  46.     turtle.select(i)
  47.     if not turtle.compareDown() then
  48.         turtle.digDown()
  49.         turtle.placeDown()
  50.     end  
  51.     turtle.forward()
  52. end
  53.  
  54. function half_lap(offset)
  55.     -- Logs or stone is in slots 2 or 3,
  56.     -- offset should be 0 or 1.
  57.     odd(offset)
  58.     even(offset)
  59.     turtle.turnRight()
  60.     turtle.forward()
  61.     even(offset)
  62.     turtle.back()
  63.     turtle.back()
  64.     turtle.turnLeft()
  65.     odd(offset)
  66.     even(offset)
  67.     odd(offset)
  68.     turtle.turnRight()
  69.     even(offset)
  70.     odd(offset)
  71.     turtle.turnRight()
  72. end
  73.  
  74. function main()
  75.     turtle.select(1)
  76.     if turtle.getItemCount() == 0 then
  77.         print("usage: SimpleLiving")
  78.         print("Slot 1: Fuel")
  79.         print("Slot 2 (Odd) : Logs or smooth stone")
  80.         print("Slot 3 (Even): Logs or smooth stone")
  81.         print("Setup")
  82.         print(".O.E.O.E.O.E.")
  83.         print(".E.P.E.O.P.O.")
  84.         print(".O.E.O.E.O.E.")
  85.         print("Place the turtle on top of the upper left 'O',")
  86.         print("place items in the indicated slots and run")
  87.         print("You can fill up the rest of the turtle with")
  88.         print("the same items as in slot 2 and 3, and they")
  89.         print("will be refilled")
  90.     else
  91.         while reFuelFill() do
  92.             half_lap(0)
  93.             half_lap(1)
  94.             sleep(90)
  95.         end
  96.     end
  97. end
  98. main()
Add Comment
Please, Sign In to add comment