SHOW:
|
|
- or go back to the newest paste.
1 | -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- | |
2 | -- Name: DanielKermanStripMining (DKSM) -- | |
3 | -- Author: Daniel_Kerman -- | |
4 | -- Version: 1.0.1 -- | |
5 | -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- | |
6 | ||
7 | ||
8 | -- Initializing -- | |
9 | ||
10 | local rowsMined = {0} | |
11 | local totalRows = {0} | |
12 | local hallLength = {0} | |
13 | local fuelNeeded = {0} | |
14 | local fuelLevel = turtle.getFuelLevel() | |
15 | local fuelLimit = turtle.getFuelLimit() | |
16 | local startConfirmed = "No" | |
17 | local slot = turtle.getSelectedSlot() | |
18 | local itemSpace = turtle.getItemSpace() | |
19 | local torchCounter = 0 | |
20 | ||
21 | -- Declaring Functions -- | |
22 | ||
23 | function forward() -- Help from the user Foogles (http://www.computercraft.info/forums2/index.php?/user/46239-foogles/) -- THANK YOU FOR THIS BUG SOLUTION! | |
24 | local x = turtle.forward() | |
25 | if (x == false) then | |
26 | return forward() | |
27 | end | |
28 | end | |
29 | ||
30 | local function clear(column,row) | |
31 | term.clear() | |
32 | if column == nil and row == nil then | |
33 | column = 1 | |
34 | row = 1 | |
35 | elseif row == nil then | |
36 | row = 1 | |
37 | elseif column == nil then | |
38 | column = 1 | |
39 | end | |
40 | term.setCursorPos(column,row) | |
41 | end | |
42 | ||
43 | local function checkNumber(varToCheck) | |
44 | assert(type(varToCheck) == "number", "Program expected number. Got string or something else instead.") | |
45 | end | |
46 | ||
47 | local function fallingBlock() | |
48 | local success, data = turtle.inspect() | |
49 | local fBlocks = | |
50 | { | |
51 | sand="minecraft:sand", | |
52 | gravel="minecraft:gravel", | |
53 | anvil="minecraft:anvil", | |
54 | dragon_egg="minecraft:dragon_egg" | |
55 | } | |
56 | if data.name==fBlocks.sand or data.name==fBlocks.gravel or data.name==fBlocks.anvil or data.name==fBlocks.dragon_egg then | |
57 | return true | |
58 | else | |
59 | return false | |
60 | end | |
61 | end | |
62 | ||
63 | local function dig(length,back) | |
64 | for i=1, length do | |
65 | torchCounter=torchCounter+1 | |
66 | while fallingBlock() == true do | |
67 | turtle.dig() | |
68 | sleep(1) | |
69 | end | |
70 | turtle.dig() | |
71 | forward() | |
72 | turtle.digDown() | |
73 | if torchCounter >= 8 then | |
74 | turtle.select(16) | |
75 | if turtle.getItemSpace() < 64 then | |
76 | local data = turtle.getItemDetail() | |
77 | if data.name == "minecraft:torch" then | |
78 | turtle.placeDown() | |
79 | end | |
80 | end | |
81 | torchCounter = 0 | |
82 | turtle.select(1) | |
83 | end | |
84 | end | |
85 | if back == true then | |
86 | turtle.turnLeft() | |
87 | turtle.turnLeft() | |
88 | for i=2, length do | |
89 | forward() | |
90 | end | |
91 | forward() | |
92 | turtle.turnLeft() | |
93 | turtle.turnLeft() | |
94 | end | |
95 | ||
96 | end | |
97 | ||
98 | -- Welcome + User input -- | |
99 | ||
100 | clear(1,1) | |
101 | ||
102 | print("Welcome to the Strip Mining Program.") | |
103 | sleep(1) | |
104 | print("Please enter a Hall/Strip Length (x = x block/s): ") | |
105 | hallLength[1] = io.read() | |
106 | hallLength[1] = tonumber(hallLength[1]) | |
107 | checkNumber(hallLength[1]) | |
108 | print("Please enter a number of rows:") | |
109 | totalRows[1] = io.read() | |
110 | totalRows[1] = tonumber(totalRows[1]) | |
111 | checkNumber(totalRows[1]) | |
112 | print("Calculating if turtle has enough fuel...") | |
113 | fuelNeeded[1] = (hallLength[1]*3*totalRows[1])+(12*totalRows[1]) | |
114 | sleep(1.0) | |
115 | assert(fuelNeeded[1]<fuelLimit, "Your fuel Limit is too low. Try an advanced turtle.") | |
116 | assert(fuelNeeded[1]<fuelLevel, "Your turtle hasn't enought fuel.") | |
117 | print("Your turtle has enough fuel. Please place a chest behind the turtle.") | |
118 | sleep(2.0) | |
119 | clear(1,1) | |
120 | print("Place a chest behind the turtle.") | |
121 | print("Place Torches to place in Slot 16 (Bottom right hand corner)") | |
122 | write("Press any key to start the program.") | |
123 | local skip = io.read() | |
124 | ||
125 | -- Post initialization -- | |
126 | ||
127 | local rowsToMine = totalRows[1]-rowsMined[1] | |
128 | clear(1,1) | |
129 | turtle.select(1) | |
130 | ||
131 | -- Main Loop -- | |
132 | ||
133 | for i=1, totalRows[1] do | |
134 | turtle.select(1) | |
135 | dig(3,false) | |
136 | turtle.turnLeft() | |
137 | dig(hallLength[1],true) | |
138 | rowsMined[1] = rowsMined[1]+1 | |
139 | clear(1,1) | |
140 | print("Rows Mined: ",rowsMined[1]) | |
141 | local z = 1 | |
142 | turtle.select(15) | |
143 | if turtle.getItemSpace() < 64 then | |
144 | turtle.turnLeft() | |
145 | for i=1,rowsMined[1]*3+1 do | |
146 | forward() | |
147 | end | |
148 | for i=1,15 do | |
149 | turtle.select(z) | |
150 | z=z+1 | |
151 | turtle.drop(64) | |
152 | end | |
153 | turtle.turnRight() | |
154 | turtle.turnRight() | |
155 | for i=1,rowsMined[1]*3+1 do | |
156 | forward() | |
157 | end | |
158 | turtle.turnLeft() | |
159 | end | |
160 | turtle.turnRight() | |
161 | rowsToMine = totalRows[1]-rowsMined[1] | |
162 | end | |
163 | ||
164 | -- Ending -- | |
165 | ||
166 | do | |
167 | print("Putting Items into chest.") | |
168 | turtle.turnLeft() | |
169 | turtle.turnLeft() | |
170 | for i=1, (rowsMined[1]*3)+1 do | |
171 | forward() | |
172 | end | |
173 | z=1 | |
174 | for i=1,16 do | |
175 | turtle.select(z) | |
176 | z=z+1 | |
177 | turtle.drop(64) | |
178 | end | |
179 | end | |
180 | ||
181 | turtle.select(1) | |
182 | ||
183 | print("Mining Complete.") | |
184 | ||
185 | sleep(2) | |
186 | ||
187 | clear(1,1) |