Advertisement
osirisgothra

turtle automation - crop sticks

Jan 1st, 2022
1,434
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Lua 1.46 KB | None | 0 0
  1. --- turtleplaceitem
  2. --- simple program to automate crop sticks
  3.  
  4. width = 8
  5. length = 8
  6. lastmoveok = true
  7. for l=1,length,1 do
  8.     for w=1,width,1 do 
  9.         turtle.placeDown()
  10.         lastmoveok=turtle.forward()
  11.     end
  12.     -- undo the last forward, if it happened ok
  13.     if lastmoveok == true
  14.         turtle.back()
  15.     end
  16.     -- to save the hastle of going back [w] spaces and shifting over a block
  17.     -- which consumes double the fuel, conserve by interleaving:
  18.     failcount=0
  19.     if ( l % 2 ) == 0 then
  20.         if turtle.turnLeft() then failcount=failcount+1; end
  21.         if turtle.forward() then failcount=failcount+1; end
  22.         if turtle.turnLeft() then failcount=failcount+1; end
  23.     else
  24.         if turtle.turnRight() then failcount=failcount+1; end
  25.         if turtle.forward() then failcount=failcount+1; end
  26.         if turtle.turnRight() then failcount=failcount+1; end
  27.     end
  28.     -- if any of the above failed, we need to stop, the turtle is either
  29.     -- obstructed or out of fuel   
  30.     if failcount > 0 then
  31.         -- do not check zero fuel level in case cheat or other alternative is active
  32.         -- let turtle run if it CAN run (not reposnsible for players that take advantage)
  33.         if turtle.getFuelLevel() == 0 then
  34.             -- strictly for info purposes only
  35.             print("out of fuel, aborting")
  36.         else     
  37.             print("turtle obstructed, aborting")
  38.         end
  39.         break
  40.     else
  41.         print("this run is aok, starting next run, if any")    
  42.     end
  43.     -- ready for next run
  44. end
  45. print("completed run exiting program")
  46. print("remaining fuel: " .. turtle.getFuelLevel() );
  47.  
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement