mirror of
https://github.com/minetest-mods/technic.git
synced 2025-02-05 06:40:31 +01:00
Update radiation.lua
I guess we only need the rad_resistance group?
This commit is contained in:
parent
0cf8159a14
commit
a9e1351181
@ -28,14 +28,15 @@ or complex internal structure should show no radiation resistance.
|
|||||||
Fractional resistance values are permitted.
|
Fractional resistance values are permitted.
|
||||||
--]]
|
--]]
|
||||||
|
|
||||||
local rad_resistance_node = {}
|
|
||||||
local rad_resistance_group = {}
|
|
||||||
local cache_radiation_resistance = {}
|
|
||||||
|
|
||||||
-- Function to register node-specific resistance
|
-- Function to register node-specific resistance
|
||||||
function technic.register_rad_resistance(node_name, resistance)
|
function technic.register_rad_resistance(node_name, resistance)
|
||||||
rad_resistance_node[node_name] = resistance
|
local node = minetest.registered_nodes[node_name]
|
||||||
cache_radiation_resistance[node_name] = nil -- Invalidate cache
|
if node then
|
||||||
|
if not node.groups then
|
||||||
|
node.groups = {}
|
||||||
|
end
|
||||||
|
node.groups.rad_resistance = resistance
|
||||||
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
local S = technic.getter
|
local S = technic.getter
|
||||||
@ -182,11 +183,11 @@ end
|
|||||||
|
|
||||||
-- Function to register group-specific resistance
|
-- Function to register group-specific resistance
|
||||||
function technic.register_group_resistance(group_name, resistance)
|
function technic.register_group_resistance(group_name, resistance)
|
||||||
rad_resistance_group[group_name] = resistance
|
for node_name, node_def in pairs(minetest.registered_nodes) do
|
||||||
-- Invalidate cache for all nodes in this group
|
if node_def.groups[group_name] then
|
||||||
for node_name, def in pairs(minetest.registered_nodes) do
|
if not node_def.groups.rad_resistance then
|
||||||
if def.groups[group_name] then
|
node_def.groups.rad_resistance = resistance
|
||||||
cache_radiation_resistance[node_name] = nil
|
end
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
@ -198,39 +199,18 @@ technic.register_group_resistance("wood", 1.7)
|
|||||||
|
|
||||||
-- Function to calculate radiation resistance
|
-- Function to calculate radiation resistance
|
||||||
local function node_radiation_resistance(node_name)
|
local function node_radiation_resistance(node_name)
|
||||||
local resistance = cache_radiation_resistance[node_name]
|
|
||||||
if resistance then
|
|
||||||
return resistance
|
|
||||||
end
|
|
||||||
local def = minetest.registered_nodes[node_name]
|
local def = minetest.registered_nodes[node_name]
|
||||||
if not def then
|
if not def then
|
||||||
cache_radiation_resistance[node_name] = 0
|
|
||||||
return 0
|
return 0
|
||||||
end
|
end
|
||||||
|
|
||||||
-- Check for rad_resistance group in node definition
|
|
||||||
resistance = 0
|
|
||||||
for g, v in pairs(def.groups) do
|
|
||||||
if g == "rad_resistance" then
|
|
||||||
resistance = resistance + v
|
|
||||||
end
|
|
||||||
end
|
|
||||||
|
|
||||||
-- If no rad_resistance group, use registered node-specific resistance
|
local resistance = 0
|
||||||
if resistance >= 0 then
|
-- Add rad_resistance group value if it exists
|
||||||
resistance = rad_resistance_node[node_name] or 0
|
if def.groups.rad_resistance then
|
||||||
|
resistance = resistance + def.groups.rad_resistance
|
||||||
end
|
end
|
||||||
|
|
||||||
-- Add group-specific resistance if applicable
|
return math.sqrt(resistance)
|
||||||
for g, v in pairs(def.groups) do
|
|
||||||
if v > 0 and rad_resistance_group[g] then
|
|
||||||
resistance = resistance + rad_resistance_group[g]
|
|
||||||
end
|
|
||||||
end
|
|
||||||
|
|
||||||
resistance = math.sqrt(resistance)
|
|
||||||
cache_radiation_resistance[node_name] = resistance
|
|
||||||
return resistance
|
|
||||||
end
|
end
|
||||||
|
|
||||||
--[[
|
--[[
|
||||||
|
Loading…
Reference in New Issue
Block a user