mirror of
https://github.com/minetest-mods/technic.git
synced 2024-11-13 05:50:41 +01:00
allow mods to change damage taken by radiation
allow using technic's radiation resistance function and add resistance to lead (needs rework)
This commit is contained in:
parent
89168bacd4
commit
a5b5ef9818
|
@ -507,22 +507,31 @@ local default_radiation_resistance_per_group = {
|
|||
local cache_radiation_resistance = {}
|
||||
local function node_radiation_resistance(nodename)
|
||||
local eff = cache_radiation_resistance[nodename]
|
||||
if eff then return eff end
|
||||
if eff then
|
||||
return eff
|
||||
end
|
||||
local def = minetest.registered_nodes[nodename] or {groups={}}
|
||||
eff = def.radiation_resistance or default_radiation_resistance_per_node[nodename]
|
||||
if not eff then
|
||||
for g, v in pairs(def.groups) do
|
||||
if v > 0 and default_radiation_resistance_per_group[g] then
|
||||
if v > 0
|
||||
and default_radiation_resistance_per_group[g] then
|
||||
eff = default_radiation_resistance_per_group[g]
|
||||
break
|
||||
end
|
||||
end
|
||||
end
|
||||
if not eff then eff = 0 end
|
||||
if not eff then
|
||||
eff = 0
|
||||
end
|
||||
cache_radiation_resistance[nodename] = eff
|
||||
return eff
|
||||
end
|
||||
|
||||
function technic.get_node_radiation_resistance(...)
|
||||
return node_radiation_resistance(...)
|
||||
end
|
||||
|
||||
-- Radioactive nodes cause damage to nearby players. The damage
|
||||
-- effect depends on the intrinsic strength of the radiation source,
|
||||
-- the distance between the source and the player, and the shielding
|
||||
|
@ -575,6 +584,16 @@ local cache_scaled_shielding = {}
|
|||
local damage_enabled = minetest.setting_getbool("enable_damage")
|
||||
|
||||
if damage_enabled then
|
||||
local registered_on_radiation_damaging = {}
|
||||
function technic.register_on_radiation_damaging(func)
|
||||
registered_on_radiation_damaging[#registered_on_radiation_damaging+1] = func
|
||||
end
|
||||
--[[technic.register_on_radiation_damaging(function(dmg, player, pos, node, strength)
|
||||
return -- do nothing
|
||||
return dmg*2 -- change damage
|
||||
return false -- do not damage player
|
||||
end)]]
|
||||
|
||||
minetest.register_abm({
|
||||
nodenames = {"group:radioactive"},
|
||||
interval = 1,
|
||||
|
@ -609,11 +628,26 @@ if damage_enabled then
|
|||
dmg_int = dmg_int + 1
|
||||
end
|
||||
if dmg_int > 0 then
|
||||
for _,func in ipairs(registered_on_radiation_damaging) do
|
||||
local newdmg = func(dmg_int, o, pos, node, strength)
|
||||
if newdmg == false then
|
||||
dmg_int = 0
|
||||
break
|
||||
elseif newdmg then
|
||||
if newdmg <= 0 then
|
||||
dmg_int = 0
|
||||
break
|
||||
end
|
||||
dmg_int = newdmg
|
||||
end
|
||||
end
|
||||
if dmg_int ~= 0 then
|
||||
o:set_hp(math.max(o:get_hp() - dmg_int, 0))
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
||||
end,
|
||||
})
|
||||
end
|
||||
|
|
|
@ -99,7 +99,8 @@ minetest.register_node(":technic:lead_block", {
|
|||
tiles = { "technic_lead_block.png" },
|
||||
is_ground_content = true,
|
||||
groups = {cracky=1, level=2},
|
||||
sounds = default.node_sound_stone_defaults()
|
||||
sounds = default.node_sound_stone_defaults(),
|
||||
radiation_resistance = 500
|
||||
})
|
||||
|
||||
minetest.register_alias("technic:wrought_iron_block", "default:steelblock")
|
||||
|
|
Loading…
Reference in New Issue
Block a user