quarry-miner.lua

198 lines · 4.1 KB

Open raw

Copy & run

wget https://perlytiara.github.io/turtles.tips/raw/programs/BigGamingGamers/quarry-miner.lua
1local SLOT_COUNT = 16
2local d = "north"
3local width, depth, height = 10, 10, 2
4
5if (#arg == 3) then
6 width = tonumber(arg[1])
7 depth = tonumber(arg[2])
8 height = tonumber(arg[3])
9else
10 print('None or Malformed Size Given, Defaulting to 10x10x2 up')
11end
12
13
14DROPPED_ITEMS = {
15 "minecraft:stone",
16 "minecraft:dirt",
17 "minecraft:cobblestone",
18 "minecraft:sand",
19 "minecraft:gravel",
20 "minecraft:redstone",
21 "minecraft:flint",
22 "railcraft:ore_metal",
23 "extrautils2:ingredients",
24 "minecraft:dye",
25 "thaumcraft:nugget",
26 "thaumcraft:crystal_essence",
27 "thermalfoundation:material",
28 "projectred-core:resource_item",
29 "thaumcraft:ore_cinnabar",
30 "deepresonance:resonating_ore",
31 "forestry:apatite"
32}
33function dropItems()
34 print("Purging Inventory...")
35 for slot = 1, SLOT_COUNT, 1 do
36 local item = turtle.getItemDetail(slot)
37 if(item ~= nil) then
38 for filterIndex = 1, #DROPPED_ITEMS, 1 do
39 if(item["name"] == DROPPED_ITEMS[filterIndex]) then
40 print("Dropping - " .. item["name"])
41 turtle.select(slot)
42 turtle.dropDown()
43 end
44 end
45 end
46 end
47end
48
49
50function getEnderIndex()
51 for slot = 1, SLOT_COUNT, 1 do
52 local item = turtle.getItemDetail(slot)
53 if(item ~= nil) then
54 if(item["name"] == "enderstorage:ender_storage") then
55 return slot
56 end
57 end
58 end
59 return nil
60end
61
62function manageInventory()
63 dropItems()
64 index = getEnderIndex()
65 if(index ~= nil) then
66 turtle.select(index)
67 turtle.digUp()
68 turtle.placeUp()
69 end
70 -- Chest is now deployed
71 for slot = 1, SLOT_COUNT, 1 do
72 local item = turtle.getItemDetail(slot)
73 if(item ~= nil) then
74 if(item["name"] ~= "minecraft:coal_block" and item["name"] ~= "minecraft:coal") then
75 turtle.select(slot)
76 turtle.dropUp()
77 end
78 end
79 end
80 -- Items are now stored
81
82 turtle.digUp()
83end
84
85function checkFuel()
86 turtle.select(1)
87
88 if(turtle.getFuelLevel() < 50) then
89 print("Attempting Refuel...")
90 for slot = 1, SLOT_COUNT, 1 do
91 turtle.select(slot)
92 if(turtle.refuel(1)) then
93 return true
94 end
95 end
96
97 return false
98 else
99 return true
100 end
101end
102
103
104function detectAndDig()
105 while(turtle.detect()) do
106 turtle.dig()
107 turtle.digUp()
108 turtle.digDown()
109 end
110end
111
112function forward()
113 detectAndDig()
114 turtle.forward()
115end
116
117function leftTurn()
118 turtle.turnLeft()
119 detectAndDig()
120 turtle.forward()
121 turtle.turnLeft()
122 detectAndDig()
123end
124
125
126function rightTurn()
127 turtle.turnRight()
128 detectAndDig()
129 turtle.forward()
130 turtle.turnRight()
131 detectAndDig()
132end
133
134function flipDirection()
135 if(d == "north") then
136 d = "south"
137 elseif(d == "south") then
138 d = "north"
139 elseif(d == "west") then
140 d = "east"
141 elseif(d == "east") then
142 d = "west"
143 end
144
145end
146
147function turnAround(tier)
148 if(tier % 2 == 1) then
149 if(d == "north" or d == "east") then
150 rightTurn()
151 elseif(d == "south" or d == "west") then
152 leftTurn()
153 end
154 else
155 if(d == "north" or d == "east") then
156 leftTurn()
157 elseif(d == "south" or d == "west") then
158 rightTurn()
159 end
160 end
161 flipDirection()
162end
163
164
165function riseTier()
166 turtle.turnRight()
167 turtle.turnRight()
168 flipDirection()
169 turtle.digUp()
170 turtle.up()
171end
172
173
174function start()
175 for tier = 1, height, 1 do
176 for col = 1, width, 1 do
177 for row = 1, depth - 1, 1 do
178 if(not checkFuel()) then
179 print("Turtle is out of fuel, Powering Down...")
180 return
181 end
182 forward()
183 print(string.format("Row: %d Col: %d", row, col))
184 end
185 if(col ~= width) then
186 turnAround(tier)
187 end
188 manageInventory()
189 end
190 riseTier()
191 end
192end
193
194start()
195
196
197
198