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