Skip to content

Commit

Permalink
Update radiation.lua
Browse files Browse the repository at this point in the history
Spaces bothered me.
  • Loading branch information
DustyDave961 authored Oct 15, 2024
1 parent cedccb4 commit 2309259
Showing 1 changed file with 43 additions and 43 deletions.
86 changes: 43 additions & 43 deletions technic/radiation.lua
Original file line number Diff line number Diff line change
Expand Up @@ -34,8 +34,8 @@ local cache_radiation_resistance = {}

-- Function to register node-specific resistance
function technic.register_rad_resistance(node_name, resistance)
rad_resistance_node[node_name] = resistance
cache_radiation_resistance[node_name] = nil -- Invalidate cache
rad_resistance_node[node_name] = resistance
cache_radiation_resistance[node_name] = nil -- Invalidate cache
end

local S = technic.getter
Expand Down Expand Up @@ -177,18 +177,18 @@ local node_resistances = {

-- Register all node resistances at once
for node_name, resistance in pairs(node_resistances) do
technic.register_rad_resistance(node_name, resistance)
technic.register_rad_resistance(node_name, resistance)
end

-- Function to register group-specific resistance
function technic.register_group_resistance(group_name, resistance)
rad_resistance_group[group_name] = resistance
-- Invalidate cache for all nodes in this group
for node_name, def in pairs(minetest.registered_nodes) do
if def.groups[group_name] then
cache_radiation_resistance[node_name] = nil
end
end
rad_resistance_group[group_name] = resistance
-- Invalidate cache for all nodes in this group
for node_name, def in pairs(minetest.registered_nodes) do
if def.groups[group_name] then
cache_radiation_resistance[node_name] = nil
end
end
end

technic.register_group_resistance("concrete", 16)
Expand All @@ -198,39 +198,39 @@ technic.register_group_resistance("wood", 1.7)

-- Function to calculate radiation resistance
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]
if not def then
cache_radiation_resistance[node_name] = 0
return 0
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
if resistance >= 0 then
resistance = rad_resistance_node[node_name] or 0
end

-- Add group-specific resistance if applicable
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
local resistance = cache_radiation_resistance[node_name]
if resistance then
return resistance
end
local def = minetest.registered_nodes[node_name]
if not def then
cache_radiation_resistance[node_name] = 0
return 0
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
if resistance >= 0 then
resistance = rad_resistance_node[node_name] or 0
end

-- Add group-specific resistance if applicable
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

--[[
Expand Down

0 comments on commit 2309259

Please sign in to comment.