SHOW:
|
|
- or go back to the newest paste.
1 | --[[ | |
2 | Expected slot assignment/content | |
3 | ||
4 | Slot 1: 64 Torches | |
5 | Slot 2: 1 Cobble (reserved for cobble compare) | |
6 | Slot 3: Fuel | |
7 | Slot 4: Enderchest | |
8 | --]] | |
9 | ||
10 | -- Parameters | |
11 | ||
12 | - | local torchSlot = 1 -- Inventory slot of torches |
12 | + | local fuelSlot = 1 -- Inventory slot of torches |
13 | - | local cobbleSlot = 2 -- Inventory slot of atleast one cobble |
13 | + | |
14 | - | local enderChestSlot = 4 -- Inventory slot of enderchest to be used for offloading |
14 | + | |
15 | - | local frequencyOfCobbleRemoval = 30 -- Remove cobble every n blocks mined |
15 | + | |
16 | - | local enderDumpInterval = 100 -- Dump content into an enderchest every 100 blocks mined |
16 | + | local firstProcessSlot = 2 |
17 | local depth = 0 | |
18 | local collected = 0 | |
19 | ||
20 | - | local firstProcessSlot = 5 |
20 | + | |
21 | - | local doProcessContent = false |
21 | + | |
22 | local tArgs = { ... } | |
23 | if #tArgs < 2 then | |
24 | - | local itemsToEnder = 0 |
24 | + | print( "Usage: Floor <length> <width>" ) |
25 | - | local cobbleDumped = 0 |
25 | + | |
26 | print( "Process If true, content -> Enderchest") | |
27 | print( "") | |
28 | print( "Expected content in inventory of turtle:" ) | |
29 | print( "Slot 1: Fuel" ) | |
30 | print( "Slot 2 to 16: Material to use") | |
31 | - | print( "Usage: Area <length> <width> [Process]" ) |
31 | + | |
32 | end | |
33 | ||
34 | local length = tonumber( tArgs[1] ) | |
35 | if length < 1 then | |
36 | - | print( "Slot 1: Torches" ) |
36 | + | |
37 | - | print( "Slot 2: Cobble (at least 1)") |
37 | + | |
38 | - | print( "Slot 3: fuel") |
38 | + | |
39 | - | print( "Slot 4: Enderchest (only if Process=true)") |
39 | + | |
40 | local width = 1 | |
41 | ||
42 | if #tArgs > 1 then | |
43 | width = tonumber( tArgs[2] ) | |
44 | if width < 1 then | |
45 | print( "Area width must be 1+" ) | |
46 | return | |
47 | end | |
48 | end | |
49 | ||
50 | local function checkSlot(slotNr,description) | |
51 | if turtle.getItemCount(slotNr)==0 then | |
52 | print("Expected item '"..description.."' in slot "..slotNr..".") | |
53 | return false | |
54 | end | |
55 | return true | |
56 | end | |
57 | - | if #tArgs > 2 then |
57 | + | |
58 | - | doProcessContent = tArgs[3]:lower()=="true" |
58 | + | |
59 | ||
60 | if not checkSlot(fuelSlot,"fuel") then return end | |
61 | ||
62 | -- Main Code | |
63 | ||
64 | local function collect() | |
65 | collected = collected + 1 | |
66 | if math.fmod(collected, 100) == 0 then | |
67 | print( "Mined "..collected.." items." ) | |
68 | end | |
69 | end | |
70 | local function refuel() | |
71 | local fuelLevel = turtle.getFuelLevel() | |
72 | - | if not checkSlot(torchSlot,"torches") then return end |
72 | + | |
73 | - | if not checkSlot(cobbleSlot,"cobbleStone (atleast 1)") then return end |
73 | + | |
74 | - | if doProcessContent then |
74 | + | |
75 | - | if not checkSlot(enderChestSlot,"enderChest") then return end |
75 | + | |
76 | local function tryRefuel() | |
77 | for n=1,16 do | |
78 | if turtle.getItemCount(n) > 0 then | |
79 | turtle.select(n) | |
80 | if turtle.refuel(1) then | |
81 | turtle.select(1) | |
82 | return true | |
83 | end | |
84 | end | |
85 | end | |
86 | turtle.select(1) | |
87 | return false | |
88 | end | |
89 | ||
90 | if not tryRefuel() then | |
91 | print( "Add more fuel to continue." ) | |
92 | while not tryRefuel() do | |
93 | sleep(1) | |
94 | end | |
95 | print( "Resuming Tunnel." ) | |
96 | end | |
97 | end | |
98 | local function tryDig() | |
99 | while turtle.detect() do | |
100 | if turtle.dig() then | |
101 | collect() | |
102 | sleep(0.5) | |
103 | else | |
104 | return false | |
105 | end | |
106 | end | |
107 | return true | |
108 | end | |
109 | local function tryDigUp() | |
110 | while turtle.detectUp() do | |
111 | if turtle.digUp() then | |
112 | collect() | |
113 | sleep(0.5) | |
114 | else | |
115 | return false | |
116 | end | |
117 | end | |
118 | return true | |
119 | end | |
120 | local function tryDigDown() | |
121 | while turtle.detectDown() do | |
122 | if turtle.digDown() then | |
123 | collect() | |
124 | sleep(0.5) | |
125 | else | |
126 | return false | |
127 | end | |
128 | end | |
129 | return true | |
130 | end | |
131 | local function tryUp() | |
132 | refuel() | |
133 | while not turtle.up() do | |
134 | if turtle.detectUp() then | |
135 | if not tryDigUp() then | |
136 | return false | |
137 | end | |
138 | elseif turtle.attackUp() then | |
139 | collect() | |
140 | else | |
141 | sleep( 0.5 ) | |
142 | end | |
143 | end | |
144 | return true | |
145 | end | |
146 | local function tryDown() | |
147 | refuel() | |
148 | while not turtle.down() do | |
149 | if turtle.detectDown() then | |
150 | if not tryDigDown() then | |
151 | return false | |
152 | end | |
153 | elseif turtle.attackDown() then | |
154 | collect() | |
155 | else | |
156 | sleep( 0.5 ) | |
157 | end | |
158 | end | |
159 | return true | |
160 | end | |
161 | local function tryForward() | |
162 | refuel() | |
163 | while not turtle.forward() do | |
164 | if turtle.detect() then | |
165 | if not tryDig() then | |
166 | return false | |
167 | end | |
168 | elseif turtle.attack() then | |
169 | collect() | |
170 | else | |
171 | sleep( 0.5 ) | |
172 | end | |
173 | end | |
174 | return true | |
175 | end | |
176 | ||
177 | local resourceIndex=2 | |
178 | ||
179 | local function seekFirstResourceSlot() | |
180 | while resourceIndex<17 do | |
181 | turtle.select(resourceIndex) | |
182 | if turtle.getItemCount(resourceIndex)>0 then | |
183 | return true | |
184 | end | |
185 | resourceIndex=resourceIndex+1 | |
186 | end | |
187 | return false | |
188 | end | |
189 | ||
190 | local function mine() | |
191 | print( "Flooring..." ) | |
192 | - | local function dumpCobble() |
192 | + | |
193 | - | for slot=firstProcessSlot,16 do |
193 | + | if not seekFirstResourceSlot(resourceIndex) then |
194 | - | turtle.select(slot) |
194 | + | return false |
195 | - | local slotQuantity=turtle.getItemCount(slot) |
195 | + | |
196 | - | if slotQuantity > 0 then |
196 | + | |
197 | - | if turtle.compareTo(cobbleSlot) then |
197 | + | |
198 | - | cobbleDumped = cobbleDumped + slotQuantity |
198 | + | tryDigDown() |
199 | - | turtle.drop() |
199 | + | |
200 | if turtle.getItemCount(resourceIndex)==0 then | |
201 | if not seekFirstResourceSlot(resourceIndex) then | |
202 | return false | |
203 | end | |
204 | - | local function dropCobbleWhenNecessary() |
204 | + | |
205 | - | if math.fmod(collected,frequencyOfCobbleRemoval)==0 then |
205 | + | |
206 | - | dumpCobble() |
206 | + | |
207 | return false | |
208 | end | |
209 | - | local function placeTorchWhenNecessary(x,y) |
209 | + | |
210 | - | if math.fmod(x,8)==1 and math.fmod(y,8)==1 then |
210 | + | |
211 | if rotation==0 then | |
212 | - | if (turtle.getItemCount(torchSlot)==0) then |
212 | + | |
213 | - | print("Out of torches, please resupply!") |
213 | + | |
214 | turtle.turnLeft() | |
215 | end | |
216 | tryDig() | |
217 | if not tryForward() then | |
218 | - | end |
218 | + | |
219 | - | return true |
219 | + | |
220 | if rotation==0 then | |
221 | - | local function placeEnderChest() |
221 | + | |
222 | - | turtle.select(enderChestSlot) |
222 | + | |
223 | - | turtle.placeDown() |
223 | + | |
224 | end | |
225 | - | local function retrieveEnderChest() |
225 | + | |
226 | - | turtle.select(enderChestSlot) |
226 | + | |
227 | - | turtle.digDown() |
227 | + | |
228 | return true | |
229 | - | local function processContent() |
229 | + | |
230 | - | if (turtle.getItemCount(enderChestSlot)==0) then |
230 | + | |
231 | - | print("No enderchest found in slot"..enderChestSlot.."!") |
231 | + | |
232 | print( "Flooring complete." ) | |
233 | else | |
234 | - | dumpCobble() |
234 | + | print( "Flooring aborted prematurely.") |
235 | - | placeEnderChest() |
235 | + | end |