Kasama

aex

Dec 28th, 2015
128
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Lua 20.99 KB | None | 0 0
  1. term.clear()
  2. print " "
  3. print "aEXcavate 1.0.3 (aex)" -- short for "Andre's Excavate"
  4.  
  5. -- turtlescripts.com aEXcavate for minecraft turtle bots from computer craft mod for minecraft.
  6. -- http://pastebin.com/UD8C9e6q
  7. --
  8. -- Written by Andre L Noel
  9. -- Creative Commons Attribution 3.0 Unported License.
  10. -- http://creativecommons.org/licenses/by/3.0/deed.en_US
  11. -- You may use/distribute/copy/modify/create new works with this as long as credit is given where it is due.
  12. --
  13. -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- --
  14. local tArgs = { ... }
  15. local argOffset = 0
  16.  
  17. -- command line options flags
  18. local enderChestFlag = 0   -- 1=enderchest is used in slot 16 to offload inventory, dedicated fuel slot 15
  19. local leftWallFlag = 0     -- wall options are for future program development
  20. local rightWallFlag = 0
  21. local botFloorFlag = 2     -- 2=one wide floor, 1=full floor three wide, 0=no floor(usually not wise)
  22. local topRoofFlag = 1      -- defaults to creating a roof
  23. local backWallFlag = 0
  24. local frontWallFlag = 0    -- creates a front wall with a 2 tall and 1 wide opening
  25. local antiLiquidFlag = 1   -- creates (or not with "-water") extra anti water/lava/liquid source actions.
  26. local useFillerBlocks = 0  -- are we using filler blocks to make walls etc
  27.  
  28. local weMoved = false -- used for detecting bedrock -- custom for aex
  29. local failMoveMax = 20
  30. local fuelingNow = false -- prevents recursive refueling infinite loop
  31.  
  32.  -- tracking turtles block position relative to start point
  33. local relForward = -1 -- initial start point facing 1st block to mine
  34. local relRight = 0
  35. local relDeep = 0
  36. local relFacing = 0 -- 0=forward 1=right 2=back 3=left
  37.  
  38. -- parse command line option words here
  39. local chosenOptions = ""
  40. local howfar = tonumber(tArgs[1 + argOffset])
  41. while ( ( not ( tArgs[1 + argOffset] == nil ) ) and ( ( howfar == nil ) or ( howfar == 0 ) ) ) do -- 1st arg is not nil and not a nonzero number so its a string.
  42.     aword = 0
  43.     p = tArgs[1 + argOffset]
  44.  
  45.     if ( ( tArgs[1 + argOffset] == "left" )
  46.         or ( tArgs[1 + argOffset] == "leftwall" )
  47.         or ( tArgs[1 + argOffset] == "wallleft" ) ) then
  48.         leftWallFlag = 1; useFillerBlocks = 1
  49.         chosenOptions = chosenOptions .. tArgs[1 + argOffset] .. " "
  50.         argOffset = argOffset + 1
  51.         aword = 1
  52.     end
  53.  
  54.     if ( ( tArgs[1 + argOffset] == "right" )
  55.         or ( tArgs[1 + argOffset] == "rightwall" )
  56.         or ( tArgs[1 + argOffset] == "wallright" ) ) then
  57.         rightWallFlag = 1; useFillerBlocks = 1
  58.         chosenOptions = chosenOptions .. tArgs[1 + argOffset] .. " "
  59.         argOffset = argOffset + 1
  60.         aword = 1
  61.     end
  62.    
  63.     if ( ( tArgs[1 + argOffset] == "floor" )
  64.         or ( tArgs[1 + argOffset] == "bottom" )
  65.         or ( tArgs[1 + argOffset] == "bot" ) ) then
  66.         botFloorFlag = 1; useFillerBlocks = 1
  67.         chosenOptions = chosenOptions .. tArgs[1 + argOffset] .. " "
  68.         argOffset = argOffset + 1
  69.         aword = 1
  70.     end
  71.    
  72.     if ( ( tArgs[1 + argOffset] == "-floor" )
  73.         or ( tArgs[1 + argOffset] == "-bottom" )
  74.         or ( tArgs[1 + argOffset] == "-bot" ) ) then
  75.         botFloorFlag = 0
  76.         chosenOptions = chosenOptions .. tArgs[1 + argOffset] .. " "
  77.         argOffset = argOffset + 1
  78.         aword = 1
  79.     end
  80.    
  81.     if ( ( tArgs[1 + argOffset] == "top" )
  82.         or ( tArgs[1 + argOffset] == "ceiling" )
  83.         or ( tArgs[1 + argOffset] == "roof" ) ) then
  84.         topRoofFlag = 1; useFillerBlocks = 1
  85.         chosenOptions = chosenOptions .. tArgs[1 + argOffset] .. " "
  86.         argOffset = argOffset + 1
  87.         aword = 1
  88.     end
  89.    
  90.     if ( ( tArgs[1 + argOffset] == "-top" )
  91.         or ( tArgs[1 + argOffset] == "-ceiling" )
  92.         or ( tArgs[1 + argOffset] == "-roof" ) ) then
  93.         topRoofFlag = 0
  94.         chosenOptions = chosenOptions .. tArgs[1 + argOffset] .. " "
  95.         argOffset = argOffset + 1
  96.         aword = 1
  97.     end
  98.    
  99.     if ( ( tArgs[1 + argOffset] == "end" )
  100.         or ( tArgs[1 + argOffset] == "theend" )
  101.         or ( tArgs[1 + argOffset] == "back" )
  102.         or ( tArgs[1 + argOffset] == "theback" )
  103.         or ( tArgs[1 + argOffset] == "thebackend" )
  104.         or ( tArgs[1 + argOffset] == "backend" )
  105.         or ( tArgs[1 + argOffset] == "backwall" )
  106.         or ( tArgs[1 + argOffset] == "thebackwall" )
  107.         or ( tArgs[1 + argOffset] == "wallback" )
  108.         or ( tArgs[1 + argOffset] == "walltheback" ) ) then
  109.         backWallFlag = 1; useFillerBlocks = 1
  110.         chosenOptions = chosenOptions .. tArgs[1 + argOffset] .. " "
  111.         argOffset = argOffset + 1
  112.         aword = 1
  113.     end
  114.    
  115.     if ( ( tArgs[1 + argOffset] == "front" )
  116.         or ( tArgs[1 + argOffset] == "thefront" )
  117.         or ( tArgs[1 + argOffset] == "thefrontwall" )
  118.         or ( tArgs[1 + argOffset] == "frontwall" )
  119.         or ( tArgs[1 + argOffset] == "face" ) ) then
  120.         frontWallFlag = 1; useFillerBlocks = 1
  121.         chosenOptions = chosenOptions .. tArgs[1 + argOffset] .. " "
  122.         argOffset = argOffset + 1
  123.         aword = 1
  124.     end
  125.    
  126.     if ( ( tArgs[1 + argOffset] == "all" )
  127.         or ( tArgs[1 + argOffset] == "allsides" )
  128.         or ( tArgs[1 + argOffset] == "everyside" )
  129.         or ( tArgs[1 + argOffset] == "full" )
  130.         or ( tArgs[1 + argOffset] == "room" )
  131.         or ( tArgs[1 + argOffset] == "every" ) ) then
  132.         backWallFlag = 1
  133.         frontWallFlag = 1
  134.         leftWallFlag = 1
  135.         rightWallFlag = 1
  136.         botFloorFlag = 1
  137.         topRoofFlag = 1
  138.                 useFillerBlocks = 1
  139.         chosenOptions = chosenOptions .. tArgs[1 + argOffset] .. " "
  140.         argOffset = argOffset + 1
  141.         aword = 1
  142.     end
  143.    
  144.     if ( ( tArgs[1 + argOffset] == "-all" )
  145.         or ( tArgs[1 + argOffset] == "-allsides" )
  146.         or ( tArgs[1 + argOffset] == "-everyside" )
  147.         or ( tArgs[1 + argOffset] == "-full" )
  148.         or ( tArgs[1 + argOffset] == "-room" )
  149.         or ( tArgs[1 + argOffset] == "-every" ) ) then
  150.         backWallFlag = 0
  151.         frontWallFlag = 0
  152.         leftWallFlag = 0
  153.         rightWallFlag = 0
  154.         botFloorFlag = 0
  155.         topRoofFlag = 0
  156.         chosenOptions = chosenOptions .. tArgs[1 + argOffset] .. " "
  157.         argOffset = argOffset + 1
  158.         aword = 1
  159.     end
  160.    
  161.     if ( ( tArgs[1 + argOffset] == "wall" ) -- words to ignore
  162.         or ( tArgs[1 + argOffset] == "side" )
  163.         or ( tArgs[1 + argOffset] == "walls" )
  164.         or ( tArgs[1 + argOffset] == "sides" )
  165.         or ( tArgs[1 + argOffset] == "block" )
  166.         or ( tArgs[1 + argOffset] == "blocks" )
  167.         or ( tArgs[1 + argOffset] == "and" )
  168.         or ( tArgs[1 + argOffset] == "the" ) ) then
  169.         -- ignore it
  170.         argOffset = argOffset + 1
  171.         aword = 1
  172.     end
  173.    
  174.     if ( ( tArgs[1 + argOffset] == "enderchest" )
  175.         or ( tArgs[1 + argOffset] == "ender" )
  176.         or ( tArgs[1 + argOffset] == "chest" ) ) then
  177.         enderChestFlag = 1
  178.         chosenOptions = chosenOptions .. tArgs[1 + argOffset] .. " "
  179.         argOffset = argOffset + 1
  180.         aword = 1
  181.     end
  182.    
  183.     if aword == 0 then -- not a recognized word
  184.         print " "
  185.         print("Error: option '" .. tArgs[1 + argOffset] .. "' is unknown.")
  186.         print("Available options are:")
  187.         print("  enderchest")
  188.         print("example: > aex enderchest 25 25 -2")
  189.         error(" ",0)
  190.     end
  191.     howfar = tonumber(tArgs[1 + argOffset])
  192. end
  193.  
  194. local howfar = tonumber(tArgs[1 + argOffset])
  195. if howfar == nil then
  196.   print " "
  197.   print "aex [<opt>] <fwd> [<right>] [<depth>]"
  198.   print "Options: enderchest (goes in slot 16)"
  199.   print "Place turtle facing the first block."
  200.   print "Dig area should be forward and right."
  201.   print "Depth should be a negative for down."
  202.   --print "Wall options: top bottom left right back front all"
  203.   print "Fuel goes in slot 15 then any other."
  204.   print " "
  205.   print "Example: > aex enderchest 24 32 -4"
  206.   print "  digs 24 forward, 32 right, & 4 deep."
  207.   error(" ",0)
  208. end
  209. if ( howfar < 1 ) then howfar = 1 end
  210. argOffset = argOffset + 1
  211.  
  212. local howright = tonumber(tArgs[1 + argOffset])
  213. if ( howright == nil ) then howright = howfar end -- default square
  214. if ( howright == 0 ) then howright = 1 end
  215. argOffset = argOffset + 1
  216.  
  217. local howdeep = tonumber(tArgs[1 + argOffset])
  218. if ( howdeep == nil ) then howdeep=-9999 end -- default to bedrock
  219. if ( howdeep == 0 ) then howdeep=-9999 end
  220. howdeep = howdeep *(-1) -- impliment positive numbers for up and negative numbers for down.
  221. argOffset = argOffset + 1
  222.  
  223. -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- --
  224. function invenCheck(selection)
  225.   local f = "stillhere" -- flag not gone to home position
  226.   local r,d,fa,scanTo,scanFrom
  227.   local where = ""
  228.   -- check inventory space
  229.   freespaces = false -- flag to see if there are any free inventory spaces
  230.   while not freespaces do
  231.     if enderChestFlag == 1 then scanTo = 14 else scanTo = 16 end -- if using enderchest then we dont put away our fuel in 15 or the chest in 16
  232.     if useFillerBlocks == 1 then scanFrom = 2 else scanFrom = 1 end -- future feature
  233.     for i=scanFrom,scanTo do
  234.       turtle.select(i)
  235.       if turtle.getItemCount(i) < 1 then
  236.         freespaces = true
  237.         break
  238.       end
  239.     end
  240.     if not freespaces then
  241.       if enderChestFlag == 1 then
  242.         facing = relFacing -- where we are facing now
  243.         turtle.select(16) -- can we place the chest?
  244.         if turtle.placeUp() then where="up" else
  245.         if turtle.placeDown() then where="down" else
  246.         if turtle.place() then where="forward" else
  247.         tright(); if turtle.place() then where="right" else
  248.         tright(); if turtle.place() then where="back" else
  249.         tright(); if turtle.place() then where="left" else
  250.         tright() -- if nowhere then face forward again
  251.         end end end end end end
  252.         if not(where == "") then
  253.           write " chest"
  254.           for i=scanFrom,scanTo do -- put stuff in chest
  255.             turtle.select(i)
  256.             if      where == "up" then
  257.               turtle.dropUp()
  258.             else if where == "down" then
  259.               turtle.dropDown()
  260.             else
  261.               turtle.drop()
  262.             end end
  263.           end -- end drop loop
  264.           turtle.select(16) -- pick up chest
  265.           if where == "up" then
  266.             turtle.digUp()
  267.           else if where == "down" then
  268.             turtle.digDown()
  269.           else
  270.             turtle.dig()
  271.           end end
  272.           faceRel(facing) -- turn back to the way we were facing
  273.           break -- break to next while loop. retest inventory etc
  274.         end -- end 'where' is not ""
  275.       end -- ender chest flag is 1
  276.       if ( where == "" ) then -- if not put in a chest already then go home
  277.         f=relForward; r=relRight; d=relDeep; fa=relFacing
  278.         goRel(0,0,0,0); tbw()
  279.       end
  280.       print " "
  281.       print " "
  282.       print "Turtle inventory has no free slots."
  283.       print "Please remove items except for"
  284.       print "any needed fuel such as coal."
  285.       turtle.select(1)
  286.       print "Press Enter when done."
  287.       x = read()
  288.     end
  289.     if selection == nil then -- parameter allows specifying the slot selection after checking inventory
  290.       turtle.select(1)
  291.     else
  292.       turtle.select(selection)
  293.     end
  294.   end -- while not free spaces
  295.   if not(f=="stillhere") then tfw(); goRel(f,r,d,fa) end -- go back to work
  296. end -- invenCheck
  297.  
  298. function fuelup()
  299.   if fuelingNow then return end -- prevent recursive fuelup() calls
  300.   fuelingNow = true
  301.   local neededFuel
  302.   local f = "stillhere" -- flag not went back to home position
  303.   local r,d,fa,scanTo,scanFrom
  304.   neededFuel = (4 + (math.abs(relForward) + math.abs(relRight) + math.abs(relDeep))*2) -- 4 fuel + round trip to the home position
  305.   if enderChestFlag == 1 then scanTo = 15 else scanTo = 16 end
  306.   if useFillerBlocks == 1 then scanFrom = 2 else scanFrom = 1 end -- future feature
  307.   result = true
  308.   while turtle.getFuelLevel() < neededFuel do
  309.     result = false
  310.     for i=scanFrom,scanTo do
  311.       turtle.select(i)
  312.       if turtle.refuel(1) then
  313.         result = true
  314.         break
  315.       end
  316.     end -- end for slot scan loop
  317.     if not result then
  318.       if (f == "stillhere") and ( turtle.getFuelLevel() >= ((math.abs(relForward) + math.abs(relRight) + math.abs(relDeep))*2)+1 ) then
  319.         f=relForward; r=relRight; d=relDeep; fa=relFacing; -- save current location and facing direction
  320.         goRel(0,0,0,0); tbw() -- home position
  321.       end -- set current location only once
  322.       print " "
  323.       print " "
  324.       print "Please add fuel such as coal."
  325.       print "Press Enter when done."
  326.       x = read()
  327.     end
  328.   end -- while need fuel loop
  329.   if not(f=="stillhere") then tfw(); goRel(f,r,d,fa); f="stillhere" end -- return to mining position
  330.   fuelingNow = false
  331. end
  332.  
  333. function digf() -- dig forward
  334.   invenCheck()
  335.   tried = 0
  336.   while turtle.dig() do
  337.     turtle.suck()
  338.     turtle.suckUp()
  339.     turtle.suckDown()
  340.     if tried > 0 then
  341.       fuelup()
  342.       -- test if it is just liquid by moving into then out of the space once
  343.       if turtle.forward() then
  344.         fuelup()
  345.         while not turtle.back() do
  346.           print " "
  347.           print "Please unblock behind me so I can backup."
  348.           print "Press Enter when done."
  349.           x = read()
  350.         end
  351.         return  
  352.       end
  353.     end
  354.     tried = 1
  355.     sleep(0.3) -- necessary falling gravel time etc
  356.   end
  357. end
  358.  
  359. function digu() -- dig up
  360.   invenCheck()
  361.   tried = 0
  362.   while turtle.digUp() do
  363.     turtle.suckUp()
  364.     turtle.suck()
  365.     turtle.suckDown()
  366.     if tried > 0 then
  367.       fuelup()
  368.       -- test if it is just liquid by moving into then out of the space once
  369.       if turtle.up() then
  370.         fuelup()
  371.         while not turtle.down() do
  372.           print " "
  373.           print "Please unblock under me so I can go down."
  374.           print "Press Enter when done."
  375.           x = read()
  376.         end
  377.         return  
  378.       end
  379.     end
  380.     tried = 1
  381.     sleep(0.3) -- necessary falling gravel time etc
  382.   end
  383. end
  384.  
  385. function digd() -- dig down
  386.   invenCheck()
  387.   tried = 0
  388.   while turtle.digDown() do
  389.     turtle.suckDown()
  390.     turtle.suck()
  391.     turtle.suckUp()
  392.     if tried > 0 then
  393.       fuelup()
  394.       -- test if it is just liquid by moving into then out of the space once
  395.       if turtle.down() then
  396.         fuelup()
  397.         while not turtle.up() do
  398.           print " "
  399.           print "Please unblock above me so I can go up."
  400.           print "Press Enter when done."
  401.           x = read()
  402.         end
  403.         return  
  404.       end
  405.     end
  406.     tried = 1
  407.   end
  408. end
  409.  
  410. function tleft() -- turn left and track direction facing
  411.   turtle.suckDown()
  412.   turtle.suck()
  413.   turtle.suckUp()
  414.   turtle.turnLeft()
  415.   turtle.suck()
  416.   relFacing = relFacing - 1
  417.   if relFacing < 0 then relFacing = relFacing + 4 end
  418. end
  419.  
  420. function tright() -- turn right and track direction facing
  421.   turtle.suckDown()
  422.   turtle.suck()
  423.   turtle.suckUp()
  424.   turtle.turnRight()
  425.   turtle.suck()
  426.   relFacing = relFacing + 1
  427.   if relFacing > 3 then relFacing = relFacing - 4 end
  428. end
  429.  
  430. function tab() -- turn around backwards
  431.   turtle.suckDown()
  432.   turtle.suck()
  433.   turtle.suckUp()
  434.   turtle.turnLeft()
  435.   turtle.suck()
  436.   turtle.turnLeft()
  437.   turtle.suck()
  438.   relFacing = relFacing - 2
  439.   if relFacing < 0 then relFacing = relFacing + 4 end
  440. end
  441.  
  442. function tfw() -- turtle move forwards
  443.   turtle.suck()
  444.   turtle.suckUp()
  445.   turtle.suckDown()
  446.   fuelup()
  447.   failCount = 0
  448.   while ((not turtle.forward()) and ( failCount < failMoveMax )) do -- failCount detects bedrock
  449.     digf()
  450.     turtle.attack()
  451.     turtle.attack()
  452.     weMoved = false
  453.     failCount = failCount + 1
  454.   end
  455.   if ( failCount < failMoveMax ) then
  456.     weMoved = true
  457.     if ( relFacing == 0 ) then -- track relative coordinates to start point
  458.       relForward = relForward + 1
  459.     else if ( relFacing == 2 ) then
  460.       relForward = relForward - 1
  461.     else if ( relFacing == 1 ) then
  462.       relRight = relRight + 1
  463.     else if ( relFacing == 3 ) then
  464.       relRight = relRight - 1
  465.     end end end end
  466.   end
  467.   if not weMoved then write " Bedrock. Turtle done! Going back."; goRel(0,0,0,0); tbw(); print " Im back!"; error(" ",0); end -- CUSTOM for aex
  468. end
  469.  
  470. function tbw() -- turtle move backwards
  471.   turtle.suck()
  472.   turtle.suckUp()
  473.   turtle.suckDown()
  474.   fuelup()
  475.   failCount = 0
  476.   while ((not turtle.back()) and ( failCount < failMoveMax )) do -- failCount detects bedrock
  477.     tab()
  478.     digf()
  479.     turtle.attack()
  480.     turtle.attack()
  481.     tab()
  482.     weMoved = false
  483.     failCount = failCount + 1
  484.   end
  485.   if ( failCount < failMoveMax ) then
  486.     weMoved = true
  487.     if ( relFacing == 0 ) then -- track relative coordinates to start point
  488.       relForward = relForward - 1
  489.     else if ( relFacing == 2 ) then
  490.       relForward = relForward + 1
  491.     else if ( relFacing == 1 ) then
  492.       relRight = relRight - 1
  493.     else if ( relFacing == 3 ) then
  494.       relRight = relRight + 1
  495.     end end end end
  496.   end
  497.   if not weMoved then write " Bedrock. Turtle done! Going back."; goRel(0,0,0,0); tbw(); print " Im back!"; error(" ",0); end -- CUSTOM for aex
  498. end
  499.  
  500. function tup() -- turtle move up
  501.   turtle.suck()
  502.   turtle.suckUp()
  503.   turtle.suckDown()
  504.   fuelup()
  505.   failCount = 0
  506.   while ((not turtle.up()) and ( failCount < failMoveMax )) do
  507.     digu()
  508.     turtle.attackUp()
  509.     turtle.attackUp()
  510.     weMoved = false
  511.     failCount = failCount + 1
  512.   end
  513.   if ( failCount < failMoveMax ) then
  514.     weMoved = true
  515.     relDeep = relDeep + 1
  516.   end
  517.   if not weMoved then write " Bedrock. Turtle done! Going back."; goRel(0,0,0,0); tbw(); print " Im back!"; error(" ",0); end -- CUSTOM for aex
  518. end
  519.  
  520. function tdn() -- turtle move down
  521.   turtle.suck()
  522.   turtle.suckUp()
  523.   turtle.suckDown()
  524.   fuelup()
  525.   failCount = 0
  526.   while ( (not turtle.down()) and ( failCount < failMoveMax )) do -- failCount detects bedrock
  527.     digd()
  528.     turtle.attackDown()
  529.     turtle.attackDown()
  530.     weMoved = false
  531.     failCount = failCount + 1
  532.   end
  533.   if ( failCount < failMoveMax ) then
  534.     weMoved = true
  535.     relDeep = relDeep - 1
  536.   end
  537.   if not weMoved then write " Bedrock. Turtle done! Going back."; goRel(0,0,0,0); tbw(); print " Im back!"; error(" ",0); end -- CUSTOM for aex
  538. end
  539.  
  540. function faceRel(whichWay) -- turn to face the desired direction relative to start position and direction
  541.   while not(relFacing == whichWay) do
  542.     tleft()
  543.   end
  544. end
  545.  
  546. function goRel(toFw,toRight,toDeep,toFacing) -- move to position relative to start position and direction
  547.   -- assumes not trapped under bedrock
  548.   while ( relDeep < toDeep) do tup() end          -- up / down
  549.   while ( relDeep > toDeep) do tdn() end
  550.   if ( not(relRight == toRight) ) then            -- right / left
  551.     if ( relRight < toRight ) then faceRel(1) end
  552.     if ( relRight > toRight ) then faceRel(3) end
  553.     while not( relRight == toRight ) do tfw() end
  554.   end
  555.   if ( not(relForward == toFw) ) then             -- forward / backward
  556.     if ( relForward < toFw ) then faceRel(0) end
  557.     if ( relForward > toFw ) then faceRel(2) end
  558.     while not( relForward == toFw ) do tfw() end
  559.   end
  560.   faceRel(toFacing)                               -- facing direction  (0=fw 1=rt 2=back 3=lft)
  561. end
  562.  
  563. function tplace(selection) -- turtle place forward
  564.   invenCheck(selection)
  565.   turtle.place()
  566. end
  567.  
  568. function tplaceu(selection) -- turtle place up
  569.   invenCheck(selection)
  570.   turtle.placeUp()
  571. end
  572.  
  573. function tplaced(selection) -- turtle place down
  574.   invenCheck(selection)
  575.   turtle.placeDown()
  576. end
  577.  
  578. function tplacel(selection) -- turtle place left
  579.   invenCheck(selection)
  580.   turtle.turnLeft()
  581.   turtle.place()
  582.   turtle.turnRight()
  583. end
  584.  
  585. function tplacer(selection) -- turtle place right
  586.   invenCheck(selection)
  587.   turtle.turnRight()
  588.   turtle.place()
  589.   turtle.turnLeft()
  590. end
  591.  
  592. function tplaceb(selection) -- turtle place back
  593.   invenCheck(selection)
  594.   tab()
  595.   turtle.place()
  596.   tab()
  597. end
  598.  
  599. -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- MAIN START
  600.  
  601. print " "
  602. write(": " .. howfar .. " forward, " .. howright .. " right, " .. math.abs(howdeep))
  603. if ( howdeep > 0 ) then print(" going down") end
  604. if ( howdeep < 0 ) then print(" going up") end
  605. if not(chosenOptions == "") then print("Options: " .. chosenOptions ) end
  606. print " "
  607. sleep(3) -- pause to let them read before it takes off
  608.  
  609. -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- MAIN LOOP
  610.  
  611. -- must use only: ( tfw tbw tup tdn; tleft tright tab ) for movement and turning (tracks relative position)
  612.  
  613. local cforeward = 0
  614. local cright = 0
  615. local cdeep = 0
  616. if ( howdeep < 0 ) then updn = -1 else updn = 1 end
  617.  
  618. tfw() -- from position -1 0 0 to position 0 0 0
  619.  
  620. write "Started"
  621. -- depth loop begin
  622. for cdeep = (updn),howdeep,updn do
  623.   local foreback = true
  624.   write(" *L" .. cdeep*updn) -- L is for layer
  625.   -- right loop begin
  626.   for cright = 1,howright do
  627.     write(" R" .. cright) -- R is for row
  628.     -- forward loop begin
  629.     for cforward = 1,(howfar - 1) do
  630.       write(" " .. cforward) -- block number in row
  631.       tfw()
  632.     end
  633.     -- forward loop end
  634.     write(" " .. howfar) -- block number in row (last one finished)
  635.     if ( cright < howright ) then  -- u turn back and forth in layer
  636.       if ( foreback == true ) then
  637.         tright()
  638.         tfw()
  639.         tright()
  640.         foreback = false
  641.       else
  642.         tleft()
  643.         tfw()
  644.         tleft()
  645.         foreback = true
  646.       end
  647.     end -- u turn
  648.   end
  649.   -- right loop end
  650.   actualDepth = cdeep*(-1); if updn == 1 then actualDepth = actualDepth + 1 else actualDepth = actualDepth - 1 end
  651.   goRel(0,0,actualDepth,0) -- go to layer start position and facing direction
  652.   write "."
  653.   if (updn == 1) and ( cdeep < howdeep ) then tdn() else if ( cdeep > howdeep ) then tup() end end -- go into next layer
  654. end
  655. -- depth loop end
  656.  
  657. print " "
  658. print " "
  659. print "Turtle done!"
  660. print "Going back."
  661. goRel(0,0,0,0); tbw()
  662. print "Im back!"
Add Comment
Please, Sign In to add comment