From 9bd0b2248b1b552628cbc267a4cb375d078f3703 Mon Sep 17 00:00:00 2001 From: Sokomine Date: Wed, 8 May 2024 23:30:42 +0200 Subject: [PATCH] added support for MineClone2; show owner of mobs; better group handling for inspector --- depends.txt | 5 ---- fs_history.lua | 6 ++-- init.lua | 43 +++++++++++++++++++--------- inspect.lua | 78 +++++++++++++++++++++++++++++++++++++++----------- mod.conf | 2 +- 5 files changed, 94 insertions(+), 40 deletions(-) delete mode 100644 depends.txt diff --git a/depends.txt b/depends.txt deleted file mode 100644 index fe0f5de..0000000 --- a/depends.txt +++ /dev/null @@ -1,5 +0,0 @@ -default? -dye? -moreblocks? -stairs? -stairsplus? diff --git a/fs_history.lua b/fs_history.lua index cbe83be..37e55f5 100644 --- a/fs_history.lua +++ b/fs_history.lua @@ -52,7 +52,7 @@ replacer.set_to = function(player_name, pattern, player, itemstack) end -- fallback if nothing is given if(not(pattern)) then - pattern = "default:dirt 0 0" + pattern = replacer.default_dirt.." 0 0" end local set_to = replacer.human_readable_pattern(pattern) @@ -156,8 +156,8 @@ replacer.get_formspec = function(player_name, current_pattern, player) if(not(parts) or #parts<1) then parts = {"does not exist"} -- TODO: handle this in a more general way - elseif(parts[1] == "default:dirt_with_grass") then - parts[1] = "default:dirt" + elseif(parts[1] == "default:dirt_with_grass" or parts[1] == "mcl_core:dirt_with_grass") then + parts[1] = replacer.default_dirt end if(counted_inv[ parts[1] ]) then amount_left = "#00FF00,"..tostring(counted_inv[ parts[1] ]).." available:".. diff --git a/init.lua b/init.lua index 60fbd30..7e4ae1e 100644 --- a/init.lua +++ b/init.lua @@ -48,6 +48,8 @@ dofile(minetest.get_modpath("replacer").."/check_owner.lua"); replacer = {}; +replacer.default_dirt = "default:dirt" + replacer.blacklist = {}; -- playing with tnt and creative building are usually contradictory @@ -119,7 +121,7 @@ minetest.register_tool( "replacer:replacer", local pos = minetest.get_pointed_thing_position( pointed_thing, false ); -- node under local node = minetest.get_node_or_nil( pos ); - local pattern = "default:dirt 0 0"; + local pattern = replacer.default_dirt.." 0 0"; if( node ~= nil and node.name ) then pattern = node.name..' '..node.param1..' '..node.param2; end @@ -162,7 +164,7 @@ replacer.replace = function( itemstack, user, pointed_thing, mode ) -- make sure it is defined if(not(pattern) or pattern == "") then - pattern = "default:dirt 0 0"; + pattern = replacer.default_dirt.." 0 0"; end local keys=user:get_player_control(); @@ -220,9 +222,9 @@ replacer.replace = function( itemstack, user, pointed_thing, mode ) -- players usually don't carry dirt_with_grass around; it's safe to assume normal dirt here -- fortunately, dirt and dirt_with_grass does not make use of rotation - if( daten[1] == "default:dirt_with_grass" ) then - daten[1] = "default:dirt"; - pattern = "default:dirt 0 0"; + if( daten[1] == "default:dirt_with_grass" or daten[1] == "mcl_core:dirt_with_grass") then + daten[1] = replacer.default_dirt + pattern = replacer.default_dirt.." 0 0"; end -- does the player carry at least one of the desired nodes with him? @@ -263,12 +265,25 @@ replacer.replace = function( itemstack, user, pointed_thing, mode ) end -minetest.register_craft({ - output = 'replacer:replacer', - recipe = { - { 'default:chest', '', '' }, - { '', 'default:stick', '' }, - { '', '', 'default:chest' }, - } -}) - +-- do the exception for MineClone first... +if(minetest.registered_nodes["mcl_chests:chest"]) then + replacer.default_dirt = "mcl_core:dirt" + minetest.register_craft({ + output = 'replacer:replacer', + recipe = { + { 'mcl_chests:chest', '', '' }, + { '', 'mcl_core:stick', '' }, + { '', '', 'mcl_chests:chest' }, + } + }) +-- then the normal receipe +elseif(minetest.registered_nodes["default:chest"]) then + minetest.register_craft({ + output = 'replacer:replacer', + recipe = { + { 'default:chest', '', '' }, + { '', 'default:stick', '' }, + { '', '', 'default:chest' }, + } + }) +end diff --git a/inspect.lua b/inspect.lua index d9ea96c..ace8529 100644 --- a/inspect.lua +++ b/inspect.lua @@ -7,14 +7,18 @@ if( minetest.get_modpath("trees") and minetest.get_modpath("instruments") and minetest.get_modpath("anvil") and minetest.get_modpath("scribing_table")) then - replacer.image_replacements[ "group:planks" ] = "trees:pine_planks"; - replacer.image_replacements[ "group:plank" ] = "trees:pine_plank"; - replacer.image_replacements[ "group:wood" ] = "trees:pine_planks"; - replacer.image_replacements[ "group:tree" ] = "trees:pine_log"; - replacer.image_replacements[ "group:sapling"] = "trees:pine_sapling"; - replacer.image_replacements[ "group:leaves" ] = "trees:pine_leaves"; +-- replacer.image_replacements[ "group:planks" ] = "trees:pine_planks"; +-- replacer.image_replacements[ "group:plank" ] = "trees:pine_plank"; +-- replacer.image_replacements[ "group:wood" ] = "trees:pine_planks"; +-- replacer.image_replacements[ "group:tree" ] = "trees:pine_log"; +-- replacer.image_replacements[ "group:sapling"] = "trees:pine_sapling"; +-- replacer.image_replacements[ "group:leaves" ] = "trees:pine_leaves"; replacer.image_replacements[ "default:furnace" ] = "oven:oven"; replacer.image_replacements[ "default:furnace_active" ] = "oven:oven_active"; +-- MineClone +elseif(minetest.registered_items["mcl_furnaces:furnace"]) then + replacer.image_replacements[ "default:furnace" ] = "mcl_furnaces:furnace" + replacer.image_replacements[ "default:furnace_active" ] = "mcl_furnaces:furnace_active" end minetest.register_tool( "replacer:inspect", @@ -86,6 +90,10 @@ replacer.inspect = function( itemstack, user, pointed_thing, mode, show_receipe if( sdata.age ) then text = text..', dropped '..tostring( math.floor( sdata.age/60 ))..' minutes ago'; end + -- show the owner of an entity + if( sdata.owner ) then + text = text..' (owned by '..minetest.formspec_escape(sdata.owner)..")" + end end else text = text..'object \"'..tostring( ref:get_entity_name() )..'\"'; @@ -164,14 +172,38 @@ if( minetest.get_modpath("dye") and dye and dye.basecolors) then end end + +-- find the first known member of a group as an example/representative +replacer.get_first_group_member = function(group_name) + for k,v in pairs(minetest.registered_items) do + if(v and v.groups and v.groups[group_name] and v.groups[group_name] > 0) then + return k + end + end + -- nothing found + return group_name +end + + replacer.image_button_link = function( stack_string ) local group = ''; if( replacer.image_replacements[ stack_string ] ) then stack_string = replacer.image_replacements[ stack_string ]; end - if( replacer.group_placeholder[ stack_string ] ) then + replacer.group_placeholder[ 'group:wood_slab'] = 'stairs:slab_wood'; + + -- if it is a group + if( string.sub(stack_string, 1, 6) == "group:" + -- ..and there is no known member of that group yet + and (not(replacer.group_placeholder[ stack_string ]) + -- or the known member does not exist + or not(minetest.registered_items[ replacer.group_placeholder[ stack_string ]]))) then + -- find and store a suitable group member as example + replacer.group_placeholder[ stack_string ] = replacer.get_first_group_member(string.sub(stack_string, 7)) + end + if(replacer.group_placeholder[ stack_string ] ) then + group = 'Group\n'..minetest.formspec_escape(string.sub(stack_string, 7)) stack_string = replacer.group_placeholder[ stack_string ]; - group = 'G'; end -- TODO: show information about other groups not handled above local stack = ItemStack( stack_string ); @@ -299,9 +331,9 @@ replacer.inspect_show_crafting = function( name, node_name, fields ) -- provide additional information regarding the node in particular that has been inspected if( fields.pos ) then formspec = formspec.."label[0.0,0.3;Located at ".. - minetest.formspec_escape( minetest.pos_to_string( fields.pos )); + minetest.formspec_escape( minetest.pos_to_string( fields.pos )).."]" if( fields.param2 ) then - formspec = formspec.." with param2="..tostring( fields.param2 ); + formspec = formspec.."label[0.0,0.6;with param2="..tostring( fields.param2 ) end if( fields.light ) then formspec = formspec.." and receiving "..tostring( fields.light ).." light"; @@ -405,10 +437,22 @@ end minetest.register_on_player_receive_fields( replacer.form_input_handler ); -minetest.register_craft({ - output = 'replacer:inspect', - recipe = { - { 'default:torch' }, - { 'default:stick' }, - } -}) +-- do the exception for MineClone first... +if(minetest.registered_items["mcl_core:stick"]) then + minetest.register_craft({ + output = 'replacer:inspect', + recipe = { + { 'mcl_torches:torch' }, + { 'mcl_core:stick' }, + } + }) +-- ..then the normal version +elseif(minetest.registered_nodes["default:torch"]) then + minetest.register_craft({ + output = 'replacer:inspect', + recipe = { + { 'default:torch' }, + { 'default:stick' }, + } + }) +end diff --git a/mod.conf b/mod.conf index f642ade..3409788 100644 --- a/mod.conf +++ b/mod.conf @@ -1,5 +1,5 @@ name = replacer description = Essential tool for builders. Allows to store material and rotation and place more blocks the same way without having to turn them all individually with the screwdriver. -optional_depends = default, dye, moreblocks, stairs, stairsplus +optional_depends = default, dye, moreblocks, stairs, stairsplus, mcl_core, mcl_chests author = Sokomine title = Replacer - Node Replace Tool