commit | author | age
|
e748af
|
1 |
local max_charge = {50000, 200000, 650000} |
Z |
2 |
local power_usage_per_node = {200, 500, 800} |
82cba9
|
3 |
|
be2f30
|
4 |
local S = technic.getter |
S |
5 |
|
82cba9
|
6 |
minetest.register_craft({ |
R |
7 |
output = 'technic:mining_drill', |
|
8 |
recipe = { |
eac484
|
9 |
{'technic:stainless_steel_ingot', 'technic:diamond_drill_head', 'technic:stainless_steel_ingot'}, |
S |
10 |
{'technic:stainless_steel_ingot', 'technic:motor', 'technic:stainless_steel_ingot'}, |
|
11 |
{'', 'technic:red_energy_crystal', 'moreores:copper_ingot'}, |
82cba9
|
12 |
} |
R |
13 |
}) |
e23f87
|
14 |
minetest.register_craft({ |
R |
15 |
output = 'technic:mining_drill_mk2', |
|
16 |
recipe = { |
eac484
|
17 |
{'technic:diamond_drill_head', 'technic:diamond_drill_head', 'technic:diamond_drill_head'}, |
S |
18 |
{'technic:stainless_steel_ingot', 'technic:mining_drill', 'technic:stainless_steel_ingot'}, |
|
19 |
{'', 'technic:green_energy_crystal', ''}, |
e23f87
|
20 |
} |
R |
21 |
}) |
|
22 |
minetest.register_craft({ |
|
23 |
output = 'technic:mining_drill_mk3', |
|
24 |
recipe = { |
eac484
|
25 |
{'technic:diamond_drill_head', 'technic:diamond_drill_head', 'technic:diamond_drill_head'}, |
S |
26 |
{'technic:stainless_steel_ingot', 'technic:mining_drill_mk2', 'technic:stainless_steel_ingot'}, |
|
27 |
{'', 'technic:blue_energy_crystal', ''}, |
e23f87
|
28 |
} |
R |
29 |
}) |
eac484
|
30 |
for i = 1, 4 do |
ee0765
|
31 |
minetest.register_craft({ |
S |
32 |
output = 'technic:mining_drill_mk3', |
|
33 |
recipe = { |
|
34 |
{'technic:diamond_drill_head', 'technic:diamond_drill_head', 'technic:diamond_drill_head'}, |
|
35 |
{'technic:stainless_steel_ingot', 'technic:mining_drill_mk2_'..i, 'technic:stainless_steel_ingot'}, |
|
36 |
{'', 'technic:blue_energy_crystal', ''}, |
|
37 |
} |
|
38 |
}) |
91329b
|
39 |
end |
82cba9
|
40 |
|
5cf765
|
41 |
local mining_drill_mode_text = { |
S |
42 |
{S("Single node.")}, |
|
43 |
{S("3 nodes deep.")}, |
|
44 |
{S("3 nodes wide.")}, |
|
45 |
{S("3 nodes tall.")}, |
|
46 |
{S("3x3 nodes.")}, |
|
47 |
} |
|
48 |
|
|
49 |
local function drill_dig_it0 (pos,player) |
bab851
|
50 |
if minetest.is_protected(pos, player:get_player_name()) then |
S |
51 |
minetest.record_protection_violation(pos, player:get_player_name()) |
|
52 |
return |
|
53 |
end |
5cf765
|
54 |
local node=minetest.env:get_node(pos) |
S |
55 |
if node.name == "air" or node.name == "ignore" then return end |
|
56 |
if node.name == "default:lava_source" then return end |
|
57 |
if node.name == "default:lava_flowing" then return end |
|
58 |
if node.name == "default:water_source" then minetest.env:remove_node(pos) return end |
|
59 |
if node.name == "default:water_flowing" then minetest.env:remove_node(pos) return end |
|
60 |
minetest.node_dig(pos,node,player) |
|
61 |
end |
|
62 |
|
|
63 |
local function drill_dig_it1 (player) |
|
64 |
local dir=player:get_look_dir() |
|
65 |
if math.abs(dir.x)>math.abs(dir.z) then |
|
66 |
if dir.x>0 then return 0 end |
|
67 |
return 1 |
|
68 |
end |
|
69 |
if dir.z>0 then return 2 end |
|
70 |
return 3 |
|
71 |
end |
|
72 |
|
|
73 |
local function drill_dig_it2 (pos,player) |
|
74 |
drill_dig_it0 (pos,player) |
|
75 |
pos.z=pos.z+1 |
|
76 |
drill_dig_it0 (pos,player) |
|
77 |
pos.z=pos.z-2 |
|
78 |
drill_dig_it0 (pos,player) |
|
79 |
pos.z=pos.z+1 |
|
80 |
pos.y=pos.y+1 |
|
81 |
drill_dig_it0 (pos,player) |
|
82 |
pos.z=pos.z+1 |
|
83 |
drill_dig_it0 (pos,player) |
|
84 |
pos.z=pos.z-2 |
|
85 |
drill_dig_it0 (pos,player) |
|
86 |
pos.z=pos.z+1 |
|
87 |
pos.y=pos.y-2 |
|
88 |
drill_dig_it0 (pos,player) |
|
89 |
pos.z=pos.z+1 |
|
90 |
drill_dig_it0 (pos,player) |
|
91 |
pos.z=pos.z-2 |
|
92 |
drill_dig_it0 (pos,player) |
|
93 |
end |
|
94 |
|
|
95 |
local function drill_dig_it3 (pos,player) |
|
96 |
drill_dig_it0 (pos,player) |
|
97 |
pos.x=pos.x+1 |
|
98 |
drill_dig_it0 (pos,player) |
|
99 |
pos.x=pos.x-2 |
|
100 |
drill_dig_it0 (pos,player) |
|
101 |
pos.x=pos.x+1 |
|
102 |
pos.y=pos.y+1 |
|
103 |
drill_dig_it0 (pos,player) |
|
104 |
pos.x=pos.x+1 |
|
105 |
drill_dig_it0 (pos,player) |
|
106 |
pos.x=pos.x-2 |
|
107 |
drill_dig_it0 (pos,player) |
|
108 |
pos.x=pos.x+1 |
|
109 |
pos.y=pos.y-2 |
|
110 |
drill_dig_it0 (pos,player) |
|
111 |
pos.x=pos.x+1 |
|
112 |
drill_dig_it0 (pos,player) |
|
113 |
pos.x=pos.x-2 |
|
114 |
drill_dig_it0 (pos,player) |
|
115 |
end |
|
116 |
|
|
117 |
local function drill_dig_it4 (pos,player) |
|
118 |
drill_dig_it0 (pos,player) |
|
119 |
pos.x=pos.x+1 |
|
120 |
drill_dig_it0 (pos,player) |
|
121 |
pos.x=pos.x-2 |
|
122 |
drill_dig_it0 (pos,player) |
|
123 |
pos.x=pos.x+1 |
|
124 |
pos.z=pos.z+1 |
|
125 |
drill_dig_it0 (pos,player) |
|
126 |
pos.x=pos.x+1 |
|
127 |
drill_dig_it0 (pos,player) |
|
128 |
pos.x=pos.x-2 |
|
129 |
drill_dig_it0 (pos,player) |
|
130 |
pos.x=pos.x+1 |
|
131 |
pos.z=pos.z-2 |
|
132 |
drill_dig_it0 (pos,player) |
|
133 |
pos.x=pos.x+1 |
|
134 |
drill_dig_it0 (pos,player) |
|
135 |
pos.x=pos.x-2 |
|
136 |
drill_dig_it0 (pos,player) |
|
137 |
end |
|
138 |
|
e748af
|
139 |
local function cost_to_use(drill_type, mode) |
Z |
140 |
local mult |
|
141 |
if mode == 1 then |
|
142 |
mult = 1 |
|
143 |
elseif mode <= 4 then |
|
144 |
mult = 3 |
|
145 |
else |
|
146 |
mult = 9 |
|
147 |
end |
|
148 |
return power_usage_per_node[drill_type] * mult |
|
149 |
end |
5cf765
|
150 |
|
e748af
|
151 |
local function drill_dig_it(pos, player, mode) |
eac484
|
152 |
if mode == 1 then |
S |
153 |
drill_dig_it0(pos, player) |
e23f87
|
154 |
end |
R |
155 |
|
eac484
|
156 |
if mode == 2 then -- 3 deep |
S |
157 |
dir = drill_dig_it1(player) |
|
158 |
if dir == 0 then -- x+ |
|
159 |
drill_dig_it0(pos, player) |
|
160 |
pos.x = pos.x + 1 |
|
161 |
drill_dig_it0(pos, player) |
|
162 |
pos.x = pos.x + 1 |
|
163 |
drill_dig_it0(pos, player) |
e23f87
|
164 |
end |
eac484
|
165 |
if dir == 1 then -- x- |
S |
166 |
drill_dig_it0(pos, player) |
e23f87
|
167 |
pos.x=pos.x-1 |
R |
168 |
drill_dig_it0 (pos,player) |
|
169 |
pos.x=pos.x-1 |
|
170 |
drill_dig_it0 (pos,player) |
|
171 |
end |
|
172 |
if dir==2 then -- z+ |
|
173 |
drill_dig_it0 (pos,player) |
|
174 |
pos.z=pos.z+1 |
|
175 |
drill_dig_it0 (pos,player) |
|
176 |
pos.z=pos.z+1 |
|
177 |
drill_dig_it0 (pos,player) |
|
178 |
end |
|
179 |
if dir==3 then -- z- |
|
180 |
drill_dig_it0 (pos,player) |
8e2cb0
|
181 |
pos.z=pos.z-1 |
e23f87
|
182 |
drill_dig_it0 (pos,player) |
8e2cb0
|
183 |
pos.z=pos.z-1 |
e23f87
|
184 |
drill_dig_it0 (pos,player) |
R |
185 |
end |
|
186 |
end |
|
187 |
|
|
188 |
if mode==3 then -- 3 wide |
|
189 |
dir=drill_dig_it1(player) |
|
190 |
if dir==0 or dir==1 then -- x |
|
191 |
drill_dig_it0 (pos,player) |
|
192 |
pos.z=pos.z+1 |
|
193 |
drill_dig_it0 (pos,player) |
|
194 |
pos.z=pos.z-2 |
|
195 |
drill_dig_it0 (pos,player) |
|
196 |
end |
|
197 |
if dir==2 or dir==3 then -- z |
|
198 |
drill_dig_it0 (pos,player) |
|
199 |
pos.x=pos.x+1 |
|
200 |
drill_dig_it0 (pos,player) |
|
201 |
pos.x=pos.x-2 |
|
202 |
drill_dig_it0 (pos,player) |
|
203 |
end |
|
204 |
end |
|
205 |
|
|
206 |
if mode==4 then -- 3 tall, selected in the middle |
|
207 |
drill_dig_it0 (pos,player) |
5cf765
|
208 |
pos.y=pos.y-1 |
e23f87
|
209 |
drill_dig_it0 (pos,player) |
5cf765
|
210 |
pos.y=pos.y-1 |
e23f87
|
211 |
drill_dig_it0 (pos,player) |
R |
212 |
end |
82cba9
|
213 |
|
e23f87
|
214 |
if mode==5 then -- 3 x 3 |
R |
215 |
local dir=player:get_look_dir() |
|
216 |
if math.abs(dir.y)<0.5 then |
|
217 |
dir=drill_dig_it1(player) |
|
218 |
if dir==0 or dir==1 then -- x |
|
219 |
drill_dig_it2(pos,player) |
|
220 |
end |
|
221 |
if dir==2 or dir==3 then -- z |
|
222 |
drill_dig_it3(pos,player) |
|
223 |
end |
|
224 |
else |
|
225 |
drill_dig_it4(pos,player) |
|
226 |
end |
|
227 |
end |
|
228 |
|
|
229 |
minetest.sound_play("mining_drill", {pos = pos, gain = 1.0, max_hear_distance = 10,}) |
|
230 |
end |
82cba9
|
231 |
|
5cf765
|
232 |
local function mining_drill_mk2_setmode(user,itemstack) |
S |
233 |
local player_name=user:get_player_name() |
|
234 |
local item=itemstack:to_table() |
|
235 |
local meta=minetest.deserialize(item["metadata"]) |
|
236 |
if meta==nil then |
|
237 |
meta={} |
|
238 |
mode=0 |
e23f87
|
239 |
end |
5cf765
|
240 |
if meta["mode"]==nil then |
04c6f5
|
241 |
minetest.chat_send_player(player_name, S("Use while sneaking to change Mining Drill Mk%d modes."):format(2)) |
5cf765
|
242 |
meta["mode"]=0 |
S |
243 |
mode=0 |
|
244 |
end |
|
245 |
mode=(meta["mode"]) |
|
246 |
mode=mode+1 |
|
247 |
if mode>=5 then mode=1 end |
|
248 |
minetest.chat_send_player(player_name, S("Mining Drill Mk%d Mode %d"):format(2, mode)..": "..mining_drill_mode_text[mode][1]) |
|
249 |
item["name"]="technic:mining_drill_mk2_"..mode |
|
250 |
meta["mode"]=mode |
|
251 |
item["metadata"]=minetest.serialize(meta) |
|
252 |
itemstack:replace(item) |
|
253 |
return itemstack |
e23f87
|
254 |
end |
R |
255 |
|
5cf765
|
256 |
local function mining_drill_mk3_setmode(user,itemstack) |
S |
257 |
local player_name=user:get_player_name() |
|
258 |
local item=itemstack:to_table() |
|
259 |
local meta=minetest.deserialize(item["metadata"]) |
|
260 |
if meta==nil then |
|
261 |
meta={} |
|
262 |
mode=0 |
|
263 |
end |
|
264 |
if meta["mode"]==nil then |
04c6f5
|
265 |
minetest.chat_send_player(player_name, S("Use while sneaking to change Mining Drill Mk%d modes."):format(3)) |
5cf765
|
266 |
meta["mode"]=0 |
S |
267 |
mode=0 |
|
268 |
end |
|
269 |
mode=(meta["mode"]) |
|
270 |
mode=mode+1 |
|
271 |
if mode>=6 then mode=1 end |
|
272 |
minetest.chat_send_player(player_name, S("Mining Drill Mk%d Mode %d"):format(3, mode)..": "..mining_drill_mode_text[mode][1]) |
|
273 |
item["name"]="technic:mining_drill_mk3_"..mode |
|
274 |
meta["mode"]=mode |
|
275 |
item["metadata"]=minetest.serialize(meta) |
|
276 |
itemstack:replace(item) |
|
277 |
return itemstack |
e23f87
|
278 |
end |
R |
279 |
|
5cf765
|
280 |
|
S |
281 |
local function mining_drill_mk2_handler(itemstack, user, pointed_thing) |
|
282 |
local keys = user:get_player_control() |
|
283 |
local player_name = user:get_player_name() |
|
284 |
local meta = minetest.deserialize(itemstack:get_metadata()) |
|
285 |
if not meta or not meta.mode or keys.sneak then |
|
286 |
return mining_drill_mk2_setmode(user, itemstack) |
|
287 |
end |
|
288 |
if pointed_thing.type ~= "node" or not meta.charge then |
|
289 |
return |
|
290 |
end |
e748af
|
291 |
local charge_to_take = cost_to_use(2, meta.mode) |
Z |
292 |
if meta.charge >= charge_to_take then |
5cf765
|
293 |
local pos = minetest.get_pointed_thing_position(pointed_thing, above) |
e748af
|
294 |
drill_dig_it(pos, user, meta.mode) |
5cf765
|
295 |
meta.charge = meta.charge - charge_to_take |
S |
296 |
itemstack:set_metadata(minetest.serialize(meta)) |
e748af
|
297 |
technic.set_RE_wear(itemstack, meta.charge, max_charge[2]) |
5cf765
|
298 |
end |
S |
299 |
return itemstack |
|
300 |
end |
|
301 |
|
|
302 |
local function mining_drill_mk3_handler(itemstack, user, pointed_thing) |
|
303 |
local keys = user:get_player_control() |
|
304 |
local player_name = user:get_player_name() |
|
305 |
local meta = minetest.deserialize(itemstack:get_metadata()) |
|
306 |
if not meta or not meta.mode or keys.sneak then |
|
307 |
return mining_drill_mk3_setmode(user, itemstack) |
|
308 |
end |
|
309 |
if pointed_thing.type ~= "node" or not meta.charge then |
|
310 |
return |
|
311 |
end |
e748af
|
312 |
local charge_to_take = cost_to_use(3, meta.mode) |
Z |
313 |
if meta.charge >= charge_to_take then |
5cf765
|
314 |
local pos = minetest.get_pointed_thing_position(pointed_thing, above) |
e748af
|
315 |
drill_dig_it(pos, user, meta.mode) |
5cf765
|
316 |
meta.charge = meta.charge - charge_to_take |
S |
317 |
itemstack:set_metadata(minetest.serialize(meta)) |
e748af
|
318 |
technic.set_RE_wear(itemstack, meta.charge, max_charge[3]) |
5cf765
|
319 |
end |
S |
320 |
return itemstack |
e23f87
|
321 |
end |
R |
322 |
|
e748af
|
323 |
technic.register_power_tool("technic:mining_drill", max_charge[1]) |
5cf765
|
324 |
|
e23f87
|
325 |
minetest.register_tool("technic:mining_drill", { |
f90915
|
326 |
description = S("Mining Drill Mk%d"):format(1), |
e23f87
|
327 |
inventory_image = "technic_mining_drill.png", |
R |
328 |
stack_max = 1, |
|
329 |
on_use = function(itemstack, user, pointed_thing) |
eac484
|
330 |
if pointed_thing.type ~= "node" then |
S |
331 |
return itemstack |
e23f87
|
332 |
end |
5cf765
|
333 |
local meta = minetest.deserialize(itemstack:get_metadata()) |
eac484
|
334 |
if not meta or not meta.charge then |
S |
335 |
return |
|
336 |
end |
e748af
|
337 |
local charge_to_take = cost_to_use(1, 1) |
Z |
338 |
if meta.charge >= charge_to_take then |
eac484
|
339 |
local pos = minetest.get_pointed_thing_position(pointed_thing, above) |
e748af
|
340 |
drill_dig_it(pos, user, 1) |
Z |
341 |
meta.charge = meta.charge - charge_to_take |
5cf765
|
342 |
itemstack:set_metadata(minetest.serialize(meta)) |
e748af
|
343 |
technic.set_RE_wear(itemstack, meta.charge, max_charge[1]) |
eac484
|
344 |
end |
S |
345 |
return itemstack |
e23f87
|
346 |
end, |
R |
347 |
}) |
|
348 |
|
|
349 |
minetest.register_tool("technic:mining_drill_mk2", { |
f90915
|
350 |
description = S("Mining Drill Mk%d"):format(2), |
e23f87
|
351 |
inventory_image = "technic_mining_drill_mk2.png", |
R |
352 |
on_use = function(itemstack, user, pointed_thing) |
eac484
|
353 |
mining_drill_mk2_handler(itemstack, user, pointed_thing) |
S |
354 |
return itemstack |
e23f87
|
355 |
end, |
R |
356 |
}) |
ee0765
|
357 |
|
e748af
|
358 |
technic.register_power_tool("technic:mining_drill_mk2", max_charge[2]) |
e23f87
|
359 |
|
eac484
|
360 |
for i = 1, 4 do |
e748af
|
361 |
technic.register_power_tool("technic:mining_drill_mk2_"..i, max_charge[2]) |
ee0765
|
362 |
minetest.register_tool("technic:mining_drill_mk2_"..i, { |
be2f30
|
363 |
description = S("Mining Drill Mk%d Mode %d"):format(2, i), |
ee0765
|
364 |
inventory_image = "technic_mining_drill_mk2.png^technic_tool_mode"..i..".png", |
S |
365 |
wield_image = "technic_mining_drill_mk2.png", |
|
366 |
groups = {not_in_creative_inventory=1}, |
|
367 |
on_use = function(itemstack, user, pointed_thing) |
|
368 |
mining_drill_mk2_handler(itemstack, user, pointed_thing) |
|
369 |
return itemstack |
|
370 |
end, |
|
371 |
}) |
e23f87
|
372 |
end |
R |
373 |
|
|
374 |
minetest.register_tool("technic:mining_drill_mk3", { |
f90915
|
375 |
description = S("Mining Drill Mk%d"):format(3), |
e23f87
|
376 |
inventory_image = "technic_mining_drill_mk3.png", |
R |
377 |
on_use = function(itemstack, user, pointed_thing) |
|
378 |
mining_drill_mk3_handler(itemstack,user,pointed_thing) |
|
379 |
return itemstack |
|
380 |
end, |
|
381 |
}) |
ee0765
|
382 |
|
e748af
|
383 |
technic.register_power_tool("technic:mining_drill_mk3", max_charge[3]) |
e23f87
|
384 |
|
R |
385 |
for i=1,5,1 do |
e748af
|
386 |
technic.register_power_tool("technic:mining_drill_mk3_"..i, max_charge[3]) |
ee0765
|
387 |
minetest.register_tool("technic:mining_drill_mk3_"..i, { |
be2f30
|
388 |
description = S("Mining Drill Mk%d Mode %d"):format(3, i), |
ee0765
|
389 |
inventory_image = "technic_mining_drill_mk3.png^technic_tool_mode"..i..".png", |
S |
390 |
wield_image = "technic_mining_drill_mk3.png", |
|
391 |
groups = {not_in_creative_inventory=1}, |
|
392 |
on_use = function(itemstack, user, pointed_thing) |
|
393 |
mining_drill_mk3_handler(itemstack,user,pointed_thing) |
|
394 |
return itemstack |
|
395 |
end, |
|
396 |
}) |
e23f87
|
397 |
end |