Advertisement
hevohevo

Frame Filler (for a flooring work)

May 23rd, 2014
310
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Lua 1.34 KB | None | 0 0
  1. -- #########################
  2. -- Frame Filler (for a flooring work)
  3. -- version0.1
  4. -- http://hevohevo.hatenablog.com/
  5.  
  6. -- 1. Build a frame for a flooring work
  7. --    The frame must be a rectangle
  8. -- 2. Set the turtle on the frame-block as follows;
  9.  
  10. -- Top view
  11. -- T: turtle, f: frame-blocks (e.g., stone-brick)
  12. -- fffffffffffffffffffff
  13. -- f                   f
  14. -- f                   f
  15. -- fTfffffffffffffffffff
  16.  
  17. -- 3. Insert Frame-blocks (stone-brick) into turtle's slot 15
  18. --    for detecting a boundary line
  19. -- 4. Slot 1-14 are used for filling blocks
  20. -- 5. Run this program
  21.  
  22. FRAME = 15
  23. FUEL = 16
  24.  
  25. function select_block(slot)
  26.   slot = slot or turtle.getSelectedSlot()
  27.   if turtle.getItemCount(slot) == 0 then
  28.     if slot < 14 then
  29.       select_block(slot+1)
  30.     else
  31.       error("Item empty: insert slots 1-14.")
  32.     end
  33.   else
  34.     turtle.select(slot)
  35.   end
  36. end
  37.  
  38. function detect_frame()
  39.   local tmp_slot = turtle.getSelectedSlot()
  40.   turtle.select(FRAME)
  41.   local status, err = turtle.compareDown()
  42.   turtle.select(tmp_slot)
  43.   return status, err
  44. end
  45.  
  46. -- main
  47. turtle.select(1)
  48. local count = 0
  49. while true do
  50.   turtle.forward()
  51.   if detect_frame() then
  52.     count = count +1
  53.     turtle.back()
  54.     turtle.turnRight()
  55.     if count > 2 then break end
  56.   else
  57.     count = 0
  58.     select_block()
  59.     turtle.placeDown()
  60.   end
  61. end
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement