From 9ac416ee3eecdc98f058c2d248a2ef1968df2639 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Mikita=20Wi=C5=9Bniewski?= Date: Wed, 31 Jul 2024 21:57:51 +0700 Subject: [PATCH] Notify the player if a picked block is already in their hotbar --- mods/PLAYER/vl_pickblock/init.lua | 12 ++++++++++++ mods/PLAYER/vl_pickblock/locale/template.txt | 2 ++ mods/PLAYER/vl_pickblock/mod.conf | 2 +- 3 files changed, 15 insertions(+), 1 deletion(-) create mode 100644 mods/PLAYER/vl_pickblock/locale/template.txt diff --git a/mods/PLAYER/vl_pickblock/init.lua b/mods/PLAYER/vl_pickblock/init.lua index 7e6257d22..3f66f6a0c 100644 --- a/mods/PLAYER/vl_pickblock/init.lua +++ b/mods/PLAYER/vl_pickblock/init.lua @@ -1,3 +1,5 @@ +local S = minetest.get_translator("vl_pickblock") + minetest.override_item("", { on_place = function(itemstack, placer, pointed_thing) if minetest.is_creative_enabled(placer:get_player_name()) then @@ -21,6 +23,16 @@ minetest.override_item("", { rnode = node end + local inv = placer:get_inventory() + for i=1,placer:hud_get_hotbar_itemcount() do + local stack = inv:get_stack("main", i) + if stack:get_name() == rnode.name then + local msg = S("@1 is on slot @2", stack:get_short_description(), i) + mcl_title.set(placer, "actionbar", {text = msg, stay = 30}) + return + end + end + return rnode end end diff --git a/mods/PLAYER/vl_pickblock/locale/template.txt b/mods/PLAYER/vl_pickblock/locale/template.txt new file mode 100644 index 000000000..0bcccddae --- /dev/null +++ b/mods/PLAYER/vl_pickblock/locale/template.txt @@ -0,0 +1,2 @@ +# textdomain: vl_pickblock +@1 is on slot @2= diff --git a/mods/PLAYER/vl_pickblock/mod.conf b/mods/PLAYER/vl_pickblock/mod.conf index cdfdf705e..f0e93509a 100644 --- a/mods/PLAYER/vl_pickblock/mod.conf +++ b/mods/PLAYER/vl_pickblock/mod.conf @@ -1,3 +1,3 @@ name = vl_pickblock description = Allows you to put the selected node in an empty slot of your hotbar when you're in creative mode. -depeds = mcl_util +depeds = mcl_util, mcl_title