SHOW:
|
|
- or go back to the newest paste.
1 | local length = 160 | |
2 | local width = 160 | |
3 | local mining = true | |
4 | local l = 0 | |
5 | local w = 0 | |
6 | local clean = 32 | |
7 | local clean_count = 0 | |
8 | local turn = 1--1=>right,-1=>left | |
9 | ||
10 | --fuel is first slot | |
11 | --then important blocks | |
12 | --then inventory | |
13 | --overlapping is undefined (except fuel slot being important) | |
14 | --gaps are undefined (except btwn important_end and inven_start, blocks there will be collected but only up to one stack) | |
15 | local fuel = 1 | |
16 | local important_start = 1 | |
17 | local important_end = 3 | |
18 | local inven_start = important_end+1 | |
19 | local inven_end = 16 | |
20 | ||
21 | function refuel()--returns false if it ran out of coal and has low energy | |
22 | if turtle.getFuelLevel() < 3 then | |
23 | if turtle.getItemCount(1) <= 1 then | |
24 | return false | |
25 | else | |
26 | print("Refueling") | |
27 | turtle.refuel(1) | |
28 | print("new fuel level: "..turtle.getFuelLevel()) | |
29 | print("remaing fuel: "..turtle.getItemCount(1)) | |
30 | return true | |
31 | end | |
32 | end | |
33 | return true | |
34 | end | |
35 | ||
36 | function dig_forward()--returns if it can dig and move forward | |
37 | while turtle.detect() do | |
38 | turtle.dig() | |
39 | end | |
40 | local rtn = turtle.forward() | |
41 | while turtle.detectUp() do | |
42 | turtle.digUp() | |
43 | end | |
44 | while turtle.detectDown() do | |
45 | turtle.digDown() | |
46 | end | |
47 | return rtn | |
48 | end | |
49 | ||
50 | function clean_inventory()--returns false if inventory is full of important blocks | |
51 | local full = 0 | |
52 | local selected = turtle.getSelectedSlot() | |
53 | for i=inven_start,inven_end do | |
54 | turtle.select(i) | |
55 | drop = true | |
56 | for i=important_start,important_end do | |
57 | if turtle.compareTo(i) then | |
58 | drop = false | |
59 | end | |
60 | end | |
61 | if drop then | |
62 | turtle.drop() | |
63 | end | |
64 | if turtle.getItemSpace(i) == 0 then | |
65 | full = full+1 | |
66 | end | |
67 | end | |
68 | turtle.select(selected) | |
69 | ||
70 | if full >= inven_end - inven_start + 1 then | |
71 | return false | |
72 | else | |
73 | return true | |
74 | end | |
75 | end | |
76 | ||
77 | while mining do | |
78 | dig_forward() | |
79 | l = l+1 | |
80 | if l>length then | |
81 | if turn > 0 then | |
82 | turtle.turnRight() | |
83 | dig_forward() | |
84 | turtle.turnRight() | |
85 | else | |
86 | turtle.turnLeft() | |
87 | dig_forward() | |
88 | turtle.turnLeft() | |
89 | end | |
90 | turn = turn*-1 | |
91 | l = 0 | |
92 | w = w+1 | |
93 | if w > width then | |
94 | print("End or route") | |
95 | w = 0 | |
96 | mining = false | |
97 | end | |
98 | end | |
99 | ||
100 | if clean_count >= clean then | |
101 | if not clean_inventory() then | |
102 | print("Inventory full") | |
103 | mining = false | |
104 | end | |
105 | clean_count = 0 | |
106 | else | |
107 | clean_count = clean_count + 1 | |
108 | end | |
109 | ||
110 | if not refuel() then | |
111 | print("out of fuel") | |
112 | mining = false | |
113 | end | |
114 | end |