diff options
author | DS <vorunbekannt75@web.de> | 2022-02-10 12:17:52 +0100 |
---|---|---|
committer | GitHub <noreply@github.com> | 2022-02-10 06:17:52 -0500 |
commit | a8707158a5be8c604fdb028a9c5f68ce5804016e (patch) | |
tree | de95d4fccfccf81c3f1dd3cce8f7146f947c1208 /games/devtest/mods/util_commands | |
parent | ad1da994b2b9d660c41f8ba784ff830aa2693d3b (diff) | |
download | minetest-a8707158a5be8c604fdb028a9c5f68ce5804016e.tar.gz minetest-a8707158a5be8c604fdb028a9c5f68ce5804016e.tar.bz2 minetest-a8707158a5be8c604fdb028a9c5f68ce5804016e.zip |
Allow to set the displayed item count and its alignment via meta (#8448)
* Allow to set the displayed item count and its offset via meta
* fix rect constr call
* devtest: add dump_item chatcommand
* fix rect2 constr call (sdim is a position (typedef for v2s32), not a dimension) and remove background because it would work now
* add missing utf8 to wide conversion
* rename to count_meta
Diffstat (limited to 'games/devtest/mods/util_commands')
-rw-r--r-- | games/devtest/mods/util_commands/init.lua | 47 |
1 files changed, 47 insertions, 0 deletions
diff --git a/games/devtest/mods/util_commands/init.lua b/games/devtest/mods/util_commands/init.lua index 79acaa0d0..9be989e67 100644 --- a/games/devtest/mods/util_commands/init.lua +++ b/games/devtest/mods/util_commands/init.lua @@ -246,3 +246,50 @@ function minetest.handle_node_drops(pos, drops, digger) end end end + +minetest.register_chatcommand("set_displayed_itemcount", { + params = "(-s \"<string>\" [-c <color>]) | -a <alignment_num>", + description = "Set the displayed itemcount of the wielded item", + func = function(name, param) + local player = minetest.get_player_by_name(name) + local item = player:get_wielded_item() + local meta = item:get_meta() + local flag1 = param:sub(1, 2) + if flag1 == "-s" then + if param:sub(3, 4) ~= " \"" then + return false, "Error: Space and string with \"s expected after -s." + end + local se = param:find("\"", 5, true) + if not se then + return false, "Error: String with two \"s expected after -s." + end + local s = param:sub(5, se - 1) + if param:sub(se + 1, se + 4) == " -c " then + s = minetest.colorize(param:sub(se + 5), s) + end + meta:set_string("count_meta", s) + elseif flag1 == "-a" then + local num = tonumber(param:sub(4)) + if not num then + return false, "Error: Invalid number: "..param:sub(4) + end + meta:set_int("count_alignment", num) + else + return false + end + player:set_wielded_item(item) + return true, "Displayed itemcount set." + end, +}) + +minetest.register_chatcommand("dump_item", { + params = "", + description = "Prints a dump of the wielded item in table form", + func = function(name, param) + local player = minetest.get_player_by_name(name) + local item = player:get_wielded_item() + local str = dump(item:to_table()) + print(str) + return true, str + end, +}) |