Add //ngroups, which lists the groups a given node is a member of

This commit is contained in:
Starbeamrainbowlabs 2023-11-27 23:44:06 +00:00
parent ef86a0658a
commit 78844484f8
Signed by: sbrl
GPG Key ID: 1BE5172E637709C2
6 changed files with 105 additions and 2 deletions

View File

@ -9,6 +9,7 @@ Note to self: See the bottom of this file for the release template text.
- Added a (rather nuclear) fix (attempt 4) at finally exterminating all zombie region marker walls forever
- This is not a hotfix to avoid endless small releases fixing the bug, as it's clear it's much more difficult to fix on all systems than initially expected
- Added [`//nodeapply`](https://worldeditadditions.mooncarrot.space/Reference/#nodeapply), a generalisation of [`//airapply`](https://worldeditadditions.mooncarrot.space/Reference/#airapply) that works with a defined list of nodes. Check out [the reference](https://worldeditadditions.mooncarrot.space/Reference/#nodeapply) - it has some cool tricks to it! (thanks for suggesting, @kliv91 from the Discord server!)
- Added [`//ngroups`](https://worldeditadditions.mooncarrot.space/Reference/#ngroups), which lists the groups that a given node is a member of. Useful when paired with [`//nodeapply`](https://worldeditadditions.mooncarrot.space/Reference/#nodeapply)!
## v1.14.5: The multipoint update, hotfix 5 (1st August 2023)

View File

@ -1401,6 +1401,42 @@ This command is intended for development and modding. You will not normally need
```
### `//ngroups <node_name> [v[erbose]]`
Lists the groups that a given node is a member of. For example:
```weacmd
//ngroups sand
```
Might return:
```
default:sand ∈ sand crumbly falling_node
```
Groups in Minetest can also have a numerical value greater than 0. Append `v` or `verbose` to see those values:
```weacmd
//ngroups sand v
//ngroups sand verbose
```
...both of the above might produce an output like this:
```
default:sand ∈ sand=1 crumbly=3 falling_node=1
```
Finally, the customary misc examples:
```weacmd
//ngroups sand
//ngroups bakedclay:orange v
//ngroups cactus
//ngroups default:dry_shrub v
```
## Extras
<!--
███████ ██ ██ ████████ ██████ █████ ███████

View File

@ -0,0 +1,11 @@
-- ███ ██ ██████ ██████ ███████ ███████
-- ████ ██ ██ ██ ██ ██ ██ ██
-- ██ ██ ██ ██ ██ ██ ██ █████ ███████
-- ██ ██ ██ ██ ██ ██ ██ ██ ██
-- ██ ████ ██████ ██████ ███████ ███████
-- Commands that operate on information about nodes, and NOT on the world itself..
local we_cmdpath = worldeditadditions_commands.modpath .. "/commands/nodes/"
dofile(we_cmdpath .. "ngroups.lua")

View File

@ -0,0 +1,52 @@
local wea_c = worldeditadditions_core
local Vector3 = wea_c.Vector3
-- ███ ██ ██████ ██████ ██████ ██ ██ ██████ ███████
-- ████ ██ ██ ██ ██ ██ ██ ██ ██ ██ ██ ██
-- ██ ██ ██ ██ ███ ██████ ██ ██ ██ ██ ██████ ███████
-- ██ ██ ██ ██ ██ ██ ██ ██ ██ ██ ██ ██ ██
-- ██ ████ ██████ ██ ██ ██████ ██████ ██ ███████
worldeditadditions_core.register_command("ngroups", {
params = "<node_name> [v[erbose]]",
description =
"Lists the groups that a given node is a part of. If v or verbose are tagged on the end, then group values are also displayed. See also //nodeapply, which pairs well with this command.",
privs = {},
parse = function(params_text)
local parts = wea_c.split_shell(params_text)
if #parts == 0 or parts[1] == "" then
return false, "Error: No node name specified."
end
local node_name = worldedit.normalize_nodename(parts[1])
if not node_name then
return false, "Error: Unknown node "..parts[1].."."
end
local verbose = false
if parts[2] == "v" or parts[2] == "verbose" then
verbose = true
end
return true, node_name, verbose
end,
nodes_needed = function()
return 0
end,
func = function(_, node_name, verbose)
local node_def = minetest.registered_nodes[node_name]
if not node_def then return false, "Error: Failed to find definition for node "..node_name.."." end
local msg = { node_name, "" }
for group_name, value in pairs(node_def.groups) do
local part = group_name
if verbose then
part = part.."="..tostring(value)
end
table.insert(msg, part)
end
return true, table.concat(msg, " ")
end
})

View File

@ -40,7 +40,10 @@ dofile(wea_cmd.modpath.."/commands/spline.lua")
dofile(wea_cmd.modpath.."/commands/revolve.lua")
-- Meta Commands
dofile(wea_cmd.modpath.."/commands/meta/init.lua")
dofile(wea_cmd.modpath .. "/commands/meta/init.lua")
-- Node Informational Commands
dofile(wea_cmd.modpath .. "/commands/nodes/init.lua")
-- Selection Tools
dofile(wea_cmd.modpath.."/commands/selectors/init.lua")

View File

@ -116,7 +116,7 @@ function NodeListMatcher.match_group(matcher, node_id, group_name)
-- 2: Nope, not in the cache. Time to query!
local node_name = minetest.get_name_from_content_id(node_id)
local group_value = minetest.get_item_group(node_name, "group:"..group_name)
local group_value = minetest.get_item_group(node_name, group_name)
if group_value == 0 then group_value = false
else group_value = true end