From 2da92ed81e9867483a4d49bc1f9cbfb104755ff7 Mon Sep 17 00:00:00 2001 From: Wuzzy Date: Sat, 8 Oct 2022 18:29:22 +0200 Subject: DevTest: Move callback entities to callbacks mod --- games/devtest/mods/callbacks/entities.lua | 78 +++++++++++++++++++++ games/devtest/mods/callbacks/init.lua | 1 + .../textures/callbacks_callback_entity.png | Bin 0 -> 156 bytes .../textures/callbacks_callback_entity_step.png | Bin 0 -> 166 bytes games/devtest/mods/testentities/callbacks.lua | 78 --------------------- games/devtest/mods/testentities/init.lua | 1 - .../textures/testentities_callback.png | Bin 156 -> 0 bytes .../textures/testentities_callback_step.png | Bin 166 -> 0 bytes 8 files changed, 79 insertions(+), 79 deletions(-) create mode 100644 games/devtest/mods/callbacks/entities.lua create mode 100644 games/devtest/mods/callbacks/textures/callbacks_callback_entity.png create mode 100644 games/devtest/mods/callbacks/textures/callbacks_callback_entity_step.png delete mode 100644 games/devtest/mods/testentities/callbacks.lua delete mode 100644 games/devtest/mods/testentities/textures/testentities_callback.png delete mode 100644 games/devtest/mods/testentities/textures/testentities_callback_step.png (limited to 'games/devtest') diff --git a/games/devtest/mods/callbacks/entities.lua b/games/devtest/mods/callbacks/entities.lua new file mode 100644 index 000000000..6a7f13d75 --- /dev/null +++ b/games/devtest/mods/callbacks/entities.lua @@ -0,0 +1,78 @@ +-- Entities that test their callbacks + +local message = function(msg) + minetest.log("action", msg) + minetest.chat_send_all(msg) +end + +local get_object_name = function(obj) + local name = "" + if obj then + if obj:is_player() then + name = obj:get_player_name() + else + name = "" + end + end + return name +end + +local spos = function(self) + return minetest.pos_to_string(vector.round(self.object:get_pos())) +end + +-- Callback test entity (all callbacks except on_step) +minetest.register_entity("callbacks:callback", { + initial_properties = { + visual = "upright_sprite", + textures = { "callbacks_callback_entity.png" }, + }, + + on_activate = function(self, staticdata, dtime_s) + message("Callback entity: on_activate! pos="..spos(self).."; dtime_s="..dtime_s) + end, + on_deactivate = function(self, removal) + message("Callback entity: on_deactivate! pos="..spos(self) .. "; removal=" .. tostring(removal)) + end, + on_punch = function(self, puncher, time_from_last_punch, tool_capabilities, dir, damage) + local name = get_object_name(puncher) + message( + "Callback entity: on_punch! ".. + "pos="..spos(self).."; puncher="..name.."; ".. + "time_from_last_punch="..time_from_last_punch.."; ".. + "tool_capabilities="..tostring(dump(tool_capabilities)).."; ".. + "dir="..tostring(dump(dir)).."; damage="..damage) + end, + on_rightclick = function(self, clicker) + local name = get_object_name(clicker) + message("Callback entity: on_rightclick! pos="..spos(self).."; clicker="..name) + end, + on_death = function(self, killer) + local name = get_object_name(killer) + message("Callback entity: on_death! pos="..spos(self).."; killer="..name) + end, + on_attach_child = function(self, child) + local name = get_object_name(child) + message("Callback entity: on_attach_child! pos="..spos(self).."; child="..name) + end, + on_detach_child = function(self, child) + local name = get_object_name(child) + message("Callback entity: on_detach_child! pos="..spos(self).."; child="..name) + end, + on_detach = function(self, parent) + local name = get_object_name(parent) + message("Callback entity: on_detach! pos="..spos(self).."; parent="..name) + end, + get_staticdata = function(self) + message("Callback entity: get_staticdata! pos="..spos(self)) + end, +}) + +-- Only test on_step callback +minetest.register_entity("callbacks:callback_step", { + visual = "upright_sprite", + textures = { "callbacks_callback_entity_step.png" }, + on_step = function(self, dtime) + message("on_step callback entity: on_step! pos="..spos(self).."; dtime="..dtime) + end, +}) diff --git a/games/devtest/mods/callbacks/init.lua b/games/devtest/mods/callbacks/init.lua index c5b0984d5..8f719a3f8 100644 --- a/games/devtest/mods/callbacks/init.lua +++ b/games/devtest/mods/callbacks/init.lua @@ -1,2 +1,3 @@ dofile(minetest.get_modpath("callbacks").."/items.lua") dofile(minetest.get_modpath("callbacks").."/nodes.lua") +dofile(minetest.get_modpath("callbacks").."/entities.lua") diff --git a/games/devtest/mods/callbacks/textures/callbacks_callback_entity.png b/games/devtest/mods/callbacks/textures/callbacks_callback_entity.png new file mode 100644 index 000000000..c4c9066d1 Binary files /dev/null and b/games/devtest/mods/callbacks/textures/callbacks_callback_entity.png differ diff --git a/games/devtest/mods/callbacks/textures/callbacks_callback_entity_step.png b/games/devtest/mods/callbacks/textures/callbacks_callback_entity_step.png new file mode 100644 index 000000000..b67506a97 Binary files /dev/null and b/games/devtest/mods/callbacks/textures/callbacks_callback_entity_step.png differ diff --git a/games/devtest/mods/testentities/callbacks.lua b/games/devtest/mods/testentities/callbacks.lua deleted file mode 100644 index a212fbfbe..000000000 --- a/games/devtest/mods/testentities/callbacks.lua +++ /dev/null @@ -1,78 +0,0 @@ --- Entities that test their callbacks - -local message = function(msg) - minetest.log("action", msg) - minetest.chat_send_all(msg) -end - -local get_object_name = function(obj) - local name = "" - if obj then - if obj:is_player() then - name = obj:get_player_name() - else - name = "" - end - end - return name -end - -local spos = function(self) - return minetest.pos_to_string(vector.round(self.object:get_pos())) -end - --- Callback test entity (all callbacks except on_step) -minetest.register_entity("testentities:callback", { - initial_properties = { - visual = "upright_sprite", - textures = { "testentities_callback.png" }, - }, - - on_activate = function(self, staticdata, dtime_s) - message("Callback entity: on_activate! pos="..spos(self).."; dtime_s="..dtime_s) - end, - on_deactivate = function(self, removal) - message("Callback entity: on_deactivate! pos="..spos(self) .. "; removal=" .. tostring(removal)) - end, - on_punch = function(self, puncher, time_from_last_punch, tool_capabilities, dir, damage) - local name = get_object_name(puncher) - message( - "Callback entity: on_punch! ".. - "pos="..spos(self).."; puncher="..name.."; ".. - "time_from_last_punch="..time_from_last_punch.."; ".. - "tool_capabilities="..tostring(dump(tool_capabilities)).."; ".. - "dir="..tostring(dump(dir)).."; damage="..damage) - end, - on_rightclick = function(self, clicker) - local name = get_object_name(clicker) - message("Callback entity: on_rightclick! pos="..spos(self).."; clicker="..name) - end, - on_death = function(self, killer) - local name = get_object_name(killer) - message("Callback entity: on_death! pos="..spos(self).."; killer="..name) - end, - on_attach_child = function(self, child) - local name = get_object_name(child) - message("Callback entity: on_attach_child! pos="..spos(self).."; child="..name) - end, - on_detach_child = function(self, child) - local name = get_object_name(child) - message("Callback entity: on_detach_child! pos="..spos(self).."; child="..name) - end, - on_detach = function(self, parent) - local name = get_object_name(parent) - message("Callback entity: on_detach! pos="..spos(self).."; parent="..name) - end, - get_staticdata = function(self) - message("Callback entity: get_staticdata! pos="..spos(self)) - end, -}) - --- Only test on_step callback -minetest.register_entity("testentities:callback_step", { - visual = "upright_sprite", - textures = { "testentities_callback_step.png" }, - on_step = function(self, dtime) - message("on_step callback entity: on_step! pos="..spos(self).."; dtime="..dtime) - end, -}) diff --git a/games/devtest/mods/testentities/init.lua b/games/devtest/mods/testentities/init.lua index df8c72ea7..94d8d47c2 100644 --- a/games/devtest/mods/testentities/init.lua +++ b/games/devtest/mods/testentities/init.lua @@ -1,3 +1,2 @@ dofile(minetest.get_modpath("testentities").."/visuals.lua") dofile(minetest.get_modpath("testentities").."/armor.lua") -dofile(minetest.get_modpath("testentities").."/callbacks.lua") diff --git a/games/devtest/mods/testentities/textures/testentities_callback.png b/games/devtest/mods/testentities/textures/testentities_callback.png deleted file mode 100644 index c4c9066d1..000000000 Binary files a/games/devtest/mods/testentities/textures/testentities_callback.png and /dev/null differ diff --git a/games/devtest/mods/testentities/textures/testentities_callback_step.png b/games/devtest/mods/testentities/textures/testentities_callback_step.png deleted file mode 100644 index b67506a97..000000000 Binary files a/games/devtest/mods/testentities/textures/testentities_callback_step.png and /dev/null differ -- cgit v1.2.3