diff --git a/init.lua b/init.lua index 315f56b..d9098e3 100644 --- a/init.lua +++ b/init.lua @@ -21,6 +21,9 @@ -- Version 3.0 -- Changelog: +-- 29.09.2021 * AUX1 key works now same as SNEAK key for storing new pattern (=easier when flying) +-- * The description of the tool now shows which pattern is stored +-- * The description of the stored pattern is more human readable -- 09.12.2017 * Got rid of outdated minetest.env -- * Fixed error in protection function. -- * Fixed minor bugs. @@ -114,7 +117,13 @@ minetest.register_tool( "replacer:replacer", end itemstack:set_metadata( metadata ); - minetest.chat_send_player( name, "Node replacement tool set to: '"..metadata.."'."); + local set_to = replacer.human_readable_metadata(metadata).." ["..tostring(metadata).."]" + -- change the description of the tool so that it's easier to see which replacer (if you + -- have more than one in your inv) is set to which node + local meta = itemstack:get_meta() + meta:set_string("description", "Replacer set to: "..set_to) + + minetest.chat_send_player( name, "Node replacement tool set to: "..set_to.."."); return itemstack; -- nothing consumed but data changed end, @@ -256,6 +265,46 @@ replacer.replace = function( itemstack, user, pointed_thing, mode ) end +-- turn stored metadata string ( ) into something readable by human beeings +replacer.human_readable_metadata = function(metadata) + if(not(metadata)) then + return "(nothing)" + end + -- data is stored in the form " " + local parts = string.split(metadata, " ") + if(not(parts) or #parts < 3) then + return "(corrupted data)" + end + local node_name = parts[1] + local param2 = parts[3] + + local def = minetest.registered_nodes[ node_name ] + if(not(def)) then + return "(unknown node)" + end + local text = "'"..tostring(def.description or "- no description -").."'" + if(not(def.description) or def.description == "") then + text = "- no description -" + end + -- facedir is probably the most commonly used rotation variant + if( def.paramtype2 == "facedir" + or def.paramtype2 == "colorfacedir") then + local axis_names = {"y+ (Ground)", "z+ (North)", "z- (South)", + "x+ (East)", "x- (West)", "y- (Sky)"} + text = text.." Rotated: "..tostring(param2 % 4).. + " around axis: "..tostring( axis_names[ math.floor( (param2%24) / 4 ) + 1 ]) + -- wallmounted is diffrent + elseif( def.paramtype2 == "wallmounted" + or def.paramtype2 == "colorwallmounted") then + local axis_names = {"y+ (Ground)", "y- (Sky)", + "z+ (North)", "z- (South)", + "x+ (East)", "x- (West)"} + text = text.." Mounted at wall: "..tostring( axis_names[ (param2 % 6)+ 1 ]) + end + return text +end + + minetest.register_craft({ output = 'replacer:replacer', recipe = {