This is a read-only snapshot of the ComputerCraft forums, taken in April 2020.
EntombedJester's profile picture

Better Excavate

Started by EntombedJester, 18 November 2012 - 09:53 AM
EntombedJester #1
Posted 18 November 2012 - 10:53 AM
Hello, I've been looking for a decent excavate program that only uses one turtle that is decently fast and fuel efficient. Then I had the idea of why not just see if the default Excavate could be adjusted to be more efficient because it works great as is. Basically I'm not all that great a code, I tried to figure out the code of the default and failed really bad. My only idea was to make it so that the turtle mines three blocks at a time instead of the one block that it currently mines. Kinda like this http://i.imgur.com/eKqCJ.png but that's all. Thanks for any help you can give.
remiX #2
Posted 18 November 2012 - 11:27 AM
So what exactly do you want? Do you want help on how to code it to mine the 3 blocks at a time?
EntombedJester #3
Posted 18 November 2012 - 12:38 PM
Yes sorry I wasn't really specific on what I need help with. Yes I need help knowing where to change the code and what to do in order to get that three block pattern
remiX #4
Posted 18 November 2012 - 01:45 PM
Oh thats easy, heres a simple code I quickly made for you:
(I wish turtles could use colour text :)/>/>)

Pastebin

or
Raw code
Spoiler

args = {...}
if not args[1] then
    print("Usage:nex <distance>")
    return
end

t = 0
dist = tonumber(args[1])
x, y = term.getSize()
term.clear()

m = "Simple Excavation program"
term.setCursorPos((x - #m)/2, y / 2 - 1)
print(m)
m = "Mining " .. dist .. " blocks forward"
term.setCursorPos((x - #m)/2, y / 2)
print(m)
m = "Fuel level: " .. turtle.getFuelLevel()
term.setCursorPos((x - #m)/2, y / 2 + 1)
print(m)
m = "Total mined: " .. t
term.setCursorPos((x - #m)/2, y / 2 + 2)
term.clearLine()
print(m)

function refuel()
    term.setCursorPos(1,1) term.clearLine()
    print("Please refuel me...")
    repeat
        term.setCursorPos(1,2) term.clearLine()
        write("Which slot: ")
        slot = tonumber(read())
    until slot ~= nil and slot > 0 and slot <= 16
    turtle.select(slot)
    term.setCursorPos(1,2) term.clearLine()
    term.setCursorPos(1,1) term.clearLine()
    if turtle.refuel() then write("Refueled! Fuel level is now " .. turtle.getFuelLevel() .. ".") else write("No available fuel in that slot.") sleep(1.25) return refuel() end
    sleep(1.25)
    term.clearLine()
end

function updateFuelAndBlocks()
    m = "Fuel level: " .. turtle.getFuelLevel()
    term.setCursorPos((x - #m)/2, y / 2 + 1)
    term.clearLine()
    print(m)
    m = "Total mined: " .. t
    term.setCursorPos((x - #m)/2, y / 2 + 2)
    term.clearLine()
    print(m)
end

function main()
    for i = 1, dist do
        if turtle.getFuelLevel() < 5 then refuel() end
        if turtle.detect() then turtle.dig() t = t + 1 end
        turtle.forward()
        if turtle.detectUp() then turtle.digUp() t = t + 1 end
        if turtle.detectDown() then turtle.digDown() t = t + 1 end
        updateFuelAndBlocks()
    end
end

main()

-- Clean up
term.clear()
term.setCursorPos(1,1)
print("Mined a total of " .. t .. " blocks.n")

Pictures
SpoilerWhile it's digging:
Spoiler
When it's done:
Spoiler