View difference between Paste ID: HP5fcVFj and 3aSHHHBD
SHOW: | | - or go back to the newest paste.
1
local tArgs = {...}
2
local length = tArgs[1]
3
local numTunnels = tArgs[2]
4
local inv = true
5
local checkTorch = 0
6
local height = 0
7
local fullInvNum = 0
8
9
function checkOreId(name)
10-
	return name == 'minecraft:coal_ore'
10+
    return name == 'minecraft:coal_ore'
11-
		or name == 'minecraft:iron_ore'
11+
        or name == 'minecraft:iron_ore'
12-
		or name == 'minecraft:gold_ore'
12+
        or name == 'minecraft:gold_ore'
13-
		or name == 'minecraft:diamond_ore'
13+
        or name == 'minecraft:diamond_ore'
14-
		or name == 'minecraft:lapis_ore'
14+
        or name == 'minecraft:lapis_ore'
15-
		or name == 'minecraft:redstone_ore'
15+
        or name == 'minecraft:redstone_ore'
16-
		or name == 'minecraft:lit_redstone_ore'
16+
        or name == 'minecraft:lit_redstone_ore'
17
end
18
19
function checkOre(func)
20-
	local success, data = func()
20+
    local success, data = func()
21-
 if not success then return false end
21+
    if not success then return false end
22-
 return checkOreId(data.name)
22+
    return checkOreId(data.name)
23
end
24
25
function isOre()
26-
 return checkOre(turtle.inspect)
26+
    return checkOre(turtle.inspect)
27
end
28
29
function isOreUp()
30-
	return checkOre(turtle.inspectUp)
30+
    return checkOre(turtle.inspectUp)
31
end
32
33
function isOreDown()
34-
	return checkOre(turtle.inspectDown)
34+
    return checkOre(turtle.inspectDown)
35
end
36
37
function repeatSuccess(func)
38-
	while func() do end
38+
    while func() do end
39
end
40
41
function dig()
42-
	repeatSuccess(turtle.dig)
42+
    repeatSuccess(turtle.dig)
43
end
44
45
function digUp()
46-
	repeatSuccess(turtle.digUp)
46+
    repeatSuccess(turtle.digUp)
47
end
48
49
function digDown()
50-
	repeatSuccess(turtle.digDown)
50+
    repeatSuccess(turtle.digDown)
51
end
52
53
isUp = false
54
55
function searchAround()
56-
 print('searching for ores')
56+
    print('searching for ores')
57-
 turtle.select(1)
57+
    turtle.select(1)
58-
	if isOre() then
58+
59-
		dig()
59+
60-
		turtle.forward()
60+
61-
		searchAround()
61+
62-
		turtle.back()
62+
63-
  turtle.place()
63+
64
    elseif isOreDown() then
65
        digDown()
66
        turtle.down()
67
        searchAround()
68
        turtle.up()
69
        turtle.placeDown()
70
    elseif isOreUp() then
71
        digUp()
72
        turtle.up()
73
        searchAround()
74
        turtle.down()
75
        turtle.placeUp()
76
    end
77-
   
77+
78
    turtle.turnLeft()
79
    if isOre() then
80
        dig()
81
        turtle.forward()
82
        searchAround()
83
        turtle.back()
84
        turtle.place()
85
    end
86-
   
86+
87
    turtle.turnRight()
88
    turtle.turnRight()
89
    if isOre() then
90
        dig()
91
        turtle.forward()
92
        searchAround()
93
        turtle.back()
94
        turtle.place()
95
    end
96
    turtle.turnLeft()
97
end
98
99
-- The basic function to move forward and dig
100
function tunnel()
101-
  -- These used throughout to erase screen
101+
    -- These used throughout to erase screen
102-
  term.clear()
102+
103-
  term.setCursorPos(1,1)
103+
104-
  print("Mining...")
104+
    print("Mining...")
105-
  for i=1,length do
105+
    for i=1,length do
106-
    fuel()
106+
        fuel()
107-
    dig()
107+
108-
	turtle.forward()
108+
109-
    digUp()
109+
110-
    isUp = false
110+
        isUp = false
111-
	searchAround()
111+
112-
    turtle.up()
112+
113-
    isUp = true
113+
        isUp = true
114-
    searchAround()
114+
115-
    turtle.down()
115+
116-
    torch()
116+
117-
  end
117+
118
end
119
120
-- The function to turn around and go the other direction down the tunnel, also clears side tunnels
121
function turnAround()
122-
  term.clear()
122+
123-
  term.setCursorPos(1,1)
123+
124-
  print("Turning around...")
124+
    print("Turning around...")
125-
  for k = 1,6 do
125+
    for k = 1,6 do
126-
    fuel()
126+
        fuel()
127-
    dig()
127+
128-
	turtle.forward()
128+
129-
    digUp()
129+
130-
    isUp = false
130+
        isUp = false
131-
	searchAround()
131+
132-
    turtle.up()
132+
133-
    isUp = true
133+
        isUp = true
134-
    searchAround()
134+
135-
    turtle.down()
135+
136-
    torch()
136+
137-
  end
137+
138-
  
138+
139-
  checkInv()
139+
    checkInv()
140-
  
140+
141-
  while turtle.back() == false do
141+
    while turtle.back() == false do
142
        turtle.turnRight()
143
        turtle.turnRight()
144-
    dig()
144+
145-
    for i = 1,3 do
145+
        for i = 1,3 do
146-
      turtle.forward()
146+
            turtle.forward()
147-
      dig()
147+
            dig()
148
        end
149
        turtle.turnRight()
150
        turtle.turnRight()
151-
    for i = 1,3 do
151+
        for i = 1,3 do
152-
      turtle.back()  
152+
            turtle.back()
153
        end
154-
  end
154+
155-
  turtle.back()
155+
    turtle.back()
156-
  turtle.back()
156+
    turtle.back()
157
end
158
159
-- Clears the specified item from the inventory, most likely cobble, also stops on full inv
160
function checkInv()
161-
  term.clear()
161+
162-
  term.setCursorPos(1,1)
162+
163-
  print("Trashing...")
163+
    print("Trashing...")
164-
  for y = 2,16 do
164+
    for y = 2,16 do
165-
    turtle.select(y)
165+
        turtle.select(y)
166-
    if turtle.compareTo(1) then
166+
        if turtle.compareTo(1) then
167-
      turtle.drop()
167+
            turtle.drop()
168
        end
169-
  end
169+
170
end
171-
    
171+
172
function fullInv()
173-
  checkInv()
173+
    checkInv()
174-
  -- To not spill items everywhere, some credit to link0153 :)
174+
    -- To not spill items everywhere, some credit to link0153 :)
175-
  for i = 1,16 do
175+
176-
    if turtle.getItemCount(i) > 0 then
176+
        if turtle.getItemCount(i) > 0 then
177-
      fullInvNum = fullInvNum + 1
177+
            fullInvNum = fullInvNum + 1
178
        end
179-
  end
179+
180-
  while fullInvNum == 16 do
180+
    while fullInvNum == 16 do
181
        term.clear()
182
        term.setCursorPos(1,1)
183-
    print("Inventory full, please clear.")
183+
        print("Inventory full, please clear.")
184-
    sleep(5)
184+
        sleep(5)
185
        for i = 1,16 do
186-
      if turtle.getItemCount(i) == 0 then
186+
            if turtle.getItemCount(i) == 0 then
187-
        fullInvNum = 0
187+
                fullInvNum = 0
188-
      end
188+
            end
189
        end
190-
  end
190+
191-
  fullInvNum = 0
191+
    fullInvNum = 0
192-
  term.clear()
192+
193-
  term.setCursorPos(1,1)
193+
194-
  print("Mining...")
194+
    print("Mining...")
195
end
196
197
-- Checks how long since the last torch, then decides to place one above or not
198
function torch()
199-
  -- Checks if low on torches
199+
    -- Checks if low on torches
200-
  if turtle.getItemCount(16) < 5 then
200+
    if turtle.getItemCount(16) < 5 then
201
        term.clear()
202
        term.setCursorPos(1,1)
203-
    print("Waiting for torches...place in bottom right.")
203+
        print("Waiting for torches...place in bottom right.")
204-
    while turtle.getItemCount(16) < 5 do
204+
        while turtle.getItemCount(16) < 5 do
205-
      sleep(2)
205+
            sleep(2)
206
        end
207-
  end
207+
208-
  term.clear()
208+
209-
  term.setCursorPos(1,1)
209+
210-
  print("Mining...")
210+
    print("Mining...")
211-
  if checkTorch == 8 then
211+
    if checkTorch == 8 then
212-
    fuel()
212+
        fuel()
213-
    turtle.select(16)
213+
        turtle.select(16)
214-
    turtle.up()
214+
215-
    digUp()
215+
216-
    -- This if and loop will bring the turtle back down from the placed torch
216+
        -- This if and loop will bring the turtle back down from the placed torch
217-
    if turtle.placeUp() or turtle.getItemCount(16) == 0 then
217+
        if turtle.placeUp() or turtle.getItemCount(16) == 0 then
218-
        for i = 0,height do
218+
            for i = 0,height do
219-
          fuel()
219+
                fuel()
220-
          turtle.down()
220+
                turtle.down()
221
            end
222-
        turtle.select(1)
222+
            turtle.select(1)
223-
        checkTorch = 0
223+
            checkTorch = 0
224-
        height = 0
224+
            height = 0
225
        else
226-
        height = height + 1
226+
            height = height + 1
227
            torch()
228
        end
229-
  -- If it's too soon, dont place a torch
229+
        -- If it's too soon, dont place a torch
230-
  else
230+
231-
    checkTorch = checkTorch + 1
231+
        checkTorch = checkTorch + 1
232-
  end
232+
233
end
234
235
-- Checks the fuel level, asks for more if necessary
236
function fuel()
237-
  if turtle.getFuelLevel() < 50 then
237+
    if turtle.getFuelLevel() < 50 then
238-
    print ("Wating for fuel...place in bottom left.")     
238+
        print ("Wating for fuel...place in bottom left.")
239-
    while turtle.getFuelLevel() < 50 do
239+
        while turtle.getFuelLevel() < 50 do
240-
      turtle.select(13)
240+
            turtle.select(13)
241-
      turtle.refuel()
241+
            turtle.refuel()
242-
      sleep(2)
242+
            sleep(2)
243
        end
244-
  end
244+
245-
  term.clear()
245+
246-
  term.setCursorPos(1,1)
246+
247-
  print("Mining...")
247+
    print("Mining...")
248-
  turtle.select(1)
248+
    turtle.select(1)
249
end
250
251
-- This function is a one time startup function, makes sure the turtle has the necessary materials
252
function begin()
253-
  turtle.select(1)
253+
    turtle.select(1)
254-
  -- Checks for trash item
254+
    -- Checks for trash item
255-
  if turtle.getItemCount(1) == 0 then
255+
    if turtle.getItemCount(1) == 0 then
256-
    print("Please place an item to trash in the top left.")
256+
        print("Please place an item to trash in the top left.")
257-
    while turtle.getItemCount(1) == 0 do
257+
        while turtle.getItemCount(1) == 0 do
258-
      sleep(1)
258+
            sleep(1)
259
        end
260
        term.clear()
261
        term.setCursorPos(1,1)
262
        begin()
263-
  -- Confirms trashed item
263+
        -- Confirms trashed item
264-
  else
264+
265-
    print("The item in the top left will be trashed...confirm?")
265+
        print("The item in the top left will be trashed...confirm?")
266-
    os.pullEvent("key")
266+
        os.pullEvent("key")
267-
  end
267+
268-
  term.clear()
268+
269-
  term.setCursorPos(1,1)
269+
270
end
271
272-
-- From here is the main code  
272+
-- From here is the main code
273
274
-- Checks for correct args
275
if not (tArgs[1] == nil or tArgs[2] == nil) then
276-
  begin()
276+
277-
  -- Loops for the specified # of tunnels, one tunnel being up and back
277+
    -- Loops for the specified # of tunnels, one tunnel being up and back
278-
  for j = 1,numTunnels do
278+
    for j = 1,numTunnels do
279-
    tunnel()
279+
        tunnel()
280-
    fullInv()
280+
        fullInv()
281
        turtle.turnLeft()
282-
    turnAround()
282+
        turnAround()
283-
    fullInv()
283+
        fullInv()
284
        turtle.turnLeft()
285-
    tunnel()
285+
        tunnel()
286-
    fullInv()
286+
        fullInv()
287
        turtle.turnRight()
288-
    turnAround()
288+
        turnAround()
289-
    fullInv()
289+
        fullInv()
290
        turtle.turnRight()
291-
  end
291+
292-
  -- Resets the screen and displays a confirmation of finishing
292+
    -- Resets the screen and displays a confirmation of finishing
293-
  term.clear()
293+
294-
  term.setCursorPos(1,1)
294+
295-
  print("Done!")
295+
    print("Done!")
296
else
297-
  term.clear()
297+
298-
  term.setCursorPos(1,1)
298+
299-
  print("Not enough arguments, should be used 'branch [length] [number of tunnels]'")
299+
    print("Not enough arguments, should be used 'branch [length] [number of tunnels]'")
300
end