Skip to content

Commit

Permalink
Change existing detection mechanism. Relates to #1296 #1273
Browse files Browse the repository at this point in the history
  • Loading branch information
Doloment committed May 4, 2024
1 parent ac9630a commit 5bdd2f2
Show file tree
Hide file tree
Showing 2 changed files with 32 additions and 22 deletions.
35 changes: 26 additions & 9 deletions mods/lord/Blocks/lord_rocks/src/rocks/api.lua
Original file line number Diff line number Diff line change
Expand Up @@ -2,45 +2,62 @@ local S = minetest.get_translator("lord_rocks")

local rocks = {
--- @type table<string,NodeDefinition>|NodeDefinition[]
nodes = {},
nodes = {},
lord_nodes = {},
}

--- @param node_name string technical node name ("<mod>:<node>").
local function add_existing(node_name)
local definition = minetest.registered_nodes[node_name]
local softness = definition.groups["cracky"] or 2

minetest.override_item(node_name, {
groups = table.overwrite(definition.groups, { rock = 1 }),
})

rocks.nodes[node_name] = {
softness = definition.groups["cracky"],
softness = softness,
definition = definition,
existing = true
}
end

--- @param node_name string technical node name ("<mod>:<node>").
--- @param softness number softness value 1-3.
--- @param definition table NodeDefinition that overrides the default one.
local function register_rock(node_name, softness, definition)
softness = softness or 2
softness = softness or 2
definition = definition or {}

local description = node_name:replace("lord_rocks:", ""):remove_underscores():to_headline()
local tile = node_name:replace(":", "_") .. ".png"
local tile = node_name:replace(":", "_") .. ".png"

-- minetest.log("info", "use texture: " .. texture .. " at " .. __FILE_LINE__())

minetest.register_node(node_name, table.overwrite({
description = S(description),
tiles = { tile },
groups = { rock = 1, stone = 1, cracky = softness, },
sounds = default.node_sound_stone_defaults(),
sounds = default.node_sound_stone_defaults(),
}, definition))

rocks.nodes[node_name] = {
softness = softness,
definition = definition,
}

rocks.lord_nodes[node_name] = {
softness = softness,
definition = definition,
}


return true
end


return {
add_existing = add_existing,
register_rock = register_rock,
get_nodes = function() return rocks.nodes end,
add_existing = add_existing,
register_rock = register_rock,
get_nodes = function() return rocks.nodes end,
get_lord_nodes = function() return rocks.lord_nodes end,
}
19 changes: 6 additions & 13 deletions mods/lord/Blocks/lord_walls/init.lua
Original file line number Diff line number Diff line change
Expand Up @@ -23,23 +23,16 @@ walls.register(":walls:green_marble", S("Green Marble Wall"), "lord_blocks_green
walls.register(":walls:dungeon_stone", S("Dungeon Stone Wall"), "castle_dungeon_stone.png",
"castle:dungeon_stone", default.node_sound_stone_defaults())

-- TODO:
-- - exclude magma from stones
--- @type string
for node_name, registration in pairs(rocks.get_nodes()) do
for node_name, registration in pairs(rocks.get_lord_nodes()) do
--- @type string
local sub_name = node_name:split(":")[2]

if not registration.existing then
local walls_node = ":walls:" .. sub_name
local description = sub_name:remove_underscores():to_headline()
local texture = registration.definition.tiles
walls.register(walls_node, S(description), texture, node_name, default.node_sound_stone_defaults())
print('---->', node_name)
print("walls: " .. walls_node)
print("description: " .. description)
print("texture: " .. minetest.serialize(texture))
end
local walls_node = ":walls:" .. sub_name
local description = sub_name:remove_underscores():to_headline()
local texture = registration.definition.tiles
walls.register(walls_node, S(description), texture, node_name, default.node_sound_stone_defaults())

end


Expand Down

0 comments on commit 5bdd2f2

Please sign in to comment.