From c691f370b4ff6054b76cc7e4c2ea623012e99238 Mon Sep 17 00:00:00 2001 From: SmallJoker Date: Sun, 10 Jul 2022 20:25:16 +0200 Subject: [PATCH] Configurable inventory log level (#17) This aims to reduce spammed log files and corrects nonsense translations to the terminal --- config.lua | 2 ++ init.lua | 6 ++++++ nodes/chute.lua | 2 +- nodes/hoppers.lua | 13 +++++++------ nodes/sorter.lua | 2 +- settingtypes.txt | 23 +++++++++++++---------- 6 files changed, 30 insertions(+), 18 deletions(-) diff --git a/config.lua b/config.lua index 6868fc0..d531d27 100644 --- a/config.lua +++ b/config.lua @@ -15,3 +15,5 @@ hopper.config.eject_button_enabled = minetest.settings:get_bool("hopper_eject_bu if hopper.config.eject_button_enabled == nil then hopper.config.eject_button_enabled = true end + +hopper.config.inv_log_level = minetest.settings:get("hopper_inventory_log_level") or "info" diff --git a/init.lua b/init.lua index 5134374..2148fa0 100644 --- a/init.lua +++ b/init.lua @@ -62,4 +62,10 @@ if minetest.get_modpath("lucky_block") then }) end +-- Utility function for inventory movement logs +function hopper.log_inventory(...) + minetest.log(hopper.config.inv_log_level, ...) +end + + minetest.log("action", "[hopper] Hopper mod loaded") diff --git a/nodes/chute.lua b/nodes/chute.lua index 21e1125..48d6b2d 100644 --- a/nodes/chute.lua +++ b/nodes/chute.lua @@ -75,7 +75,7 @@ minetest.register_node("hopper:chute", { end, on_metadata_inventory_put = function(pos, listname, index, stack, player) - minetest.log("action", S("@1 moves stuff to chute at @2", + hopper.log_inventory(("%s moves stuff to chute at %s"):format( player:get_player_name(), minetest.pos_to_string(pos))) local timer = minetest.get_node_timer(pos) diff --git a/nodes/hoppers.lua b/nodes/hoppers.lua index d08d63e..d1e6456 100644 --- a/nodes/hoppers.lua +++ b/nodes/hoppers.lua @@ -121,17 +121,17 @@ minetest.register_node("hopper:hopper", { end, on_metadata_inventory_move = function(pos, from_list, from_index, to_list, to_index, count, player) - minetest.log("action", S("@1 moves stuff in hopper at @2", + minetest.log("action", ("%s moves stuff in hopper at %s"):format( player:get_player_name(), minetest.pos_to_string(pos))) end, on_metadata_inventory_put = function(pos, listname, index, stack, player) - minetest.log("action", S("@1 moves stuff to hopper at @2", + hopper.log_inventory(("%s moves stuff to hopper at %s"):format( player:get_player_name(), minetest.pos_to_string(pos))) end, on_metadata_inventory_take = function(pos, listname, index, stack, player) - minetest.log("action", S("@1 moves stuff from hopper at @2", + hopper.log_inventory(("%s moves stuff from hopper at %s"):format( player:get_player_name(), minetest.pos_to_string(pos))) end, }) @@ -214,17 +214,18 @@ minetest.register_node("hopper:hopper_side", { end, on_metadata_inventory_move = function(pos, from_list, from_index, to_list, to_index, count, player) - minetest.log("action", S("@1 moves stuff in hopper at @2", + -- Only players move items. "action" is generally okay here. + minetest.log("action", ("%s moves stuff in hopper at %s"):format( player:get_player_name(), minetest.pos_to_string(pos))) end, on_metadata_inventory_put = function(pos, listname, index, stack, player) - minetest.log("action", S("@1 moves stuff to hopper at @2", + hopper.log_inventory(("%s moves stuff to hopper at%s"):format( player:get_player_name(), minetest.pos_to_string(pos))) end, on_metadata_inventory_take = function(pos, listname, index, stack, player) - minetest.log("action", S("@1 moves stuff from hopper at @2", + hopper.log_inventory(("%s moves stuff from hopper at %s"):format( player:get_player_name(), minetest.pos_to_string(pos))) end, }) diff --git a/nodes/sorter.lua b/nodes/sorter.lua index 5f0858c..e0dc12b 100644 --- a/nodes/sorter.lua +++ b/nodes/sorter.lua @@ -141,7 +141,7 @@ minetest.register_node("hopper:sorter", { end, on_metadata_inventory_put = function(pos, listname, index, stack, player) - minetest.log("action", S("@1 moves stuff to sorter at @2", + hopper.log_inventory(("%s moves stuff to sorter at %s"):format( player:get_player_name(), minetest.pos_to_string(pos))) local timer = minetest.get_node_timer(pos) diff --git a/settingtypes.txt b/settingtypes.txt index 611b25e..a7c341f 100644 --- a/settingtypes.txt +++ b/settingtypes.txt @@ -1,14 +1,17 @@ -#Dimensions of the textures used, in pixels. +# Dimensions of the textures used, in pixels. hopper_texture_size (Hopper texture size) enum 16 16,32 -#When true, the hopper mod uses a single craftable item that auto-selects -#a top hopper or side hopper depending on the context the player places it in. -#When false, top hoppers and side hoppers are explicitly craftable as separate -#items. +# When true, the hopper mod uses a single craftable item that auto-selects +# a top hopper or side hopper depending on the context the player places it in. +# When false, top hoppers and side hoppers are explicitly craftable as separate +# items. hopper_single_craftable_item (Single craftable item) bool true -#This enables a toggle button in the hopper formspecs that allows a hopper -#to be set to "eject" items out into the world if there's no suitable node -#in their target location to receive them. By default hoppers do not eject -#items like this, the player must set this on a per-hopper basis. -hopper_eject_button (Eject items button) bool true \ No newline at end of file +# This enables a toggle button in the hopper formspecs that allows a hopper +# to be set to "eject" items out into the world if there's no suitable node +# in their target location to receive them. By default hoppers do not eject +# items like this, the player must set this on a per-hopper basis. +hopper_eject_button (Eject items button) bool true + +# The Minetest log level to use for inventory take/put actions +hopper_inventory_log_level (Inventory log level) enum action none,action,info,verbose