Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- args = { ... }
- function usage()
- usages = {
- "fence",
- "destroy",
- "compute",
- "mark"
- }
- for i = 1, #usages do
- print("Usage: " .. shell.getRunningProgram() .. " " .. usages[i] .. " <length> <width>")
- end
- end
- function distance(dist, exec)
- for i = 1, dist do
- while not turtle.forward() do turtle.dig() turtle.attack() end
- exec(i == dist)
- end
- end
- function goSize(length, width, exec)
- distance(length, exec)
- turtle.turnLeft()
- distance(width, exec)
- turtle.turnLeft()
- distance(length, exec)
- turtle.turnLeft()
- distance(width, exec)
- turtle.turnLeft()
- end
- if #args < 3 then
- usage()
- return
- end
- local execute = function() end
- local length = args[2] - 1
- local width = args[3] - 1
- if args[1] == "fence" then
- execute = function()
- turtle.digDown()
- slot = 2
- while turtle.getItemCount(1) <= 1 do
- if slot > 16 then error("Could not find more fences!") os.exit(1) end
- turtle.select(slot)
- if turtle.compareTo(1) then
- turtle.transferTo(1)
- end
- slot = slot + 1
- end
- turtle.select(1)
- turtle.placeDown()
- end
- elseif args[1] == "destroy" then
- execute = function()
- turtle.digDown()
- end
- elseif args[1] == "mark" then
- execute = function(atEnd)
- if atEnd then
- while not turtle.down() do turtle.digDown() turtle.attackDown() end
- turtle.select(2)
- turtle.placeDown()
- while not turtle.up() do turtle.digUp() turtle.attackUp() end
- turtle.select(1)
- turtle.placeDown()
- end
- end
- elseif args[1] == "compute" then
- print("Fence needed: " .. tostring(2 * length + 2 * width))
- return
- else
- return
- end
- goSize(length, width, execute)
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement