Advertisement
Rusettsten

BasicDig

Nov 30th, 2020 (edited)
763
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Lua 7.30 KB | None | 0 0
  1. -- A Basic Dig API for DanetOS3
  2. local tArgs = { ... }
  3. if #tArgs == nil then
  4.     print("Basic Dig ERROR: Incorrect Usage. BasicDig <distance> <digMode> <homeBoolean>")
  5.     return
  6. end
  7.  
  8. local homeBoolean = true;
  9.  
  10.  
  11. --DigMode 1: Just breaks blocks in front of itself
  12. --DigMode 2: Breaks blocks in front of and on top of itself
  13. --DigMode 3: Breaks blocks in front of and below itself
  14.  
  15. function dig1(distance) --DigMode 1: Just breaks blocks in front of itself
  16.     --Calculate fuel usage and refuel to that amount
  17.     local distanceNum = tonumber(distance)
  18.     if homeBoolean then
  19.         local fuelUsage = distanceNum * 3 --for the dig/travel & home
  20.         shell.run("TurtleRefuel " .. fuelUsage)
  21.     else
  22.         local fuelUsage = distanceNum * 2 --for the dig/travel
  23.         shell.run("TurtleRefuel " .. fuelUsage)
  24.     end
  25.     shell.run("TurtleRefuel " .. fuelUsage)
  26.    
  27.     for x=1,distance do --Go forth and dig
  28.         local blockInfo = {}
  29.         local isBlock = true;
  30.         while(isBlock == true) do --Until there's no block in front of the miner
  31.             isBlock, blockInfo = turtle.inspect()
  32.             if blockInfo.name == "minecraft:gravel" or blockInfo.name == "minecraft:sand" then --If it's gravel or sand
  33.                 turtle.select(2)
  34.                 turtle.equipLeft()
  35.                 while not turtle.dig("left") do sleep(0.5) end
  36.                 turtle.equipLeft()
  37.             else
  38.                 while not turtle.dig("left") do sleep(0.5) end
  39.             end
  40.         end
  41.         turtle.suck()
  42.         while not turtle.forward() do sleep(0.5) end
  43.     end
  44.    
  45.     if homeBoolean then
  46.         --Turn the turtle around
  47.         shell.run("TurtleTurn right")
  48.         shell.run("TurtleTurn right")
  49.         for x=1,distance do --Go back home
  50.             turtle.forward()
  51.         end
  52.         --Turn back around
  53.         shell.run("TurtleTurn right")
  54.         shell.run("TurtleTurn right")
  55.     end
  56. end
  57.  
  58.  
  59.  
  60. function dig2(distance) --DigMode 2: Breaks blocks in front of and on top of itself
  61.     --Calculate fuel usage and refuel to that amount
  62.     local distanceNum = tonumber(distance)
  63.     if homeBoolean then
  64.         local fuelUsage = distanceNum * 4 --for the dig/travel & home
  65.         shell.run("TurtleRefuel " .. fuelUsage)
  66.     else
  67.         local fuelUsage = distanceNum * 3 --for the dig/travel
  68.         shell.run("TurtleRefuel " .. fuelUsage)
  69.     end
  70.    
  71.     for x=1,distance do --Go forth and dig
  72.         local blockInfo = {}
  73.         local isBlock = true;
  74.         --DIGGING FORWARD
  75.         isBlock, blockInfo = turtle.inspect()
  76.         while isBlock do --Until there's no block in front of the miner
  77.             if blockInfo.name == "minecraft:gravel" or blockInfo.name == "minecraft:sand" then --If it's gravel or sand
  78.                 turtle.select(2)
  79.                 turtle.equipLeft()
  80.                 while not turtle.dig("left") do sleep(0.5) end
  81.                 turtle.equipLeft()
  82.             else
  83.                 while not turtle.dig("left") do sleep(0.5) end
  84.             end
  85.             isBlock, blockInfo = turtle.inspect()
  86.         end
  87.         turtle.suck()
  88.         while not turtle.forward() do sleep(0.5) end
  89.         --DIGGING UP
  90.         isBlock, blockInfo = turtle.inspectUp()
  91.         while isBlock do --Until there's no block on top of the miner
  92.             isBlock, blockInfo = turtle.inspectUp()
  93.             if blockInfo.name == "minecraft:gravel" or blockInfo.name == "minecraft:sand" then --If it's gravel or sand
  94.                 turtle.select(2)
  95.                 turtle.equipLeft()
  96.                 while not turtle.digUp("left") do sleep(0.5) end
  97.                 turtle.equipLeft()
  98.             else
  99.                 while not turtle.digUp("left") do sleep(0.5) end
  100.             end
  101.             isBlock, blockInfo = turtle.inspectUp()
  102.         end
  103.         turtle.suck()
  104.     end
  105.    
  106.     if homeBoolean then
  107.         --Turn the turtle around
  108.         shell.run("TurtleTurn right")
  109.         shell.run("TurtleTurn right")
  110.         for x=1,distance do --Go back home
  111.             turtle.forward()
  112.         end
  113.         --Turn back around
  114.         shell.run("TurtleTurn right")
  115.         shell.run("TurtleTurn right")
  116.     end
  117. end
  118.  
  119.  
  120.  
  121. function dig3(distance) --DigMode 3: Breaks blocks in front of and below itself
  122.     --Calculate fuel usage and refuel to that amount
  123.     local distanceNum = tonumber(distance)
  124.     if homeBoolean then
  125.         local fuelUsage = distanceNum * 4 --for the dig/travel & home
  126.         shell.run("TurtleRefuel " .. fuelUsage)
  127.     else
  128.         local fuelUsage = distanceNum * 3 --for the dig/travel
  129.         shell.run("TurtleRefuel " .. fuelUsage)
  130.     end
  131.    
  132.     for x=1,distance do --Go forth and dig
  133.         if turtle.detect() then
  134.             while not turtle.dig("left") do sleep(0.5) end
  135.         end
  136.         turtle.suck()
  137.         while not turtle.forward() do sleep(0.5) end
  138.         if turtle.detectDown() then
  139.             while not turtle.digDown("left") do sleep(0.5) end
  140.         end
  141.         turtle.suck()
  142.     end
  143.    
  144.     if homeBoolean then
  145.         --Turn the turtle around
  146.         shell.run("TurtleTurn right")
  147.         shell.run("TurtleTurn right")
  148.         for x=1,distance do --Go back home
  149.             turtle.forward()
  150.         end
  151.         --Turn back around
  152.         shell.run("TurtleTurn right")
  153.         shell.run("TurtleTurn right")
  154.     end
  155. end
  156.  
  157. function dig4(distance) --DigMode 4: Breaks blocks infront of, above, and below.
  158.     --Calculate fuel usage and refuel to that amount
  159.     local distanceNum = tonumber(distance)
  160.     if homeBoolean then
  161.         local fuelUsage = distanceNum * 5 --for the dig/travel & home
  162.         shell.run("TurtleRefuel " .. fuelUsage)
  163.     else
  164.         local fuelUsage = distanceNum * 4 --for the dig/travel
  165.         shell.run("TurtleRefuel " .. fuelUsage)
  166.     end
  167.    
  168.     for x=1,distance do --Go forth and dig
  169.         local blockInfo = {}
  170.         local isBlock = true;
  171.         --DIGGING FORWARD
  172.         isBlock, blockInfo = turtle.inspect()
  173.         while isBlock do --Until there's no block in front of the miner
  174.             if blockInfo.name == "minecraft:gravel" or blockInfo.name == "minecraft:sand" then --If it's gravel or sand
  175.                 turtle.select(2)
  176.                 turtle.equipLeft()
  177.                 while not turtle.dig("left") do sleep(0.5) end
  178.                 turtle.equipLeft()
  179.             else
  180.                 while not turtle.dig("left") do sleep(0.5) end
  181.             end
  182.             isBlock, blockInfo = turtle.inspect()
  183.         end
  184.         turtle.suck()
  185.         while not turtle.forward() do sleep(0.5) end
  186.         --DIGGING UP
  187.         isBlock, blockInfo = turtle.inspectUp()
  188.         while isBlock do --Until there's no block on top of the miner
  189.             isBlock, blockInfo = turtle.inspectUp()
  190.             if blockInfo.name == "minecraft:gravel" or blockInfo.name == "minecraft:sand" then --If it's gravel or sand
  191.                 turtle.select(2)
  192.                 turtle.equipLeft()
  193.                 while not turtle.digUp("left") do sleep(0.5) end
  194.                 turtle.equipLeft()
  195.             else
  196.                 while not turtle.digUp("left") do sleep(0.5) end
  197.             end
  198.             isBlock, blockInfo = turtle.inspectUp()
  199.         end
  200.         turtle.suck()
  201.         --DIGGING DOWN
  202.         isBlock, blockInfo = turtle.inspectDown()
  203.         while isBlock do --Until there's no block on top of the miner
  204.             isBlock, blockInfo = turtle.inspectDown()
  205.             if blockInfo.name == "minecraft:gravel" or blockInfo.name == "minecraft:sand" then --If it's gravel or sand
  206.                 turtle.select(2)
  207.                 turtle.equipLeft()
  208.                 while not turtle.digDown("left") do sleep(0.5) end
  209.                 turtle.equipLeft()
  210.             else
  211.                 while not turtle.digDown("left") do sleep(0.5) end
  212.             end
  213.             isBlock, blockInfo = turtle.inspectDown()
  214.         end
  215.         turtle.suck()
  216.     end
  217.    
  218.     if homeBoolean then
  219.         --Turn the turtle around
  220.         shell.run("TurtleTurn right")
  221.         shell.run("TurtleTurn right")
  222.         for x=1,distance do --Go back home
  223.             while not turtle.forward() do sleep(0.5) end
  224.         end
  225.         --Turn back around
  226.         shell.run("TurtleTurn right")
  227.         shell.run("TurtleTurn right")
  228.     end
  229. end
  230.  
  231. --MAIN INSTRUCTIONS GO HERE
  232. homeBoolean = tArgs[3] --Set homeBoolean
  233.  
  234. if tArgs[2] == "1" then --Select digMode
  235.     dig1(tArgs[1])
  236. elseif tArgs[2] == "2" then
  237.     dig2(tArgs[1])
  238. elseif tArgs[2] == "3" then
  239.     dig3(tArgs[1])
  240. elseif tArgs[2] == "4" then
  241.     dig4(tArgs[1])
  242. else
  243.     print("Basic Dig ERROR: Incorrect args. Must be a digMode from 1 to 3.")
  244.     return
  245. end
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement