View difference between Paste ID: QuK84isB and 6BbAp9Na
SHOW: | | - or go back to the newest paste.
1
local tArgs = { ... }
2
local numBlocks = 0
3
4
local function pbBuildRow(length)
5
  if length > 0 then
6
    shell.run("go", "[_9_8_7_6_5_4_3_2_1f]" .. length-1)
7
    shell.run("go", "[_9_8_7_6_5_4_3_2_1]")
8
  else
9
    print("Plane length must be at least one")
10
  end
11
end
12
13
local function pbCheckInventory()
14
  numBlocks = 0
15
  for j=1,9 do
16
    numBlocks = numBlocks + turtle.getItemCount(j)
17
  end
18
  if numBlocks < planeLength then
19
    print("Not enough blocks to complete the next row, please add more blocks to slots 1 through 9 and press a key to continue")
20-
    local input = read("*")
20+
    event = os.pullEvent()
21
    if event == "char" then
22
      pbCheckInventory()
23
    end
24
  else
25
    return true
26
  end
27
end
28
29
local function pbNextLayer()
30
  shell.run("go", "ua")
31
end
32
33
local function pbNextRow(direction)
34
  if direction == 1 then
35
    shell.run("go", "rfr")
36
  else
37
    shell.run("go", "lfl")
38
  end
39
end
40
41
if fs.exists("go") then
42
  if #tArgs < 2 or #tArgs > 4 then
43
    shell.run("clear")
44
    print("The number of parameters must be 2-4, first length then height, then optionally an orientation character, 'h' for horizontal, 'v' for vertical (default). Then the direction relative to the turtle for the plane to extend: l for left or 'r' for right (default).")
45
    return false
46
  end
47
  
48
  planeLength = tonumber(tArgs[1])
49
  planeHeight = tonumber(tArgs[2])
50
  planeOrientation = "v"
51
  -- turn dir is specified by the parameter and represents the direction from the turtle's start position that the horizontal planes are placed in
52
  -- the decision whether to turn right or left at the end of a row is decided by the modulus of a division by 2 of the row count, modified by the turnDir
53
  turnDir = "r"
54
  -- turnDir has a default value, as does planeOrientation, but turnDir is only ever used when planeOrientation is set to horizontal
55
  if #tArgs > 2 then
56
    planeOrientation = tArgs[3]
57
  end
58
59
  if #tArgs > 3 then
60
    turnDir = tArgs[4]
61
  end
62
  
63
  -- For the 'height' aka depth dimension, do a row of the specified length of blocks
64
  for i=1,planeHeight do
65
    -- Place the row of blocks for the specified row length regardless of plane orientation
66
    pbCheckInventory()
67
    pbBuildRow(planeLength)
68
    -- If the orientation is vertical, call the function to continue the plane in that direction, and when coming to the end of the plane, go back to near the starting location
69
    if planeOrientation == "v" then
70
      pbNextLayer()
71
    -- If the orientation is horizontal, call the function to continue the plane in that direction, and when coming to the end of the plane, go back to near the starting location
72
    else
73
      if turnDir == "r" then
74
        pbNextRow((i+2)%2)
75
      else
76
        pbNextRow((i+1)%2)
77
      end
78
    end
79
  end
80
else
81
  shell.run("clear")
82
  print("You must install rob's modified version of the 'go' utility program, located on pastebin at t0vyUwmt")
83
end