From 3752bf2e645391afce10bdb7866406d03e95916d Mon Sep 17 00:00:00 2001 From: crabman77 Date: Sun, 14 Aug 2016 00:31:58 +0200 Subject: [PATCH] rewrite minetest.rotate_node() to auto refill inventory on place node, issue https://github.com/MinetestForFun/server-minetestforfun/issues/462 --- .../mods/default/functions.lua | 24 +++++++++++++++++++ 1 file changed, 24 insertions(+) diff --git a/minetestforfun_game/mods/default/functions.lua b/minetestforfun_game/mods/default/functions.lua index 9138f53d..501e51a1 100755 --- a/minetestforfun_game/mods/default/functions.lua +++ b/minetestforfun_game/mods/default/functions.lua @@ -534,3 +534,27 @@ function default.intersects_protection(minp, maxp, player_name, interval) return false end + + +--rewrite function minetest.rotate_node(itemstack, placer, pointed_thing) to refill inventory +local old_rotate_node = minetest.rotate_node +function minetest.rotate_node(itemstack, placer, pointed_thing) + local stack_name = itemstack:get_name() + local ret = old_rotate_node(itemstack, placer, pointed_thing) + if ret:get_count() == 0 and not minetest.setting_getbool("creative_mode") then + local index = placer:get_wield_index() + local inv = placer:get_inventory() + if inv:get_list("main") then + for i, stack in ipairs(inv:get_list("main")) do + if i ~= index and stack:get_name() == stack_name then + ret:add_item(stack) + stack:clear() + inv:set_stack("main", i, stack) + minetest.log("action", "Inventory Tweaks: refilled stack("..stack_name..") of " .. placer:get_player_name()) + break + end + end + end + end + return ret +end