SHOW:
|
|
- or go back to the newest paste.
1 | -- Build Tools | |
2 | -- dig v1 | |
3 | ||
4 | local args = { ... } | |
5 | ||
6 | if args[1] == nil or args[2] == nil or args[3] == nil or turtle.getItemCount(1) < 1 or args[1] == "help" then | |
7 | print ("Usage: dig [forward length] [right length] [depth]") | |
8 | print ("Put an ender chest in the first slot") | |
9 | return | |
10 | end | |
11 | ||
12 | local tilt = 0 | |
13 | local flength = tonumber(args[1]) | |
14 | local rlength = tonumber(args[2]) | |
15 | local depth = tonumber(args[3]) | |
16 | local blocks = rlength * flength * depth | |
17 | ||
18 | if turtle.getFuelLevel() < blocks + rlength + flength + depth and args[4] ~= "-f" then | |
19 | print ("You do not have enough fuel. This job needs ", fuelreq, " fuel.") | |
20 | print ("Add more fuel, or append -f to dig anyway.") | |
21 | return | |
22 | end | |
23 | ||
24 | function step() | |
25 | while not turtle.forward() do | |
26 | turtle.dig() | |
27 | end | |
28 | end | |
29 | ||
30 | function stepUp() | |
31 | while not turtle.up() do | |
32 | turtle.digUp() | |
33 | end | |
34 | end | |
35 | ||
36 | function stepDown() | |
37 | while not turtle.down() do | |
38 | turtle.digDown() | |
39 | end | |
40 | end | |
41 | ||
42 | function placeUp() | |
43 | while not turtle.placeUp() do | |
44 | turtle.digUp() | |
45 | end | |
46 | end | |
47 | ||
48 | function rotateRight() | |
49 | turtle.turnRight() | |
50 | if vertical then | |
51 | stepUp() | |
52 | else | |
53 | step() | |
54 | end | |
55 | turtle.turnRight() | |
56 | end | |
57 | ||
58 | function rotateLeft() | |
59 | turtle.turnLeft() | |
60 | if vertical then | |
61 | stepUp() | |
62 | else | |
63 | step() | |
64 | end | |
65 | turtle.turnLeft() | |
66 | end | |
67 | ||
68 | -- Dump inventory into ender chest. | |
69 | function dump() | |
70 | turtle.select(1) | |
71 | placeUp() | |
72 | for m = 2, 16, 1 do | |
73 | turtle.select(m) | |
74 | turtle.dropUp() | |
75 | end | |
76 | turtle.select(1) | |
77 | turtle.digUp() | |
78 | end | |
79 | ||
80 | -- Dig 'em up. | |
81 | for i = 1, depth, 1 do | |
82 | for j = 1, rlength, 1 do | |
83 | for k = 1, flength, 1 do | |
84 | if turtle.getItemCount(16) > 1 then | |
85 | dump() | |
86 | end | |
87 | turtle.digDown() | |
88 | if k < flength then | |
89 | step() | |
90 | end | |
91 | end | |
92 | if j < rlength then | |
93 | if (j + tilt) % 2 ~= 0 then | |
94 | rotateRight() | |
95 | else | |
96 | rotateLeft() | |
97 | end | |
98 | end | |
99 | end | |
100 | if rlength % 2 == 0 and i % 2 ~= 0 then | |
101 | tilt = 1 | |
102 | else | |
103 | tilt = 0 | |
104 | end | |
105 | turtle.turnRight() | |
106 | turtle.turnRight() | |
107 | stepDown() | |
108 | end | |
109 | ||
110 | -- Raise to initial height. | |
111 | for i = 1, depth, 1 do | |
112 | stepUp() | |
113 | end | |
114 | ||
115 | -- Return to origin. | |
116 | if depth % 2 ~= 0 then | |
117 | if rlength % 2 == 0 then | |
118 | turtle.turnLeft() | |
119 | for i = 1, rlength - 1, 1 do | |
120 | step() | |
121 | end | |
122 | else | |
123 | turtle.turnRight() | |
124 | for i = 1, rlength - 1, 1 do | |
125 | step() | |
126 | end | |
127 | turtle.turnLeft() | |
128 | for i = 1, flength - 1, 1 do | |
129 | step() | |
130 | end | |
131 | end | |
132 | end |