Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- --Programmed by Nick Mead(NickM13)
- dimension = {}
- coordinate = {}
- rotation = 0
- back = false
- blocksMined = 0
- minimumFuel = 40
- finish = false
- name = nil
- term.clear()
- term.setCursorPos(1, 1)
- print("Enter dimensions you would like in the form x z y, eg: 5 5 2")
- print("")
- print("Height of the area is multiplied by 3 for efficiency")
- print("")
- print("Entering only x and z will assume you want to dig to the bottom of the map.")
- print("")
- io.write("Size: ")
- input = io.read()
- args = {}
- i=0
- for s in input:gmatch("%S+") do
- i=i+1
- args[i] = s
- end
- local function setup()
- dimension.x = tonumber(args[1])
- dimension.z = tonumber(args[2])
- if #args == 3 then
- dimension.y = tonumber(args[3])
- else
- dimension.y = 256
- end
- term.clear()
- term.setCursorPos(1, 1)
- print("Width(Right): "..dimension.x.."\nLength(Forward): "..dimension.z.."\nDepth(Down): "..dimension.y * 3)
- coordinate.x = 0
- coordinate.y = 0
- coordinate.z = 0
- print("\nAll fuel will be input at start")
- print("Press the any key to begin")
- os.pullEvent("key")
- if turtle.getItemCount(2) ~= 0 then
- turtle.select(2)
- if turtle.refuel() then
- print("Fuel found")
- else
- print("No fuel found")
- end
- end
- print("Starting fuel: "..turtle.getFuelLevel().." units")
- turtle.select(1)
- end
- local function deposit()
- slot = 0
- for i=1, 16 do
- name = turtle.getItemDetail(i)
- if name ~= nil and name.name == "minecraft:chest" then
- slot = i
- break
- end
- end
- if slot == 0 then return false end
- turtle.select(slot)
- if not turtle.placeUp() then
- if not turtle.placeDown() then
- print("no place for chest")
- return false
- else chestdir = "down" end
- else chestdir = "up" end
- for i=1, 16 do
- name = turtle.getItemDetail(i)
- if name ~= nil and name.name ~= "minecraft:chest" then
- turtle.select(i)
- if chestdir == "up" then turtle.dropUp()
- else turtle.dropDown() end
- end
- end
- return true
- end
- local function dig(dir)
- local buffer = 5
- if dir == "up" then
- os.sleep(0.5)
- while turtle.detectUp() do
- if not turtle.digUp() then buffer = buffer - 1 if buffer <= 0 then return false end else
- buffer = 5
- blocksMined = blocksMined + 1
- end
- os.sleep(0.5)
- end
- elseif dir == "front" or dir == "forward" then
- while turtle.detect() do
- if not turtle.dig() then buffer = buffer - 1 if buffer <= 0 then return false end else
- buffer = 5
- end
- blocksMined = blocksMined + 1
- os.sleep(0.1)
- end
- elseif dir == "down" then
- while turtle.detectDown() do
- if not turtle.digDown() then buffer = buffer - 1 if buffer <= 0 then return false end else
- buffer = 5
- end
- blocksMined = blocksMined + 1
- end
- else
- error("dig error")
- end
- return true
- end
- local function refuel()
- for i=1, 16 do
- name = turtle.getItemDetail(i)
- if name ~= nil and name.name == "minecraft:coal" then
- turtle.select(i)
- turtle.refuel(1)
- return true
- end
- end
- return false
- end
- local function move(dir)
- local moved = false
- if turtle.getFuelLevel() < minimumFuel then
- print("Low fuel: "..turtle.getFuelLevel())
- refuel()
- end
- while turtle.getFuelLevel() == 0 do
- print("Out of fuel")
- repeat until (refuel())
- end
- turtle.select(1)
- if dir == "forward" then
- while not moved do
- if turtle.forward() then
- moved = true
- if rotation == 0 then
- coordinate.x = coordinate.x + 1
- elseif rotation == 1 then
- coordinate.z = coordinate.z + 1
- elseif rotation == 2 then
- coordinate.x = coordinate.x - 1
- elseif rotation == 3 then
- coordinate.z = coordinate.z - 1
- else
- error("rotation error in move function")
- end
- end
- if not moved then
- if turtle.detect() then if not dig"front" then finish = true return end end
- end
- end
- elseif dir == "up" then
- while not moved do
- if turtle.up() then
- moved = true
- coordinate.y = coordinate.y + 1
- end
- if not moved then
- if turtle.detectUp() then if not dig"up" then finish = true return end end
- end
- end
- elseif dir == "down" then
- while not moved do
- if turtle.down() then
- moved = true
- coordinate.y = coordinate.y - 1
- end
- if not moved then
- if turtle.detectDown() then if not dig"down" then finish = true return end end
- end
- end
- else
- error("move error")
- end
- return moved
- end
- local function turn(dir)
- if dir == "right" then
- turtle.turnRight()
- rotation = rotation + 1
- elseif dir == "left" then
- turtle.turnLeft()
- rotation = rotation - 1
- else
- error("turn error")
- end
- rotation = rotation%4
- end
- local function chunk()
- if turtle.getSelectedSlot() ~= 1 then
- turtle.select(1)
- end
- if (not dig"front" and turtle.detect()) then finish = true return end
- move"forward"
- if (not dig"down" and turtle.detectDown()) then finish = true return end
- if (not dig"up" and turtle.detectUp()) then finish = true return end
- if turtle.getItemCount(16) ~= 0 then
- deposit()
- end
- end
- local function recall()
- local c = 1
- while (c < 4 and coordinate.y < 0) do
- move"up"
- c = c + 1
- end
- while rotation ~= 2 do turn"right" end
- while coordinate.x > 0 do
- move"forward"
- end
- while rotation ~= 3 do turn"right" end
- while coordinate.z > 0 do
- move"forward"
- end
- while rotation ~= 0 do turn"right" end
- while coordinate.y < 0 do
- move"up"
- end
- end
- setup()
- dig"up"
- dig"down"
- for y=1, dimension.y do
- for z=1, dimension.z, 1 do
- for x=1, dimension.x-1, 1 do
- chunk()
- if finish then break end
- end
- if finish then break end
- if z == dimension.z then break end
- if back then
- turn"left"
- chunk()
- turn"left"
- else
- turn"right"
- chunk()
- turn"right"
- end
- back = not back
- end
- if finish then break end
- if y < dimension.y then
- for j=1, 3, 1 do
- dig"down"
- move"down"
- end
- dig"down"
- turn"right"
- turn"right"
- end
- end
- deposit()
- recall()
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement