-
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 all 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,20 @@ or complex internal structure should show no radiation resistance. | |
Fractional resistance values are permitted. | ||
--]] | ||
|
||
-- Function to register node-specific resistance | ||
function technic.register_rad_resistance(node_name, resistance) | ||
local node = minetest.registered_nodes[node_name] | ||
if node then | ||
if not node.groups then | ||
node.groups = {} | ||
end | ||
node.groups.rad_resistant = resistance | ||
end | ||
end | ||
|
||
local S = technic.getter | ||
|
||
local rad_resistance_node = { | ||
local node_resistances = { | ||
["default:brick"] = 13, | ||
["default:bronzeblock"] = 45, | ||
["default:clay"] = 15, | ||
|
@@ -147,56 +158,56 @@ local rad_resistance_node = { | |
["moreores:silver_block"] = 53, | ||
["snow:snow_brick"] = 2.8, | ||
["basic_materials:brass_block"] = 43, | ||
["technic:carbon_steel_block"] = 40, | ||
["technic:cast_iron_block"] = 40, | ||
["technic:chernobylite_block"] = 40, | ||
["technic:chromium_block"] = 37, | ||
["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, | ||
["technic:mineral_uranium"] = 71, | ||
["technic:mineral_zinc"] = 19, | ||
["technic:stainless_steel_block"] = 40, | ||
["technic:zinc_block"] = 36, | ||
["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] | ||
|
||
-- Register all node resistances at once | ||
for node_name, resistance in pairs(node_resistances) do | ||
technic.register_rad_resistance(node_name, resistance) | ||
end | ||
|
||
-- Function to register group-specific resistance | ||
function technic.register_group_resistance(group_name, resistance) | ||
for node_name, node_def in pairs(minetest.registered_nodes) do | ||
if node_def.groups[group_name] then | ||
if not node_def.groups.rad_resistant then | ||
node_def.groups.rad_resistant = resistance | ||
end | ||
end | ||
end | ||
resistance = math.sqrt(resistance) | ||
cache_radiation_resistance[node_name] = resistance | ||
return resistance | ||
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 |
||
|
||
--Radiation resistances cache | ||
technic.resistance_cache = {} | ||
|
||
function technic.cache_resistances() | ||
for node_name, node_def in pairs(minetest.registered_nodes) do | ||
local resistance = 0 | ||
if node_def.groups and node_def.groups.rad_resistant then | ||
resistance = node_def.groups.rad_resistant | ||
end | ||
technic.resistance_cache[node_name] = resistance | ||
end | ||
end | ||
|
||
local function node_radiation_resistance(node_name) | ||
technic.cache_resistances() | ||
|
||
local cached_resistance = technic.resistance_cache[node_name] | ||
if cached_resistance then | ||
return math.sqrt(cached_resistance) | ||
else | ||
return 0 | ||
end | ||
end | ||
|
||
--[[ | ||
Radioactive nodes cause damage to nearby players. The damage | ||
|
@@ -456,7 +467,7 @@ minetest.register_node("technic:chernobylite_block", { | |
description = S("Chernobylite Block"), | ||
tiles = {"technic_chernobylite_block.png"}, | ||
is_ground_content = true, | ||
groups = {cracky=1, radioactive=4, level=2}, | ||
groups = {cracky=1, radioactive=4, level=2, rad_resistant=40}, | ||
sounds = default.node_sound_stone_defaults(), | ||
light_source = 2, | ||
}) | ||
|
Uh oh!
There was an error while loading. Please reload this page.