-
Notifications
You must be signed in to change notification settings - Fork 155
Radiation API #651
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: master
Are you sure you want to change the base?
Radiation API #651
Changes from 3 commits
3e9eb08
b9de49b
174ba17
268d7bc
930efcc
cedccb4
2309259
11f982a
0cf8159
a9e1351
9eb7d0e
8ad1f58
5b8e7fb
60b22e3
f9026bf
af6ab28
cf01860
feb853c
28a9068
4a5537f
225d7df
23905d3
ae99b1d
e3e007a
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -28,9 +28,26 @@ or complex internal structure should show no radiation resistance. | |
Fractional resistance values are permitted. | ||
--]] | ||
|
||
local rad_resistance_node = {} | ||
local rad_resistance_group = {} | ||
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 | ||
end | ||
|
||
-- Function to register multiple node resistances at once | ||
function technic.register_multiple_resistances(resistances) | ||
for node_name, resistance in pairs(resistances) do | ||
technic.register_rad_resistance(node_name, resistance) | ||
end | ||
end | ||
DustyDave961 marked this conversation as resolved.
Show resolved
Hide resolved
|
||
|
||
local S = technic.getter | ||
|
||
local rad_resistance_node = { | ||
local node_resistances = { | ||
["default:brick"] = 13, | ||
["default:bronzeblock"] = 45, | ||
["default:clay"] = 15, | ||
|
@@ -154,7 +171,6 @@ local rad_resistance_node = { | |
["technic:corium_flowing"] = 40, | ||
["technic:corium_source"] = 80, | ||
["technic:granite"] = 18, | ||
["technic:lead_block"] = 80, | ||
["technic:marble"] = 18, | ||
["technic:marble_bricks"] = 18, | ||
["technic:mineral_chromium"] = 19, | ||
|
@@ -165,38 +181,62 @@ local rad_resistance_node = { | |
["tnt:tnt"] = 11, | ||
["tnt:tnt_burning"] = 11, | ||
} | ||
local rad_resistance_group = { | ||
concrete = 16, | ||
tree = 3.4, | ||
uranium_block = 500, | ||
wood = 1.7, | ||
} | ||
local cache_radiation_resistance = {} | ||
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] | ||
if not def then | ||
cache_radiation_resistance[node_name] = 0 | ||
return 0 | ||
end | ||
resistance = def.radiation_resistance or | ||
rad_resistance_node[node_name] | ||
if not resistance then | ||
resistance = 0 | ||
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 | ||
end | ||
resistance = math.sqrt(resistance) | ||
cache_radiation_resistance[node_name] = resistance | ||
return resistance | ||
|
||
-- Register all node resistances at once | ||
technic.register_multiple_resistances(node_resistances) | ||
|
||
-- 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 | ||
end | ||
|
||
technic.register_group_resistance("concrete", 16) | ||
technic.register_group_resistance("tree", 3.4) | ||
technic.register_group_resistance("uranium_block", 500) | ||
technic.register_group_resistance("wood", 1.7) | ||
Comment on lines
+183
to
+186
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Unfortunately this only works on nodes that are already registered when
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I found such functions in the Minetest lua api, but I'm unsure how to use the Edit: @DustyBagel has informed me that function is not backwards compatible with certain versions of Minetest. I don't think it's a big deal, but should we consider the There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
Here's what I would do: loop through Changelog If functions are not mentioned in the changelog, you might as well have a look at the git blame of the |
||
|
||
-- Function to calculate radiation resistance | ||
function node_radiation_resistance(node_name) | ||
DustyDave961 marked this conversation as resolved.
Show resolved
Hide resolved
|
||
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 | ||
DustyDave961 marked this conversation as resolved.
Show resolved
Hide resolved
|
||
|
||
-- If no rad_resistance group, use registered node-specific resistance | ||
if resistance == 0 then | ||
DustyDave961 marked this conversation as resolved.
Show resolved
Hide resolved
|
||
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 | ||
|
||
--[[ | ||
Radioactive nodes cause damage to nearby players. The damage | ||
|
Uh oh!
There was an error while loading. Please reload this page.