Main Menu

Help with Mine and Refuel

Started by Ninjajake725, Apr 29, 2025, 10:50 AM

Previous topic - Next topic
Hello fellow miners, I am very new to CC and have no programming experience so all this is very much out of my depth. I am looking to make a program where the mining turtle will keep mining a 2x2x2 tunnel as far as it can go but auto refuel to a specfic location. (I have a GPS tower set up but am not sure how to translate this into getting the turtle to go to a specfic coord or if there is just an easier way of sending turtle back to start location).

I'm assuming I will have to write a digging program , but add an If statement that if its low on fuel to retun home and refuel before carry on digging. I just dont really know how to combine everything together or make it go home! Any help would be much appreciated!

ReTylinate

dud go find out yourself its not that hard
learn lua, find out what built in functions there are to use the turtle, and make a program

Kestin

Since your new to programming you can probably get away with just "hardcoding" stuff like so:
local function DoDig() --Dig 1 depth of a tunnel
    turtle.dig()
    turtle.forward()
    turtle.turnLeft()
    turtle.dig()
    turtle.digDown()
    turtle.down()
    turtle.dig()
    turtle.up()
    turtle.turnRight()
end
This function has 3 movement calls (forward, down, up) and will thus consume 3 fuel!
So you can make the turtle return to "home" like so!

local depth = 0 --Tunnel depth
while true do --Do forever:
    local fuel = turtle.getFuelLevel() --Store fuel level
    if type(fuel) == 'number' and fuel-3 < depth then --If stored fuel level is number check if we have enough fuel to go home after digging...
        DoRefuel() --If not return home
    end
    DoDig() --Otherwise dig tunnel!
    depth = depth + 1 --Increase tunnel depth
end
The tunnel depth should indecate the fuel cost to get back "home". So if current fuel level minus 3 is below the tunnel depth. Then we are low on fuel and we should refuel!

Speaking of you can refuel like so:
local function DoRefuel()
    for i=1, depth do --Repeat %TunnelDepth% times
        turtle.back() --Backing up to "home"
    end
    turtle.suckDown(64) --Retrieve fuel from fuel chest
    for i=1, 16 do --Repeat 16 times
        turtle.select(i) --Select slot %i%
        turtle.refuel() --Refuel with selected slot
    end
    for i=1, depth do --Repeat %TunnelDepth% times
        turtle.forward() --Go back into the tunnel
    end
end
Now I'm missing allot of things here... Like unloading loot from the turtle. But I'm leaving that as a challenge to you!
For now I recommend looking at the tweaked.cc for excellent documentation on ComputerCraft!
I also want to warn you now! Turtle do not work when the player is to far from them! (even vanilla chunk loaders break them...) So keep that in mind!
One last tip: If you copy and past my code... Make sure you put the tunnel depth variable at the top of the file then the local functions then the while true do code! (Otherwise it won't work)