forked from martin2250/ComputerCraftLuaPrograms
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathroom.lua
132 lines (104 loc) · 2.86 KB
/
room.lua
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
local args = {...}
local direction = 0
local minedblocks = 0
local x, y, z = 0, 0, 0
local function printstats()
term.clear()
term.setCursorPos(1, 1)
print("Room Digger - by martin2250")
print("")
print("Mining out a "..args[1].."x"..args[2].."x"..args[3].." area")
print("")
print("My position is "..x.." "..y.." "..z)
print(" (relative to my starting point)")
print("I mined "..minedblocks.. " blocks")
print("My fuel level is "..turtle.getFuelLevel())
end
local function left()
turtle.turnLeft() -- 0 +x
direction = direction - 1 -- 3 1 -z +z
if direction == -1 then direction = 3 end -- 2 -x
end
local function right()
turtle.turnRight()
direction = direction + 1
if direction == 4 then direction = 0 end
end
local function forward()
local sucess = turtle.forward()
if sucess then
if direction == 0 then x = x + 1 end
if direction == 1 then z = z + 1 end
if direction == 2 then x = x - 1 end
if direction == 3 then z = z - 1 end
end
return sucess
end
local function up()
if turtle.up() then y = y + 1 return true end return false
end
local function down()
if turtle.down() then y = y - 1 return true end return false
end
local function goforward(laenge, digup)
local pos = 0
while pos < laenge do
printstats()
if turtle.dig() then minedblocks = minedblocks + 1 end
if digup then while turtle.detectUp() do if turtle.digUp() then minedblocks = minedblocks + 1 end end end
if forward() then pos = pos + 1 end
if digup then while turtle.detectUp() do if turtle.digUp() then minedblocks = minedblocks + 1 end end end
end
end
local function forcefwd()
repeat if turtle.dig() then minedblocks = minedblocks + 1 end
until forward()
end
local function forceup()
repeat if turtle.digUp() then minedblocks = minedblocks + 1 end
until up()
end
----------------------------------------------------------------------------
if not turtle then
print("this program can only be used on turtles")
end
if #args ~= 3 then
print("Usage: ")
print("room <length> <width> <height>")
return
end
local maxx = tonumber(args[1]) - 1
local maxz = tonumber(args[2])
local maxy = tonumber(args[3])
term.clear()
term.setCursorPos(1, 1)
local zdir = true
zdir = true
local candigup = false
while y < maxy do
if maxy - y > 1 then candigup = true else candigup = false end
while true do
goforward(maxx, candigup)
if zdir then
if (z + 1) < maxz then
if direction == 0 then right() forcefwd() right()
else left() forcefwd() left() end
else
break
end
else
if z > 0 then
if direction == 0 then left() forcefwd() left()
else right() forcefwd() right() end
else
break
end
end
end
zdir = not zdir
if y ~= maxy - 1 then
forceup() if candigup then forceup() end right() right() else y = y + 1 end
end
y = y - 1
printstats()
print("finished!")