Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- args = {...}
- nArgs = #args
- version = "pattern: Rev 1.2"
- mission = "Lay down the specified pattern."
- instructions = "Place stack(s) of material starting in first slot."
- usage = "usage: pattern <pattern name>"
- funnel12 = {
- "============",
- "============",
- "============",
- "============",
- "============",
- "===== =====",
- "===== =====",
- "============",
- "============",
- "============",
- "============",
- "============",
- }
- fullShape = {
- " = ",
- " === ",
- " ===== ",
- " ======= ",
- " ========= ",
- " =========== ",
- " ============= ",
- " =============== ",
- "=================",
- " =============== ",
- " ============= ",
- " =========== ",
- " ========= ",
- " ======= ",
- " ===== ",
- " === ",
- " = ",
- }
- reducedShape = {
- " ",
- " = ",
- " === ",
- " ===== ",
- " ======= ",
- " ========= ",
- " =========== ",
- " ============= ",
- " =============== ",
- " ============= ",
- " =========== ",
- " ========= ",
- " ======= ",
- " ===== ",
- " === ",
- " = ",
- " ",
- }
- walls = {
- " = ",
- " = = ",
- " = = ",
- " = = ",
- " = = ",
- " = = ",
- " = = ",
- " = = ",
- "= =",
- " = = ",
- " = = ",
- " = = ",
- " = = ",
- " = = ",
- " = = ",
- " = = ",
- " = ",
- }
- x = 0
- y = 0
- z = 0
- -- The following 'face' directions are relative to the starting position of the turtle in this program
- north = 0
- west = 1
- south = 2
- east = 3
- materialSlot = 1
- face = north
- nextTurn = "right"
- 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 left()
- if face == 0 then face = 1 turtle.turnLeft() return end
- if face == 1 then face = 2 turtle.turnLeft() return end
- if face == 2 then face = 3 turtle.turnLeft() return end
- if face == 3 then face = 0 turtle.turnLeft() return end
- print("function left\(\): Bad face value: ", face)
- end
- function right()
- if face == 0 then face = 3 turtle.turnRight() return end
- if face == 1 then face = 0 turtle.turnRight() return end
- if face == 2 then face = 1 turtle.turnRight() return end
- if face == 3 then face = 2 turtle.turnRight() return end
- print("function right\(\): Bad face value: ", face)
- end
- function turn()
- if nextTurn == "left" then
- left()
- else
- right()
- end
- forward()
- if nextTurn == "left" then
- left()
- nextTurn = "right"
- else
- right()
- nextTurn = "left"
- end
- end
- function forward()
- for i=1,10 do -- This loop trys to handle pests (mob) that might be in the way
- if turtle.forward() then
- break
- end
- turtle.attack()
- sleep(2)
- end
- if face == north then z = z+1 return end
- if face == west then x = x-1 return end
- if face == south then z = z-1 return end
- if face == east then x = x+1 return end
- end
- function setFace(f)
- if f == 0 then
- if face == 0 then return end
- if face == 1 then right() return end
- if face == 2 then right() right() return end
- if face == 3 then left() return end
- end
- if f == 1 then
- if face == 0 then left() return end
- if face == 1 then return end
- if face == 2 then right() return end
- if face == 3 then right() right() return end
- end
- if f == 2 then
- if face == 0 then left() left() return end
- if face == 1 then left() return end
- if face == 2 then return end
- if face == 3 then right() return end
- end
- if f == 3 then
- if face == 0 then right() return end
- if face == 1 then left() left() return end
- if face == 2 then left() return end
- if face == 3 then return end
- end
- end
- function home(targetY)
- -- print("home:face ", face, ", x = ", x, ", z = ", z)
- if x < 0 then
- setFace(east)
- while x < 0 do
- forward()
- end
- else
- if x > 0 then
- setFace(west)
- while x > 0 do
- forward()
- end
- end
- end
- if z < 0 then
- setFace(north)
- while z < 0 do
- forward()
- end
- else
- if z > 0 then
- setFace(south)
- while z > 0 do
- forward()
- end
- end
- end
- if y > 0 then
- while y > 0 do
- down()
- end
- end
- setFace(0)
- end
- function layPattern(pattern)
- for i=1,#pattern do
- row = pattern[i]
- length = string.len(row)
- for j=1,string.len(row) do
- char = string.sub(row, j, j)
- if char ~= " " then
- ensureMaterial()
- turtle.select(materialSlot)
- turtle.placeDown()
- end
- if j < length then
- forward()
- end
- end
- turn()
- end
- end
- if nArgs < 1 then
- print(usage)
- return
- end
- if args[1] == "funnel12" then
- layPattern(funnel12)
- elseif args[1] == "full" then
- layPattern(fullShape)
- elseif args[1] == "reduced" then
- layPattern(reducedShape)
- elseif args[1] == "walls" then
- layPattern(walls)
- else
- print("Unknown pattern: \"", args[1], "\"")
- return
- end
- home()
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement