Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- local function is_facing_name(str)
- local success, data = turtle.inspect()
- if not success then
- return false
- end
- if data.name == str then
- return true
- end
- return false
- end
- local function is_facing_something_interesting()
- if is_facing_name("minecraft:stone") then
- return true
- elseif is_facing_name("minecraft:flowing_lava") then
- return true
- elseif is_facing_name("minecraft:redstone_wire") then
- return true
- elseif is_facing_name("minecraft:obsidian") then
- return true
- end
- return false
- end
- local function orient()
- local turned = 0
- while not is_facing_something_interesting() do
- turtle.turnLeft()
- turned = turned + 1
- if turned >= 4 then
- print("Could not find orientation")
- return false
- end
- end
- return true
- end
- local function get_state()
- if is_facing_name("minecraft:flowing_lava") then
- return 4
- elseif is_facing_name("minecraft:redstone_wire") then
- return 2
- elseif is_facing_name("minecraft:obsidian") then
- return 3
- end
- return 4
- end
- local function select_redstone()
- for s = 2, 9 do
- turtle.select(s)
- if turtle.getItemCount() > 0 then
- return true
- end
- end
- return false
- end
- local function get_redstone()
- if select_redstone() then
- return
- end
- turtle.turnRight()
- for s = 2, 14 do
- turtle.select(s)
- turtle.suck(64)
- end
- if select_redstone() then
- turtle.turnLeft()
- return
- end
- print("Redstone chest is empty!")
- while not select_redstone() do
- sleep(5)
- end
- turtle.turnLeft()
- end
- local function empty_inventory()
- turtle.select(15)
- if turtle.getItemCount() == 64 then
- turtle.turnLeft()
- if turtle.drop(64) then
- turtle.turnRight()
- return
- end
- print("Dumping chest is full")
- while not turtle.drop(64) do
- sleep(5)
- end
- end
- end
- local function do_iteration(initial_state)
- if not initial_state then
- initial_state = 1
- end
- if initial_state < 2 then
- -- Place redstone wire
- turtle.select(15)
- turtle.dig()
- select_redstone()
- turtle.place()
- end
- if initial_state < 3 then
- redstone.setOutput("top", false)
- -- Wait for a bit
- while not is_facing_name("minecraft:obsidian") do
- sleep(1)
- end
- end
- if initial_state < 4 then
- redstone.setOutput("top", true)
- -- Make sure you have enough redstone and stuff for the next
- -- iteration
- get_redstone()
- empty_inventory()
- -- Mine it
- turtle.select(15)
- turtle.dig()
- end
- end
- local function start()
- redstone.setOutput("top", true)
- do_iteration(get_state())
- while true do
- do_iteration()
- end
- end
- local function init()
- orient()
- start()
- end
- init()
Add Comment
Please, Sign In to add comment