View difference between Paste ID: E98CYMQV and SNXdXJmZ
SHOW: | | - or go back to the newest paste.
1
local tArgs = { ... }
2
3-
if #tArgs ~= 2 then
3+
if #tArgs == 0 then
4-
        print( "Usage: stairs <depth>, <length>" )
4+
        print( "Usage: wallup <length> [depth] " )
5
        return
6
end
7
8-
local depth = tonumber( tArgs[1] )
8+
local length = tonumber( tArgs[1] )
9-
if depth < 1 then
9+
if length < 2 then
10-
        print( "stair depth must be positive" )
10+
        print( "wall length must be > 2" )
11
        return
12
end
13
14-
local length = tonumber( tArgs[2] )
14+
local depth = 256
15-
if length < 1 then
15+
if #tArgs >= 2 then
16-
        print( "stair length must be positive" )
16+
  depth = tonumber( tArgs[2] )
17
  if depth < 1 then
18
        print( "wall depth must be positive" )
19
        return
20
  end
21
end
22
23
local function digForward()
24
  while (turtle.detect()) do
25
    turtle.dig()
26
    sleep(0.2)
27
  end
28
end
29
30
local function digUp()
31
  while (turtle.detectUp()) do
32
    turtle.digUp()
33
    sleep(0.2)
34-
turtle.select(16)
34+
35-
local requiredFuel = (depth*2 / 80) + 1
35+
36-
if (requiredFuel < turtle.getFuelLevel()) then
36+
37-
  turtle.refuel()
37+
38
local relY = 0
39
40-
local fuelLevel = turtle.getFuelLevel()
40+
local function tryDown()
41-
print("Fuel level: "..fuelLevel)
41+
  if (turtle.detectDown()) then
42-
if fuelLevel < 1 then
42+
     turtle.digDown()
43-
 return
43+
44
45
  if (turtle.detectDown()) then
46-
print("stairs "..depth.." x "..length)
46+
    return false
47
  end
48-
local curDepth = 0
48+
  if (turtle.down()) then
49
    relY = relY-1
50
    return true
51-
while (curDepth < depth) do
51+
  else
52-
  for i=1,length do
52+
    return false
53-
    digForward() 
53+
54-
    turtle.forward()
54+
55-
    turtle.digDown()
55+
56-
    digUp()
56+
57-
    turtle.down()
57+
local function tryUp()
58-
    if (not turtle.detectDown()) then
58+
59-
      turtle.placeDown()   
59+
     turtle.digUp()
60-
    else
60+
61-
      if (not turtle.compareDown()) then
61+
  if (turtle.up()) then
62-
        turtle.digDown()
62+
    relY = relY + 1
63-
        turtle.placeDown()    
63+
    return true
64
  else
65
    return false
66-
  
66+
67-
    curDepth = curDepth + 1
67+
68-
    if (curDepth == depth) then
68+
69-
      return
69+
local function suckAll()
70
  while turtle.suck() do
71
  end
72-
  turtle.turnRight()
72+
73
74
local function wallLayer()
75-
turtle.turnRight()
75+
  for side=1,4 do
76-
turtle.turnRight()
76+
    for i=1,(length) do
77
      turtle.turnLeft()
78-
curDepth = 0
78+
      suckAll()
79-
while (curDepth < depth) do
79+
      if not turtle.compare() then
80-
  for i=1,length do
80+
        digForward()
81-
    turtle.up()
81+
        suckAll()
82-
    turtle.forward()
82+
        turtle.place()
83
      end
84-
    curDepth = curDepth + 1
84+
      turtle.turnRight()
85-
    if (curDepth == depth) then
85+
      if i< length then
86-
      return
86+
        digForward()
87
        turtle.forward()
88
      end
89-
  turtle.turnLeft()
89+
90-
end
90+
    turtle.turnRight()
91
  end
92
end
93
94
local function returnToTop()
95
  while relY < 0 do
96
    local canUp = tryUp()
97
    if not canUp then
98
      break
99
    end
100
  end
101
end
102
103
turtle.select(1)
104
for curDepth=1,depth do
105
  wallLayer()
106
  if curDepth < depth then
107
    local canDown = tryDown()
108
    if not canDown then
109
      break
110
    end
111
  end
112
end
113
returnToTop()