mirror of
https://github.com/Sokomine/replacer.git
synced 2025-07-20 00:40:24 +02:00
Compare commits
2 Commits
master
...
c0fa835364
Author | SHA1 | Date | |
---|---|---|---|
c0fa835364 | |||
95ce57d6e5 |
5
depends.txt
Normal file
5
depends.txt
Normal file
@ -0,0 +1,5 @@
|
|||||||
|
default?
|
||||||
|
dye?
|
||||||
|
moreblocks?
|
||||||
|
stairs?
|
||||||
|
stairsplus?
|
@ -52,7 +52,7 @@ replacer.set_to = function(player_name, pattern, player, itemstack)
|
|||||||
end
|
end
|
||||||
-- fallback if nothing is given
|
-- fallback if nothing is given
|
||||||
if(not(pattern)) then
|
if(not(pattern)) then
|
||||||
pattern = replacer.default_dirt.." 0 0"
|
pattern = "default:dirt 0 0"
|
||||||
end
|
end
|
||||||
|
|
||||||
local set_to = replacer.human_readable_pattern(pattern)
|
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
|
if(not(parts) or #parts<1) then
|
||||||
parts = {"does not exist"}
|
parts = {"does not exist"}
|
||||||
-- TODO: handle this in a more general way
|
-- TODO: handle this in a more general way
|
||||||
elseif(parts[1] == "default:dirt_with_grass" or parts[1] == "mcl_core:dirt_with_grass") then
|
elseif(parts[1] == "default:dirt_with_grass") then
|
||||||
parts[1] = replacer.default_dirt
|
parts[1] = "default:dirt"
|
||||||
end
|
end
|
||||||
if(counted_inv[ parts[1] ]) then
|
if(counted_inv[ parts[1] ]) then
|
||||||
amount_left = "#00FF00,"..tostring(counted_inv[ parts[1] ]).." available:"..
|
amount_left = "#00FF00,"..tostring(counted_inv[ parts[1] ]).." available:"..
|
||||||
|
30
init.lua
30
init.lua
@ -48,8 +48,6 @@ dofile(minetest.get_modpath("replacer").."/check_owner.lua");
|
|||||||
|
|
||||||
replacer = {};
|
replacer = {};
|
||||||
|
|
||||||
replacer.default_dirt = "default:dirt"
|
|
||||||
|
|
||||||
replacer.blacklist = {};
|
replacer.blacklist = {};
|
||||||
|
|
||||||
-- playing with tnt and creative building are usually contradictory
|
-- playing with tnt and creative building are usually contradictory
|
||||||
@ -110,7 +108,7 @@ minetest.register_tool( "replacer:replacer",
|
|||||||
-- just place the stored node if no new one is to be selected
|
-- just place the stored node if no new one is to be selected
|
||||||
if( not( keys["sneak"] ) and not( keys["aux1"])) then
|
if( not( keys["sneak"] ) and not( keys["aux1"])) then
|
||||||
|
|
||||||
return replacer.replace( itemstack, placer, pointed_thing, 0 ); end
|
return replacer.replace( itemstack, placer, pointed_thing, true ); end
|
||||||
|
|
||||||
|
|
||||||
if( pointed_thing.type ~= "node" ) then
|
if( pointed_thing.type ~= "node" ) then
|
||||||
@ -121,7 +119,7 @@ minetest.register_tool( "replacer:replacer",
|
|||||||
local pos = minetest.get_pointed_thing_position( pointed_thing, false ); -- node under
|
local pos = minetest.get_pointed_thing_position( pointed_thing, false ); -- node under
|
||||||
local node = minetest.get_node_or_nil( pos );
|
local node = minetest.get_node_or_nil( pos );
|
||||||
|
|
||||||
local pattern = replacer.default_dirt.." 0 0";
|
local pattern = "default:dirt 0 0";
|
||||||
if( node ~= nil and node.name ) then
|
if( node ~= nil and node.name ) then
|
||||||
pattern = node.name..' '..node.param1..' '..node.param2;
|
pattern = node.name..' '..node.param1..' '..node.param2;
|
||||||
end
|
end
|
||||||
@ -164,7 +162,7 @@ replacer.replace = function( itemstack, user, pointed_thing, mode )
|
|||||||
|
|
||||||
-- make sure it is defined
|
-- make sure it is defined
|
||||||
if(not(pattern) or pattern == "") then
|
if(not(pattern) or pattern == "") then
|
||||||
pattern = replacer.default_dirt.." 0 0";
|
pattern = "default:dirt 0 0";
|
||||||
end
|
end
|
||||||
|
|
||||||
local keys=user:get_player_control();
|
local keys=user:get_player_control();
|
||||||
@ -222,9 +220,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
|
-- 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
|
-- fortunately, dirt and dirt_with_grass does not make use of rotation
|
||||||
if( daten[1] == "default:dirt_with_grass" or daten[1] == "mcl_core:dirt_with_grass") then
|
if( daten[1] == "default:dirt_with_grass" ) then
|
||||||
daten[1] = replacer.default_dirt
|
daten[1] = "default:dirt";
|
||||||
pattern = replacer.default_dirt.." 0 0";
|
pattern = "default:dirt 0 0";
|
||||||
end
|
end
|
||||||
|
|
||||||
-- does the player carry at least one of the desired nodes with him?
|
-- does the player carry at least one of the desired nodes with him?
|
||||||
@ -265,19 +263,6 @@ replacer.replace = function( itemstack, user, pointed_thing, mode )
|
|||||||
end
|
end
|
||||||
|
|
||||||
|
|
||||||
-- 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({
|
minetest.register_craft({
|
||||||
output = 'replacer:replacer',
|
output = 'replacer:replacer',
|
||||||
recipe = {
|
recipe = {
|
||||||
@ -286,4 +271,5 @@ elseif(minetest.registered_nodes["default:chest"]) then
|
|||||||
{ '', '', 'default:chest' },
|
{ '', '', 'default:chest' },
|
||||||
}
|
}
|
||||||
})
|
})
|
||||||
end
|
|
||||||
|
minetest.log("action", "[replacer] loaded.")
|
||||||
|
64
inspect.lua
64
inspect.lua
@ -7,18 +7,14 @@ if( minetest.get_modpath("trees")
|
|||||||
and minetest.get_modpath("instruments")
|
and minetest.get_modpath("instruments")
|
||||||
and minetest.get_modpath("anvil")
|
and minetest.get_modpath("anvil")
|
||||||
and minetest.get_modpath("scribing_table")) then
|
and minetest.get_modpath("scribing_table")) then
|
||||||
-- replacer.image_replacements[ "group:planks" ] = "trees:pine_planks";
|
replacer.image_replacements[ "group:planks" ] = "trees:pine_planks";
|
||||||
-- replacer.image_replacements[ "group:plank" ] = "trees:pine_plank";
|
replacer.image_replacements[ "group:plank" ] = "trees:pine_plank";
|
||||||
-- replacer.image_replacements[ "group:wood" ] = "trees:pine_planks";
|
replacer.image_replacements[ "group:wood" ] = "trees:pine_planks";
|
||||||
-- replacer.image_replacements[ "group:tree" ] = "trees:pine_log";
|
replacer.image_replacements[ "group:tree" ] = "trees:pine_log";
|
||||||
-- replacer.image_replacements[ "group:sapling"] = "trees:pine_sapling";
|
replacer.image_replacements[ "group:sapling"] = "trees:pine_sapling";
|
||||||
-- replacer.image_replacements[ "group:leaves" ] = "trees:pine_leaves";
|
replacer.image_replacements[ "group:leaves" ] = "trees:pine_leaves";
|
||||||
replacer.image_replacements[ "default:furnace" ] = "oven:oven";
|
replacer.image_replacements[ "default:furnace" ] = "oven:oven";
|
||||||
replacer.image_replacements[ "default:furnace_active" ] = "oven:oven_active";
|
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
|
end
|
||||||
|
|
||||||
minetest.register_tool( "replacer:inspect",
|
minetest.register_tool( "replacer:inspect",
|
||||||
@ -90,10 +86,6 @@ replacer.inspect = function( itemstack, user, pointed_thing, mode, show_receipe
|
|||||||
if( sdata.age ) then
|
if( sdata.age ) then
|
||||||
text = text..', dropped '..tostring( math.floor( sdata.age/60 ))..' minutes ago';
|
text = text..', dropped '..tostring( math.floor( sdata.age/60 ))..' minutes ago';
|
||||||
end
|
end
|
||||||
-- show the owner of an entity
|
|
||||||
if( sdata.owner ) then
|
|
||||||
text = text..' (owned by '..minetest.formspec_escape(sdata.owner)..")"
|
|
||||||
end
|
|
||||||
end
|
end
|
||||||
else
|
else
|
||||||
text = text..'object \"'..tostring( ref:get_entity_name() )..'\"';
|
text = text..'object \"'..tostring( ref:get_entity_name() )..'\"';
|
||||||
@ -172,38 +164,14 @@ if( minetest.get_modpath("dye") and dye and dye.basecolors) then
|
|||||||
end
|
end
|
||||||
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 )
|
replacer.image_button_link = function( stack_string )
|
||||||
local group = '';
|
local group = '';
|
||||||
if( replacer.image_replacements[ stack_string ] ) then
|
if( replacer.image_replacements[ stack_string ] ) then
|
||||||
stack_string = replacer.image_replacements[ stack_string ];
|
stack_string = replacer.image_replacements[ stack_string ];
|
||||||
end
|
end
|
||||||
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
|
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 ];
|
stack_string = replacer.group_placeholder[ stack_string ];
|
||||||
|
group = 'G';
|
||||||
end
|
end
|
||||||
-- TODO: show information about other groups not handled above
|
-- TODO: show information about other groups not handled above
|
||||||
local stack = ItemStack( stack_string );
|
local stack = ItemStack( stack_string );
|
||||||
@ -222,7 +190,7 @@ replacer.add_circular_saw_receipe = function( node_name, receipes )
|
|||||||
if( not( help ) or #help ~= 2 or help[1]=='stairs') then
|
if( not( help ) or #help ~= 2 or help[1]=='stairs') then
|
||||||
return;
|
return;
|
||||||
end
|
end
|
||||||
help2 = help[2]:split('_');
|
local help2 = help[2]:split('_');
|
||||||
if( not( help2 ) or #help2 < 2 or (help2[1]~='micro' and help2[1]~='panel' and help2[1]~='stair' and help2[1]~='slab')) then
|
if( not( help2 ) or #help2 < 2 or (help2[1]~='micro' and help2[1]~='panel' and help2[1]~='stair' and help2[1]~='slab')) then
|
||||||
return;
|
return;
|
||||||
end
|
end
|
||||||
@ -331,9 +299,9 @@ replacer.inspect_show_crafting = function( name, node_name, fields )
|
|||||||
-- provide additional information regarding the node in particular that has been inspected
|
-- provide additional information regarding the node in particular that has been inspected
|
||||||
if( fields.pos ) then
|
if( fields.pos ) then
|
||||||
formspec = formspec.."label[0.0,0.3;Located at "..
|
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
|
if( fields.param2 ) then
|
||||||
formspec = formspec.."label[0.0,0.6;with param2="..tostring( fields.param2 )
|
formspec = formspec.." with param2="..tostring( fields.param2 );
|
||||||
end
|
end
|
||||||
if( fields.light ) then
|
if( fields.light ) then
|
||||||
formspec = formspec.." and receiving "..tostring( fields.light ).." light";
|
formspec = formspec.." and receiving "..tostring( fields.light ).." light";
|
||||||
@ -437,17 +405,6 @@ end
|
|||||||
minetest.register_on_player_receive_fields( replacer.form_input_handler );
|
minetest.register_on_player_receive_fields( replacer.form_input_handler );
|
||||||
|
|
||||||
|
|
||||||
-- 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({
|
minetest.register_craft({
|
||||||
output = 'replacer:inspect',
|
output = 'replacer:inspect',
|
||||||
recipe = {
|
recipe = {
|
||||||
@ -455,4 +412,3 @@ elseif(minetest.registered_nodes["default:torch"]) then
|
|||||||
{ 'default:stick' },
|
{ 'default:stick' },
|
||||||
}
|
}
|
||||||
})
|
})
|
||||||
end
|
|
||||||
|
2
mod.conf
2
mod.conf
@ -1,5 +1,5 @@
|
|||||||
name = replacer
|
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.
|
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, mcl_core, mcl_chests
|
optional_depends = default, dye, moreblocks, stairs, stairsplus
|
||||||
author = Sokomine
|
author = Sokomine
|
||||||
title = Replacer - Node Replace Tool
|
title = Replacer - Node Replace Tool
|
||||||
|
@ -5,8 +5,8 @@ replacer.user_mode = {}
|
|||||||
-- descriptions for the dropdown menu (accessible via AUX1 + left-click)
|
-- descriptions for the dropdown menu (accessible via AUX1 + left-click)
|
||||||
replacer.mode_descriptions = {
|
replacer.mode_descriptions = {
|
||||||
"[ normal ] replace material, shape and orientation according to the stored pattern",
|
"[ normal ] replace material, shape and orientation according to the stored pattern",
|
||||||
"[ material ] replace the material only (if possible), while keeping shape and orientation",
|
"[ material ] replace the material only (if possible), but keep shape and orientation",
|
||||||
"[ shape ] replace shape and orientation (if possible), while keeping the material"}
|
"[ shape ] replace shape and orientation (if possible), but keep the material"}
|
||||||
|
|
||||||
-- internal names for the above modes (will be stored in replacer.user_mode[ player_name ])
|
-- internal names for the above modes (will be stored in replacer.user_mode[ player_name ])
|
||||||
replacer.mode_names = {"normal", "material", "shape"}
|
replacer.mode_names = {"normal", "material", "shape"}
|
||||||
|
Reference in New Issue
Block a user