Advertisement
Chronno

ComputercraftTurtleFloor

Mar 7th, 2013
66
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Lua 4.61 KB | None | 0 0
  1. -- Created by Chronno S. Trigger
  2. -- Http://www.youtube.com/chronnotrigg
  3. -- Version 2.0
  4.     local size = {...}
  5.     slot = 1
  6.      
  7.     function place(i)
  8.             slotCheck()
  9.             if turtle.compareDown() == false then
  10.                     turtle.digDown()
  11.             end
  12.             turtle.placeDown()
  13.             for o=2,size[1] do
  14.                     if math.fmod(o,5) == 0 and math.fmod(i,4) == 0 then
  15.                             torch(i)
  16.                     end
  17.                     dig()
  18.                     attack()
  19.                     turtle.forward()
  20.                     slotCheck()
  21.                     if turtle.compareDown() == false then
  22.                             turtle.digDown()
  23.                     end
  24.                     turtle.placeDown()
  25.             end
  26.     end
  27.      
  28.     function slotCheck()
  29.             if turtle.getItemCount(slot) == 0 then
  30.                     if slot == 15 then
  31.                             outOfItems()
  32.                     else
  33.                             slot = slot + 1
  34.                             turtle.select(slot)
  35.                             slotCheck()
  36.                     end
  37.             end
  38.     end
  39.      
  40.     function outOfItems()
  41.             term.clear()
  42.             term.setCursorPos(1,1)
  43.             print("Out of items, please replace and press any key when ready")
  44.             local event, param1 = os.pullEvent ("char")
  45.             slot = 1
  46.             turtle.select(slot)
  47.             slotCheck()
  48.     end
  49.      
  50.     function left()
  51.             turtle.turnLeft()
  52.             dig()
  53.             attack()
  54.             turtle.forward()
  55.             turtle.turnLeft()
  56.     end
  57.      
  58.     function right()
  59.             turtle.turnRight()
  60.             dig()
  61.             attack()
  62.             turtle.forward()
  63.             turtle.turnRight()
  64.     end
  65.      
  66.     function torch(i)
  67.             if math.fmod(i,2) == 1 then
  68.                     turtle.turnLeft()
  69.                     turtle.select(16)
  70.                     if turtle.getItemCount(16) == 0 then
  71.                             term.clear()
  72.                             term.setCursorPos(1,1)
  73.                             print("Out of torches, please insert some more and press any key")
  74.                             local event, param1 = os.pullEvent ("char")
  75.                     end
  76.                     turtle.place()
  77.                     turtle.select(slot)
  78.                     turtle.turnRight()
  79.             elseif math.fmod(i,2) == 0 then
  80.                     turtle.turnRight()
  81.                     turtle.select(16)
  82.                     if turtle.getItemCount(16) == 0 then
  83.                             term.clear()
  84.                             term.setCursorPos(1,1)
  85.                             print("Out of torches, please insert some more and press any key")
  86.                             local event, param1 = os.pullEvent ("char")
  87.                     end
  88.                     turtle.place()
  89.                     turtle.select(slot)
  90.                     turtle.turnLeft()
  91.             end
  92.     end
  93.      
  94.     function attack()
  95.             if turtle.attack == true then
  96.                     attack()
  97.             end
  98.     end
  99.      
  100.     function dig()
  101.             if turtle.dig() == true then
  102.                     os.sleep(1)
  103.                     dig()
  104.             end
  105.     end
  106.      
  107.     function home()
  108.             if math.fmod(size[1],2) == 1 then
  109.                     turtle.digUp()
  110.                     turtle.up()
  111.                     turtle.turnRight()
  112.                     turtle.turnRight()
  113.                     for i=2,size[1] do
  114.                             attack()
  115.                             dig()
  116.                             turtle.forward()
  117.                     end
  118.                     turtle.turnRight()
  119.                     for i=2,size[1] do
  120.                             attack()
  121.                             dig()
  122.                             turtle.forward()
  123.                     end
  124.                     turtle.turnLeft()
  125.                     turtle.down()
  126.             elseif math.fmod(size[1],2) == 0 then
  127.                     turtle.up()
  128.                     turtle.turnRight()
  129.                     for i=2,size[1] do
  130.                             turtle.forward()
  131.                     end
  132.                     turtle.turnLeft()
  133.                     turtle.down()
  134.             end
  135.     end
  136.      
  137.     place(1)
  138.     for i=2,size[1] do
  139.             if i == size[1] then
  140.                     break
  141.             elseif math.fmod(i,2) == 1 then
  142.                     left()
  143.             elseif math.fmod(i,2) == 0 then
  144.                     right()
  145.             end
  146.             place(i)
  147.     end
  148.     home()
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement