From daae15eb57164f0eea14e6e12907d3c84fb04e79 Mon Sep 17 00:00:00 2001 From: Starbeamrainbowlabs Date: Mon, 31 Jul 2023 22:06:44 +0100 Subject: [PATCH 1/7] EventEmitter: improve debug logging --- worldeditadditions_core/utils/EventEmitter.lua | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/worldeditadditions_core/utils/EventEmitter.lua b/worldeditadditions_core/utils/EventEmitter.lua index 4632606..adbde5a 100644 --- a/worldeditadditions_core/utils/EventEmitter.lua +++ b/worldeditadditions_core/utils/EventEmitter.lua @@ -58,8 +58,12 @@ end -- @param event_name string The name of the event to emit. -- @param args table|any The argument(s) to pass to listener functions. It is strongly advised you pass a table here. function EventEmitter.emit(this, event_name, args) + if this.debug then + listeners = 0 + if this.events[event_name] ~= nil then listeners = #this.events[event_name] end + print("DEBUG:EventEmitter emit", event_name, "listeners", listeners, "args", wea_c.inspect(args)) + end if this.events[event_name] == nil then return end - if this.debug then print("DEBUG:EventEmitter emit", event_name, "args", wea_c.inspect(args)) end for index,next_func in ipairs(this.events[event_name]) do next_func(args) From aec204de8ee3d9147be8ce9e915a1afc563273f1 Mon Sep 17 00:00:00 2001 From: Starbeamrainbowlabs Date: Tue, 1 Aug 2023 00:07:10 +0100 Subject: [PATCH 2/7] add //listentities --- CHANGELOG.md | 4 ++ .../commands/meta/init.lua | 2 + .../commands/meta/listentities.lua | 39 +++++++++++++++++++ 3 files changed, 45 insertions(+) create mode 100644 worldeditadditions_commands/commands/meta/listentities.lua diff --git a/CHANGELOG.md b/CHANGELOG.md index f99247d..6b6e177 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -3,6 +3,9 @@ It's about time I started a changelog! This will serve from now on as the main c Note to self: See the bottom of this file for the release template text. +## v1.14.5: The multipoint update, hotfix 5 (unreleased) +- Added `//listentities`, which lists all currently loaded `ObjectRef`s. This is intended for debugging mods. + ## v1.14.4: The multipoint update, hotfix 4 (31st July 2023) - When any segment of the marker wall is punched, unmark the entire wall @@ -11,6 +14,7 @@ Note to self: See the bottom of this file for the release template text. ## v1.14.3: The multipoint update, hotfix 3 (18th July 2023) - Fix regions not remembering their state and being unresettable + ## v1.14.2: The multipoint update, hotfix 2 (15th July 2023) - Fix crash in `//subdivide`, again due to the new position system diff --git a/worldeditadditions_commands/commands/meta/init.lua b/worldeditadditions_commands/commands/meta/init.lua index 30924fb..15ad16c 100644 --- a/worldeditadditions_commands/commands/meta/init.lua +++ b/worldeditadditions_commands/commands/meta/init.lua @@ -16,3 +16,5 @@ dofile(we_cmdpath.."many.lua") dofile(we_cmdpath.."multi.lua") dofile(we_cmdpath.."noiseapply2d.lua") dofile(we_cmdpath.."subdivide.lua") + +dofile(we_cmdpath.."listentities.lua") \ No newline at end of file diff --git a/worldeditadditions_commands/commands/meta/listentities.lua b/worldeditadditions_commands/commands/meta/listentities.lua new file mode 100644 index 0000000..538b964 --- /dev/null +++ b/worldeditadditions_commands/commands/meta/listentities.lua @@ -0,0 +1,39 @@ +-- Lists all currently loaded entities. + +local weac = worldeditadditions_core + +minetest.register_chatcommand("/listentities", { + params = "", + description = + "Lists all currently loaded entities. This is a command for debugging and development. You will not need this unless you are developing a mod.", + privs = { worldedit = true }, + func = function(name, params_text) + local table_vals = { + { "ID", "Name", "Position" }, + { "------", "-------", "---------" }, + } + for id, obj in pairs(minetest.object_refs) do + local obj_name = "[ObjectRef]" + if obj.get_luaentity then + local luaentity = obj:get_luaentity() + if luaentity then + obj_name = "[LuaEntity:"..luaentity.name.."]" + else + obj_name = "[LuaEntity:__UNKNOWN__]" + end + end + local pos = weac.Vector3.clone(obj:get_pos()) + table.insert(table_vals, { + id, + obj_name, + tostring(pos) + }) + end + worldedit.player_notify(name, table.concat({ + "Currently loaded entities:", + weac.format.make_ascii_table(table_vals), + "", + "Total "..tostring(#table_vals).." objects" + }, "\n")) + end +}) From abfd76930a0027d683bb84c387d264d729a0064c Mon Sep 17 00:00:00 2001 From: Starbeamrainbowlabs Date: Tue, 1 Aug 2023 00:11:49 +0100 Subject: [PATCH 3/7] reference: add //listentities --- Chat-Command-Reference.md | 11 +++++++++++ 1 file changed, 11 insertions(+) diff --git a/Chat-Command-Reference.md b/Chat-Command-Reference.md index d522630..95fd7e2 100644 --- a/Chat-Command-Reference.md +++ b/Chat-Command-Reference.md @@ -1349,6 +1349,17 @@ Here are some more examples: ``` +### `//listentities` +Lists all currently loaded ObjectRefs. Displays their IDs, Names (if possible), and possitions. + +This command is intended for development and modding. You will not normally need to use this command using WorldEditAdditions. + +`//listentities` takes no arguments. + +``` +//listentities +``` + ## Extras