update replacer mod

master
Vanessa Ezekowitz 2015-08-01 06:50:19 -04:00
parent b0d0b8335c
commit 80c7cf973e
3 changed files with 157 additions and 24 deletions

View File

@ -1,18 +1,17 @@
TODO: A distinct image is still missing. Right now, it looks like a steel axe!
Replacement tool for creative building (Mod for MineTest)
This tool is helpful for creative purposes (i.e. build a wall and "paint" windows into it).
It replaces nodes with a previously selected other type of node (i.e. places said windows
into a brick wall).
Crafting: (nothing) stick (nothing)
(nothing) stick (nothing)
(nothing) empty_bucket (nothing)
Crafting: chest - -
- stick -
- - chest
Or just use /giveme replacer:replacer
Usage: Right-click on a node of that type you want to replace other nodes with.
Left-click (normal usage) on any nodes you want to replace with the type you previously right-clicked on.
SHIFT-Right-click in order to store a new pattern.
When in creative mode, the node will just be replaced. Your inventory will not be changed.
@ -20,8 +19,16 @@ When not in creative mode, digging will be simulated and you will get what was t
will be taken from your inventory.
The second tool included in this mod is the inspector.
Copyright (C) 2013 Sokomine
Crafting: torch
stick
Just wield it and click on any node or entity you want to know more about. A limited craft-guide is included.
Copyright (C) 2013,2014,2015 Sokomine
This program is free software: you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by

View File

@ -0,0 +1,2 @@
default?
dye?

View File

@ -1,4 +1,22 @@
replacer.image_replacements = {};
-- support for RealTest
if( minetest.get_modpath("trees")
and minetest.get_modpath("core")
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[ "default:furnace" ] = "oven:oven";
replacer.image_replacements[ "default:furnace_active" ] = "oven:oven_active";
end
minetest.register_tool( "replacer:inspect",
{
description = "Node inspection tool",
@ -21,12 +39,12 @@ minetest.register_tool( "replacer:inspect",
on_use = function(itemstack, user, pointed_thing)
return replacer.inspect( itemstack, user, pointed_thing, above, false );
return replacer.inspect( itemstack, user, pointed_thing, nil, true ); --false );
end,
on_place = function(itemstack, placer, pointed_thing)
return replacer.inspect( itemstack, placer, pointed_thing, above, true );
return replacer.inspect( itemstack, placer, pointed_thing, nil, true );
end,
})
@ -59,7 +77,8 @@ replacer.inspect = function( itemstack, user, pointed_thing, mode, show_receipe
if( sdata.itemstring ) then
text = text..' ['..tostring( sdata.itemstring )..']';
if( show_receipe ) then
replacer.inspect_show_crafting( name, sdata.itemstring, nil );
-- the fields part is used here to provide additional information about the entity
replacer.inspect_show_crafting( name, sdata.itemstring, { pos=pos, luaob=luaob} );
end
end
if( sdata.age ) then
@ -93,15 +112,24 @@ replacer.inspect = function( itemstack, user, pointed_thing, mode, show_receipe
else
text = 'This is a \"'..tostring( minetest.registered_nodes[ node.name ].description or ' - no description provided -')..'\" block'..text;
end
local protected_info = "";
if( minetest.is_protected( pos, name )) then
text = text..' You can\'t dig this node. It is protected.';
protected_info = 'WARNING: You can\'t dig this node. It is protected.';
elseif( minetest.is_protected( pos, '_THIS_NAME_DOES_NOT_EXIST_' )) then
text = text..' You can dig this node, but others can\'t.';
protected_info = 'INFO: You can dig this node, but others can\'t.';
end
minetest.chat_send_player( name, text );
text = text..' '..protected_info;
-- no longer spam the chat; the craft guide is more informative
-- minetest.chat_send_player( name, text );
if( show_receipe ) then
replacer.inspect_show_crafting( name, node.name, nil );
-- get light of the node at the current time
local light = minetest.get_node_light(pos, nil);
if( light==0 ) then
light = minetest.get_node_light( {x=pos.x,y=pos.y+1,z=pos.z});
end
-- the fields part is used here to provide additional information about the node
replacer.inspect_show_crafting( name, node.name, {pos=pos, param2=node.param2, light=light, protected_info=protected_info} );
end
return nil; -- no item shall be removed from inventory
end
@ -110,15 +138,35 @@ end
replacer.group_placeholder = {};
replacer.group_placeholder[ 'group:wood' ] = 'default:wood';
replacer.group_placeholder[ 'group:tree' ] = 'default:tree';
replacer.group_placeholder[ 'group:sapling']= 'default:sapling';
replacer.group_placeholder[ 'group:stick' ] = 'default:stick';
replacer.group_placeholder[ 'group:stone' ] = 'default:stone';
replacer.group_placeholder[ 'group:stone' ] = 'default:cobble'; -- 'default:stone'; point people to the cheaper cobble
replacer.group_placeholder[ 'group:sand' ] = 'default:sand';
replacer.group_placeholder[ 'group:leaves'] = 'default:leaves';
replacer.group_placeholder[ 'group:wood_slab'] = 'stairs:slab_wood';
replacer.group_placeholder[ 'group:wool' ] = 'wool:white';
-- handle the standard dye color groups
if( minetest.get_modpath("dye") and dye and dye.basecolors) then
for i,color in ipairs( dye.basecolors ) do
local def = minetest.registered_items[ "dye:"..color ];
if( def and def.groups ) then
for k,v in pairs( def.groups ) do
if( k ~= 'dye' ) then
replacer.group_placeholder[ 'group:dye,'..k ] = 'dye:'..color;
end
end
replacer.group_placeholder[ 'group:flower,color_'..color ] = 'dye:'..color;
end
end
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
stack_string = replacer.group_placeholder[ stack_string ];
group = 'G';
@ -133,7 +181,7 @@ replacer.image_button_link = function( stack_string )
end
replacer.add_circular_saw_receipe = function( node_name, receipes )
if( not( node_name ) or not( circular_saw ) or not( circular_saw.names) or (node_name=='moreblocks:circular_saw')) then
if( not( node_name ) or not( minetest.get_modpath("moreblocks")) or not( circular_saw ) or not( circular_saw.names) or (node_name=='moreblocks:circular_saw')) then
return;
end
local help = node_name:split( ':' );
@ -157,7 +205,7 @@ help[1]='default';
end
replacer.add_colormachine_receipe = function( node_name, receipes )
if( not( colormachine )) then
if( not( minetest.get_modpath("colormachine")) or not( colormachine )) then
return;
end
local res = colormachine.get_node_name_painted( node_name, "" );
@ -175,11 +223,15 @@ replacer.inspect_show_crafting = function( name, node_name, fields )
if( not( name )) then
return;
end
local receipe_nr = 1;
if( not( node_name )) then
node_name = fields.node_name;
receipe_nr = tonumber(fields.receipe_nr);
end
-- turn it into an item stack so that we can handle dropped stacks etc
local stack = ItemStack( node_name );
node_name = stack:get_name();
-- the player may ask for receipes of indigrents to the current receipe
if( fields ) then
@ -209,11 +261,57 @@ replacer.inspect_show_crafting = function( name, node_name, fields )
receipe_nr = receipe_nr + 1;
end
local desc = nil;
if( minetest.registered_nodes[ node_name ] ) then
if( minetest.registered_nodes[ node_name ].description
and minetest.registered_nodes[ node_name ].description~= "") then
desc = "\""..minetest.registered_nodes[ node_name ].description.."\" block";
elseif( minetest.registered_nodes[ node_name ].name ) then
desc = "\""..minetest.registered_nodes[ node_name ].name.."\" block";
else
desc = " - no description provided - block";
end
elseif( minetest.registered_items[ node_name ] ) then
if( minetest.registered_items[ node_name ].description
and minetest.registered_items[ node_name ].description~= "") then
desc = "\""..minetest.registered_items[ node_name ].description.."\" item";
elseif( minetest.registered_items[ node_name ].name ) then
desc = "\""..minetest.registered_items[ node_name ].name.."\" item";
else
desc = " - no description provided - item";
end
end
if( not( desc ) or desc=="") then
desc = ' - no description provided - ';
end
local formspec = "size[6,6]"..
"label[0,5.5;This is a "..minetest.formspec_escape( desc )..".]"..
"button_exit[5.0,4.3;1,0.5;quit;Exit]"..
"label[0,0;Name:]"..
"field[20,20;0.1,0.1;node_name;node_name;"..node_name.."]".. -- invisible field for passing on information
"field[21,21;0.1,0.1;receipe_nr;receipe_nr;"..tostring( receipe_nr ).."]".. -- another invisible field
"label[1,0;"..tostring( node_name ).."]"..
"item_image_button[5,2;1.0,1.0;"..tostring( node_name )..";normal;]";
-- 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 ));
if( fields.param2 ) then
formspec = formspec.." with param2="..tostring( fields.param2 );
end
if( fields.light ) then
formspec = formspec.." and receiving "..tostring( fields.light ).." light";
end
formspec = formspec..".]";
end
-- show information about protection
if( fields.protected_info and fields.protected_info ~= "" ) then
formspec = formspec.."label[0.0,4.5;"..minetest.formspec_escape( fields.protected_info ).."]";
end
if( not( res ) or receipe_nr > #res or receipe_nr < 1 ) then
receipe_nr = 1;
end
@ -221,16 +319,33 @@ replacer.inspect_show_crafting = function( name, node_name, fields )
formspec = formspec.."button[3.8,5;1,0.5;prev_receipe;prev]";
end
if( res and receipe_nr < #res ) then
formspec = formspec.."button[5.0,5;1,0.5;next_receipe;next]";
formspec = formspec.."button[5.0,5.0;1,0.5;next_receipe;next]";
end
if( not( res ) or #res<1) then
formspec = formspec..'label[3,1;No receipes.]';
if( minetest.registered_nodes[ node_name ]
and minetest.registered_nodes[ node_name ].drop ) then
local drop = minetest.registered_nodes[ node_name ].drop;
if( drop and type( drop )=='string' and drop ~= node_name ) then
formspec = formspec.."label[2,1.6;Drops on dig:]"..
"item_image_button[2,2;1.0,1.0;"..replacer.image_button_link( drop ).."]";
if( drop ) then
if( type( drop )=='string' and drop ~= node_name ) then
formspec = formspec.."label[2,1.6;Drops on dig:]"..
"item_image_button[2,2;1.0,1.0;"..replacer.image_button_link( drop ).."]";
elseif( type( drop )=='table' and drop.items ) then
local droplist = {};
for _,drops in ipairs( drop.items ) do
for _,item in ipairs( drops.items ) do
-- avoid duplicates; but include the item itshelf
droplist[ item ] = 1;
end
end
local i = 1;
formspec = formspec.."label[2,1.6;May drop on dig:]";
for k,v in pairs( droplist ) do
formspec = formspec..
"item_image_button["..(((i-1)%3)+1)..","..math.floor(((i-1)/3)+2)..";1.0,1.0;"..replacer.image_button_link( k ).."]";
i = i+1;
end
end
end
end
else
@ -238,12 +353,22 @@ replacer.inspect_show_crafting = function( name, node_name, fields )
-- reverse order; default receipes (and thus the most intresting ones) are usually the oldest
local receipe = res[ #res+1-receipe_nr ];
if( receipe.type=='normal' and receipe.items) then
local width = receipe.width;
if( not( width ) or width==0 ) then
width = 3;
end
for i=1,9 do
if( receipe.items[i] ) then
formspec = formspec.."item_image_button["..(((i-1)%3)+1)..','..(math.floor((i-1)/3)+1)..";1.0,1.0;"..
formspec = formspec.."item_image_button["..(((i-1)%width)+1)..','..(math.floor((i-1)/width)+1)..";1.0,1.0;"..
replacer.image_button_link( receipe.items[i] ).."]";
end
end
elseif( receipe.type=='cooking' and receipe.items and #receipe.items==1
and receipe.output=="" ) then
formspec = formspec.."item_image_button[1,1;3.4,3.4;"..replacer.image_button_link( 'default:furnace_active' ).."]".. --default_furnace_front.png]"..
"item_image_button[2.9,2.7;1.0,1.0;"..replacer.image_button_link( receipe.items[1] ).."]"..
"label[1.0,0;"..tostring(receipe.items[1]).."]"..
"label[0,0.5;This can be used as a fuel.]";
elseif( receipe.type=='cooking' and receipe.items and #receipe.items==1 ) then
formspec = formspec.."item_image_button[1,1;3.4,3.4;"..replacer.image_button_link( 'default:furnace' ).."]".. --default_furnace_front.png]"..
"item_image_button[2.9,2.7;1.0,1.0;"..replacer.image_button_link( receipe.items[1] ).."]";
@ -281,8 +406,7 @@ minetest.register_on_player_receive_fields( replacer.form_input_handler );
minetest.register_craft({
output = 'replacer:inspect',
recipe = {
{ '', 'default:mese_crystal', '' },
{ '', 'default:sign_wall', '' },
{ '', '', '' },
{ 'default:torch' },
{ 'default:stick' },
}
})