Posted 09 March 2013 - 01:08 AM
Ever started a mining program, only to for the server to restart/the chunk being reloaded, and then you had to descend to the bowels of the earth in an epic adventure to find said robot? Yes? Fear no more!
Just get ubolt from
pastebin get bVmtbdsm
( http://pastebin.com/bVmtbdsm )
Run ubolt, and then any turtle program.
When the mining turtle restarts next, it will return approximately to the height where it was when ubolt was run, mining it's way through if necessary.
For instance, works flawlessly with
http://www.computerc...tle-ore-quarry/
Code:
For advanced users:
After going to the initial position, it resets itself by deleting the temporary file temp_ubolt and the startup file.
Terminating any program while running ubolt will reset ubolt.
You can also reset ubolt by running:
ubolt reset
This is a temporary solution for state loss during chunk reloads; it has been reported that there is random loss of movements, e.g. any scheme of movement-saving movement is due to miss steps.
y-state is less sensible to loss of steps: +1/-1 height difference from the starting height won't hinder your ability to find it…much. But missing a turn and going right instead of front is more problematic, so I ignored it.
The perfect solution is GPS and matching position and orientation to state, but for my situation it seemed overkill.
Just get ubolt from
pastebin get bVmtbdsm
( http://pastebin.com/bVmtbdsm )
Run ubolt, and then any turtle program.
When the mining turtle restarts next, it will return approximately to the height where it was when ubolt was run, mining it's way through if necessary.
For instance, works flawlessly with
http://www.computerc...tle-ore-quarry/
Code:
Spoiler
local main_api=[[
--from quarry program
local function moveTurtle(moveFn, detectFn, digFn, attackFn, maxDigCount)
-- Flag to determine whether digging has been tried yet. If it has
-- then pause briefly before digging again to allow sand or gravel to
-- drop
local digCount = 0
local moveSuccess = moveFn()
while ((moveSuccess == false) and (digCount < maxDigCount)) do
-- If there is a block in front, dig it
if (detectFn() == true) then
-- If we've already tried digging, then pause before digging again to let
-- any sand or gravel drop
if(digCount > 0) then
sleep(0.4)
end
digFn()
digCount = digCount + 1
else
-- Am being stopped from moving by a mob, attack it
attackFn()
end
-- Try the move again
moveSuccess = moveFn()
end
-- Return the move success
return moveSuccess
end
local function has()
return fs.exists'temp_ubolt'
end
local function save(n)
f=fs.open('temp_ubolt','w')
f.write(tostring(n))
f.close()
end
local function get()
f=fs.open('temp_ubolt','r')
local n=tonumber(f.readLine())
f.close()
return n
end
local old_up,old_down,old_pull_event
local function erase()
fs.delete'temp_ubolt'
fs.delete'startup'
turtle.up=old_up
turtle.down=old_down
os.pullEvent=old_pull_event
end
old_up=turtle.up
turtle.up=function(...)
local r=old_up(...)
save(get()+(r and 1 or 0))
--print(get())
return r
end
old_down=turtle.down
turtle.down=function(...)
local r=old_down(...)
save(get()+(r and -1 or 0))
--print(get())
return r
end
old_pull_event=os.pullEvent
os.pullEvent=function(_sFilter)
local eventData = {os.pullEventRaw( _sFilter )}
if eventData[1] == "terminate" then
erase()
--print(get())
printError( "Terminated" )
error()
end
return unpack(eventData)
end
if not has() then save(0) end
]]
local args={...}
if #args>0 then
if args[1]=='reset' then
main_api=main_api..[[
erase()
]]
setfenv(loadstring(main_api),getfenv())()
else
print([[
Usage: ubolt reset
]])
end
return
end
setfenv(loadstring(main_api),getfenv())()
local s=fs.open('startup','w')
s.write(main_api..[[
if has() then
repeat
if get()<0 then
moveTurtle(turtle.up, turtle.detectUp, turtle.digUp, turtle.attackUp, math.huge)
elseif get()>0 then
moveTurtle(turtle.down, turtle.detectDown, turtle.digDown, turtle.attackDown, math.huge)
end
until get()==0
end
erase()
]])
s.close()
For advanced users:
Spoiler
This programs deletes any startup file you may have.After going to the initial position, it resets itself by deleting the temporary file temp_ubolt and the startup file.
Terminating any program while running ubolt will reset ubolt.
You can also reset ubolt by running:
ubolt reset
This is a temporary solution for state loss during chunk reloads; it has been reported that there is random loss of movements, e.g. any scheme of movement-saving movement is due to miss steps.
y-state is less sensible to loss of steps: +1/-1 height difference from the starting height won't hinder your ability to find it…much. But missing a turn and going right instead of front is more problematic, so I ignored it.
The perfect solution is GPS and matching position and orientation to state, but for my situation it seemed overkill.