Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- -- netherite and pyrite strip miner - gps required
- --changes needed
- --refuel funtion
- --testing required
- --dig_home() while loops needs error detection
- local strip_start_level = 15
- local lava_gather_level = 29
- local bedrock_level_start = 4
- local length_blocks = 50 -- blocks long
- local width_blocks = 50 -- blocks wide
- local height_blocks = strip_start_level -- blocks high
- local important_ores = {["minecraft:ancient_debris"]=true,["techreborn:pyrite_ore"]=true,["minecraft:nether_quartz_ore"]=true,["techreborn:cinnabar_ore"]=true,["techreborn:sphalerite_ore"]=true,["betternether:nether_redstone_ore"]=true,
- ["betternether:nether_ruby_ore"]=true,["betternether:cincinnasite_ore"]=true,["archon:fire_node"]=true,["minecraft:nether_gold_ore"]=true}
- local saved_blocks = {["minecraft:ancient_debris"]=true,["techreborn:yellow_garnet_gem"]=true,["techreborn:red_garnet_gem"]=true}
- os.loadAPI("grey_api/move.lua")
- os.loadAPI("grey_api/util.lua")
- local log_filename = "mine_nether.log"
- local log_file = io.open(log_filename, "w")
- if not log_file then print("log file: "..log_filename.." could not be opened") else io.output(log_file) end
- local length = length_blocks --strip length in blocks - forward
- local floor_spacing = 3
- local width = math.floor(((width_blocks+1)/3)+1) --number of strips- right
- local height = math.floor(((height_blocks+1)/floor_spacing)+1) -- number of levels of strips - down
- local current_width = width
- local current_height = height
- local minimum_fuel_level = 1000
- local maximum_fuel_level = 5000
- local face_forward = nil
- local face_backward = nil
- local face_right = nil
- local x_home = nil
- local y_home = nil
- local z_home = nil
- local facing_home = nil
- local max_depth = 25
- local function_blocks = {["minecraft:lava_bucket"]=true,["minecraft:bucket"]=true}
- local quit = false
- function quit_program()
- while not quit do
- os.sleep(0.5)
- end
- end
- --drop all items that aren't in saved_blocks or function_blocks
- function purge_inventory(dir,start,stop)
- dir = dir or "down"
- start = start or 1
- stop = stop or 16
- local item = nil
- --place lava
- if dir=="down" then
- turtle.digDown()
- elseif dir=="up" then
- turtle.digUp()
- else
- turtle.dig()
- end
- while not util.select_item("minecraft:lava_bucket") do io.write("purge_inventory() can't find lava bucket. Going to get some lava\n") refuel(true) end
- turtle.placeDown()
- --drop items
- for i=start,stop do
- item = turtle.getItemDetail(i)
- if item~=nil and not (saved_blocks[item["name"]] or function_blocks[item["name"]]) then
- turtle.select(i)
- if dir=="down" then
- turtle.dropDown()
- elseif dir=="up" then
- turtle.dropUp()
- else
- turtle.drop()
- end
- end
- end
- --pcik up lava
- util.select_item("minecraft:bucket")
- if dir=="down" then
- turtle.placeDown()
- elseif dir=="up" then
- turtle.placeUp()
- else
- turtle.place()
- end
- -- if still full return false
- if util.is_full() then
- return false
- end
- return true
- end
- --tests block in direction dir.
- --if block["name"] is in important_ores
- function test(dir, dig)
- dir = dir or "forward" --can be forward, up, down, left or right
- if dig==nil then dig=true end
- local b,block = nil
- local rtn = true
- if dir=="up" then
- b,block = turtle.inspectUp()
- elseif dir=="down" then
- b,block = turtle.inspectDown()
- elseif dir=="left" or dir=="right" then
- move.turn(dir)
- b,block = turtle.inspect()
- else
- b,block = turtle.inspect()
- end
- if b and important_ores[block["name"]] then
- --print("Found Vein of "..block["name"])
- rtn = dig_vein(block["name"])
- elseif dig then
- if dir=="up" then
- rtn = turtle.digUp()
- elseif dir=="down" then
- rtn = turtle.digDown()
- else
- rtn = turtle.dig()
- end
- end
- if dir=="left" then
- move.turn("right")
- elseif dir=="right" then
- move.turn("left")
- end
- if util.is_full() then
- if not purge_inventory("down") then
- print("inventory is full of goodies!")
- dig_home()
- quit = true
- os.sleep(1)
- end
- end
- return rtn
- end
- --goes to 0,0,0,0 while testing
- function dig_home(go_x,go_y,go_z,go_face)
- if go_x==nil then
- go_x = true
- end
- if go_y==nil then
- go_y = true
- end
- if go_z==nil then
- go_z = true
- end
- if go_face==nil then
- go_face = true
- end
- local _x = move.get_x()
- local _y = move.get_y()
- local _z = move.get_z()
- --go x
- if go_x then
- if _x > x_home then
- move.face(2)
- else
- move.face(0)
- end
- while move.get_x() ~= x_home do
- test()
- move.go("forward",1,true)
- test("up",false)
- test("down",false)
- end
- end
- --go z
- if go_z then
- if _z > z_home then
- move.face(3)
- else
- move.face(1)
- end
- while move.get_z() ~= z_home do
- test()
- move.go("forward",1,true)
- test("up",false)
- test("down",false)
- end
- end
- --go y
- if go_y then
- while move.get_y() ~= y_home do
- if _y>y_home then
- test("down")
- move.go("down",1,true)
- else
- test("up")
- move.go("up",1,true)
- end
- end
- end
- --go face
- if go_face then
- move.face(facing_home)
- end
- end
- function dig_vein(block_name, depth)
- depth = depth or 0
- --print("digging vein at depth: "..depth)
- if depth > max_depth then io.write("Warning: dig_vein() hit max depth at "..max_depth.." on "..block_name..".\n") return false end
- local b,block = nil
- --check up
- --print("check up")
- b,block = turtle.inspectUp()
- if b and block_name == block["name"] then
- move.go("up",1,true)
- dig_vein(block_name,depth+1)
- move.go("down",1,true)
- end
- --check forward
- --print("check forward")
- b,block = turtle.inspect()
- if b and block_name == block["name"] then
- move.go("forward",1,true)
- dig_vein(block_name,depth+1)
- move.turn("right",2)
- move.go("forward",1,true)
- move.turn("right",2)
- end
- --check left
- --print("check left")
- move.turn("left")
- b,block = turtle.inspect()
- if b and block_name == block["name"] then
- move.go("forward",1,true)
- dig_vein(block_name,depth+1)
- move.turn("right",2)
- move.go("forward",1,true)
- move.turn("right",2)
- end
- --check back
- --print("check back")
- move.turn("left")
- b,block = turtle.inspect()
- if b and block_name == block["name"] then
- move.go("forward",1,true)
- dig_vein(block_name,depth+1)
- move.turn("right",2)
- move.go("forward",1,true)
- move.turn("right",2)
- end
- --check right
- --print("check right")
- move.turn("left")
- b,block = turtle.inspect()
- if b and block_name == block["name"] then
- move.go("forward",1,true)
- dig_vein(block_name,depth+1)
- move.turn("right",2)
- move.go("forward",1,true)
- move.turn("right",2)
- end
- --check down
- --print("check down")
- move.turn("left")
- b,block = turtle.inspectDown()
- if b and block_name == block["name"] then
- move.go("down",1,true)
- dig_vein(block_name,depth+1)
- move.go("up",1,true)
- end
- return true
- end
- function refuel(override)
- if override == nil then override = false end
- if turtle.getFuelLevel() < minimum_fuel_level or override then
- local b,block = nil
- io.write("Refueling\n")
- move.sync_coords_gps() --error prevention
- --make sure we have an empty bucket and a lava bucket
- if not (util.count_items("minecraft:bucket") > 0 or util.count_items("minecraft:lava_bucket") > 0) then
- io.write("refueling function couldn't find buckets\n")
- return false
- end
- --save location
- local saved_x,saved_y,saved_z = gps.locate()
- local saved_facing = move.get_facing()
- --go up to lava level
- move.goto(move.get_x(), lava_gather_level, move.get_z(), move.get_facing(), true)
- --get lava from front back left right and up - use all of it
- while turtle.getFuelLevel() < maximum_fuel_level or not util.select_item("minecraft:lava_bucket") do
- --get lava from forward
- b,block = turtle.inspect()
- if b and block["name"] == "minecraft:lava" and block["state"]["level"]==0 then
- if util.select_item("minecraft:bucket") then turtle.place() end
- --use it
- if turtle.getFuelLevel() < maximum_fuel_level or util.count_items("minecraft:lava_bucket") > 1 then
- if util.select_item("minecraft:lava_bucket") then turtle.refuel() end
- end
- end
- --get lava from up
- b,block = turtle.inspectUp()
- if b and block["name"] == "minecraft:lava" and block["state"]["level"]==0 then
- if util.select_item("minecraft:bucket") then turtle.place() end
- --use it
- if turtle.getFuelLevel() < maximum_fuel_level or util.count_items("minecraft:lava_bucket") > 1 then
- if util.select_item("minecraft:lava_bucket") then turtle.refuel() end
- end
- end
- --get lava from down
- b,block = turtle.inspectDown()
- if b and block["name"] == "minecraft:lava" and block["state"]["level"]==0 then
- if util.select_item("minecraft:bucket") then turtle.place() end
- --use it
- if turtle.getFuelLevel() < maximum_fuel_level or util.count_items("minecraft:lava_bucket") > 1 then
- if util.select_item("minecraft:lava_bucket") then turtle.refuel() end
- end
- end
- --get lava from left
- move.turn("left")
- b,block = turtle.inspect()
- if b and block["name"] == "minecraft:lava" and block["state"]["level"]==0 then
- if util.select_item("minecraft:bucket") then turtle.place() end
- --use it
- if turtle.getFuelLevel() < maximum_fuel_level or util.count_items("minecraft:lava_bucket") > 1 then
- if util.select_item("minecraft:lava_bucket") then turtle.refuel() end
- end
- end
- --get lava from back
- move.turn("left")
- b,block = turtle.inspect()
- if b and block["name"] == "minecraft:lava" and block["state"]["level"]==0 then
- if util.select_item("minecraft:bucket") then turtle.place() end
- --use it
- if turtle.getFuelLevel() < maximum_fuel_level or util.count_items("minecraft:lava_bucket") > 1 then
- if util.select_item("minecraft:lava_bucket") then turtle.refuel() end
- end
- end
- --get lava from right
- move.turn("left")
- b,block = turtle.inspect()
- if b and block["name"] == "minecraft:lava" and block["state"]["level"]==0 then
- if util.select_item("minecraft:bucket") then turtle.place() end
- --use it
- if turtle.getFuelLevel() < maximum_fuel_level or util.count_items("minecraft:lava_bucket") > 1 then
- if util.select_item("minecraft:lava_bucket") then turtle.refuel() end
- end
- end
- move.turn("left")--back to starting direction
- if turtle.getFuelLevel() < maximum_fuel_level or not util.select_item("minecraft:lava_bucket") then
- move.go("forward",1,true)
- end
- end
- --go back to saved location
- move.goto(saved_x,saved_y,saved_z,saved_facing,true)
- --continue mining
- return true
- end
- return true
- end
- function mine_line()
- if not refuel() then return false end
- test()
- move.go("forward",1,true)
- test("down",false)
- test("up",false)
- test("left",false)
- test("right",false)
- return not util.is_full()
- end
- function mine_turn()
- if not refuel() then return false end
- local old_facing = move.get_facing()
- move.face(face_right)
- for i=1,3 do
- test()
- move.go("forward",1,true)
- test("up",false)
- test("down",false)
- end
- if old_facing==face_forward then
- move.face(face_backward)
- elseif old_facing==face_backward then
- move.face(face_forward)
- end
- return true
- end
- function mine_down()
- move.sync_coords_gps()
- if move.get_y() - floor_spacing <= bedrock_level_start then
- io.write("mine_down() ran into bedrock. Returning home\n")
- dig_home()
- quit = true
- os.sleep(1)
- return false
- end
- if not refuel() then return false end
- current_width = width
- dig_home(true,false,true,true)
- for i=1,floor_spacing do
- test("down")
- move.go("down",1,true)
- end
- test("down",false)
- return true
- end
- function mine()
- --io.input(stdin)
- refuel()
- --mine to start height
- io.write("Started at "..textutils.formatTime(os.time("local")).."\n")
- io.write("Mine to starting level\n")
- --io.read()
- while move.get_y() > strip_start_level do
- test("down")
- move.go("down")
- end
- while move.get_y() < strip_start_level do
- test("up")
- move.go("up")
- end
- test("down", false)
- test("up", false)
- io.write("Start strip mining\n")
- io.write(current_height.." levels left\n")
- --io.read()
- while true do
- for i=1,length-1 do
- if not mine_line() then break end
- end
- current_width = current_width-1
- if current_width<=0 then
- current_height = current_height-1
- if current_height <= 0 then
- io.write("Done. Going home: ("..x_home..","..y_home..","..z_home..","..facing_home..")\n")
- dig_home()
- break
- else
- mine_down()
- --print(current_height.." levels left")
- end
- else
- mine_turn()
- end
- end
- return true
- end
- if length<=0 or width<=0 or height<=0 then io.write("invalid strip mine dimensions\n") return false end
- if turtle.getFuelLevel() < minimum_fuel_level and not util.fuel(1,{"minecraft:lava_bucket"}) then io.write("Out of fuel before starting\n") return false end
- if not (util.count_items("minecraft:bucket") > 0 or util.count_items("minecraft:lava_bucket") > 0) then
- io.write("Can't find bucket\n")
- return false
- end
- if not move.load_gps() then io.write("mine_nether couldn't load gps\n") return false end
- face_forward = move.get_facing()
- face_backward = (move.get_facing() + 2) % 4
- face_right = (move.get_facing() + 1) % 4
- x_home = move.get_x()
- y_home = move.get_y()
- z_home = move.get_z()
- facing_home = move.get_facing()
- parallel.waitForAny(quit_program, mine)
- purge_inventory()
- io.write("Finished at "..textutils.formatTime(os.time("local")).."\n")
- io.close(log_file)
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement