Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- function turn(left, mirrored)
- if left ~= mirrored then
- turtle.turnLeft()
- else
- turtle.turnRight()
- end
- end
- function digAll(depthleft)
- if turtle.detect() then
- turtle.dig()
- end
- if turtle.detectUp() and depthleft > 1 then
- turtle.digUp()
- end
- if turtle.detectDown() and depthleft > 2 then
- turtle.digDown()
- end
- end
- function nextSlotIfEmpty()
- while turtle.getItemCount() == 0 do
- turtle.select(turtle.getSelectedSlot() + 1)
- end
- end
- function place()
- nextSlotIfEmpty()
- turtle.place()
- end
- function placeUp()
- nextSlotIfEmpty()
- turtle.placeUp()
- end
- function placeDown()
- nextSlotIfEmpty()
- turtle.placeDown()
- end
- function placeAll(height)
- turtle.place()
- if height > 1 then
- turtle.placeDown()
- end
- if height > 2 then
- turtle.placeUp()
- end
- end
- function move()
- if turtle.detect() then
- return false
- end
- while not turtle.forward() do
- turtle.attack()
- end
- return true
- end
- function moveDown()
- if turtle.detectDown() then
- return false
- end
- while not turtle.down() do
- turtle.attackDown()
- end
- return true
- end
- function moveUp()
- if turtle.detectUp() then
- return false
- end
- while not turtle.up() do
- turtle.attackUp()
- end
- return true
- end
- function moveBack()
- if not turtle.back() then
- turtle.turnLeft()
- turtle.turnLeft()
- if turtle.detect() then
- return false
- end
- while not turtle.forward() do
- turtle.attack()
- end
- turtle.turnRight()
- turtle.turnRight()
- return true
- end
- end
- function Dmove()
- if turtle.detect() then
- if not turtle.dig() then
- return false
- end
- end
- while not turtle.forward() do
- turtle.attack()
- end
- return true
- end
- function DmoveDown()
- if turtle.detectDown() then
- if not turtle.digDown() then
- return false
- end
- end
- while not turtle.down() do
- turtle.attackDown()
- end
- return true
- end
- function DmoveUp()
- if turtle.detectUp() then
- if not turtle.digUp() then
- return false
- end
- end
- while not turtle.up() do
- turtle.attackUp()
- end
- return true
- end
- function DmoveBack()
- if not turtle.back() then
- turtle.turnLeft()
- turtle.turnLeft()
- if turtle.detect() then
- if not turtle.dig() then
- return false
- end
- end
- while not turtle.forward() do
- turtle.attack()
- end
- turtle.turnRight()
- turtle.turnRight()
- return true
- end
- end
- local cube = {
- help = "cube <length> <width> <depth> [left]"
- }
- function cube.fuel(length, width, depth)
- length = tonumber(length)
- width = tonumber(width)
- depth = tonumber(depth)
- return depth + math.ceil(depth / 3) * (length * width - 1)
- end
- function cube.run(length, width, depth, mirrored)
- length = tonumber(length)
- width = tonumber(width)
- depth = tonumber(depth)
- if mirrored ~= true then mirrored = false end
- local depthleft = depth
- local direction = false
- while depthleft > 0 do
- if turtle.detectDown() then
- turtle.digDown()
- end
- moveDown()
- if depthleft > 1 then
- if turtle.detectDown() then
- turtle.digDown()
- end
- moveDown()
- end
- if depthleft > 2 then
- turtle.digDown()
- end
- local x = 1
- local y = 1
- while true do
- if x >= length then --turn
- if y >= width then --down
- if turtle.detectUp() and depthleft > 1 then
- turtle.digUp()
- end
- if turtle.detectDown() and depthleft > 2 then
- turtle.digDown()
- end
- turtle.turnLeft()
- turtle.turnLeft()
- if depthleft > 2 then
- turtle.down()
- end
- depthleft = depthleft - 3
- break
- end
- turn(direction, mirrored)
- digAll(depthleft)
- move()
- turn(direction, mirrored)
- digAll(depthleft)
- move()
- y = y + 1
- x = 1
- direction = not direction
- else
- digAll(depthleft)
- move()
- end
- x = x + 1
- end
- end
- end
- local wall = {
- help = "wall <length> <width> <height> [left]"
- }
- function wall.fuel(length, width, height)
- length = tonumber(length)
- width = tonumber(width)
- height = tonumber(height)
- return height + math.ceil(height / 3) * (2 * length + 2 * width - 1)
- end
- function wall.run(length, width, height, mirrored)
- length = tonumber(length)
- width = tonumber(width)
- height = tonumber(height)
- if mirrored ~= true then mirrored = false end
- Dmove()
- turtle.turnLeft()
- turtle.turnLeft()
- while height > 0 do
- if height > 1 then
- DmoveUp()
- placeDown()
- if height > 2 then
- placeUp()
- end
- end
- local direction = 0
- while direction < 4 do
- local i = 1
- while i < (direction % 2 == 0 and length or width) do
- DmoveBack()
- placeAll(height)
- i = i + 1
- end
- turn(true, mirrored)
- direction = direction + 1
- end
- end
- end
- function getCommand(command)
- if command == "help" then return help end
- if command == "wall" then return wall end
- if command == "cube" then return cube end
- return nil
- end
- local help = {
- help = "help <command>"
- }
- function help.run(command)
- local result = getCommand(command)
- if result == nil then
- print("help: command not found")
- else
- print("usage: " .. result.help)
- end
- end
- args = {...}
- local command = getCommand(table.remove(args, 1))
- if command == nil then
- print("command not found")
- return
- end
- if command.fuel ~= nil then
- local required = command.fuel(unpack(args))
- local now = turtle.getFuelLevel()
- if required > now then
- print("not enough fuel: " .. required .. " needed, has " .. now .. " (" .. (required - now) .. " short)")
- return
- end
- end
- command.run(unpack(args))
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement