Azalen

Turtle V1

Oct 16th, 2013
134
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Lua 22.38 KB | None | 0 0
  1. HeightOfTunnel=4
  2. WidthOfTunnel=4
  3. TorchEvery=5
  4. LengthCount=0
  5. MaxLength=0
  6.  
  7. SpaceWithBlock=2
  8. SpaceWithTorch=1
  9. SpaceWithFuel=3
  10. SpaceWithChest=4
  11.  
  12. FirstEmptySlot=5
  13. LastEmptySlot=16
  14.  
  15. CoalThreshold=0
  16. BlockThreshold=5
  17. ChestThreshold=2
  18.  
  19. StuckCounter=1
  20. MaxStuckCount=50
  21.  
  22. SliceNumber=0
  23. TorchNumber=0
  24. ChestNumber=0
  25.  
  26. MoveCounter=0
  27. DigCounter=0
  28. PlaceCounter=0
  29. --simple functions######################################################
  30. --######################################################################
  31. function moveForward()
  32.    
  33.     --reset stuckcounter just incase shoddy coding left a value in it
  34.     StuckCounter=1
  35.    
  36.     --Attempts to dig down, if it fails go into the while loop
  37.     while not turtle.forward() do
  38.    
  39.         --wait 1 to let whatever is in the way bugger off
  40.         sleep(1)
  41.        
  42.         --increment the stuck counter as another attempt was failed
  43.         StuckCounter=StuckCounter+1
  44.        
  45.         --if the stuck counter exceeds the number of attempts allowed
  46.         if StuckCounter>=MaxStuckCount then
  47.        
  48.             --ask for help
  49.             print(">>Hilfe! Ich stecke fest")
  50.             print(">>Befreie mich und drücke Enter")
  51.             print(" ")
  52.            
  53.             --pause for user input to proceed
  54.             read()
  55.            
  56.         end
  57.        
  58.     end
  59.    
  60.     --reset the stuck counter
  61.     StuckCounter=1
  62.    
  63.     MoveCounter=MoveCounter+1
  64. end
  65.  
  66. function moveBack()
  67.     --reset stuckcounter just incase shoddy coding left a value in it
  68.     StuckCounter=1
  69.    
  70.     --Attempts to dig down, if it fails go into the while loop
  71.     while not turtle.back() do
  72.    
  73.         --wait 1 to let whatever is in the way bugger off
  74.         sleep(1)
  75.        
  76.         --increment the stuck counter as another attempt was failed
  77.         StuckCounter=StuckCounter+1
  78.        
  79.         --if the stuck counter exceeds the number of attempts allowed
  80.         if StuckCounter>=MaxStuckCount then
  81.        
  82.             --ask for help
  83.             print(">>Hilfe! Ich stecke fest")
  84.             print(">>Befreie mich und drücke Enter")
  85.             print(" ")
  86.            
  87.             --pause for user input to proceed
  88.             read()
  89.            
  90.         end
  91.        
  92.     end
  93.    
  94.     --reset the stuck counter
  95.     StuckCounter=1
  96.    
  97.     MoveCounter=MoveCounter+1
  98.    
  99. end
  100.  
  101. function moveUp()
  102.    
  103.     --reset stuckcounter just incase shoddy coding left a value in it
  104.     StuckCounter=1
  105.    
  106.     --Attempts to dig down, if it fails go into the while loop
  107.     while not turtle.up() do
  108.    
  109.         --wait 1 to let whatever is in the way bugger off
  110.         sleep(1)
  111.        
  112.         --increment the stuck counter as another attempt was failed
  113.         StuckCounter=StuckCounter+1
  114.        
  115.         --if the stuck counter exceeds the number of attempts allowed
  116.         if StuckCounter>=MaxStuckCount then
  117.        
  118.             --ask for help
  119.             print(">>Hilfe! Ich stecke fest")
  120.             print(">>Befreie mich und drücke Enter")
  121.             print(" ")
  122.            
  123.             --pause for user input to proceed
  124.             read()
  125.            
  126.         end
  127.        
  128.     end
  129.    
  130.     --reset the stuck counter
  131.     StuckCounter=1
  132.    
  133.     MoveCounter=MoveCounter+1
  134.    
  135. end
  136.  
  137. function moveDown()
  138.    
  139.     --reset stuckcounter just incase shoddy coding left a value in it
  140.     StuckCounter=1
  141.    
  142.     --Attempts to dig down, if it fails go into the while loop
  143.     while not turtle.down() do
  144.    
  145.         --wait 1 to let whatever is in the way bugger off
  146.         sleep(1)
  147.        
  148.         --increment the stuck counter as another attempt was failed
  149.         StuckCounter=StuckCounter+1
  150.        
  151.         --if the stuck counter exceeds the number of attempts allowed
  152.         if StuckCounter>=MaxStuckCount then
  153.        
  154.             --ask for help
  155.             print(">>Hilfe! Ich stecke fest")
  156.             print(">>Befreie mich und drücke Enter")
  157.             print(" ")
  158.            
  159.             --pause for user input to proceed
  160.             read()
  161.            
  162.         end
  163.        
  164.     end
  165.    
  166.     --reset the stuck counter
  167.     StuckCounter=1
  168.    
  169.     MoveCounter=MoveCounter+1
  170.    
  171. end
  172.  
  173. function placeBlock()
  174.    
  175.     --select the fill block
  176.     turtle.select(SpaceWithBlock)
  177.    
  178.     --reset stuckcounter just incase shoddy coding left a value in it
  179.     StuckCounter=1
  180.    
  181.     --attempts block place, if fail then go into the loop
  182.     while not turtle.place() do
  183.    
  184.         --wait 1 to let whatever is in the way bugger off
  185.         sleep(1)
  186.        
  187.         --increment the stuck counter as another attempt was failed
  188.         StuckCounter=StuckCounter+1
  189.        
  190.         --if the stuck counter exceeds the number of attempts allowed
  191.         if StuckCounter>=MaxStuckCount then
  192.        
  193.             --ask for help
  194.             print(">>Hilfe! Ich kann keinen Block vor mir platzieren ")
  195.             print(">>Zerstöre den Block vor mir und Drücke Enter")
  196.             print(" ")
  197.            
  198.             --pause for user input to proceed
  199.             read()
  200.            
  201.         end
  202.        
  203.     end
  204.    
  205.     --reset the stuck counter
  206.     StuckCounter=1
  207.    
  208.     PlaceCounter=PlaceCounter+1
  209.    
  210. end
  211.  
  212. function placeBlockDown()
  213.    
  214.     --select the fill block
  215.     turtle.select(SpaceWithBlock)
  216.    
  217.     --reset stuckcounter just incase shoddy coding left a value in it
  218.     StuckCounter=1
  219.    
  220.     --attempts block place, if fail then go into the loop
  221.     while not turtle.placeDown() do
  222.    
  223.         --wait 1 to let whatever is in the way bugger off
  224.         sleep(1)
  225.        
  226.         --increment the stuck counter as another attempt was failed
  227.         StuckCounter=StuckCounter+1
  228.        
  229.         --if the stuck counter exceeds the number of attempts allowed
  230.         if StuckCounter>=MaxStuckCount then
  231.        
  232.             --ask for help
  233.             print(">>Hilfe! Ich kann keinen Block unter mir platzieren ")
  234.             print(">>Zerstöre den Block unter mir und Drücke Enter")
  235.             print(" ")
  236.            
  237.             --pause for user input to proceed
  238.             read()
  239.            
  240.         end
  241.        
  242.     end
  243.    
  244.     --reset the stuck counter
  245.     StuckCounter=1
  246.    
  247.     PlaceCounter=PlaceCounter+1
  248.    
  249. end
  250.  
  251. function placeBlockUp()
  252.    
  253.     --select the fill block
  254.     turtle.select(SpaceWithBlock)
  255.    
  256.     --reset stuckcounter just incase shoddy coding left a value in it
  257.     StuckCounter=1
  258.    
  259.     --attempts block place, if fail then go into the loop
  260.     while not turtle.placeUp() do
  261.    
  262.         --wait 1 to let whatever is in the way bugger off
  263.         sleep(1)
  264.        
  265.         --increment the stuck counter as another attempt was failed
  266.         StuckCounter=StuckCounter+1
  267.        
  268.         --if the stuck counter exceeds the number of attempts allowed
  269.         if StuckCounter>=MaxStuckCount then
  270.        
  271.             --ask for help
  272.             print(">>Hilfe! Ich kann keinen Block über mir platzieren ")
  273.             print(">>Zerstöre den Block über mir und Drücke Enter")
  274.             print(" ")
  275.            
  276.             --pause for user input to proceed
  277.             read()
  278.            
  279.         end
  280.        
  281.     end
  282.    
  283.     --reset the stuck counter
  284.     StuckCounter=1
  285.    
  286.     PlaceCounter=PlaceCounter+1
  287.    
  288. end
  289.  
  290. function moveLeftOne()
  291.     --simple bit of code to strafe left one space
  292.     --checkFuelLevel()
  293.     turtle.turnLeft()
  294.     moveForward()
  295.     turtle.turnRight()
  296. end
  297.  
  298. function moveRightOne()
  299.     --simple bit of code to strafe right one space
  300.     --checkFuelLevel()
  301.     turtle.turnRight()
  302.     moveForward()
  303.     turtle.turnLeft()
  304. end
  305.  
  306. function digBlock()
  307.    
  308.     MinicheckFuelLevel()
  309.  
  310.     --reset stuckcounter just incase shoddy coding left a value in it
  311.     StuckCounter=1
  312.    
  313.     --attempts dig, if fail then go into the loop
  314.     while not turtle.dig() do
  315.  
  316.         if turtle.detect()==false then break end
  317.    
  318.         --wait 1 to let whatever is in the way bugger off
  319.         sleep(1)
  320.        
  321.         --increment the stuck counter as another attempt was failed
  322.         StuckCounter=StuckCounter+1
  323.        
  324.         --if the stuck counter exceeds the number of attempts allowed
  325.         if StuckCounter>=MaxStuckCount then
  326.        
  327.             --ask for help
  328.             print(">>Hilfe! Ich kann den Block vor mir nicht abbauen ")
  329.             print(">>Zerstöre den Block vor mir und Drücke Enter")
  330.             print(" ")
  331.            
  332.             --pause for user input to proceed
  333.             read()
  334.            
  335.         end
  336.    
  337.     end
  338.    
  339.     DigCounter=DigCounter+1
  340.    
  341.  
  342. end
  343.  
  344. function digBlockDown()
  345.    
  346.     MinicheckFuelLevel()
  347.  
  348.     --reset stuckcounter just incase shoddy coding left a value in it
  349.     StuckCounter=1
  350.    
  351.     --attempts dig, if fail then go into the loop
  352.     while not turtle.digDown() do
  353.    
  354.         if turtle.detectDown()==false then break end
  355.  
  356.         --wait 1 to let whatever is in the way bugger off
  357.         sleep(1)
  358.        
  359.         --increment the stuck counter as another attempt was failed
  360.         StuckCounter=StuckCounter+1
  361.        
  362.         --if the stuck counter exceeds the number of attempts allowed
  363.         if StuckCounter>=MaxStuckCount then
  364.        
  365.             --ask for help
  366.             print(">>Hilfe! Ich kann den Block unter mir nicht abbauen ")
  367.             print(">>Zerstöre den Block unter mir und Drücke Enter")
  368.             print(" ")
  369.            
  370.             --pause for user input to proceed
  371.             read()
  372.            
  373.         end
  374.    
  375.     end
  376.  
  377.     DigCounter=DigCounter+1
  378.        
  379. end
  380.  
  381. function digBlockUp()
  382.    
  383.     MinicheckFuelLevel()
  384.  
  385.     --reset stuckcounter just incase shoddy coding left a value in it
  386.     StuckCounter=1
  387.    
  388.     --attempts dig, if fail then go into the loop
  389.     while not turtle.digUp() do
  390.  
  391.         if turtle.detectUp()==false then break end
  392.    
  393.         --wait 1 to let whatever is in the way bugger off
  394.         sleep(1)
  395.        
  396.         --increment the stuck counter as another attempt was failed
  397.         StuckCounter=StuckCounter+1
  398.        
  399.         --if the stuck counter exceeds the number of attempts allowed
  400.         if StuckCounter>=MaxStuckCount then
  401.        
  402.             --ask for help
  403.             print(">>Hilfe! Ich kann den Block über mir nicht abbauen ")
  404.             print(">>Zerstöre den Block über mir und Drücke Enter")
  405.             print(" ")
  406.            
  407.             --pause for user input to proceed
  408.             read()
  409.            
  410.         end
  411.    
  412.     end
  413.  
  414.     DigCounter=DigCounter+1
  415.        
  416. end
  417.  
  418. function digDownLoop()
  419.    
  420.     -- Dig infront until successful
  421.     digUntilClear()
  422.  
  423.     -- Dig a column out infront of the turtle at the height set
  424.     -- DiggingDown can be set to false if digging up is required
  425.     for Counter=1,HeightOfTunnel do
  426.    
  427.         --dig the block infront
  428.         digBlock()
  429.        
  430.         --moves down unless it has reached the last space
  431.         --if counter is not equal to the height of the tunnel
  432.         if Counter~=HeightOfTunnel then
  433.        
  434.             --move
  435.             moveDown()
  436.            
  437.         end
  438.        
  439.     end
  440.  
  441.      --puts the turtle back to where he left off
  442.      --loop round a number of times = to the height of the tunnel
  443.     for Counter=1,HeightOfTunnel-1 do
  444.    
  445.         --do a fuel check
  446.         --checkFuelLevel()
  447.        
  448.         --move
  449.         moveUp()
  450.        
  451.     end
  452.    
  453. end
  454.  
  455. function digUntilClear()
  456.  
  457.     --while there is something infront of the turtle do this loop
  458.     while turtle.detect()==true do
  459.    
  460.         --dig infront
  461.         digBlock()
  462.        
  463.         --wait 1
  464.         sleep(1)
  465.        
  466.     end
  467.    
  468. end
  469.  
  470. function lineWallDown()
  471.    
  472.     --repeat from 1 to the height of the tunnel
  473.     for OtherWallCounter=1,HeightOfTunnel do
  474.    
  475.         -- fill a hole if there is one infront
  476.         placeIfBlockMissing()
  477.        
  478.         --if it isn't the last cycle fo the for loop
  479.         if OtherWallCounter~=HeightOfTunnel then
  480.        
  481.             --move
  482.             moveDown()         
  483.            
  484.         end
  485.        
  486.     end
  487.    
  488. end
  489.  
  490. function lineWallUp()
  491.  
  492.     --repeat from 1 to the height of the tunnel
  493.     for WallCounter=1,HeightOfTunnel do
  494.    
  495.         -- fill a hole if there is one infront
  496.         placeIfBlockMissing()
  497.        
  498.         --if it isn't the last cycle fo the for loop
  499.         if WallCounter~=HeightOfTunnel then
  500.        
  501.             --move
  502.             moveUp()           
  503.            
  504.         end
  505.        
  506.     end
  507.    
  508. end
  509.  
  510. function lineFloor()
  511.  
  512.     --repeat from 1 to the width of the tunnel
  513.     for FloorCounter=1,WidthOfTunnel do
  514.    
  515.         -- fill a hole if there is one below
  516.         placeIfBlockMissingDown()
  517.        
  518.         --if it isn't the last cycle fo the for loop
  519.         if FloorCounter~=WidthOfTunnel then
  520.        
  521.             --move
  522.             moveBack()         
  523.            
  524.         end
  525.        
  526.     end
  527.    
  528. end
  529.  
  530. function lineRoof()
  531.    
  532.     --repeat from 1 to the width of the tunnel
  533.     for RoofCounter=1,WidthOfTunnel do
  534.    
  535.         -- fill a hole if there is one above
  536.         placeIfBlockMissingUp()
  537.        
  538.         --if it isn't the last cycle for the for loop
  539.         if RoofCounter~=WidthOfTunnel then
  540.        
  541.             --move
  542.             moveBack()     
  543.            
  544.         end    
  545.        
  546.     end
  547.    
  548. end
  549.  
  550. function placeIfBlockMissing()
  551.    
  552.     --if there is no block infront then
  553.     if turtle.detect()==false then
  554.    
  555.         --select the fill block
  556.         turtle.select(SpaceWithBlock)
  557.        
  558.         --place the fill block infront
  559.         placeBlock()
  560.        
  561.     end
  562.    
  563. end
  564.  
  565. function placeIfBlockMissingDown()
  566.    
  567.     --if there is no block below then
  568.     if turtle.detectDown()==false then
  569.    
  570.         --select the fill block
  571.         turtle.select(SpaceWithBlock)
  572.        
  573.         --place the fill block below
  574.         turtle.placeDown()
  575.        
  576.     end
  577.    
  578. end
  579.  
  580. function placeIfBlockMissingUp()
  581.    
  582.     --if there is no block above then
  583.     if turtle.detectUp()==false then
  584.    
  585.         --select the fill block
  586.         turtle.select(SpaceWithBlock)
  587.        
  588.         --place the fill block above
  589.         turtle.placeUp()
  590.        
  591.     end
  592.    
  593. end
  594.  
  595. function placeChest()
  596.  
  597.     --simple bit of code to select and then place a chest
  598.     turtle.select(SpaceWithChest)
  599.     turtle.place()
  600.    
  601. end
  602.  
  603. function placeInChest()
  604.  
  605.     --cycle from first to last slot
  606.     for ChestDumpCounter=FirstEmptySlot,LastEmptySlot do
  607.    
  608.         --select the slot for this cycle
  609.         turtle.select(ChestDumpCounter)
  610.        
  611.         --dump into chest
  612.         turtle.drop()
  613.        
  614.     end
  615.    
  616. end
  617.  
  618. function digChestHole()
  619.    
  620.     --Clear infront
  621.     digUntilClear()
  622.    
  623.     --now place and fill chest
  624.     placeChest()
  625.     placeInChest()
  626.    
  627. end
  628.  
  629. function placeTorch()
  630.    
  631.     -- loop round for the height of the tunnel -1
  632.     for PlaceCounter=1,HeightOfTunnel-2 do
  633.    
  634.         --move down
  635.         moveDown()
  636.        
  637.     end
  638.    
  639.     --move back two and turn 180
  640.     moveBack()
  641.     moveBack()
  642.     turtle.turnRight()
  643.     turtle.turnRight()
  644.    
  645.     --select the torches and place infront
  646.     turtle.select(SpaceWithTorch)
  647.     turtle.place()
  648.    
  649.     --turn back to the tunnel face and move towards it
  650.     turtle.turnLeft()
  651.     turtle.turnLeft()
  652.     moveForward()
  653.     moveForward()
  654.    
  655.     --loop round for the height of the tunnel
  656.     for PlaceCounter=1,HeightOfTunnel-2 do
  657.    
  658.         --move up
  659.         moveUp()
  660.        
  661.     end
  662.    
  663. end
  664.  
  665. function torchCheck()
  666.  
  667.     --checks to see if there are any torches left in the torch slot
  668.     if turtle.getItemCount(SpaceWithTorch)==0 then
  669.    
  670.         --returns false if there are no torches
  671.         return false
  672.        
  673.     else
  674.    
  675.         --returns true if there are torches
  676.         return true
  677.        
  678.     end
  679.    
  680. end
  681.  
  682. function lengthCheck()
  683.     if LengthCount>=MaxLength then
  684.  
  685.         return false
  686.  
  687.     else
  688.  
  689.         return true
  690.     end
  691. end
  692.  
  693. function amIEmpty()
  694.    
  695.     --set the spaceleft variable to 0
  696.     SpaceLeft=0
  697.    
  698.     --cycle round for each slot
  699.     for emptyCounter=FirstEmptySlot,LastEmptySlot do
  700.    
  701.         --if the slot is empty then
  702.         if turtle.getItemCount(emptyCounter)==0 then
  703.        
  704.             --increment the spaceleft variable to count empty spaces
  705.             SpaceLeft=SpaceLeft+1
  706.            
  707.         end
  708.        
  709.     end
  710.    
  711.     --if there are 1 or less spaces left in the inventory return true
  712.     if SpaceLeft<=1 then
  713.    
  714.         return true
  715.        
  716.     else
  717.    
  718.         return false
  719.        
  720.     end
  721.    
  722. end
  723.  
  724. function MinicheckFuelLevel()
  725.      
  726.         -- check the fuel level, if it's less than 50 then refuel or pause
  727.         CurrentFuel = turtle.getFuelLevel()
  728.         --print ("Current fuel = " .. CurrentFuel)
  729.         while checkCoalRemaining()==false do
  730.        
  731.                 pauseForMoreCoal()
  732.                
  733.         end
  734.  
  735.     --if the turtle fuel level is less than 50
  736.     if turtle.getFuelLevel()<=50 then
  737.        
  738.         --select the fuel slot
  739.         turtle.select(SpaceWithFuel)
  740.        
  741.         --refuel with 1 peice
  742.         turtle.refuel(1)
  743.        
  744.     end
  745.  
  746. end
  747.  
  748. function checkFuelLevel()
  749.  
  750.     -- check the fuel level, if it's less than 50 then refuel or pause
  751.     CurrentFuel = turtle.getFuelLevel()
  752.     print ("Current fuel = " .. CurrentFuel)
  753.     while checkCoalRemaining()==false do
  754.    
  755.         pauseForMoreCoal()
  756.        
  757.     end
  758.    
  759.     --check the block level, if it's less than 5 refill or pause
  760.     while checkBlocksRemaining()==false do
  761.    
  762.         pauseForMoreBlocks()
  763.        
  764.     end
  765.    
  766.     --check the chest level, if it's less than 2 refill or pause
  767.     while checkChestRemaining()==false do
  768.    
  769.         pauseForMoreChest()
  770.    
  771.     end
  772.    
  773.     --if the turtle fuel level is less than 50
  774.     if turtle.getFuelLevel()<=50 then
  775.        
  776.         --select the fuel slot
  777.         turtle.select(SpaceWithFuel)
  778.        
  779.         --refuel with 1 peice
  780.         turtle.refuel(1)
  781.        
  782.     end
  783.    
  784. end
  785.  
  786. function checkCoalRemaining()
  787.    
  788.     --if fuel remaining is less than threshold then return false
  789.     if turtle.getItemCount(SpaceWithFuel) < CoalThreshold then
  790.    
  791.         return false
  792.        
  793.     else
  794.    
  795.         return true
  796.        
  797.     end
  798.    
  799. end
  800.  
  801. function checkBlocksRemaining()
  802.  
  803.     --cycle round each inventory slot
  804.     for BlockCheckCounter=FirstEmptySlot,LastEmptySlot do
  805.    
  806.         --select the current slot for this cycle
  807.         turtle.select(BlockCheckCounter)
  808.        
  809.         --compare the selected block to the fill block
  810.         if turtle.compareTo(SpaceWithBlock)==true then
  811.            
  812.             --if there is a match then use it to refill fill block
  813.             turtle.transferTo(SpaceWithBlock)
  814.            
  815.         end
  816.        
  817.     end
  818.  
  819.     -- checks to see how many blocks remain
  820.     -- returns false if below BlockThreshold
  821.     if turtle.getItemCount(SpaceWithBlock) < BlockThreshold then
  822.    
  823.         return false
  824.        
  825.     else
  826.    
  827.         return true
  828.        
  829.     end
  830.    
  831. end
  832.  
  833. function checkChestRemaining()
  834.    
  835.     --if fuel remaining is less than threshold then return false
  836.     if turtle.getItemCount(SpaceWithChest) < ChestThreshold then
  837.    
  838.         return false
  839.        
  840.     else
  841.    
  842.         return true
  843.        
  844.     end
  845.    
  846. end
  847.  
  848. function pauseForMoreCoal()
  849.    
  850.     --print to user
  851.     print(">>Bitte mehr Kohle!")
  852.     print(">>und drücke Enter")
  853.    
  854.     --pause for user input
  855.     PauseHere=read()
  856.    
  857. end
  858.  
  859.  
  860. function pauseForMoreBlocks()
  861.     --print to user
  862.     print(">>Bitte mehr Blocks!")
  863.     print(">>und drücke Enter")
  864.    
  865.     --pause for user input
  866.     PauseHere=read()
  867.    
  868. end
  869.  
  870.  
  871. function pauseForMoreChest()
  872.  
  873.     --print to user
  874.     print(">>Bitte mehr Truhen!")
  875.     print(">>und drücke Enter")
  876.    
  877.     --pause for user input
  878.     PauseHere=read()
  879.    
  880. end
  881.  
  882.  
  883. --MAIN CODE START#######################################################
  884. --######################################################################
  885.  
  886.  
  887. --initial printed info for user
  888. print(">>Wilkommen Tunnel Maker V1 By Azalen")
  889. print(">>Anleitung gibt es aufhttp://azalen.de/turtel/")
  890.  
  891. --request tunnel height info, pause for input, converts to number
  892. print(">>Bitte Tunnel Höhe eingeben:")
  893. HeightOfTunnel = read()
  894. HeightOfTunnel=tonumber(HeightOfTunnel)
  895.  
  896. --if tunnel height is invalid
  897. while HeightOfTunnel<2 do
  898.  
  899.     print ">>Üngültig"
  900.     print ">>Tunnel Höhe muss mindesten 2 betragen"
  901.     HeightOfTunnel = read()
  902.     HeightOfTunnel=tonumber(HeightOfTunnel)
  903.    
  904. end
  905.  
  906. --request tunnel width info, pause for input, converts to number
  907. print(">>Bitte Tunnel Breite eingeben:")
  908. WidthOfTunnel = read()
  909. WidthOfTunnel=tonumber(WidthOfTunnel)
  910.  
  911. --if tunnel width is invalid
  912. while WidthOfTunnel<2 do
  913.  
  914.     print ">>Ungültig"
  915.     print ">>Tunnel Breite muss mindestes 2 betragen"
  916.     WidthOfTunnel = read()
  917.     WidthOfTunnel=tonumber(HeightOfTunnel)
  918.  
  919. end
  920.  
  921. print(">>Bitte Tunnel Länge eingeben:")
  922. MaxLength = read()
  923. MaxLength=tonumber(MaxLength)
  924.  
  925. --if tunnel width is invalid
  926. while MaxLength<2 do
  927.  
  928.     print ">>Ungültig"
  929.     print ">>Tunne Länge muss mindestens 2 betragen"
  930.     MaxLength = read()
  931.     MaxLength=tonumber(MaxLength)
  932. end
  933.  
  934. --request torch spacing info, pause for input, converts to number
  935. print(">>Fackel abstand eingeben:")
  936. TorchEvery = read()
  937. TorchEvery=tonumber(TorchEvery)
  938.  
  939. --if spacing is invalid
  940. while TorchEvery<=2 do
  941.  
  942.     print ">>Ungültig"
  943.     print ">>Abstand muss mindestens 2 betragen"
  944.     TorchEvery = read()
  945.     TorchEvery=tonumber(TorchEvery)
  946.  
  947. end
  948.  
  949. --print user info regarding slot layout
  950. print(">>Slot 1: Fackeln")
  951. print(">>Slot 2: Blocks zum füllen")
  952. print(">>Slot 3: Kohle (bei Bedarf)")
  953. print(">>Slot 4: Truhen (Min 2)")
  954. print(" ")
  955.  
  956. --print user info regarding stop and start
  957. print(">>Zum Stoppen Fackeln entfernen")
  958. print(">>Zum Starten Enter drücken")
  959.  
  960. --pause for user input to begin executing tunnel dig
  961. StartString = read()
  962.  
  963. --set the torch counter to 1
  964. TorchCounter=1
  965.  
  966. --Does initial check to see the slots are filled
  967. --Adds initial fuel if required
  968. checkFuelLevel()
  969.  
  970. --This while loop holds the continuous process of tunnel creation
  971. --while torches are still available run the loop
  972. while torchCheck()==true do
  973.  
  974.     --dig the tunnel face
  975.     --loop round for thw width of the tunnel
  976.     print (">>Graben Abschnitt " .. SliceNumber)
  977.     SliceNumber=SliceNumber+1
  978.     LengthCount=LengthCount+1
  979.    
  980.     for LeftCounter=1,WidthOfTunnel do
  981.    
  982.         --dig a column out
  983.         digDownLoop()
  984.        
  985.         --if it's not the last column, move left one space
  986.         if LeftCounter~=WidthOfTunnel then
  987.            
  988.             moveLeftOne()
  989.            
  990.         end
  991.        
  992.     end
  993.    
  994.     --do a fuel check
  995.     checkFuelLevel()
  996.     if lengthCheck()==false then break end
  997.    
  998.     --print ">>Slice cut, moving back"
  999.     --move in and turn right
  1000.     moveForward()
  1001.     turtle.turnRight()
  1002.    
  1003.     --for the width of the tunnel move forwards
  1004.     for ReturnCounter=1,WidthOfTunnel-1 do
  1005.    
  1006.         moveForward()
  1007.        
  1008.     end
  1009.    
  1010.     --turn to face the tunnel wall at the top right position
  1011.     turtle.turnLeft()
  1012.    
  1013.     --print ">>Checking for torches"
  1014.     --TORCHCHECK, if no torches left then break the while loop
  1015.     --this will end the code running
  1016.     if torchCheck()==false then break end
  1017.     --TORCHCHECK
  1018.    
  1019.     --print ">>Lining the walls of the new slice"
  1020.     --move in and line the tunnel walls if gaps are found
  1021.     turtle.turnRight()
  1022.     --right wall
  1023.     lineWallDown()
  1024.     --floor
  1025.     lineFloor()
  1026.     turtle.turnLeft()
  1027.     turtle.turnLeft()
  1028.     --left wall
  1029.     lineWallUp()
  1030.     --roof
  1031.     lineRoof()
  1032.    
  1033.     --turn to face the tunnel wall at the top right position
  1034.     turtle.turnRight()
  1035.    
  1036.     --print ">>Checking for torches"
  1037.     --TORCHCHECK, if no torches left then break the while loop
  1038.     --this will end the code running
  1039.     if torchCheck()==false then break end
  1040.     --TORCHCHECK
  1041.    
  1042.     --print "Checking if a torch is needed"
  1043.     --if the current torch counter reaches the set limit
  1044.     if TorchCounter==TorchEvery then
  1045.    
  1046.         print (">>Setze Fackel " .. TorchNumber)
  1047.         TorchNumber=TorchNumber+1
  1048.         --place a torch then reset the counter
  1049.         placeTorch()
  1050.         TorchCounter=0
  1051.        
  1052.     end
  1053.    
  1054.     --increment the torch counter
  1055.     TorchCounter=TorchCounter+1
  1056.    
  1057.     --print ">>Checking for torches"
  1058.     --TORCHCHECK, if no torches left then break the while loop
  1059.     --this will end the code running
  1060.     if torchCheck()==false then break end
  1061.     --TORCHCHECK
  1062.    
  1063.     --print ">>Checking if a chest is needed"
  1064.     --checks if getting near full, if so places chest and empties itself
  1065.     --if full then
  1066.     if amIEmpty()==true then
  1067.        
  1068.         --print ">>Chest needed"
  1069.         -- move back and face the right hand wall
  1070.         moveBack()
  1071.         turtle.turnRight()
  1072.        
  1073.         --for each height of the tunnel
  1074.         for EmptyHeightCounter=1,HeightOfTunnel-1 do
  1075.            
  1076.             --move down
  1077.             moveDown()
  1078.            
  1079.         end
  1080.        
  1081.  
  1082.         --this chest check should be in a seperate function
  1083.         --i know, but i'm being lazy and putting it here :P
  1084.         --check the chest level, if it's less than 2 refill or pause
  1085.         while checkChestRemaining()==false do
  1086.    
  1087.             pauseForMoreChest()
  1088.    
  1089.         end
  1090.        
  1091.         print (">>Placing chest" .. ChestNumber)
  1092.         ChestNumber=ChestNumber+1
  1093.         --dig the chest hole, place chest, fill chest
  1094.         digChestHole()
  1095.        
  1096.         --move back up to the top right of the tunnel face
  1097.         --fill any gravel fall gaps on the way
  1098.         for EmptyHeightCounter=1,HeightOfTunnel-1 do
  1099.        
  1100.             moveUp()
  1101.            
  1102.            
  1103.            
  1104.         end
  1105.        
  1106.         turtle.turnLeft()
  1107.         moveForward()
  1108.        
  1109.     end
  1110.  
  1111.        
  1112. end
  1113.  
  1114. print ("Ende:")
  1115. print ("Abgebaute Blöcke " .. DigCounter .. " ")
  1116. print ("Aufgefüllte Blöcke " .. PlaceCounter .. " ")
  1117. print ("Gegrabene Abschnitte " .. SliceNumber .. " ")
  1118. print ("Länge des Tunnels " .. LengthCount .." ")
  1119. print ("Fackeln gesetzt " .. TorchNumber .. " ")
  1120. print ("Truhen verwendet  " .. ChestNumber .. " ")
Add Comment
Please, Sign In to add comment