From 9d0e3ee7a20069218216e9d2367058fd6f777dc7 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Mikita=20Wi=C5=9Bniewski?= Date: Wed, 31 Jul 2024 20:38:29 +0700 Subject: [PATCH] Implement basic pickblock functionality (on rightclick) --- mods/PLAYER/vl_pickblock/LICENSE | 22 ++++++++++++++++++++++ mods/PLAYER/vl_pickblock/README.md | 13 +++++++++++++ mods/PLAYER/vl_pickblock/init.lua | 25 +++++++++++++++++++++++++ mods/PLAYER/vl_pickblock/mod.conf | 2 ++ 4 files changed, 62 insertions(+) create mode 100644 mods/PLAYER/vl_pickblock/LICENSE create mode 100644 mods/PLAYER/vl_pickblock/README.md create mode 100644 mods/PLAYER/vl_pickblock/init.lua create mode 100644 mods/PLAYER/vl_pickblock/mod.conf diff --git a/mods/PLAYER/vl_pickblock/LICENSE b/mods/PLAYER/vl_pickblock/LICENSE new file mode 100644 index 000000000..42dbb9c7c --- /dev/null +++ b/mods/PLAYER/vl_pickblock/LICENSE @@ -0,0 +1,22 @@ +MIT License + +Copyright (c) 2022 ROllerozxa +Copyright (c) 2024 Mikita 'rudzik8' Wiśniewski + +Permission is hereby granted, free of charge, to any person obtaining a copy +of this software and associated documentation files (the "Software"), to deal +in the Software without restriction, including without limitation the rights +to use, copy, modify, merge, publish, distribute, sublicense, and/or sell +copies of the Software, and to permit persons to whom the Software is +furnished to do so, subject to the following conditions: + +The above copyright notice and this permission notice shall be included in all +copies or substantial portions of the Software. + +THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR +IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, +FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE +AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER +LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, +OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE +SOFTWARE. diff --git a/mods/PLAYER/vl_pickblock/README.md b/mods/PLAYER/vl_pickblock/README.md new file mode 100644 index 000000000..14a6a69c6 --- /dev/null +++ b/mods/PLAYER/vl_pickblock/README.md @@ -0,0 +1,13 @@ +# `vl_pickblock` + +Allows you to put the selected node in an empty slot of your hotbar when you're in creative mode. + +You select them with the build key (right-click) as compared to with middle-click as it usually is in Minecraft. + + +## License + +Copyright (C) 2022 ROllerozxa\ +Copyright (C) 2024 Mikita 'rudzik8' Wiśniewski + +MIT (see `LICENSE` file) diff --git a/mods/PLAYER/vl_pickblock/init.lua b/mods/PLAYER/vl_pickblock/init.lua new file mode 100644 index 000000000..0e776acbe --- /dev/null +++ b/mods/PLAYER/vl_pickblock/init.lua @@ -0,0 +1,25 @@ +minetest.override_item("", { + on_place = function(itemstack, placer, pointed_thing) + if minetest.is_creative_enabled(placer:get_player_name()) then + local node = minetest.get_node_or_nil(pointed_thing.under) + if not node then return end + + local def = minetest.registered_nodes[node.name] + if not def then return end + + local rnode + -- if this is an 'illegal' node and there's an explicit `_vl_pickblock` field, then return it + -- if the node isn't 'illegal', return it as-is + -- (and if it's 'illegal' and no `_vl_pickblock` is defined, well, bad luck) + if def.groups.not_in_creative_inventory and def.groups.not_in_creative_inventory ~= 0 then + if def._vl_pickblock then + rnode = def._vl_pickblock + end + else + rnode = node.name + end + + return {name = rnode} + end + end +}) diff --git a/mods/PLAYER/vl_pickblock/mod.conf b/mods/PLAYER/vl_pickblock/mod.conf new file mode 100644 index 000000000..79a8a45e5 --- /dev/null +++ b/mods/PLAYER/vl_pickblock/mod.conf @@ -0,0 +1,2 @@ +name = vl_pickblock +description = Allows you to put the selected node in an empty slot of your hotbar when you're in creative mode.