Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- -- Turtle always keeps moving forward.
- -- You can program physically by setting some blocks!
- local max_step = 10 -- for your safety
- local min_fuel_level = 1000 -- maintain this minimum fuel levels
- local sleep_time = 10 -- define "os.sleep(sleep_time)" in your block_ruls
- local wait_time = 1 -- wait [wait_time] seconds for each step
- -- define your block_rules. Turtle can't braek these blocks.
- local front_rule = {}
- front_rule["minecraft:cobblestone"] = turtle.turnRight
- front_rule["minecraft:stonebrick"] = turtle.turnLeft
- front_rule["minecraft:stone_brick_stairs"] = turtle.up
- front_rule["minecraft:stone_stairs"] = turtle.down -- cobblestone stairs
- front_rule["minecraft:chest"] = os.shutdown
- local top_rule = {}
- top_rule["minecraft:glass"] = function() os.sleep(sleep_time) end
- top_rule["minecraft:chest"] = function()
- while turtle.suckUp(1) and (turtle.getFuelLevel() < min_fuel_level) do
- if turtle.getFuelLevel() < min_fuel_level then os.shutdown() end -- the fuel level is low, and shutdown
- end
- end
- local bottom_rule = {}
- bottom_rule["minecraft:glass"] = function() os.sleep(sleep_time) end
- bottom_rule["minecraft:chest"] = function()
- for i=16,1,-1 do
- turtle.select(i)
- local success, msg = turtle.dropDown()
- if not(success) and string.find(msg, "space") then os.shutdown() end -- the chest is full, and shutdown
- end
- end
- -- sub functions
- function get_func(inspect_func, rule)
- inspect_func = inspect_func or turtle.inspect
- local success, info = inspect_func()
- local bname = info["name"]
- if success then
- return rule[ bname ], bname
- else
- return nil
- end
- end
- function exec_func(inspect_func, rule)
- local func, bname = get_func(inspect_func, rule)
- if func then
- print(" ",bname)
- return func()
- end
- return nil
- end
- function safe_dig(dig_func, inspect_func, rule)
- if get_func(inspect_func, rule) then
- print("decline to dig"); return false
- else
- local success, msg = dig_func()
- print(" dig ->",success,"(",msg,")")
- return success, msg
- end
- end
- function go_fwd() -- dig the top,bottom,front. and go forward.
- while safe_dig(turtle.digUp, turtle.inspectUp, top_rule) do os.sleep() end -- prepare for a sand or a gravel
- safe_dig(turtle.digDown, turtle.inspectDown, bottom_rule)
- while safe_dig(turtle.dig, turtle.inspect, front_rule) do os.sleep() end -- prepare for a sand or a gravel
- return turtle.forward()
- end
- -- Main
- turtle.select(1)
- for step=1,max_step do
- print(step,":")
- print(" -top"); exec_func(turtle.inspectUp, top_rule)
- print(" -bottom"); exec_func(turtle.inspectDown, bottom_rule)
- print(" -front"); exec_func(turtle.inspect, front_rule)
- go_fwd()
- os.sleep(wait_time)
- end
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement