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