Facebook
From Shane C, 1 Year ago, written in Lua.
Embed
Download Paste or View Raw
Hits: 120
  1. --[[
  2.   Automated stair digger
  3.   - Digs down DIG_DEPTH amount
  4.   - Each stairs has a height of STAIR_HEIGHT
  5.   - The top of every other stair will have a torch
  6.     _ (If you place torches in inventory slot 2)
  7.   http://davehendler.com/tracedata/
  8. --]]
  9.  
  10. local tArgs = { ... }
  11.  
  12. if (#tArgs ~= 2) then
  13.   print( "USAGE: stairs DIG_DEPTH STAIR_HEIGHT" )
  14.   return
  15. end
  16.  
  17. depth=tonumber(tArgs[1])
  18. stairHeight=tonumber(tArgs[2])
  19.  
  20. fuelSlot = 1
  21. torchSlot = 2
  22.  
  23. torchEvery = 2
  24.  
  25. -- TODO: limit to rational sizes
  26.  
  27. t=turtle
  28.  
  29. climb = stairHeight-2
  30.  
  31. -- TODO: fuel management
  32.  
  33. t.select( fuelSlot )
  34. t.refuel( 1 )
  35.  
  36. for i = 1, depth do
  37.   print( "Step " .. i .. " of " .. depth )
  38.   print( "Fuel level: " .. t.getFuelLevel() )
  39.  
  40.   -- move up to top of stair level
  41.   for j = 1, climb do
  42.     t.digUp()
  43.     t.up()
  44.   end
  45.  
  46.   -- move in
  47.   dug = t.dig()
  48.   went = t.forward()
  49.  
  50.   -- TODO: variable stair width
  51.   -- TODO: place stairs blocks
  52.   -- TODO: fill in empty spots?
  53.  
  54.   -- dig out the stair
  55.   for j = 1, stairHeight do
  56.     t.turnLeft()
  57.     t.dig()
  58.     t.turnRight()
  59.     t.turnRight()
  60.     t.dig()
  61.     t.turnLeft()
  62.     -- Don't go down on last iteration
  63.     if j ~= stairHeight then
  64.       t.digDown()
  65.       t.down()
  66.  
  67.       -- TODO: check for empty spots to fill in
  68.     end
  69.  
  70.     -- Only place torches at the top
  71.     if j == 1 then
  72.       -- place torch every Nth level
  73.       if 0 == i % torchEvery then
  74.         t.select( torchSlot )
  75.         t.placeUp()
  76.       end
  77.     end
  78.   end
  79. end