Skip to content

Commit f013d2d

Browse files
HybridDogSmallJoker
authored andcommitted
Mining laser fixes (#421)
Do not remove air and group:hot nodes instead of using a fixed list Abort mining when encountering an unknown node Add random to the smoke puff particle Set mining laser tool range to 0
1 parent 80c6a14 commit f013d2d

File tree

1 file changed

+47
-37
lines changed

1 file changed

+47
-37
lines changed

technic/tools/mining_lasers.lua

Lines changed: 47 additions & 37 deletions
Original file line numberDiff line numberDiff line change
@@ -4,43 +4,43 @@ local mining_lasers_list = {
44
{"2", 14, 200000, 2000},
55
{"3", 21, 650000, 3000},
66
}
7+
local allow_entire_discharging = true
78

89
local S = technic.getter
910

1011
minetest.register_craft({
11-
output = 'technic:laser_mk1',
12+
output = "technic:laser_mk1",
1213
recipe = {
13-
{'default:diamond', 'technic:brass_ingot', 'default:obsidian_glass'},
14-
{'', 'technic:brass_ingot', 'technic:red_energy_crystal'},
15-
{'', '', 'default:copper_ingot'},
14+
{"default:diamond", "technic:brass_ingot", "default:obsidian_glass"},
15+
{"", "technic:brass_ingot", "technic:red_energy_crystal"},
16+
{"", "", "default:copper_ingot"},
1617
}
1718
})
1819
minetest.register_craft({
19-
output = 'technic:laser_mk2',
20+
output = "technic:laser_mk2",
2021
recipe = {
21-
{'default:diamond', 'technic:carbon_steel_ingot', 'technic:laser_mk1'},
22-
{'', 'technic:carbon_steel_ingot', 'technic:green_energy_crystal'},
23-
{'', '', 'default:copper_ingot'},
22+
{"default:diamond", "technic:carbon_steel_ingot", "technic:laser_mk1"},
23+
{"", "technic:carbon_steel_ingot", "technic:green_energy_crystal"},
24+
{"", "", "default:copper_ingot"},
2425
}
2526
})
2627
minetest.register_craft({
27-
output = 'technic:laser_mk3',
28+
output = "technic:laser_mk3",
2829
recipe = {
29-
{'default:diamond', 'technic:carbon_steel_ingot', 'technic:laser_mk2'},
30-
{'', 'technic:carbon_steel_ingot', 'technic:blue_energy_crystal'},
31-
{'', '', 'default:copper_ingot'},
30+
{"default:diamond", "technic:carbon_steel_ingot", "technic:laser_mk2"},
31+
{"", "technic:carbon_steel_ingot", "technic:blue_energy_crystal"},
32+
{"", "", "default:copper_ingot"},
3233
}
3334
})
3435

3536
local function laser_node(pos, node, player)
3637
local def = minetest.registered_nodes[node.name]
37-
if def and def.liquidtype ~= "none" then
38+
if def.liquidtype ~= "none" and def.buildable_to then
3839
minetest.remove_node(pos)
3940
minetest.add_particle({
4041
pos = pos,
41-
velocity = {x=0, y=2, z=0},
42-
acceleration = {x=0, y=-1, z=0},
43-
expirationtime = 1.5,
42+
velocity = {x = 0, y = 1.5 + math.random(), z = 0},
43+
acceleration = {x = 0, y = -1, z = 0},
4444
size = 6 + math.random() * 2,
4545
texture = "smoke_puff.png^[transform" .. math.random(0, 7),
4646
})
@@ -49,24 +49,28 @@ local function laser_node(pos, node, player)
4949
minetest.node_dig(pos, node, player)
5050
end
5151

52-
local no_destroy = {
53-
["air"] = true,
54-
["default:lava_source"] = true,
55-
["default:lava_flowing"] = true,
56-
}
52+
local keep_node = {air = true}
53+
local function can_keep_node(name)
54+
if keep_node[name] ~= nil then
55+
return keep_node[name]
56+
end
57+
keep_node[name] = minetest.get_item_group(name, "hot") ~= 0
58+
return keep_node[name]
59+
end
60+
5761
local function laser_shoot(player, range, particle_texture, sound)
5862
local player_pos = player:getpos()
5963
local player_name = player:get_player_name()
6064
local dir = player:get_look_dir()
6165

6266
local start_pos = vector.new(player_pos)
6367
-- Adjust to head height
64-
start_pos.y = start_pos.y + 1.6
68+
start_pos.y = start_pos.y + (player:get_properties().eye_height or 1.625)
6569
minetest.add_particle({
66-
pos = startpos,
70+
pos = start_pos,
6771
velocity = dir,
6872
acceleration = vector.multiply(dir, 50),
69-
expirationtime = range / 11,
73+
expirationtime = (math.sqrt(1 + 100 * (range + 0.4)) - 1) / 50,
7074
size = 1,
7175
texture = particle_texture .. "^[transform" .. math.random(0, 7),
7276
})
@@ -76,42 +80,48 @@ local function laser_shoot(player, range, particle_texture, sound)
7680
minetest.record_protection_violation(pos, player_name)
7781
break
7882
end
79-
local node = minetest.get_node_or_nil(pos)
80-
if not node then
83+
local node = minetest.get_node(pos)
84+
if node.name == "ignore"
85+
or not minetest.registered_nodes[node.name] then
8186
break
8287
end
83-
if not no_destroy[node.name] then
88+
if not can_keep_node(node.name) then
8489
laser_node(pos, node, player)
8590
end
8691
end
8792
end
8893

89-
9094
for _, m in pairs(mining_lasers_list) do
9195
technic.register_power_tool("technic:laser_mk"..m[1], m[3])
9296
minetest.register_tool("technic:laser_mk"..m[1], {
9397
description = S("Mining Laser Mk%d"):format(m[1]),
9498
inventory_image = "technic_mining_laser_mk"..m[1]..".png",
99+
range = 0,
95100
stack_max = 1,
96101
wear_represents = "technic_RE_charge",
97102
on_refill = technic.refill_RE_charge,
98103
on_use = function(itemstack, user)
99104
local meta = minetest.deserialize(itemstack:get_metadata())
100-
if not meta or not meta.charge then
105+
if not meta or not meta.charge or meta.charge == 0 then
101106
return
102107
end
103108

104-
-- If there's enough charge left, fire the laser
105-
if meta.charge >= m[4] then
106-
laser_shoot(user, m[2], "technic_laser_beam_mk"..m[1]..".png", "technic_laser_mk"..m[1])
107-
if not technic.creative_mode then
108-
meta.charge = meta.charge - m[4]
109-
technic.set_RE_wear(itemstack, meta.charge, m[3])
110-
itemstack:set_metadata(minetest.serialize(meta))
109+
local range = m[2]
110+
if meta.charge < m[4] then
111+
if not allow_entire_discharging then
112+
return
111113
end
114+
-- If charge is too low, give the laser a shorter range
115+
range = range * meta.charge / m[4]
116+
end
117+
laser_shoot(user, range, "technic_laser_beam_mk" .. m[1] .. ".png",
118+
"technic_laser_mk" .. m[1])
119+
if not technic.creative_mode then
120+
meta.charge = math.max(meta.charge - m[4], 0)
121+
technic.set_RE_wear(itemstack, meta.charge, m[3])
122+
itemstack:set_metadata(minetest.serialize(meta))
112123
end
113124
return itemstack
114125
end,
115126
})
116127
end
117-

0 commit comments

Comments
 (0)