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