-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathapi_digTunnels.lua
122 lines (116 loc) · 3.89 KB
/
api_digTunnels.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
-- VALUES FOR THE DIRECTIONS
local up = "up"
local down = "down"
local forward = "forward"
local back = "back"
local right = "right"
local left = "left"
-- LOAD FUNCTIONS FROM THE OTHER FILES
os.loadAPI("api_sharedFunctions")
os.loadAPI("api_turtleExt")
-- --------------------------------------------- --
-- START OF THE FUNCTIONS SPECIFIC TO digTunnels --
-- --------------------------------------------- --
-- DIGS A SEGMENT (FROM ONE SHAFT TO THE NEXT) DIGGING OUT THE SIDES ASWELL
function digSegmentAndSides(configuration, slices)
local torchOffset=0
if ((configuration.currentL % 2 == 0) and (configuration.currentS == 0)) then
torchOffset=configuration.evenLevelOffset
end
api_turtleExt.digAndMove(forward, 1, 0)
api_turtleExt.digAndMove(down, 1, 0)
for i=1, slices do
if i~=1 then
api_turtleExt.digAndMove(forward, 1, 0)
end
api_turtleExt.turnTo(left)
api_turtleExt.dig(up)
api_turtleExt.dig(down)
api_turtleExt.digAndMove(forward, 1, 0)
api_turtleExt.dig(down)
api_turtleExt.dig(forward)
api_turtleExt.digAndMove(up, 1, 0)
api_turtleExt.dig(forward)
if configuration.placeTorches and ((i+torchOffset) % (configuration.blocksBetweenShafts+1) == math.floor((configuration.blocksBetweenShafts+1)/2)) then
api_turtleExt.place(forward, 1)
end
if configuration.height == 3 then
api_turtleExt.digAndMove(up, 1, 0)
api_turtleExt.dig(forward)
end
api_turtleExt.dig(up)
api_turtleExt.turnTo(back)
api_turtleExt.digAndMove(forward, 1, 0)
api_turtleExt.dig(up)
api_turtleExt.digAndMove(forward, 1, 0)
api_turtleExt.dig(up)
api_turtleExt.dig(forward)
if configuration.height == 3 then
api_turtleExt.digAndMove(down, 1, 0)
api_turtleExt.dig(forward)
end
api_turtleExt.digAndMove(down, 1, 0)
api_turtleExt.dig(forward)
api_turtleExt.dig(down)
if configuration.placeTorches and ((i+torchOffset) % (configuration.blocksBetweenShafts+1) == (configuration.blocksBetweenShafts+1)/2) then
api_turtleExt.digAndMove(up, 1, 0)
api_turtleExt.place(forward, 1)
api_turtleExt.digAndMove(down, 1, 0)
end
api_turtleExt.turnTo(back)
api_turtleExt.digAndMove(forward, 1, 0)
api_turtleExt.turnTo(right)
end
api_turtleExt.digAndMove(up, 1, 0)
configuration.currentS = configuration.currentS + 1
end
-- DIGS A SEGMENT (FROM ONE SHAFT TO THE NEXT) LEAVING THE SIDES INTACT
function digSegmentNoSides(configuration, slices)
api_turtleExt.digAndMove(forward, 1, 0)
api_turtleExt.digAndMove(left, 1, 0)
local dir = right
for i=1, slices do
if i~=1 then
api_turtleExt.digAndMove(forward, 1, 0)
end
api_turtleExt.turnTo(dir)
if configuration.height == 3 then
api_turtleExt.dig(up)
end
api_turtleExt.dig(down)
api_turtleExt.digAndMove(forward, 1, 0)
if configuration.height == 3 then
api_turtleExt.dig(up)
end
api_turtleExt.dig(down)
api_turtleExt.digAndMove(forward, 1, 0)
if configuration.height == 3 then
api_turtleExt.dig(up)
end
api_turtleExt.dig(down)
api_turtleExt.turnFrom(dir)
dir=api_turtleExt.reverseDir(dir)
end
api_turtleExt.turnTo(dir)
api_turtleExt.digAndMove(forward, 1, 0)
api_turtleExt.turnFrom(dir)
configuration.currentS = configuration.currentS + 1
if configuration.placeTorches then
api_turtleExt.place(down, 1)
end
end
-- DIGS A SEGMENT (FROM ONE SHAFT TO THE NEXT)
function digSegment(configuration)
local slices = api_sharedFunctions.calculateMoves(configuration, configuration.currentL, configuration.currentS, configuration.currentS+1)
if slices == 0 then
return
end
if configuration.digSidesToo then
digSegmentAndSides(configuration, slices)
else
digSegmentNoSides(configuration, slices)
end
end
-- ------------------------------------------- --
-- END OF THE FUNCTIONS SPECIFIC TO digTunnels --
-- ------------------------------------------- --