Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- local tunnel_length = 0
- local cluster_width = 0
- local cluster_height = 0
- local done_width = 0
- local done_height = 0
- local pos_x = 0
- local pos_y = 0
- local pos_z = 0
- local facing_pos = {"front", "right", "back", "left"}
- local facing_nb = 1
- local facing = facing_pos[facing_nb]
- local useless_ressources = {"minecraft:stone", "minecraft:cobblestone","minecraft:dirt", "chisel:limestone2", "chisel:marble2"}
- function read_cluster_params()
- write("Enter tunnel length : ")
- tunnel_length = tonumber(read())
- write("Enter cluster width : ")
- cluster_width = tonumber(read())
- write("Enter cluster height : ")
- cluster_height = tonumber(read())
- end
- function turnleft()
- turtle.turnLeft()
- facing_nb = ((facing_nb + 3) % 4)
- if (facing_nb == 0) then
- facing_nb = 4
- end
- facing = facing_pos[facing_nb]
- end
- function turnright()
- turtle.turnRight()
- facing_nb = ((facing_nb + 1) % 4)
- if (facing_nb == 0) then
- facing_nb = 4
- end
- facing = facing_pos[facing_nb]
- end
- function turn_180_r()
- turtle.turnRight()
- turtle.turnRight()
- facing_nb = ((facing_nb + 2) % 4)
- if (facing_nb == 0) then
- facing_nb = 4
- end
- facing = facing_pos[facing_nb]
- end
- function turn_180_l()
- turtle.turnLeft()
- turtle.turnLeft()
- facing_nb = ((facing_nb + 2) % 4)
- if (facing_nb == 0) then
- facing_nb = 4
- end
- facing = facing_pos[facing_nb]
- end
- function is_useless(n)
- for i=1, 5 do
- if (n == useless_ressources[i]) then
- return true
- end
- end
- return false
- end
- function detect_up_down()
- local success, data = turtle.inspectUp()
- if success then
- if (is_useless(data.name)) then
- else
- turtle.digUp()
- end
- end
- local s, d = turtle.inspectDown()
- if s then
- if (is_useless(d.name)) then
- else
- turtle.digDown()
- end
- end
- end
- function face_correct_side(toface)
- if (facing_nb == toface) then
- return true
- end
- turnleft()
- if (facing_nb == toface) then
- return true
- end
- turnleft()
- if (facing_nb == toface) then
- return true
- end
- turnleft()
- if (facing_nb == toface) then
- return true
- end
- end
- function drop_to_chest()
- local selected_slot = 1
- while (selected_slot <= 16) do
- turtle.select(selected_slot)
- turtle.drop()
- selected_slot = selected_slot + 1
- end
- turtle.select(1)
- end
- function clear_inventory()
- local selected_slot = 1
- while (selected_slot <= 16) do
- turtle.select(selected_slot)
- local tmp = turtle.getItemDetail()
- if (tmp ~= nil) then
- if (is_useless(tmp.name)) then
- turtle.drop()
- end
- end
- selected_slot = selected_slot + 1
- end
- turtle.select(1)
- end
- function is_inv_full()
- turtle.select(16)
- local tmp = turtle.getItemDetail()
- turtle.select(1)
- if (tmp == nil) then
- return false
- else
- return true
- end
- end
- function mine_tunnel()
- while (pos_z + 1 < tunnel_length) do
- detect_up_down()
- turtle.dig()
- while (turtle.forward() == false) do
- turtle.dig()
- end
- detect_up_down()
- pos_z = pos_z + 1
- end
- end
- function mine_tunnel_invert()
- while (pos_z > 0) do
- detect_up_down()
- turtle.dig()
- while (turtle.forward() == false) do
- turtle.dig()
- end
- detect_up_down()
- pos_z = pos_z - 1
- end
- end
- function go_to_next_tunnel()
- if (facing_nb == 1) then
- turnright()
- while (turtle.forward() == false) do
- turtle.dig()
- end
- pos_x = pos_x + 1
- turnright()
- elseif (facing_nb == 3) then
- turnleft()
- while (turtle.forward() == false) do
- turtle.dig()
- end
- pos_x = pos_x + 1
- turnleft()
- end
- end
- function go_to_next_tunnel_invert()
- if (facing_nb == 3) then
- turnright()
- while (turtle.forward() == false) do
- turtle.dig()
- end
- pos_x = pos_x - 1
- turnright()
- elseif (facing_nb == 1) then
- turnleft()
- while (turtle.forward() == false) do
- turtle.dig()
- end
- pos_x = pos_x - 1
- turnleft()
- end
- end
- function handle_x_mining()
- while (done_width == 0) do
- mine_tunnel()
- go_to_next_tunnel()
- mine_tunnel_invert()
- clear_inventory()
- if (pos_x + 1 < cluster_width) then
- go_to_next_tunnel()
- else
- done_width = 1
- end
- end
- end
- function handle_x_mining_invert()
- while (done_width == 0) do
- mine_tunnel()
- go_to_next_tunnel_invert()
- mine_tunnel_invert()
- if (pos_x > 0) then
- go_to_next_tunnel_invert()
- else
- done_width = 1
- end
- end
- end
- function move_down()
- if (pos_z == 0) then
- face_correct_side(1)
- else
- face_correct_side(3)
- end
- while (turtle.down() == false) do
- turtle.digDown()
- end
- pos_y = pos_y + 1
- while (turtle.down() == false) do
- turtle.digDown()
- end
- pos_y = pos_y + 1
- while (turtle.down() == false) do
- turtle.digDown()
- end
- pos_y = pos_y + 1
- end
- function deposit_inventory()
- local lx = pos_x
- local ly = pos_y
- print("Inventory is full")
- print("Positon before x:"..lx.." y:"..ly)
- if (lx > 0) then
- face_correct_side(4)
- while (lx > 0) do
- while (turtle.forward() == false) do
- turtle.dig()
- end
- lx = lx - 1
- end
- end
- if (ly > 0) then
- while (ly > 0) do
- while (turtle.up() == false) do
- turtle.digUp()
- end
- ly = ly - 1
- end
- end
- face_correct_side(3)
- print("Should be in front of chest")
- print("Positon x:"..lx.." y:"..ly)
- drop_to_chest()
- while (ly ~= pos_y) do
- while (turtle.down() == false) do
- turtle.digDown()
- end
- ly = ly + 1
- end
- if (lx ~= pos_x) then
- face_correct_side(2)
- while (lx ~= pos_x) do
- while (turtle.forward() == false) do
- turtle.dig()
- end
- lx = lx + 1
- end
- end
- print("Positon after x:"..lx.." y:"..ly)
- end
- read_cluster_params()
- while (pos_y <= cluster_height) do
- while (turtle.forward() == false) do
- turtle.dig()
- end
- handle_x_mining()
- done_width = 0
- while (turtle.forward() == false) do
- turtle.dig()
- end
- --right side
- if (is_inv_full()) then
- deposit_inventory()
- end
- move_down()
- while (turtle.forward() == false) do
- turtle.dig()
- end
- handle_x_mining_invert()
- done_width = 0
- while (turtle.forward() == false) do
- turtle.dig()
- end
- if (pos_y <= cluster_height) then
- --left side
- if (is_inv_full()) then
- deposit_inventory()
- end
- move_down()
- end
- end
- --go back to chest
- if (pos_x > 0) then
- face_correct_side(4)
- while (pos_x > 0) do
- while (turtle.forward() == false) do
- turtle.dig()
- end
- pos_x = pos_x - 1
- end
- end
- if (pos_y > 0) then
- while (pos_y > 0) do
- while (turtle.up() == false) do
- turtle.digUp()
- end
- pos_y = pos_y - 1
- end
- end
- face_correct_side(3)
- print("Should be in front of chest")
- print("Positon z:"..pos_z.." x:"..pos_x.." y:"..pos_y)
- drop_to_chest()
- print("Have fun with your new ores!")
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement