Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- args = {...}
- local floorType
- local orientation
- local currentSlot = 2
- if #args > 1 then
- if tostring(args[1]) == "top" then
- floorType = "top"
- elseif tostring(args[1]) == "bottom" then
- floorType = "bottom"
- elseif not tostring(args[1]) == "top" or not tostring(args[1]) == "bottom" then
- error("Usage: placeFloor <position> (either top or bottom) <direction> (either left or right)")
- end
- if tostring(args[2]) == "left" then
- orientation = 1
- elseif tostring(args[2]) == "right" then
- orientation = 3
- elseif not tostring(args[2]) == "left" or not tostring(args[2]) == "right" then
- error("Usage: placeFloor <position> (either top or bottom) <direction> (either left or right)")
- end
- else
- error("Usage: placeFloor <position> (either top or bottom) <direction> (either left or right)")
- end
- function gotoNextSlotIfEmpty()
- if turtle.getItemCount(currentSlot) == 0 then
- currentSlot = currentSlot + 1
- turtle.select(currentSlot)
- while not turtle.compareTo(1) do
- currentSlot = currentSlot + 1
- if currentSlot > 16 then
- return false
- end
- turtle.select(currentSlot)
- end
- end
- return true
- end
- function reSupply()
- resupplied = false
- print("turtle out of items. waiting for new items in slot 2-16. once you place blocks in the 2nd slot it will count to 10 and then continue.")
- repeat
- if turtle.getItemCount(2) > 0 then
- sleep(10)
- resupplied = true
- currentSlot = 2
- turtle.select(currentSlot)
- end
- sleep(0.5)
- until resupplied
- end
- function checkFuelLevel()
- if turtle.getFuelLevel() < 10 then
- return false
- end
- return true
- end
- function reFuel()
- refueled = false
- print("turtle out of fuel. waiting for fuel in slot 2-16. once you place fuel in the 2nd slot it will count to 10 and then consume all it can and then continue.")
- repeat
- if turtle.getItemCount(2) > 0 then
- sleep(10)
- for i=2,16 do
- turtle.select(i)
- turtle.refuel()
- end
- currentSlot = 2
- turtle.select(currentSlot)
- refueled = true
- end
- sleep(0.5)
- until refueled
- end
- function left()
- if turtle then turtle.turnLeft() end
- orientation = orientation - 1
- if orientation < 1 then orientation = 4 end
- return orientation
- end
- function right()
- if turtle then turtle.turnRight() end
- orientation = orientation + 1
- if orientation > 1 then orientation = 1 end
- return orientation
- end
- function placeBlock()
- if not gotoNextSlotIfEmpty() then
- reSupply()
- end
- if not checkFuelLevel() then
- reFuel()
- end
- if floorType == "top" then
- if not turtle.detectUp() then
- turtle.placeUp()
- else
- turtle.digUp()
- turtle.placeUp()
- end
- elseif floorType == "bottom" then
- if not turtle.detectDown() then
- turtle.placeDown()
- else
- turtle.digDown()
- turtle.placeDown()
- end
- end
- end
- function moveTurtle()
- if orientation == 1 then
- left()
- if turtle.detect() then
- error()
- else
- turtle.forward()
- right()
- if not turtle.detect() then
- left()
- left()
- while true do
- if turtle.detect() then
- left()
- break
- end
- turtle.forward()
- end
- else
- left()
- end
- end
- left()
- elseif orientation == 3 then
- right()
- if turtle.detect() then
- error()
- else
- turtle.forward()
- left()
- if not turtle.detect() then
- right()
- right()
- while true do
- if turtle.detect() then
- right()
- break;
- end
- turtle.forward()
- end
- else
- right()
- end
- end
- right()
- end
- end
- turtle.select(currentSlot)
- while true do
- if turtle.detect() then
- placeBlock()
- moveTurtle()
- else
- placeBlock()
- turtle.forward()
- end
- end
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement