Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- version = "walls3: Rev 0.1"
- mission= "Place 3-block high walls at the length and width specified."
- instructions = "Place stack(s) of material starting in first slot."
- args = {...}
- nArgs = #args
- usage = "walls3 <length> <width>"
- materialSlot = 1
- if nArgs == 0 or (nArgs == 1 and args[1]== "help") then
- print(version)
- print(mission)
- print(instructions)
- print(usage)
- return
- end
- if nArgs ~= 2 then
- print(usage)
- return
- end
- length = tonumber(args[1])
- if length == nil then
- print("\"", args[1], "\" is not a valid length")
- return
- end
- if length < 1 then
- print("length must be a positive number greater than zero")
- end
- width = tonumber(args[2])
- if width == nil then
- print("\"", args[2], "\" is not a valid width")
- return
- end
- if width < 1 then
- print("width must be a positive number greater than zero")
- end
- function place()
- ensureMaterial()
- turtle.place()
- end
- function placeUp()
- ensureMaterial()
- turtle.placeUp()
- end
- function placeDown()
- ensureMaterial()
- turtle.placeDown()
- 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 < 6 then
- -- print("Attempting to refill slot ", materialSlot)
- for i=2,12 do
- turtle.select(i)
- if turtle.compareTo(materialSlot) then
- turtle.transferTo(materialSlot)
- end
- end
- end
- turtle.select(materialSlot)
- end
- function buildWall(length)
- for i=1,length do
- ensureMaterial()
- turtle.select(materialSlot)
- placeUp()
- placeDown()
- if i == length then
- turtle.turnLeft()
- end
- turtle.back()
- place()
- end
- end
- turtle.turnLeft()
- turtle.turnLeft()
- turtle.up()
- buildWall(length)
- buildWall(length-1)
- buildWall(length-1)
- buildWall(length-2)
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement