diff --git a/CHANGELOG.md b/CHANGELOG.md index ff58473..a81b158 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -15,6 +15,7 @@ Note to self: See the bottom of this file for the release template text. - Also added an associated [movement speed adjustment tool](https://worldeditadditions.mooncarrot.space/Reference/#movement), which looks like this: ![A picture of the move speed adjustment tool. It looks like a monarch butterfly.](https://raw.githubusercontent.com/sbrl/Minetest-WorldEditAdditions/dev/worldeditadditions_farwand/textures/worldeditadditions_movement.png) - Added [`//set+`](https://worldeditadditions.mooncarrot.space/Reference/#set) for setting nodes and param2/light levels quickly. - NOTE TO SELF: Setting light values doesn't appear to be working very well for some reason +- Added [`//ndef`](https://worldeditadditions.mooncarrot.space/Reference/#ndef) to print a given node's definition table. This is for debugging and development purposes. ### Bugfixes and changes - Don't warn on failed registration of `//flora` → [`//bonemeal`](https://worldeditadditions.mooncarrot.space/Reference/#bonemeal) if the `bonemeal` mod isn't installed (e.g. in MineClone2) - thanks @VorTechnix in #106 diff --git a/Chat-Command-Reference.md b/Chat-Command-Reference.md index 9c73859..1256280 100644 --- a/Chat-Command-Reference.md +++ b/Chat-Command-Reference.md @@ -1047,6 +1047,77 @@ Finally, the customary misc examples: //ngroups default:dry_shrub v ``` +### `//ndef ` +Short for *Node Definition*. Prints the definition table for the node with the given name. In other words. the output could look a little like this: + +``` +stairs:stair_birch_wood { + description = (string) "Birch Wood Stair" + sounds = (table) { + dig = (table) { + name = (string) "default_dig_choppy" + gain = (number) 0.4 + } + place = (table) { + name = (string) "default_place_node_hard" + gain = (number) 1 + } + dug = (table) { + name = (string) "default_wood_footstep" + gain = (number) 1 + } + footstep = (table) { + name = (string) "default_wood_footstep" + gain = (number) 0.15 + } + } + name = (string) "stairs:stair_birch_wood" + light_source = (number) 0 + mod_origin = (string) "ethereal" + selection_box = (table) { + fixed = (table) { + 1 = (table) [truncated] + 2 = (table) [truncated] + } + type = (string) "fixed" + } + paramtype = (string) "light" + groups = (table) { + flammable = (number) 3 + stair = (number) 1 + choppy = (number) 2 + oddly_breakable_by_hand = (number) 1 + } + is_ground_content = (boolean) false + on_place = (function) function: 0x765b01d0edb8 + drawtype = (string) "nodebox" + tiles = (table) { + 1 = (table) { + name = (string) "moretrees_birch_wood.png" + backface_culling = (boolean) true + } + } + paramtype2 = (string) "facedir" + sunlight_propagates = (boolean) false + node_box = (table) { + fixed = (table) { + 1 = (table) [truncated] + 2 = (table) [truncated] + } + type = (string) "fixed" + } + type = (string) "node" +} +``` + +This command is intended for debugging and development purposes, but if you're implementing a mod yourself you might find it useful too. + +```weacmd +//ndef stone +//ndef stairs:stair_birch_wood +//ndef glass +``` + ## Selection diff --git a/worldeditadditions_commands/commands/nodes/init.lua b/worldeditadditions_commands/commands/nodes/init.lua index 0829687..e87f9c7 100644 --- a/worldeditadditions_commands/commands/nodes/init.lua +++ b/worldeditadditions_commands/commands/nodes/init.lua @@ -9,3 +9,4 @@ local we_cmdpath = worldeditadditions_commands.modpath .. "/commands/nodes/" dofile(we_cmdpath .. "ngroups.lua") +dofile(we_cmdpath .. "ndef.lua") diff --git a/worldeditadditions_commands/commands/nodes/ndef.lua b/worldeditadditions_commands/commands/nodes/ndef.lua new file mode 100644 index 0000000..0088c50 --- /dev/null +++ b/worldeditadditions_commands/commands/nodes/ndef.lua @@ -0,0 +1,36 @@ +local core = worldeditadditions_core +local Vector3 = core.Vector3 + +-- ███ ██ ██████ ███████ ███████ +-- ████ ██ ██ ██ ██ ██ +-- ██ ██ ██ ██ ██ █████ █████ +-- ██ ██ ██ ██ ██ ██ ██ +-- ██ ████ ██████ ███████ ██ +worldeditadditions_core.register_command("ndef", { + params = "", + description = + "Prints the current definintion for the given node.", + privs = {}, + parse = function(params_text) + params_text = core.trim(params_text) + if params_text == "" then return false, "No node name specified." end + + local node_name = worldedit.normalize_nodename(params_text) + if not node_name then + return false, "Error: Unknown node " .. params_text .. "." + end + + return true, node_name + end, + nodes_needed = function() + return 0 + end, + func = function(_, node_name) + 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, core.inspect(node_def) } + print(table.concat(msg, " ")) + return true, table.concat(msg, " ") + end +})