From a8707158a5be8c604fdb028a9c5f68ce5804016e Mon Sep 17 00:00:00 2001 From: DS Date: Thu, 10 Feb 2022 12:17:52 +0100 Subject: 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 --- games/devtest/mods/util_commands/init.lua | 47 +++++++++++++++++++++++++++++++ 1 file changed, 47 insertions(+) (limited to 'games/devtest') 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 \"\" [-c ]) | -a ", + 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, +}) -- cgit v1.2.3