From 07624125efece00728b166b36e53a7ad85619556 Mon Sep 17 00:00:00 2001 From: Desour Date: Sat, 17 Sep 2022 00:09:50 +0200 Subject: [PATCH] Devtest: Add branding iron Allows giving names to objects. --- LICENSE.txt | 3 ++ games/devtest/mods/testtools/README.md | 11 ++++ games/devtest/mods/testtools/init.lua | 47 ++++++++++++++++++ .../textures/testtools_branding_iron.png | Bin 0 -> 130 bytes 4 files changed, 61 insertions(+) create mode 100644 games/devtest/mods/testtools/textures/testtools_branding_iron.png 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:" 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:\" 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 0000000000000000000000000000000000000000..40c09b1632acb2fa76727e71d6c65847fb09eafd GIT binary patch literal 130 zcmeAS@N?(olHy`uVBq!ia0vp^0wB!61|;P_|4#%`o}Mm_Ar_~T6Bd~Luy1^5Z));S zG5m4;BwmNh9Ld6OdDS$|a%}y|&&BO~b-~JDD-XQfU{Q&Pz;|!jK dHyA7!7+hW%+*B70)&v^L;OXk;vd$@?2>^c6Da!x= literal 0 HcmV?d00001