ShadowNinja
2013-12-17 5cf765b2f19ef9bf443178e26787fe16233b3f4c
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
be2f30 8 local S = technic.getter
S 9
82cba9 10 minetest.register_craft({
R 11     output = 'technic:mining_drill',
12     recipe = {
eac484 13         {'technic:stainless_steel_ingot', 'technic:diamond_drill_head', 'technic:stainless_steel_ingot'},
S 14         {'technic:stainless_steel_ingot', 'technic:motor',              'technic:stainless_steel_ingot'},
15         {'',                              'technic:red_energy_crystal', 'moreores:copper_ingot'},
82cba9 16     }
R 17 })
e23f87 18 minetest.register_craft({
R 19     output = 'technic:mining_drill_mk2',
20     recipe = {
eac484 21         {'technic:diamond_drill_head',    'technic:diamond_drill_head',   'technic:diamond_drill_head'},
S 22         {'technic:stainless_steel_ingot', 'technic:mining_drill',         'technic:stainless_steel_ingot'},
23         {'',                              'technic:green_energy_crystal', ''},
e23f87 24     }
R 25 })
26 minetest.register_craft({
27     output = 'technic:mining_drill_mk3',
28     recipe = {
eac484 29         {'technic:diamond_drill_head',    'technic:diamond_drill_head',  'technic:diamond_drill_head'},
S 30         {'technic:stainless_steel_ingot', 'technic:mining_drill_mk2',    'technic:stainless_steel_ingot'},
31         {'',                              'technic:blue_energy_crystal', ''},
e23f87 32     }
R 33 })
eac484 34 for i = 1, 4 do
ee0765 35     minetest.register_craft({
S 36         output = 'technic:mining_drill_mk3',
37         recipe = {
38             {'technic:diamond_drill_head',    'technic:diamond_drill_head',   'technic:diamond_drill_head'},
39             {'technic:stainless_steel_ingot', 'technic:mining_drill_mk2_'..i, 'technic:stainless_steel_ingot'},
40             {'',                              'technic:blue_energy_crystal',  ''},
41         }
42     })
91329b 43 end
82cba9 44
5cf765 45 local mining_drill_mode_text = {
S 46     {S("Single node.")},
47     {S("3 nodes deep.")},
48     {S("3 nodes wide.")},
49     {S("3 nodes tall.")},
50     {S("3x3 nodes.")},
51 }
52
53 local function drill_dig_it0 (pos,player)
54     local node=minetest.env:get_node(pos)
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
139
140 local function drill_dig_it(pos, player, drill_type, mode)
e23f87 141     local charge
eac484 142     if mode == 1 then
S 143         drill_dig_it0(pos, player)
e23f87 144     end
R 145     
eac484 146     if mode == 2 then -- 3 deep
S 147         dir = drill_dig_it1(player)
148         if dir == 0 then -- x+
149             drill_dig_it0(pos, player)
150             pos.x = pos.x + 1
151             drill_dig_it0(pos, player)
152             pos.x = pos.x + 1
153             drill_dig_it0(pos, player)
e23f87 154         end
eac484 155         if dir == 1 then  -- x-
S 156             drill_dig_it0(pos, player)
e23f87 157             pos.x=pos.x-1
R 158             drill_dig_it0 (pos,player)
159             pos.x=pos.x-1
160             drill_dig_it0 (pos,player)
161         end
162         if dir==2 then  -- z+
163             drill_dig_it0 (pos,player)
164             pos.z=pos.z+1
165             drill_dig_it0 (pos,player)
166             pos.z=pos.z+1
167             drill_dig_it0 (pos,player)
168         end
169         if dir==3 then  -- z-
170             drill_dig_it0 (pos,player)
171             pos.z=pos.z+1
172             drill_dig_it0 (pos,player)
173             pos.z=pos.z+1
174             drill_dig_it0 (pos,player)
175         end
176     end
177     
178     if mode==3 then -- 3 wide
179         dir=drill_dig_it1(player)
180         if dir==0 or dir==1 then -- x
181             drill_dig_it0 (pos,player)
182             pos.z=pos.z+1
183             drill_dig_it0 (pos,player)
184             pos.z=pos.z-2
185             drill_dig_it0 (pos,player)
186         end
187         if dir==2 or dir==3 then  -- z
188             drill_dig_it0 (pos,player)
189             pos.x=pos.x+1
190             drill_dig_it0 (pos,player)
191             pos.x=pos.x-2
192             drill_dig_it0 (pos,player)
193         end
194     end
195     
196     if mode==4 then -- 3 tall, selected in the middle
197         drill_dig_it0 (pos,player)
5cf765 198         pos.y=pos.y-1
e23f87 199         drill_dig_it0 (pos,player)
5cf765 200         pos.y=pos.y-1
e23f87 201         drill_dig_it0 (pos,player)
R 202     end
82cba9 203
e23f87 204     if mode==5 then -- 3 x 3
R 205         local dir=player:get_look_dir()
206         if math.abs(dir.y)<0.5 then
207             dir=drill_dig_it1(player)
208                 if dir==0 or dir==1 then -- x
209                     drill_dig_it2(pos,player)
210                 end
211                 if dir==2 or dir==3 then  -- z
212                     drill_dig_it3(pos,player)
213                 end
214         else
215         drill_dig_it4(pos,player)
216         end
217     end
218     
219     if drill_type==1 then charge=mining_drill_power_usage end
220     if drill_type==2 then 
221         if  mode==1 then charge=mining_drill_mk2_power_usage end
222         if (mode==2 or mode==3 or mode==4) then charge=mining_drill_mk2_power_usage*3 end
223     end
224     if drill_type==3 then 
225         if  mode==1 then charge=mining_drill_power_usage end
226         if (mode==2 or mode==3 or mode==4) then charge=mining_drill_mk2_power_usage*6 end
227         if mode==5 then charge=mining_drill_mk2_power_usage*9 end
228     end
229     minetest.sound_play("mining_drill", {pos = pos, gain = 1.0, max_hear_distance = 10,})
230     return charge
231 end
82cba9 232
5cf765 233 local function mining_drill_mk2_setmode(user,itemstack)
S 234     local player_name=user:get_player_name()
235     local item=itemstack:to_table()
236     local meta=minetest.deserialize(item["metadata"])
237     if meta==nil then
238         meta={}
239         mode=0
e23f87 240     end
5cf765 241     if meta["mode"]==nil then
S 242         minetest.chat_send_player(player_name, S("Hold shift and use to change Mining Drill Mk%d modes."):format(2))
243         meta["mode"]=0
244         mode=0
245     end
246     mode=(meta["mode"])
247     mode=mode+1
248     if mode>=5 then mode=1 end
249     minetest.chat_send_player(player_name, S("Mining Drill Mk%d Mode %d"):format(2, mode)..": "..mining_drill_mode_text[mode][1])
250     item["name"]="technic:mining_drill_mk2_"..mode
251     meta["mode"]=mode
252     item["metadata"]=minetest.serialize(meta)
253     itemstack:replace(item)
254     return itemstack
e23f87 255 end
R 256
5cf765 257 local function mining_drill_mk3_setmode(user,itemstack)
S 258     local player_name=user:get_player_name()
259     local item=itemstack:to_table()
260     local meta=minetest.deserialize(item["metadata"])
261     if meta==nil then
262         meta={}
263         mode=0
264     end
265     if meta["mode"]==nil then
266         minetest.chat_send_player(player_name, S("Hold shift and use to change Mining Drill Mk%d modes."):format(3))
267         meta["mode"]=0
268         mode=0
269     end
270     mode=(meta["mode"])
271     mode=mode+1
272     if mode>=6 then mode=1 end
273     minetest.chat_send_player(player_name, S("Mining Drill Mk%d Mode %d"):format(3, mode)..": "..mining_drill_mode_text[mode][1])
274     item["name"]="technic:mining_drill_mk3_"..mode
275     meta["mode"]=mode
276     item["metadata"]=minetest.serialize(meta)
277     itemstack:replace(item)
278     return itemstack
e23f87 279 end
R 280
5cf765 281
S 282 local function mining_drill_mk2_handler(itemstack, user, pointed_thing)
283     local keys = user:get_player_control()
284     local player_name = user:get_player_name()
285     local meta = minetest.deserialize(itemstack:get_metadata())
286     if not meta or not meta.mode or keys.sneak then
287         return mining_drill_mk2_setmode(user, itemstack)
288     end
289     if pointed_thing.type ~= "node" or not meta.charge then
290         return
291     end
292     if meta.charge - mining_drill_power_usage > 0 then
293         local pos = minetest.get_pointed_thing_position(pointed_thing, above)
294         local charge_to_take = drill_dig_it(pos, user, 2, meta.mode)
295         meta.charge = meta.charge - charge_to_take
296         meta.charge = math.max(meta.charge, 0)
297         itemstack:set_metadata(minetest.serialize(meta))
298         technic.set_RE_wear(itemstack, meta.charge, mining_drill_mk2_max_charge)
299     end
300     return itemstack
301 end
302
303 local function mining_drill_mk3_handler(itemstack, user, pointed_thing)
304     local keys = user:get_player_control()
305     local player_name = user:get_player_name()
306     local meta = minetest.deserialize(itemstack:get_metadata())
307     if not meta or not meta.mode or keys.sneak then
308         return mining_drill_mk3_setmode(user, itemstack)
309     end
310     if pointed_thing.type ~= "node" or not meta.charge then
311         return
312     end
313     if meta.charge - mining_drill_power_usage > 0 then
314         local pos = minetest.get_pointed_thing_position(pointed_thing, above)
315         local charge_to_take = drill_dig_it(pos, user, 3, meta.mode)
316         meta.charge = meta.charge - charge_to_take
317         meta.charge = math.max(meta.charge, 0)
318         itemstack:set_metadata(minetest.serialize(meta))
319         technic.set_RE_wear(itemstack, meta.charge, mining_drill_mk3_max_charge)
320     end
321     return itemstack
e23f87 322 end
R 323
ee0765 324 technic.register_power_tool("technic:mining_drill", mining_drill_max_charge)
5cf765 325
e23f87 326 minetest.register_tool("technic:mining_drill", {
f90915 327     description = S("Mining Drill Mk%d"):format(1),
e23f87 328     inventory_image = "technic_mining_drill.png",
R 329     stack_max = 1,
330     on_use = function(itemstack, user, pointed_thing)
eac484 331         if pointed_thing.type ~= "node" then
S 332             return itemstack
e23f87 333         end
5cf765 334         local meta = minetest.deserialize(itemstack:get_metadata())
eac484 335         if not meta or not meta.charge then
S 336             return
337         end
338         if meta.charge - mining_drill_power_usage > 0 then
339             local pos = minetest.get_pointed_thing_position(pointed_thing, above)
340             charge_to_take = drill_dig_it(pos, user, 1, 1)
341             meta.charge = meta.charge - mining_drill_power_usage
5cf765 342             itemstack:set_metadata(minetest.serialize(meta))
eac484 343             technic.set_RE_wear(itemstack, meta.charge, mining_drill_max_charge)
S 344         end
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
S 358 technic.register_power_tool("technic:mining_drill_mk2", mining_drill_mk2_max_charge)
e23f87 359
eac484 360 for i = 1, 4 do
ee0765 361     technic.register_power_tool("technic:mining_drill_mk2_"..i, mining_drill_mk2_max_charge)
S 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
S 383 technic.register_power_tool("technic:mining_drill_mk3", mining_drill_mk3_max_charge)
e23f87 384
R 385 for i=1,5,1 do
ee0765 386     technic.register_power_tool("technic:mining_drill_mk3_"..i, mining_drill_mk3_max_charge)
S 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