Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- -- A Basic Dig API for DanetOS3
- local tArgs = { ... }
- if #tArgs == nil then
- print("Basic Dig ERROR: Incorrect Usage. BasicDig <distance> <digMode> <homeBoolean>")
- return
- end
- local homeBoolean = true;
- --DigMode 1: Just breaks blocks in front of itself
- --DigMode 2: Breaks blocks in front of and on top of itself
- --DigMode 3: Breaks blocks in front of and below itself
- function dig1(distance) --DigMode 1: Just breaks blocks in front of itself
- --Calculate fuel usage and refuel to that amount
- local distanceNum = tonumber(distance)
- if homeBoolean then
- local fuelUsage = distanceNum * 3 --for the dig/travel & home
- shell.run("TurtleRefuel " .. fuelUsage)
- else
- local fuelUsage = distanceNum * 2 --for the dig/travel
- shell.run("TurtleRefuel " .. fuelUsage)
- end
- shell.run("TurtleRefuel " .. fuelUsage)
- for x=1,distance do --Go forth and dig
- local blockInfo = {}
- local isBlock = true;
- while(isBlock == true) do --Until there's no block in front of the miner
- isBlock, blockInfo = turtle.inspect()
- if blockInfo.name == "minecraft:gravel" or blockInfo.name == "minecraft:sand" then --If it's gravel or sand
- turtle.select(2)
- turtle.equipLeft()
- while not turtle.dig("left") do sleep(0.5) end
- turtle.equipLeft()
- else
- while not turtle.dig("left") do sleep(0.5) end
- end
- end
- turtle.suck()
- while not turtle.forward() do sleep(0.5) end
- end
- if homeBoolean then
- --Turn the turtle around
- shell.run("TurtleTurn right")
- shell.run("TurtleTurn right")
- for x=1,distance do --Go back home
- turtle.forward()
- end
- --Turn back around
- shell.run("TurtleTurn right")
- shell.run("TurtleTurn right")
- end
- end
- function dig2(distance) --DigMode 2: Breaks blocks in front of and on top of itself
- --Calculate fuel usage and refuel to that amount
- local distanceNum = tonumber(distance)
- if homeBoolean then
- local fuelUsage = distanceNum * 4 --for the dig/travel & home
- shell.run("TurtleRefuel " .. fuelUsage)
- else
- local fuelUsage = distanceNum * 3 --for the dig/travel
- shell.run("TurtleRefuel " .. fuelUsage)
- end
- for x=1,distance do --Go forth and dig
- local blockInfo = {}
- local isBlock = true;
- --DIGGING FORWARD
- isBlock, blockInfo = turtle.inspect()
- while isBlock do --Until there's no block in front of the miner
- if blockInfo.name == "minecraft:gravel" or blockInfo.name == "minecraft:sand" then --If it's gravel or sand
- turtle.select(2)
- turtle.equipLeft()
- while not turtle.dig("left") do sleep(0.5) end
- turtle.equipLeft()
- else
- while not turtle.dig("left") do sleep(0.5) end
- end
- isBlock, blockInfo = turtle.inspect()
- end
- turtle.suck()
- while not turtle.forward() do sleep(0.5) end
- --DIGGING UP
- isBlock, blockInfo = turtle.inspectUp()
- while isBlock do --Until there's no block on top of the miner
- isBlock, blockInfo = turtle.inspectUp()
- if blockInfo.name == "minecraft:gravel" or blockInfo.name == "minecraft:sand" then --If it's gravel or sand
- turtle.select(2)
- turtle.equipLeft()
- while not turtle.digUp("left") do sleep(0.5) end
- turtle.equipLeft()
- else
- while not turtle.digUp("left") do sleep(0.5) end
- end
- isBlock, blockInfo = turtle.inspectUp()
- end
- turtle.suck()
- end
- if homeBoolean then
- --Turn the turtle around
- shell.run("TurtleTurn right")
- shell.run("TurtleTurn right")
- for x=1,distance do --Go back home
- turtle.forward()
- end
- --Turn back around
- shell.run("TurtleTurn right")
- shell.run("TurtleTurn right")
- end
- end
- function dig3(distance) --DigMode 3: Breaks blocks in front of and below itself
- --Calculate fuel usage and refuel to that amount
- local distanceNum = tonumber(distance)
- if homeBoolean then
- local fuelUsage = distanceNum * 4 --for the dig/travel & home
- shell.run("TurtleRefuel " .. fuelUsage)
- else
- local fuelUsage = distanceNum * 3 --for the dig/travel
- shell.run("TurtleRefuel " .. fuelUsage)
- end
- for x=1,distance do --Go forth and dig
- if turtle.detect() then
- while not turtle.dig("left") do sleep(0.5) end
- end
- turtle.suck()
- while not turtle.forward() do sleep(0.5) end
- if turtle.detectDown() then
- while not turtle.digDown("left") do sleep(0.5) end
- end
- turtle.suck()
- end
- if homeBoolean then
- --Turn the turtle around
- shell.run("TurtleTurn right")
- shell.run("TurtleTurn right")
- for x=1,distance do --Go back home
- turtle.forward()
- end
- --Turn back around
- shell.run("TurtleTurn right")
- shell.run("TurtleTurn right")
- end
- end
- function dig4(distance) --DigMode 4: Breaks blocks infront of, above, and below.
- --Calculate fuel usage and refuel to that amount
- local distanceNum = tonumber(distance)
- if homeBoolean then
- local fuelUsage = distanceNum * 5 --for the dig/travel & home
- shell.run("TurtleRefuel " .. fuelUsage)
- else
- local fuelUsage = distanceNum * 4 --for the dig/travel
- shell.run("TurtleRefuel " .. fuelUsage)
- end
- for x=1,distance do --Go forth and dig
- local blockInfo = {}
- local isBlock = true;
- --DIGGING FORWARD
- isBlock, blockInfo = turtle.inspect()
- while isBlock do --Until there's no block in front of the miner
- if blockInfo.name == "minecraft:gravel" or blockInfo.name == "minecraft:sand" then --If it's gravel or sand
- turtle.select(2)
- turtle.equipLeft()
- while not turtle.dig("left") do sleep(0.5) end
- turtle.equipLeft()
- else
- while not turtle.dig("left") do sleep(0.5) end
- end
- isBlock, blockInfo = turtle.inspect()
- end
- turtle.suck()
- while not turtle.forward() do sleep(0.5) end
- --DIGGING UP
- isBlock, blockInfo = turtle.inspectUp()
- while isBlock do --Until there's no block on top of the miner
- isBlock, blockInfo = turtle.inspectUp()
- if blockInfo.name == "minecraft:gravel" or blockInfo.name == "minecraft:sand" then --If it's gravel or sand
- turtle.select(2)
- turtle.equipLeft()
- while not turtle.digUp("left") do sleep(0.5) end
- turtle.equipLeft()
- else
- while not turtle.digUp("left") do sleep(0.5) end
- end
- isBlock, blockInfo = turtle.inspectUp()
- end
- turtle.suck()
- --DIGGING DOWN
- isBlock, blockInfo = turtle.inspectDown()
- while isBlock do --Until there's no block on top of the miner
- isBlock, blockInfo = turtle.inspectDown()
- if blockInfo.name == "minecraft:gravel" or blockInfo.name == "minecraft:sand" then --If it's gravel or sand
- turtle.select(2)
- turtle.equipLeft()
- while not turtle.digDown("left") do sleep(0.5) end
- turtle.equipLeft()
- else
- while not turtle.digDown("left") do sleep(0.5) end
- end
- isBlock, blockInfo = turtle.inspectDown()
- end
- turtle.suck()
- end
- if homeBoolean then
- --Turn the turtle around
- shell.run("TurtleTurn right")
- shell.run("TurtleTurn right")
- for x=1,distance do --Go back home
- while not turtle.forward() do sleep(0.5) end
- end
- --Turn back around
- shell.run("TurtleTurn right")
- shell.run("TurtleTurn right")
- end
- end
- --MAIN INSTRUCTIONS GO HERE
- homeBoolean = tArgs[3] --Set homeBoolean
- if tArgs[2] == "1" then --Select digMode
- dig1(tArgs[1])
- elseif tArgs[2] == "2" then
- dig2(tArgs[1])
- elseif tArgs[2] == "3" then
- dig3(tArgs[1])
- elseif tArgs[2] == "4" then
- dig4(tArgs[1])
- else
- print("Basic Dig ERROR: Incorrect args. Must be a digMode from 1 to 3.")
- return
- end
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement