Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- function select_fuel()
- local slot = 1
- local data = turtle.getItemDetail(slot)
- if select_item("minecraft:lava_bucket") then
- return true
- end
- while slot <= 16 do
- if data and (data.name == "minecraft:coal" or data.name == "minecraft:planks" or data.name == "minecraft:log"or data.name == "minecraft:stick") then
- break
- end
- slot = slot + 1
- if slot <= 16 then
- turtle.select(slot)
- data = turtle.getItemDetail(slot)
- end
- end
- if (slot > 16) then
- return false
- end
- turtle.select(slot)
- return true
- end
- function check_fuel()
- select_fuel()
- if turtle.getFuelLevel() < 1000 then
- while turtle.refuel(1) == false do
- print("No fuel available. Retrying refuel in 10 seconds")
- sleep(10)
- end
- end
- end
- function avance(x)
- while x > 0 do
- if quick_inspect("front") == "minecraft:lava" or quick_inspect("front") == "minecraft:flowing_lava" then
- search_and_fill_lava()
- end
- while turtle.forward() == false do
- check_fuel()
- search_and_mine_ore()
- turtle.dig()
- end
- x = x - 1
- end
- end
- function line(maxx, maxz)
- local z = 0
- while z <= maxz do
- avance(maxx)
- turtle.turnLeft()
- turtle.turnLeft()
- avance(maxx)
- turtle.turnRight()
- turtle.turnRight()
- while turtle.up() == false do
- check_fuel()
- turtle.digUp()
- end
- z = z + 1
- end
- while z > 0 do
- while turtle.down() == false do
- check_fuel()
- turtle.digDown()
- end
- z = z - 1
- end
- end
- function select_item(item)
- local slot = 1
- while slot <= 16 do
- local data = turtle.getItemDetail(slot)
- if data and data.name == item then
- turtle.select(slot)
- return true
- end
- slot = slot + 1
- end
- return false
- end
- function search_bloc(bloc)
- if quick_inspect("up") == bloc then return "up"
- elseif quick_inspect("front") == bloc then return "front"
- elseif quick_inspect("down") == bloc then return "down"
- end
- turtle.turnLeft()
- if quick_inspect("front") == bloc then
- turtle.turnRight()
- return "left"
- end
- turtle.turnRight()
- turtle.turnRight()
- if quick_inspect("front") == bloc then
- turtle.turnLeft()
- return "right"
- end
- turtle.turnLeft()
- return "none"
- end
- function quick_inspect(direction)
- local success = false
- local data
- if direction == "up" then success, data = turtle.inspectUp()
- elseif direction == "front" then success, data = turtle.inspect()
- elseif direction == "down" then success, data = turtle.inspectDown()
- end
- if success then
- return data.name
- else
- return "none"
- end
- end
- function search_and_fill_lava()
- local direction = search_bloc("minecraft:lava")
- if direction ~= "none" and select_item("minecraft:lava_bucket") then
- turtle.refuel()
- end
- if direction ~= "none" and select_item("minecraft:bucket") then
- if direction == "up" then turtle.placeUp()
- elseif direction == "down" then turtle.placeDown()
- elseif direction == "left" then
- turtle.turnLeft()
- turtle.place()
- turtle.turnRight()
- elseif direction == "right" then
- turtle.turnRight()
- turtle.place()
- turtle.turnLeft()
- elseif direction == "front" then
- turtle.place()
- end
- end
- end
- function search_and_mine_ore()
- if quick_inspect("up") == "minecraft:iron_ore" or
- quick_inspect("up") == "minecraft:gold_ore" or
- quick_inspect("up") == "minecraft:diamond_ore" or
- quick_inspect("up") == "minecraft:emerald_ore" or
- quick_inspect("up") == "minecraft:lapis_ore" or
- quick_inspect("up") == "minecraft:redstone_ore" or
- quick_inspect("up") == "minecraft:coal_ore" then
- turtle.digUp()
- return "up"
- elseif quick_inspect("front") == "minecraft:iron_ore" or
- quick_inspect("front") == "minecraft:gold_ore" or
- quick_inspect("front") == "minecraft:diamond_ore" or
- quick_inspect("front") == "minecraft:emerald_ore" or
- quick_inspect("front") == "minecraft:lapis_ore" or
- quick_inspect("front") == "minecraft:redstone_ore" or
- quick_inspect("front") == "minecraft:coal_ore" then
- turtle.dig()
- return "front"
- elseif quick_inspect("") == "minecraft:iron_ore" or
- quick_inspect("down") == "minecraft:gold_ore" or
- quick_inspect("down") == "minecraft:diamond_ore" or
- quick_inspect("down") == "minecraft:emerald_ore" or
- quick_inspect("down") == "minecraft:lapis_ore" or
- quick_inspect("down") == "minecraft:redstone_ore" or
- quick_inspect("down") == "minecraft:coal_ore" then
- turtle.digDown()
- return "down"
- end
- turtle.turnLeft()
- if quick_inspect("front") == "minecraft:iron_ore" or
- quick_inspect("front") == "minecraft:gold_ore" or
- quick_inspect("front") == "minecraft:diamond_ore" or
- quick_inspect("front") == "minecraft:emerald_ore" or
- quick_inspect("front") == "minecraft:lapis_ore" or
- quick_inspect("front") == "minecraft:redstone_ore" or
- quick_inspect("front") == "minecraft:coal_ore" then
- turtle.dig()
- return "left"
- end
- turtle.turnRight()
- turtle.turnRight()
- if quick_inspect("front") == "minecraft:iron_ore" or
- quick_inspect("front") == "minecraft:gold_ore" or
- quick_inspect("front") == "minecraft:diamond_ore" or
- quick_inspect("front") == "minecraft:emerald_ore" or
- quick_inspect("front") == "minecraft:lapis_ore" or
- quick_inspect("front") == "minecraft:redstone_ore" or
- quick_inspect("front") == "minecraft:coal_ore" then
- turtle.dig()
- return "right"
- end
- turtle.turnLeft()
- return "none"
- end
- function is_inventory_full()
- local slot = 1
- while slot <= 16 do
- if not turtle.getItemDetail(slot) then
- return false
- end
- slot = slot + 1
- end
- return true
- end
- function drop_all_shit()
- local slot = 1
- local data
- while slot <= 16 do
- data = turtle.getItemDetail(slot)
- if data and (data.name == "minecraft:cobblestone" or data.name == "minecraft:granite" or data.name == "minecraft:diorite" or data.name == "minecraft:andesite" or data.name == "minecraft:gravel" or data.name == "minecraft:dirt") then
- turtle.select(slot)
- turtle.drop()
- end
- slot = slot + 1
- end
- end
- function go_drop_ores(xbase, ybase, zbase)
- local x, y, z = secure_gps()
- goto_coordinates(xbase, ybase, zbase)
- wait_chest()
- drop_all_non_fuel()
- goto_coordinates(x, y, z)
- end
- function drop_all_non_fuel()
- local slot = 1
- local data
- while slot <= 16 do
- data = turtle.getItemDetail(slot)
- if data and data.name ~= "minecraft:coal" and
- data.name ~= "minecraft:planks" and
- data.name ~= "minecraft:log"and
- data.name ~= "minecraft:stick" then
- turtle.select(slot)
- turtle.dropDown()
- end
- slot = slot + 1
- end
- end
- function wait_chest()
- while quick_inspect("down") ~= "minecraft:chest" do
- print("Waiting for chest bottom me. Retrying in 20 secs")
- sleep(20)
- end
- end
- function secure_gps()
- local x, y, z = gps.locate()
- local i = 0
- while not x do
- print("Can't communicate with GPS. Retrying in 10 seconds. I will shutdown after 50 try")
- x, y, z = gps.locate()
- i = i + 1
- if i >= 50 then os.shutdown() end
- end
- return x, y, z
- end
- function goto_coordinates(x, y, z)
- local xn, yn, zn = secure_gps()
- look_at_north(xn, zn)
- xn, yn, zn = secure_gps()
- if (z - zn) < 0 then
- turtle.turnLeft()
- turtle.turnLeft()
- avance(abs(z - zn))
- turtle.turnRight()
- turtle.turnRight()
- else
- avance(abs(z - zn))
- end
- if (x - xn) < 0 then
- turtle.turnLeft()
- elseif (x - xn) > 0 then
- turtle.turnRight()
- end
- avance(abs(x - xn))
- if (z - zn) < 0 then
- descend(abs(z - zn))
- elseif (z - zn) > 0 then
- ascend(abs(z - zn))
- end
- end
- function look_at_north(x, z)
- local xn, yn, zn
- if turtle.detect() then
- check_fuel()
- while not turtle.back() do
- check_fuel()
- end
- xn, yn, zn = get_coords()
- if x > xn then turtle.turnRight()
- elseif x < xn then turtle.turnLeft()
- elseif z < zn then
- turtle.turnLeft()
- turtle.turnLeft()
- end
- return true
- end
- check_avance()
- xn, yn, zn = get_coords()
- if x < xn then turtle.turnRight()
- elseif x > xn then turtle.turnLeft()
- elseif z > zn then
- turtle.turnLeft()
- turtle.turnLeft()
- end
- return true
- end
- function abs(x)
- if x < 0 then return -x end return x
- end
- function move_to_direction(direction)
- if direction == "front" then avance(1)
- elseif direction == "back" then
- turtle.turnLeft()
- turtle.turnLeft()
- avance(1)
- turtle.turnLeft()
- turtle.turnLeft()
- elseif direction == "left" then
- turtle.turnLeft()
- avance(1)
- turtle.turnRight()
- elseif direction == "right" then
- turtle.turnRight()
- avance(1)
- turtle.turnLeft()
- elseif direction == "down" then
- descend(1)
- elseif direction == "up" then
- ascend(1)
- end
- end
- function descend(max)
- local i = 0
- while i < max do
- if turtle.down() == false then
- check_fuel()
- turtle.digDown()
- else
- i = i + 1
- end
- end
- end
- function ascend(max)
- local i = 0
- while i < max do
- if turtle.up() == false then
- check_fuel()
- turtle.digUp()
- else
- i = i + 1
- end
- end
- end
- function check_inventory(x, y, z)
- if is_inventory_full() then
- go_drop_ores(x, y, z)
- end
- end
- local xhome, yhome, zhome = secure_gps()
- print("Don't forget to put chest bottom me before I start !")
- io.write("Nbr of blocs to mine in front of: ")
- local maxx = tonumber(read())
- io.write("Nbr of blocs to mine at right: ")
- local maxz = tonumber(read())
- io.write("Nbr of blocs to mine at top: ")
- local maxy = tonumber(read())
- local z = 0
- while z < maxz do
- line(maxx, maxy)
- drop_all_shit()
- check_inventory()
- turtle.turnRight()
- line(3, maxy)
- avance(4)
- turtle.turnLeft()
- z = z + 3
- end
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement