Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- --Programmed by Nick Mead(NickM13)
- --Refloor, arguments when calling program should be "Flooring <Forward> <Right>"
- args = {...}
- m_pos = {}
- m_dim = {}
- m_floorMat = ""
- m_dirSwitch = false
- m_blocksMined = 0
- m_fuelUsed = 0
- m_pos.x = 0
- m_pos.z = 0
- m_rot = 0
- local function clear()
- term.clear()
- term.setCursorPos(1, 1)
- end
- local function showStats()
- clear()
- print("Excavation statistics screen")
- print("*Hold CTRL+T to cancel excavation*\n")
- print("Floor material: "..m_floorMat)
- print("Blocks Mined: "..m_blocksMined)
- print("Distance Moved: "..m_fuelUsed)
- print("Fuel Level: "..turtle.getFuelLevel().."\n")
- print("Position")
- print("X: "..m_pos.x.."/"..m_dim.x)
- print("Z: "..m_pos.z.."/"..m_dim.z)
- print("")
- io.write("Rotation: "..m_rot.." (")
- if m_rot == 0 then
- io.write("Forward")
- elseif m_rot == 1 then
- io.write("Right")
- elseif m_rot == 2 then
- io.write("Backward")
- elseif m_rot == 3 then
- io.write("Left")
- end
- print(")")
- end
- local function getMaterial()
- for i = 1, 16 do
- if turtle.getItemCount(i) > 0 and turtle.getItemDetail(i).name == m_floorMat then
- turtle.select(i)
- return true
- end
- end
- print("Out of <"..m_floorMat..">! Waiting for more material.")
- while true do
- for i = 1, 16 do
- if turtle.getItemCount(i) > 0 and turtle.getItemDetail(i).name == m_floorMat then
- turtle.select(i)
- return true
- end
- end
- sleep(1)
- end
- end
- local function dig(direction)
- dug = false
- if direction == "forward" then
- if turtle.dig() then
- m_blocksMined = m_blocksMined + 1
- dug = true
- end
- elseif direction == "up" then
- if turtle.digUp() then
- m_blocksMined = m_blocksMined + 1
- dug = true
- end
- elseif direction == "down" then
- if turtle.digDown() then
- m_blocksMined = m_blocksMined + 1
- dug = true
- end
- end
- showStats()
- return dug
- end
- local function move(direction, distance)
- m_fuelUsed = m_fuelUsed + distance
- warned = false
- if direction == "forward" then
- for i = 1, distance do
- while not turtle.forward() do
- dig("forward")
- sleep(1)
- if not warned then
- print("Forward movement blocked!")
- warned = true
- end
- end
- dig("down")
- getMaterial()
- turtle.placeDown()
- if m_rot == 0 then
- m_pos.x = m_pos.x + 1
- elseif m_rot == 1 then
- m_pos.z = m_pos.z + 1
- elseif m_rot == 2 then
- m_pos.x = m_pos.x - 1
- elseif m_rot == 3 then
- m_pos.z = m_pos.z - 1
- end
- showStats()
- end
- elseif direction == "back" then
- for i = 1, distance do
- while not turtle.back() do
- sleep(1)
- if not warned then
- print("Backward movement blocked!")
- warned = true
- end
- end
- if m_rot == 0 then
- m_pos.x = m_pos.x - 1
- elseif m_rot == 1 then
- m_pos.z = m_pos.z - 1
- elseif m_rot == 2 then
- m_pos.x = m_pos.x + 1
- elseif m_rot == 3 then
- m_pos.z = m_pos.z + 1
- end
- showStats()
- end
- elseif direction == "up" then
- for i = 1, distance do
- while dig("up") do sleep(0.1) end
- while not turtle.up() do
- dig("up")
- sleep(1)
- if not warned then
- print("Up movement blocked!")
- warned = true
- end
- end
- m_pos.y = m_pos.y - 1
- showStats()
- end
- elseif direction == "down" then
- for i = 1, distance do
- dig("down")
- while not turtle.down() do
- dig("down")
- sleep(1)
- if not warned then
- print("Down movement blocked!")
- warned = true
- end
- end
- m_pos.y = m_pos.y + 1
- showStats()
- end
- end
- end
- local function turn(direction)
- if direction == "right" then
- turtle.turnRight()
- m_rot = m_rot + 1
- elseif direction == "left" then
- turtle.turnLeft()
- m_rot = m_rot - 1
- elseif direction == "around" then
- turtle.turnRight()
- turtle.turnRight()
- m_rot = m_rot + 2
- end
- while m_rot > 3 do
- m_rot = m_rot - 4
- end
- while m_rot < 0 do
- m_rot = m_rot + 4
- end
- showStats()
- end
- if #args >= 2 then
- m_dim.x = tonumber(args[1])
- m_dim.z = tonumber(args[2])
- turtle.select(1)
- print("Place desired floor material in first slot and press any key.")
- sleep(0.5)
- os.pullEvent("key")
- m_floorMat = turtle.getItemDetail(1).name
- print("Material: "..m_floorMat)
- print("Checking fuel...")
- if turtle.getFuelLevel() < m_dim.x * m_dim.z then
- print("Not enough fuel. Insert coal.")
- while turtle.getFuelLevel() < m_dim.x * m_dim.z do
- for i = 1, 16 do
- if turtle.getItemCount(i) > 0 and turtle.getItemDetail(i).name == "minecraft:coal" then
- turtle.select(i)
- turtle.refuel(1)
- break
- end
- end
- sleep(0.25)
- end
- turtle.select(1)
- else
- print("Enough fuel. Beginning reflooring process.")
- end
- dig("down")
- getMaterial()
- turtle.placeDown()
- for r = 1, m_dim.x do
- move("forward", m_dim.z - 1)
- if r < m_dim.x then
- if m_dirSwitch == true then turn("left")
- else turn("right") end
- move("forward", 1)
- if m_dirSwitch == true then turn("left")
- else turn("right") end
- else
- if m_dirSwitch == true then turn("right")
- else turn("left") end
- end
- m_dirSwitch = not m_dirSwitch
- end
- else
- error("Incorrect usage of program: Floor <Forward> <Right>")
- end
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement