SHOW:
|
|
- or go back to the newest paste.
1 | - | -- quarry |
1 | + | -- chquarry |
2 | - | -- "swapper" (engineering turtle (turtle+crescent hammer)) must face NORTH |
2 | + | -- |
3 | - | -- "mover" (digging turtle) must face the swapper from the right (should face west) |
3 | + | -- At the beginning everything must be already placed: |
4 | - | -- the quarry, 3 enderchests and a power cell must be placed at the beginning |
4 | + | -- a quarry facing North, |
5 | -- an "item" enderchest on the West side of the quarry, | |
6 | - | local args = {...} |
6 | + | -- a full power cell on the East side of the querry, |
7 | - | local role = args[1] |
7 | + | -- a chunkloading mining turtle running this program facing the power cell from its East side, |
8 | -- (ie. the turtle must face West) | |
9 | -- a "charged power cell" enderchest above the turtle, and | |
10 | -- a "discharged power cell" enderchest below the turtle. | |
11 | -- Download this as chquarry and put this code into the "startup" file: shell.run("chquarry") | |
12 | ||
13 | local FUEL_SLOT = 1 | |
14 | local QUARRY_SLOT = 2 | |
15 | local ENERGY_CELL_SLOT = 3 | |
16 | local CHARGED_CELLS_ENDERCHEST_SLOT = 4 | |
17 | local EMPTY_CELLS_ENDERCHEST_SLOT = 5 | |
18 | - | local STEP_SLEEP = 360 |
18 | + | |
19 | - | local MEETING_SLEEP = 5 |
19 | + | |
20 | - | local MOVING_SLEEP = 1 |
20 | + | |
21 | - | local QUARRY_STOP_SLEEP = 45 -- wait for the quarry to stop after disconnecting power |
21 | + | |
22 | - | local WAIT_FOR_MOVER = 20 |
22 | + | |
23 | local STEP_SLEEP = 600 | |
24 | - | function saveState(state) |
24 | + | local QUARRY_STOP_SLEEP = 30 -- wait for the quarry to stop after disconnecting power |
25 | - | f = fs.open("state","w") |
25 | + | |
26 | - | f.write(tostring(state)) |
26 | + | function recharge() |
27 | - | f.close() |
27 | + | |
28 | turtle.dig() | |
29 | turtle.dropDown() | |
30 | - | function swapper_recharge() |
30 | + | |
31 | turtle.suckUp() | |
32 | if turtle.getItemCount(ENERGY_CELL_SLOT)==0 then | |
33 | sleep(1) | |
34 | end | |
35 | end | |
36 | turtle.place() | |
37 | end | |
38 | ||
39 | function cleanup() | |
40 | - | function swapper_pack() |
40 | + | |
41 | turtle.dig() | |
42 | turtle.digUp() | |
43 | turtle.digDown() | |
44 | turtle.dropDown() | |
45 | - | turtle.back() -- make room for mover |
45 | + | |
46 | end | |
47 | - | while not(turtle.forward()) do |
47 | + | |
48 | - | sleep(1) |
48 | + | function pack() |
49 | turtle.select(ENERGY_CELL_SLOT) | |
50 | - | sleep(1) |
50 | + | |
51 | - | while not(turtle.forward()) do |
51 | + | |
52 | - | sleep(1) |
52 | + | |
53 | turtle.select(CHARGED_CELLS_ENDERCHEST_SLOT) | |
54 | turtle.digUp() | |
55 | - | print("giving mover time to relocate in front of swapper") |
55 | + | |
56 | - | sleep(WAIT_FOR_MOVER) |
56 | + | |
57 | sleep(0.5) | |
58 | turtle.forward() | |
59 | - | function swapper_relocate() |
59 | + | |
60 | turtle.dig() | |
61 | - | sleep(MOVING_SLEEP) |
61 | + | sleep(0.5) |
62 | - | while not turtle.forward() do |
62 | + | |
63 | - | print("couldn't move forward, sleeping for a while") |
63 | + | |
64 | - | sleep(MOVING_SLEEP) |
64 | + | |
65 | turtle.turnRight() | |
66 | end | |
67 | function unpack() | |
68 | cleanup() | |
69 | - | function swapper_unpack() |
69 | + | |
70 | cleanup() | |
71 | - | while not(turtle.forward()) do |
71 | + | |
72 | - | print("couldn't move forward, sleeping for a while") |
72 | + | |
73 | - | sleep(1) |
73 | + | |
74 | turtle.turnRight() | |
75 | - | sleep(1) |
75 | + | cleanup() |
76 | - | while not(turtle.forward()) do |
76 | + | |
77 | - | print("couldn't move forward, sleeping for a while") |
77 | + | |
78 | - | sleep(1) |
78 | + | |
79 | turtle.select(QUARRY_SLOT) | |
80 | turtle.place() | |
81 | - | sleep(WAIT_FOR_MOVER) |
81 | + | |
82 | - | while not turtle.forward() do |
82 | + | |
83 | - | sleep(MEETING_SLEEP) |
83 | + | cleanup() |
84 | turtle.forward() | |
85 | - | swapper_recharge() |
85 | + | |
86 | turtle.turnRight() | |
87 | turtle.select(EMPTY_CELLS_ENDERCHEST_SLOT) | |
88 | - | function swapper_cycle() |
88 | + | |
89 | turtle.select(CHARGED_CELLS_ENDERCHEST_SLOT) | |
90 | - | print("giving quarry time") |
90 | + | |
91 | recharge() | |
92 | - | print("recharging quarry") |
92 | + | |
93 | - | swapper_recharge() |
93 | + | function relocate() |
94 | for i=1,RELOCATE_DISTANCE do | |
95 | - | print("giving quarry time") |
95 | + | cleanup() |
96 | turtle.forward() | |
97 | end | |
98 | - | swapper_pack() |
98 | + | |
99 | function cycle() | |
100 | - | swapper_relocate() |
100 | + | print("waiting for quarry") |
101 | sleep(STEP_SLEEP) | |
102 | - | swapper_unpack() |
102 | + | |
103 | print("recharging") | |
104 | recharge() | |
105 | - | function mover_cleanup() |
105 | + | |
106 | end | |
107 | print("packing") | |
108 | pack() | |
109 | print("relocating") | |
110 | relocate() | |
111 | print("unpacking") | |
112 | unpack() | |
113 | end | |
114 | - | function mover_pack() |
114 | + | |
115 | function check_fuel() | |
116 | if turtle.getFuelLevel() < MIN_FUEL_FOR_CYCLE then | |
117 | -- TODO: try to get fuel from the "charged cells" enderchest | |
118 | print("not enough fuel, waiting for fuel") | |
119 | while turtle.getFuelLevel() < MIN_FUEL_FOR_CYCLE do | |
120 | sleep(5) | |
121 | turtle.select(FUEL_SLOT) | |
122 | turtle.suckUp() | |
123 | if turtle.refuel() then | |
124 | moreFuel = True | |
125 | while moreFuel do | |
126 | sleep(3) | |
127 | turtle.suckUp() | |
128 | if not turtle.refuel() then | |
129 | moreFuel = False | |
130 | - | function mover_unpack() |
130 | + | turtle.dropUp() |
131 | - | mover_cleanup() |
131 | + | end |
132 | end | |
133 | else | |
134 | turtle.dropUp() -- not fuel, return to chest | |
135 | end | |
136 | end | |
137 | - | mover_cleanup() |
137 | + | |
138 | end | |
139 | ||
140 | -- *********************************************************************** | |
141 | ||
142 | print("starting automated quarry operation") | |
143 | - | mover_cleanup() |
143 | + | while true do |
144 | check_fuel() | |
145 | cycle() | |
146 | end |