Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- -- patch
- -- Patches holes in wall, as in side of turel-dug hole
- -- Place patch material starting in slot 1
- -- Written by HarvDad, June 2014
- args = {...}
- nArgs = #args
- version = "Rev 0.1"
- usage = "Usage: patch <height> <width>"
- help1 = "height may be positive or negative"
- help2 = "width extends to the left"
- help3 = "Turtle must start facing wall."
- height = 0
- width = 0
- distance = 0
- x = 0
- y = 0
- z = 0
- materialSlot = 1
- if nArgs == 0 or (nArgs == 1 and args[1]== "help") then
- print(usage)
- print(help1)
- print(help2)
- print(help3)
- return
- end
- if nArgs ~= 2 then
- print(usage)
- return
- end
- height = tonumber(args[1])
- if height == nil then
- print("\"", args[1], "\" is not a valid height")
- return
- end
- if height > 0 then
- distance = height
- else
- distance = -height
- end
- width = tonumber(args[2])
- if width == nil then
- print("\"", args[1], "\" is not a valid width")
- return
- end
- if width < 1 then
- print("width must be a positive integer")
- return
- end
- function ensureMaterial()
- if turtle.getItemCount(materialSlot) < 3 then
- organizeMaterial()
- end
- if turtle.getItemCount(materialSlot) < 3 then
- print("No more material")
- return false
- end
- return true
- end
- function organizeMaterial()
- local i
- materialCount = turtle.getItemCount(materialSlot)
- if materialCount < 3 then
- -- print("Attempting to refill slot ", materialSlot)
- for i=2,16 do
- turtle.select(i)
- if turtle.compareTo(materialSlot) then
- turtle.transferTo(materialSlot)
- end
- end
- end
- turtle.select(materialSlot)
- end
- function patchUp()
- for i=1,distance do
- if not turtle.detect() then
- ensureMaterial()
- turtle.place()
- end
- turtle.up()
- y = y+1
- end
- if not turtle.detect() then
- ensureMaterial()
- turtle.place()
- end
- end
- function patchDown()
- for i=1,distance do
- if not turtle.detect() then
- ensureMaterial()
- turtle.place()
- end
- turtle.down()
- y = y-1
- end
- if not turtle.detect() then
- ensureMaterial()
- turtle.place()
- end
- end
- function home()
- if x < 0 then
- turtle.turnRight()
- while x < 0 do
- turtle.forward()
- x = x+1
- end
- end
- turtle.turnLeft()
- if y < 0 then
- while y < 0 do
- turtle.up()
- y = y+1
- end
- elseif y > 0 then
- while y > 0 do
- turtle.down()
- y = y-1
- end
- end
- end
- -- Main Program
- goingUp = true
- if height < 0 then
- goingUp = false
- end
- for i=1,width do
- if goingUp then
- patchUp()
- goingUp = false
- else
- patchDown()
- goingUp = true
- end
- if i < width then
- turtle.turnLeft()
- turtle.forward()
- turtle.turnRight()
- x = x-1
- else
- break
- end
- end
- home()
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement