Vanessa Ezekowitz
2017-03-06 05dfc14fdb487857052524e7324d2f2f278e9976
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     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
c39498 232 local function pos_is_pointable(pos)
a41390 233     local node = minetest.get_node(pos)
c39498 234     local nodedef = minetest.registered_nodes[node.name]
Z 235     return nodedef and nodedef.pointable
236 end
237
5cf765 238 local function mining_drill_mk2_setmode(user,itemstack)
S 239     local player_name=user:get_player_name()
240     local item=itemstack:to_table()
241     local meta=minetest.deserialize(item["metadata"])
242     if meta==nil then
243         meta={}
244         mode=0
e23f87 245     end
5cf765 246     if meta["mode"]==nil then
04c6f5 247         minetest.chat_send_player(player_name, S("Use while sneaking to change Mining Drill Mk%d modes."):format(2))
5cf765 248         meta["mode"]=0
S 249         mode=0
250     end
251     mode=(meta["mode"])
252     mode=mode+1
253     if mode>=5 then mode=1 end
254     minetest.chat_send_player(player_name, S("Mining Drill Mk%d Mode %d"):format(2, mode)..": "..mining_drill_mode_text[mode][1])
1765c3 255     itemstack:set_name("technic:mining_drill_mk2_"..mode);
5cf765 256     meta["mode"]=mode
11610c 257     itemstack:set_metadata(minetest.serialize(meta))
5cf765 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
04c6f5 270         minetest.chat_send_player(player_name, S("Use while sneaking to change Mining Drill Mk%d modes."):format(3))
5cf765 271         meta["mode"]=0
S 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])
1765c3 278     itemstack:set_name("technic:mining_drill_mk3_"..mode);
5cf765 279     meta["mode"]=mode
11610c 280     itemstack:set_metadata(minetest.serialize(meta))
5cf765 281     return itemstack
e23f87 282 end
R 283
5cf765 284
S 285 local function mining_drill_mk2_handler(itemstack, user, pointed_thing)
286     local keys = user:get_player_control()
287     local player_name = user:get_player_name()
288     local meta = minetest.deserialize(itemstack:get_metadata())
289     if not meta or not meta.mode or keys.sneak then
290         return mining_drill_mk2_setmode(user, itemstack)
291     end
c39498 292     if pointed_thing.type ~= "node" or not pos_is_pointable(pointed_thing.under) or not meta.charge then
5cf765 293         return
S 294     end
e748af 295     local charge_to_take = cost_to_use(2, meta.mode)
Z 296     if meta.charge >= charge_to_take then
7890ff 297         local pos = minetest.get_pointed_thing_position(pointed_thing, false)
e748af 298         drill_dig_it(pos, user, meta.mode)
b8c902 299         if not technic.creative_mode then
M 300             meta.charge = meta.charge - charge_to_take
301             itemstack:set_metadata(minetest.serialize(meta))
302             technic.set_RE_wear(itemstack, meta.charge, max_charge[2])
303         end
5cf765 304     end
S 305     return itemstack
306 end
307
308 local function mining_drill_mk3_handler(itemstack, user, pointed_thing)
309     local keys = user:get_player_control()
310     local player_name = user:get_player_name()
311     local meta = minetest.deserialize(itemstack:get_metadata())
312     if not meta or not meta.mode or keys.sneak then
313         return mining_drill_mk3_setmode(user, itemstack)
314     end
c39498 315     if pointed_thing.type ~= "node" or not pos_is_pointable(pointed_thing.under) or not meta.charge then
5cf765 316         return
S 317     end
e748af 318     local charge_to_take = cost_to_use(3, meta.mode)
Z 319     if meta.charge >= charge_to_take then
7890ff 320         local pos = minetest.get_pointed_thing_position(pointed_thing, false)
e748af 321         drill_dig_it(pos, user, meta.mode)
b8c902 322         if not technic.creative_mode then
M 323             meta.charge = meta.charge - charge_to_take
324             itemstack:set_metadata(minetest.serialize(meta))
325             technic.set_RE_wear(itemstack, meta.charge, max_charge[3])
326         end
5cf765 327     end
S 328     return itemstack
e23f87 329 end
R 330
e748af 331 technic.register_power_tool("technic:mining_drill", max_charge[1])
5cf765 332
e23f87 333 minetest.register_tool("technic:mining_drill", {
f90915 334     description = S("Mining Drill Mk%d"):format(1),
e23f87 335     inventory_image = "technic_mining_drill.png",
R 336     stack_max = 1,
99fd5d 337     wear_represents = "technic_RE_charge",
00d7c9 338     on_refill = technic.refill_RE_charge,
e23f87 339     on_use = function(itemstack, user, pointed_thing)
c39498 340         if pointed_thing.type ~= "node" or not pos_is_pointable(pointed_thing.under) then
eac484 341             return itemstack
e23f87 342         end
5cf765 343         local meta = minetest.deserialize(itemstack:get_metadata())
eac484 344         if not meta or not meta.charge then
S 345             return
346         end
e748af 347         local charge_to_take = cost_to_use(1, 1)
Z 348         if meta.charge >= charge_to_take then
7890ff 349             local pos = minetest.get_pointed_thing_position(pointed_thing, false)
e748af 350             drill_dig_it(pos, user, 1)
b8c902 351             if not technic.creative_mode then
M 352                 meta.charge = meta.charge - charge_to_take
353                 itemstack:set_metadata(minetest.serialize(meta))
354                 technic.set_RE_wear(itemstack, meta.charge, max_charge[1])
355             end
eac484 356         end
S 357         return itemstack
e23f87 358     end,
R 359 })
360
361 minetest.register_tool("technic:mining_drill_mk2", {
f90915 362     description = S("Mining Drill Mk%d"):format(2),
e23f87 363     inventory_image = "technic_mining_drill_mk2.png",
99fd5d 364     wear_represents = "technic_RE_charge",
00d7c9 365     on_refill = technic.refill_RE_charge,
e23f87 366     on_use = function(itemstack, user, pointed_thing)
eac484 367         mining_drill_mk2_handler(itemstack, user, pointed_thing)
S 368         return itemstack
e23f87 369     end,
R 370 })
ee0765 371
e748af 372 technic.register_power_tool("technic:mining_drill_mk2", max_charge[2])
e23f87 373
eac484 374 for i = 1, 4 do
e748af 375     technic.register_power_tool("technic:mining_drill_mk2_"..i, max_charge[2])
ee0765 376     minetest.register_tool("technic:mining_drill_mk2_"..i, {
be2f30 377         description = S("Mining Drill Mk%d Mode %d"):format(2, i),
ee0765 378         inventory_image = "technic_mining_drill_mk2.png^technic_tool_mode"..i..".png",
S 379         wield_image = "technic_mining_drill_mk2.png",
99fd5d 380         wear_represents = "technic_RE_charge",
00d7c9 381         on_refill = technic.refill_RE_charge,
ee0765 382         groups = {not_in_creative_inventory=1},
S 383         on_use = function(itemstack, user, pointed_thing)
384             mining_drill_mk2_handler(itemstack, user, pointed_thing)
385             return itemstack
386         end,
387     })
e23f87 388 end
R 389
390 minetest.register_tool("technic:mining_drill_mk3", {
f90915 391     description = S("Mining Drill Mk%d"):format(3),
e23f87 392     inventory_image = "technic_mining_drill_mk3.png",
99fd5d 393     wear_represents = "technic_RE_charge",
00d7c9 394     on_refill = technic.refill_RE_charge,
e23f87 395     on_use = function(itemstack, user, pointed_thing)
R 396     mining_drill_mk3_handler(itemstack,user,pointed_thing)
397     return itemstack
398     end,
399 })
ee0765 400
e748af 401 technic.register_power_tool("technic:mining_drill_mk3", max_charge[3])
e23f87 402
R 403 for i=1,5,1 do
e748af 404     technic.register_power_tool("technic:mining_drill_mk3_"..i, max_charge[3])
ee0765 405     minetest.register_tool("technic:mining_drill_mk3_"..i, {
be2f30 406         description = S("Mining Drill Mk%d Mode %d"):format(3, i),
ee0765 407         inventory_image = "technic_mining_drill_mk3.png^technic_tool_mode"..i..".png",
S 408         wield_image = "technic_mining_drill_mk3.png",
99fd5d 409         wear_represents = "technic_RE_charge",
00d7c9 410         on_refill = technic.refill_RE_charge,
ee0765 411         groups = {not_in_creative_inventory=1},
S 412         on_use = function(itemstack, user, pointed_thing)
413         mining_drill_mk3_handler(itemstack,user,pointed_thing)
414         return itemstack
415         end,
416     })
e23f87 417 end