aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorDesour <vorunbekannt75@web.de>2022-09-17 00:09:50 +0200
committerx2048 <codeforsmile@gmail.com>2023-01-06 22:38:35 +0100
commit07624125efece00728b166b36e53a7ad85619556 (patch)
tree2cbf49236d12f9c7656c67c7a7ed2e3fd245836e
parentbb74da590349643403df2c99ddc2d1584d4324ad (diff)
downloadminetest-07624125efece00728b166b36e53a7ad85619556.tar.xz
Devtest: Add branding iron
Allows giving names to objects.
-rw-r--r--LICENSE.txt3
-rw-r--r--games/devtest/mods/testtools/README.md11
-rw-r--r--games/devtest/mods/testtools/init.lua47
-rw-r--r--games/devtest/mods/testtools/textures/testtools_branding_iron.pngbin0 -> 130 bytes
4 files changed, 61 insertions, 0 deletions
diff --git a/LICENSE.txt b/LICENSE.txt
index 339798939..77228684a 100644
--- a/LICENSE.txt
+++ b/LICENSE.txt
@@ -76,6 +76,9 @@ SmallJoker:
textures/base/pack/cdb_clear.png
textures/base/pack/server_favorite_delete.png (based on server_favorite.png)
+DS:
+ games/devtest/mods/testtools/textures/testtools_branding_iron.png
+
License of Minetest source code
-------------------------------
diff --git a/games/devtest/mods/testtools/README.md b/games/devtest/mods/testtools/README.md
index 3de2969a7..03d826da7 100644
--- a/games/devtest/mods/testtools/README.md
+++ b/games/devtest/mods/testtools/README.md
@@ -120,6 +120,17 @@ Usage:
* Punch entity to increase visual size
* Sneak+punch entity to decrease visual size
+## Branding Iron
+Give an object a temporary name.
+
+Usage:
+* Punch object: Brand the object
+* Punch air: Brand yourself
+* The name is valid until the object unloads.
+* Devices that accept the returned name also accept "player:<playername>" for players.
+
+Use `testtools.get_branded_object(name)` to get an ObjRef.
+
## Note Meta Privatizer
Sets the 'formspec' and 'infotext' metadata fields of a node
to private. This means that clients can no longer access these
diff --git a/games/devtest/mods/testtools/init.lua b/games/devtest/mods/testtools/init.lua
index 6db5a7cd1..7aa55bdb3 100644
--- a/games/devtest/mods/testtools/init.lua
+++ b/games/devtest/mods/testtools/init.lua
@@ -1,6 +1,8 @@
local S = minetest.get_translator("testtools")
local F = minetest.formspec_escape
+testtools = {}
+
dofile(minetest.get_modpath("testtools") .. "/light.lua")
dofile(minetest.get_modpath("testtools") .. "/privatizer.lua")
dofile(minetest.get_modpath("testtools") .. "/particles.lua")
@@ -330,6 +332,51 @@ minetest.register_tool("testtools:entity_scaler", {
end,
})
+
+-- value-weak tables, because we don't want to keep the objrefs of unloaded objects
+local branded_objects = setmetatable({}, {__mode = "v"})
+local next_brand_num = 1
+
+function testtools.get_branded_object(name)
+ if name:sub(1, 7) == "player:" then
+ return minetest.get_player_by_name(name:sub(8))
+ elseif name:sub(1, 4) == "obj:" then
+ return branded_objects[tonumber(name:sub(5)) or 0]
+ end
+ return nil
+end
+
+minetest.register_tool("testtools:branding_iron", {
+ description = S("Branding Iron") .."\n"..
+ S("Give an object a temporary name.") .."\n"..
+ S("Punch object: Brand the object") .."\n"..
+ S("Punch air: Brand yourself") .."\n"..
+ S("The name is valid until the object unloads.") .."\n"..
+ S("Devices that accept the returned name also accept \"player:<playername>\" for players."),
+ inventory_image = "testtools_branding_iron.png",
+ groups = { testtool = 1, disable_repair = 1 },
+ on_use = function(_itemstack, user, pointed_thing)
+ local obj
+ local msg
+ if pointed_thing.type == "object" then
+ obj = pointed_thing.ref
+ msg = "You can now refer to this object with: \"@1\""
+ elseif pointed_thing.type == "nothing" then
+ obj = user
+ msg = "You can now refer to yourself with: \"@1\""
+ else
+ return
+ end
+
+ local brand_num = next_brand_num
+ next_brand_num = next_brand_num + 1
+ branded_objects[brand_num] = obj
+
+ minetest.chat_send_player(user:get_player_name(), S(msg, "obj:"..brand_num))
+ end,
+})
+
+
local selections = {}
local entity_list
local function get_entity_list()
diff --git a/games/devtest/mods/testtools/textures/testtools_branding_iron.png b/games/devtest/mods/testtools/textures/testtools_branding_iron.png
new file mode 100644
index 000000000..40c09b163
--- /dev/null
+++ b/games/devtest/mods/testtools/textures/testtools_branding_iron.png
Binary files differ