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
This commit is contained in:
HybridDog 2018-07-21 19:10:32 +02:00 committed by SmallJoker
parent 80c6a14566
commit f013d2dd1f

@ -4,43 +4,43 @@ local mining_lasers_list = {
{"2", 14, 200000, 2000}, {"2", 14, 200000, 2000},
{"3", 21, 650000, 3000}, {"3", 21, 650000, 3000},
} }
local allow_entire_discharging = true
local S = technic.getter local S = technic.getter
minetest.register_craft({ minetest.register_craft({
output = 'technic:laser_mk1', output = "technic:laser_mk1",
recipe = { recipe = {
{'default:diamond', 'technic:brass_ingot', 'default:obsidian_glass'}, {"default:diamond", "technic:brass_ingot", "default:obsidian_glass"},
{'', 'technic:brass_ingot', 'technic:red_energy_crystal'}, {"", "technic:brass_ingot", "technic:red_energy_crystal"},
{'', '', 'default:copper_ingot'}, {"", "", "default:copper_ingot"},
} }
}) })
minetest.register_craft({ minetest.register_craft({
output = 'technic:laser_mk2', output = "technic:laser_mk2",
recipe = { recipe = {
{'default:diamond', 'technic:carbon_steel_ingot', 'technic:laser_mk1'}, {"default:diamond", "technic:carbon_steel_ingot", "technic:laser_mk1"},
{'', 'technic:carbon_steel_ingot', 'technic:green_energy_crystal'}, {"", "technic:carbon_steel_ingot", "technic:green_energy_crystal"},
{'', '', 'default:copper_ingot'}, {"", "", "default:copper_ingot"},
} }
}) })
minetest.register_craft({ minetest.register_craft({
output = 'technic:laser_mk3', output = "technic:laser_mk3",
recipe = { recipe = {
{'default:diamond', 'technic:carbon_steel_ingot', 'technic:laser_mk2'}, {"default:diamond", "technic:carbon_steel_ingot", "technic:laser_mk2"},
{'', 'technic:carbon_steel_ingot', 'technic:blue_energy_crystal'}, {"", "technic:carbon_steel_ingot", "technic:blue_energy_crystal"},
{'', '', 'default:copper_ingot'}, {"", "", "default:copper_ingot"},
} }
}) })
local function laser_node(pos, node, player) local function laser_node(pos, node, player)
local def = minetest.registered_nodes[node.name] local def = minetest.registered_nodes[node.name]
if def and def.liquidtype ~= "none" then if def.liquidtype ~= "none" and def.buildable_to then
minetest.remove_node(pos) minetest.remove_node(pos)
minetest.add_particle({ minetest.add_particle({
pos = pos, pos = pos,
velocity = {x=0, y=2, z=0}, velocity = {x = 0, y = 1.5 + math.random(), z = 0},
acceleration = {x=0, y=-1, z=0}, acceleration = {x = 0, y = -1, z = 0},
expirationtime = 1.5,
size = 6 + math.random() * 2, size = 6 + math.random() * 2,
texture = "smoke_puff.png^[transform" .. math.random(0, 7), texture = "smoke_puff.png^[transform" .. math.random(0, 7),
}) })
@ -49,11 +49,15 @@ local function laser_node(pos, node, player)
minetest.node_dig(pos, node, player) minetest.node_dig(pos, node, player)
end end
local no_destroy = { local keep_node = {air = true}
["air"] = true, local function can_keep_node(name)
["default:lava_source"] = true, if keep_node[name] ~= nil then
["default:lava_flowing"] = true, return keep_node[name]
} end
keep_node[name] = minetest.get_item_group(name, "hot") ~= 0
return keep_node[name]
end
local function laser_shoot(player, range, particle_texture, sound) local function laser_shoot(player, range, particle_texture, sound)
local player_pos = player:getpos() local player_pos = player:getpos()
local player_name = player:get_player_name() local player_name = player:get_player_name()
@ -61,12 +65,12 @@ local function laser_shoot(player, range, particle_texture, sound)
local start_pos = vector.new(player_pos) local start_pos = vector.new(player_pos)
-- Adjust to head height -- Adjust to head height
start_pos.y = start_pos.y + 1.6 start_pos.y = start_pos.y + (player:get_properties().eye_height or 1.625)
minetest.add_particle({ minetest.add_particle({
pos = startpos, pos = start_pos,
velocity = dir, velocity = dir,
acceleration = vector.multiply(dir, 50), acceleration = vector.multiply(dir, 50),
expirationtime = range / 11, expirationtime = (math.sqrt(1 + 100 * (range + 0.4)) - 1) / 50,
size = 1, size = 1,
texture = particle_texture .. "^[transform" .. math.random(0, 7), texture = particle_texture .. "^[transform" .. math.random(0, 7),
}) })
@ -76,42 +80,48 @@ local function laser_shoot(player, range, particle_texture, sound)
minetest.record_protection_violation(pos, player_name) minetest.record_protection_violation(pos, player_name)
break break
end end
local node = minetest.get_node_or_nil(pos) local node = minetest.get_node(pos)
if not node then if node.name == "ignore"
or not minetest.registered_nodes[node.name] then
break break
end end
if not no_destroy[node.name] then if not can_keep_node(node.name) then
laser_node(pos, node, player) laser_node(pos, node, player)
end end
end end
end end
for _, m in pairs(mining_lasers_list) do for _, m in pairs(mining_lasers_list) do
technic.register_power_tool("technic:laser_mk"..m[1], m[3]) technic.register_power_tool("technic:laser_mk"..m[1], m[3])
minetest.register_tool("technic:laser_mk"..m[1], { minetest.register_tool("technic:laser_mk"..m[1], {
description = S("Mining Laser Mk%d"):format(m[1]), description = S("Mining Laser Mk%d"):format(m[1]),
inventory_image = "technic_mining_laser_mk"..m[1]..".png", inventory_image = "technic_mining_laser_mk"..m[1]..".png",
range = 0,
stack_max = 1, stack_max = 1,
wear_represents = "technic_RE_charge", wear_represents = "technic_RE_charge",
on_refill = technic.refill_RE_charge, on_refill = technic.refill_RE_charge,
on_use = function(itemstack, user) on_use = function(itemstack, user)
local meta = minetest.deserialize(itemstack:get_metadata()) local meta = minetest.deserialize(itemstack:get_metadata())
if not meta or not meta.charge then if not meta or not meta.charge or meta.charge == 0 then
return return
end end
-- If there's enough charge left, fire the laser local range = m[2]
if meta.charge >= m[4] then if meta.charge < m[4] then
laser_shoot(user, m[2], "technic_laser_beam_mk"..m[1]..".png", "technic_laser_mk"..m[1]) if not allow_entire_discharging then
if not technic.creative_mode then return
meta.charge = meta.charge - m[4]
technic.set_RE_wear(itemstack, meta.charge, m[3])
itemstack:set_metadata(minetest.serialize(meta))
end end
-- If charge is too low, give the laser a shorter range
range = range * meta.charge / m[4]
end
laser_shoot(user, range, "technic_laser_beam_mk" .. m[1] .. ".png",
"technic_laser_mk" .. m[1])
if not technic.creative_mode then
meta.charge = math.max(meta.charge - m[4], 0)
technic.set_RE_wear(itemstack, meta.charge, m[3])
itemstack:set_metadata(minetest.serialize(meta))
end end
return itemstack return itemstack
end, end,
}) })
end end