SHOW:
|
|
- or go back to the newest paste.
1 | ----------------- | |
2 | --Name: miningLIB | |
3 | --Version: 1.0.0 | |
4 | --Requires: riewestLIB | |
5 | --By: Riewest (AKA Riewest14) | |
6 | ----------------- | |
7 | ||
8 | os.loadAPI("riewestLIB") | |
9 | lib = riewestLIB | |
10 | ||
11 | function test() | |
12 | --strip(10, true, false, 15) | |
13 | branchMine(10, 2, 2, true, false, 15) | |
14 | lib.turnAround() | |
15 | end | |
16 | ||
17 | --Veinmine the block in front | |
18 | --Returning to the starting position | |
19 | function veinMine() | |
20 | --TODO | |
21 | end | |
22 | ||
23 | --Does a branch mine | |
24 | --Length: length of the mine | |
25 | --spaceBet: space between branches | |
26 | --branchLength: length of branches | |
27 | --retStart: returns to start if true | |
28 | --chestSlot: if not nil will dump items | |
29 | -- into that chest | |
30 | --fuelSlot: slot to attempt refueling | |
31 | -- from if not nil | |
32 | ||
33 | function branchMine(length, spaceBet, branchLength, retStart, fuelSlot, chestSlot) | |
34 | if not length then | |
35 | length = 15 | |
36 | end | |
37 | if not spaceBet then | |
38 | spaceBet = 1 | |
39 | end | |
40 | if not branchLength then | |
41 | branchLength = 5 | |
42 | end | |
43 | if not retStart then | |
44 | retStart = false | |
45 | end | |
46 | if not fuelSlot then | |
47 | fuelSlot = false | |
48 | end | |
49 | if not chestSlot then | |
50 | chestSlot = false | |
51 | end | |
52 | local count = 0 | |
53 | local lengthLeft = length | |
54 | for i = 1, length do | |
55 | if count > 10 then | |
56 | count = 0 | |
57 | end | |
58 | if lengthLeft < spaceBet then | |
59 | strip(lengthLeft, false, fuelSlot, chestSlot) | |
60 | break | |
61 | end | |
62 | local moved = strip(spaceBet + 1, false, fuelSlot, chestSlot) | |
63 | i = i + moved | |
64 | count = count + math.fmod(moved, 10) | |
65 | lengthLeft = lengthLeft - moved | |
66 | turtle.turnLeft() | |
67 | local s1 = strip(branchLength, true, fuelSlot, chestSlot) | |
68 | local s2 = strip(branchLength, true, fuelSlot, chestSlot) | |
69 | count = count + (math.fmod(s1, 10) + math.fmod(s2, 10)) | |
70 | print("Count: " .. count) | |
71 | doChestG(chestSlot, count, 10, fuelSlot) | |
72 | turtle.turnRight() | |
73 | end | |
74 | if retStart then | |
75 | lib.turnAround() | |
76 | lib.tMoveF(length) | |
77 | end | |
78 | end | |
79 | ||
80 | --Method to check if chest should be | |
81 | --placed above and empty the inventory | |
82 | --chestSlot: slot the chest is in if nil | |
83 | -- will not empty inventory | |
84 | --dist: Distance the turtle has traveled | |
85 | --interval: interval inventory should | |
86 | -- be checked | |
87 | --fuelSlot: optional fuelslot | |
88 | function doChest(chestSlot, dist, interval, fuelSlot) | |
89 | if chestSlot and (math.fmod(dist, interval) == 0) and (turtle.getItemCount(chestSlot) > 0 ) then | |
90 | local oldSlot = turtle.getSelectedSlot() | |
91 | turtle.select(chestSlot) | |
92 | local chestData = turtle.getItemDetail() | |
93 | turtle.placeUp() | |
94 | local slotsToKeep = {chestSlot} | |
95 | if fuelSlot then | |
96 | lib.sortItem(fuelSlot) | |
97 | table.insert(slotsToKeep, fuelSlot) | |
98 | end | |
99 | lib.emptyInvExcept(slotsToKeep, "top") | |
100 | turtle.select(chestSlot) | |
101 | if not (chestData.name == "minecraft:chest") then | |
102 | while not turtle.digUp() do | |
103 | sleep(.1) | |
104 | end | |
105 | end | |
106 | turtle.select(oldSlot) | |
107 | end | |
108 | end | |
109 | ||
110 | --Slight variation on do chest where | |
111 | -- it does the function if blocks | |
112 | -- moved is greater than chest interval | |
113 | -- takes same parameters | |
114 | function doChestG(chestSlot, dist, interval, fuelSlot) | |
115 | if not chestSlot then | |
116 | return | |
117 | end | |
118 | if dist > interval then | |
119 | dist = interval | |
120 | end | |
121 | doChest(chestSlot, dist, interval, fuelSlot) | |
122 | end | |
123 | ||
124 | --Mine a 1b wide 3b tall tunnel | |
125 | --for length passed. Returns to | |
126 | -- the start if retStart is true | |
127 | -- chestSlot: if not nil will dump items | |
128 | -- into that chest | |
129 | -- fuelSlot: if not nill will refuel from | |
130 | -- that slot. | |
131 | function strip(length, retStart, fuelSlot, chestSlot) | |
132 | if not length then | |
133 | length = 5 | |
134 | end | |
135 | if not retStart then | |
136 | retStart = false | |
137 | end | |
138 | if not chestSlot then | |
139 | chestSlot = false | |
140 | end | |
141 | if not fuelSlot then | |
142 | fuelSlot = false | |
143 | end | |
144 | ||
145 | for i = 1, length do | |
146 | lib.tMoveF() | |
147 | turtle.digUp() | |
148 | turtle.digDown() | |
149 | if fuelSlot then | |
150 | lib.tRefuel(fuelSlot) | |
151 | end | |
152 | doChest(chestSlot, i, 10, fuelSlot) | |
153 | end | |
154 | if retStart then | |
155 | lib.turnAround() | |
156 | lib.tMoveF(length) | |
157 | end | |
158 | return length | |
159 | end | |
160 | ||
161 | ||
162 | ||
163 | ||
164 | test() |