Skip to content

Commit

Permalink
added support for MineClone2; show owner of mobs; better group handli…
Browse files Browse the repository at this point in the history
…ng for inspector
  • Loading branch information
Sokomine committed May 8, 2024
1 parent d69fcb3 commit 9bd0b22
Show file tree
Hide file tree
Showing 5 changed files with 94 additions and 40 deletions.
5 changes: 0 additions & 5 deletions depends.txt

This file was deleted.

6 changes: 3 additions & 3 deletions fs_history.lua
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down Expand Up @@ -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:"..
Expand Down
43 changes: 29 additions & 14 deletions init.lua
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -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();
Expand Down Expand Up @@ -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?
Expand Down Expand Up @@ -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
78 changes: 61 additions & 17 deletions inspect.lua
Original file line number Diff line number Diff line change
Expand Up @@ -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",
Expand Down Expand Up @@ -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() )..'\"';
Expand Down Expand Up @@ -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 );
Expand Down Expand Up @@ -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";
Expand Down Expand Up @@ -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
2 changes: 1 addition & 1 deletion mod.conf
Original file line number Diff line number Diff line change
@@ -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

1 comment on commit 9bd0b22

@SwissalpS
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Have you considered [xcompat]? That would make this mod even more game independant.
https://github.com/mt-mods/xcompat
The branch I'm working on in my fork: SwissalpS#53

Please sign in to comment.