Erlendftw

min3rb0t 1.3

May 25th, 2013
131
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Lua 2.77 KB | None | 0 0
  1. -- ER library start
  2. -- Written by Erlend Ellingsen
  3. botName = 'min3rB0t'
  4.  
  5. function printMsg(content)
  6.     print('[' .. botName .. '] ' .. content)
  7. end
  8.  
  9. function exit(msg)
  10.     error(msg)
  11.     return
  12. end
  13.  
  14.  
  15. -- turtle specific functions
  16. function moveDig(direction, times)
  17.  
  18.     for i = 1, times do
  19.         if (direction == 'forward') then
  20.             while(turtle.forward() ~= true) do
  21.                 while (turtle.detect()) do
  22.                     turtle.dig()
  23.                 end
  24.             end
  25.         elseif (direction == 'up') then
  26.             while(turtle.up() ~= true) do
  27.                 while (turtle.detectUp()) do
  28.                     turtle.digUp()
  29.                 end
  30.             end
  31.         elseif (direction == 'down') then
  32.             while(turtle.down() ~= true) do
  33.                 while (turtle.detectDown()) do
  34.                     turtle.digDown()
  35.                 end
  36.             end
  37.         end
  38.     end
  39. end
  40.  
  41. function rotate(direction, times)
  42.     for i = 1, times do
  43.         if (direction == 'left') then
  44.             turtle.turnLeft()
  45.         elseif (direction == 'right') then
  46.             turtle.turnRight()
  47.         end
  48.     end
  49. end
  50.  
  51. function selectSlot(slot)
  52.     turtle_slot_current = slot
  53.     turtle.select(slot)
  54. end
  55.  
  56. function storage_disposeAllItems()
  57.     --dispose all items
  58.     for i = 1, 16 do
  59.         selectSlot(i)
  60.         turtle.drop()
  61.     end
  62. end
  63.  
  64. -- ER library end
  65.  
  66.  
  67. --Min3rb0t
  68.  
  69.  
  70. --vars
  71. torchEnabled = false
  72. torchAmount = 0
  73. turtle_slot_torch = 1
  74.  
  75. --functions
  76.  
  77. function placeTorch()
  78.     if (torchEnabled == false) then
  79.         return
  80.     end
  81.  
  82.     if (torchAmount ~= turtle.getItemCount(turtle_slot_torch)) then
  83.         printMsg('No more torches. Disabling.')
  84.         printMsg('Expected amount: ' .. torchAmount .. ' actual amount: ' .. turtle.getItemCount(turtle_slot_torch))
  85.         torchEnabled = false
  86.         return
  87.     end
  88.  
  89.     rotate('right', 2)
  90.     while (turtle.detect()) do
  91.         turtle.dig()
  92.     end
  93.  
  94.     selectSlot(turtle_slot_torch)
  95.     turtle.place()
  96.  
  97.     rotate('left', 2)
  98.  
  99.     torchAmount = torchAmount - 1
  100. end
  101.  
  102. --INIT
  103.  
  104. term.clear()
  105. printMsg('Welcome to Min3rb0t')
  106. printMsg('Coded by Erlend Ellingsen')
  107.  
  108. printMsg('Length of single-tunnel?')
  109. tunnelLength = read()
  110.  
  111. printMsg('Use torch-placement? (Slot 1)')
  112. torchPlacementAnswer = read()
  113.  
  114. if (torchPlacementAnswer == 'yes') then
  115.     torchEnabled = true
  116.     torchAmount = turtle.getItemCount(turtle_slot_torch)
  117. elseif (torchPlacementAnswer == 'no') then
  118.     torchEnabled = false
  119.     torchAmount = 0
  120. end
  121.  
  122.  
  123. --Actual process
  124.  
  125. torchPlacement = 0
  126. for i = 1, tunnelLength do
  127.     torchPlacement = torchPlacement + 1
  128.  
  129.     printMsg('Processing ' .. i .. '/' .. tunnelLength)
  130.  
  131.     while (turtle.detect()) do
  132.         turtle.dig()
  133.     end
  134.  
  135.     if (torchPlacement >= 15) then
  136.  
  137.         if (torchEnabled) then
  138.             if (torchAmount > 0) then
  139.                 currentTorchAmount = turtle.getItemCount(turtle_slot_torch)
  140.                 if (currentTorchAmount > 0) then
  141.                     placeTorch()
  142.                 end
  143.             end
  144.         end
  145.  
  146.         torchPlacement = 0
  147.     end
  148.  
  149.     while (turtle.detectUp()) do
  150.         turtle.digUp()
  151.     end
  152.  
  153.     moveDig('forward', 1)
  154. end
Advertisement
Add Comment
Please, Sign In to add comment