Compare commits

...

5 Commits

Author SHA1 Message Date
Beha 1894adcae6 local 2017-07-03 07:13:16 -04:00
Beha c6061c999f local 2015-12-15 09:44:03 -05:00
Beha 90bbf5a666 local 2015-12-03 08:28:38 -05:00
Beha 04973f449c local 2015-12-02 08:30:23 -05:00
Sokomine 3f4ed7dc34 updated readme 2015-07-28 22:54:15 +02:00
5 changed files with 221 additions and 146 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

@ -1,2 +1,3 @@
default?
dye?
technic

312
init.lua
View File

@ -1,5 +1,5 @@
--[[
Replacement tool for creative building (Mod for MineTest)
Copyright (C) 2013 Sokomine
@ -20,7 +20,7 @@
-- Version 3.0
-- Changelog:
-- Changelog:
-- 02.10.2014 * Some more improvements for inspect-tool. Added craft-guide.
-- 01.10.2014 * Added inspect-tool.
-- 12.01.2013 * If digging the node was unsuccessful, then the replacement will now fail
@ -29,10 +29,10 @@
-- in order to check if the replacement is allowed
-- 24.04.2013 * param1 and param2 are now stored
-- * hold sneak + right click to store new pattern
-- * right click: place one of the itmes
-- * right click: place one of the itmes
-- * receipe changed
-- * inventory image added
-- adds a function to check ownership of a node; taken from VanessaEs homedecor mod
dofile(minetest.get_modpath("replacer").."/check_owner.lua");
@ -41,10 +41,30 @@ replacer = {};
-- adds a tool for inspecting nodes and entities
dofile(minetest.get_modpath("replacer").."/inspect.lua");
function Set (list)
local set = {}
for _, l in ipairs(list) do set[l] = true end
return set
end
local blacklist = Set {
"protector:protect",
"protector:protect2",
"protector:protect3",
"protector:teamprotect",
"protector:pvpprotect",
"air",
}
local replacer_charge = 50000
local replacer_charge_per_node = 200
technic.register_power_tool("replacer:replacer", replacer_charge)
minetest.register_tool( "replacer:replacer",
{
description = "Node replacement tool",
groups = {},
description = "Node Replacement Tool",
groups = {},
inventory_image = "replacer_replacer.png",
wield_image = "",
wield_scale = {x=1,y=1,z=1},
@ -62,7 +82,10 @@ minetest.register_tool( "replacer:replacer",
}
},
node_placement_prediction = nil,
metadata = "default:dirt", -- default replacement: common dirt
metadata = minetest.serialize({item = "default:dirt"}), -- default replacement: common dirt
wear_represents = "technic_RE_charge",
on_refill = technic.refill_RE_charge,
on_place = function(itemstack, placer, pointed_thing)
@ -73,13 +96,13 @@ minetest.register_tool( "replacer:replacer",
--minetest.chat_send_player( name, "You PLACED this on "..minetest.serialize( pointed_thing )..".");
local keys=placer:get_player_control();
-- just place the stored node if now new one is to be selected
if( not( keys["sneak"] )) then
return replacer.replace( itemstack, placer, pointed_thing, 0 ); end
if( pointed_thing.type ~= "node" ) then
minetest.chat_send_player( name, " Error: No node selected.");
return nil;
@ -87,152 +110,179 @@ minetest.register_tool( "replacer:replacer",
local pos = minetest.get_pointed_thing_position( pointed_thing, under );
local node = minetest.env:get_node_or_nil( pos );
--minetest.chat_send_player( name, " Target node: "..minetest.serialize( node ).." at pos "..minetest.serialize( pos )..".");
local item = itemstack:to_table();
if blacklist[node.name] then
minetest.chat_send_player(name, "You cannot use '"..node.name.."' in a replacer.")
return nil;
end
--minetest.chat_send_player( name, " Target node: "..minetest.serialize( node ).." at pos "..minetest.serialize( pos )..".");
local meta = minetest.deserialize(itemstack:get_metadata())
if not meta or not meta.charge then
return
end
-- make sure metadata is always set
if( node ~= nil and node.name ) then
item[ "metadata" ] = node.name..' '..node.param1..' '..node.param2;
meta.item = node.name..' '..node.param1..' '..node.param2;
else
item[ "metadata" ] = "default:dirt 0 0";
meta.item = "default:dirt 0 0";
end
itemstack:replace( item );
minetest.chat_send_player( name, "Node replacement tool set to: '"..item[ "metadata" ].."'.");
itemstack:set_metadata(minetest.serialize(meta))
itemstack:get_meta():set_string("description", "Node Replacement Tool ("..meta.item..")")
return itemstack; -- nothing consumed but data changed
minetest.chat_send_player( name, "Node replacement tool set to: '"..meta.item.."'.");
return itemstack -- nothing consumed but data changed
end,
-- on_drop = func(itemstack, dropper, pos),
on_use = function(itemstack, user, pointed_thing)
return replacer.replace( itemstack, user, pointed_thing, above );
end,
})
replacer.replace = function( itemstack, user, pointed_thing, mode )
if( user == nil or pointed_thing == nil) then
return nil;
end
local name = user:get_player_name();
--minetest.chat_send_player( name, "You USED this on "..minetest.serialize( pointed_thing )..".");
if( pointed_thing.type ~= "node" ) then
minetest.chat_send_player( name, " Error: No node.");
return nil;
end
local pos = minetest.get_pointed_thing_position( pointed_thing, mode );
local node = minetest.env:get_node_or_nil( pos );
--minetest.chat_send_player( name, " Target node: "..minetest.serialize( node ).." at pos "..minetest.serialize( pos )..".");
if( node == nil ) then
minetest.chat_send_player( name, "Error: Target node not yet loaded. Please wait a moment for the server to catch up.");
return nil;
end
local item = itemstack:to_table();
-- make sure it is defined
if( not( item[ "metadata"] ) or item["metadata"]=="" ) then
item["metadata"] = "default:dirt 0 0";
end
-- regain information about nodename, param1 and param2
local daten = item[ "metadata"]:split( " " );
-- the old format stored only the node name
if( #daten < 3 ) then
daten[2] = 0;
daten[3] = 0;
end
-- if someone else owns that node then we can not change it
if( replacer_homedecor_node_is_owned(pos, user)) then
return nil;
end
-- do not replace if there is nothing to be done
if( node.name == daten[1] ) then
-- the node itshelf remains the same, but the orientation was changed
if( node.param1 ~= daten[2] or node.param2 ~= daten[3] ) then
minetest.env:add_node( pos, { name = node.name, param1 = daten[2], param2 = daten[3] } );
end
return nil;
end
-- in survival mode, the player has to provide the node he wants to be placed
if( not(minetest.setting_getbool("creative_mode") )) then
-- players usually don't carry dirt_with_grass around; it's safe to assume normal dirt here
-- fortionately, dirt and dirt_with_grass does not make use of rotation
if( daten[1] == "default:dirt_with_grass" ) then
daten[1] = "default:dirt";
item["metadata"] = "default:dirt 0 0";
end
-- does the player carry at least one of the desired nodes with him?
if( not( user:get_inventory():contains_item("main", daten[1]))) then
minetest.chat_send_player( name, "You have no further '"..( daten[1] or "?" ).."'. Replacement failed.");
return nil;
end
-- give the player the item by simulating digging if possible
if( node.name ~= "air"
and node.name ~= "ignore"
and node.name ~= "default:lava_source"
and node.name ~= "default:lava_flowing"
and node.name ~= "default:water_source"
and node.name ~= "default:water_flowing" ) then
minetest.node_dig( pos, node, user );
local digged_node = minetest.env:get_node_or_nil( pos );
if( not( digged_node )
or digged_node.name == node.name ) then
minetest.chat_send_player( name, "Replacing '"..( node.name or "air" ).."' with '"..( item[ "metadata"] or "?" ).."' failed. Unable to remove old node.");
return nil;
end
end
-- consume the item
user:get_inventory():remove_item("main", daten[1].." 1");
--user:get_inventory():add_item( "main", node.name.." 1");
end
--minetest.chat_send_player( name, "Replacing node '"..( node.name or "air" ).."' with '"..( item[ "metadata"] or "?" ).."'.");
--minetest.env:place_node( pos, { name = item[ "metadata" ] } );
minetest.env:add_node( pos, { name = daten[1], param1 = daten[2], param2 = daten[3] } );
return nil; -- no item shall be removed from inventory
local meta = minetest.deserialize(itemstack:get_metadata())
if not meta or not meta.charge then
return
end
if( user == nil or pointed_thing == nil) then
return nil;
end
local name = user:get_player_name();
--minetest.chat_send_player( name, "You USED this on "..minetest.serialize( pointed_thing )..".");
if( pointed_thing.type ~= "node" ) then
minetest.chat_send_player( name, " Error: No node.");
return nil;
end
local pos = minetest.get_pointed_thing_position( pointed_thing, mode );
local node = minetest.env:get_node_or_nil( pos );
--minetest.chat_send_player( name, " Target node: "..minetest.serialize( node ).." at pos "..minetest.serialize( pos )..".");
if( node == nil ) then
minetest.chat_send_player( name, "Error: Target node not yet loaded. Please wait a moment for the server to catch up.");
return nil;
end
local item = itemstack:to_table();
-- make sure it is defined
if( not( meta.item ) or meta.item=="" ) then
meta.item = "default:dirt 0 0";
end
-- regain information about nodename, param1 and param2
local daten = meta.item:split( " " );
-- the old format stored only the node name
if( #daten < 3 ) then
daten[2] = 0;
daten[3] = 0;
end
-- if someone else owns that node then we can not change it
if( replacer_homedecor_node_is_owned(pos, user)) then
return nil;
end
if blacklist[daten[1]] then
minetest.chat_send_player(name, "You cannot use '"..node.name.."' in a replacer.")
return nil;
end
-- do not replace if there is nothing to be done
if( node.name == daten[1] ) then
-- the node itshelf remains the same, but the orientation was changed
if( node.param1 ~= daten[2] or node.param2 ~= daten[3] ) then
minetest.env:add_node( pos, { name = node.name, param1 = daten[2], param2 = daten[3] } );
end
return nil;
end
-- in survival mode, the player has to provide the node he wants to be placed
if( not(minetest.setting_getbool("creative_mode") )) then
-- players usually don't carry dirt_with_grass around; it's safe to assume normal dirt here
-- fortionately, dirt and dirt_with_grass does not make use of rotation
if( daten[1] == "default:dirt_with_grass" ) then
daten[1] = "default:dirt";
meta.item = "default:dirt 0 0";
end
-- does the player carry at least one of the desired nodes with him?
if( not( user:get_inventory():contains_item("main", daten[1]))) then
minetest.chat_send_player( name, "You have no further '"..( daten[1] or "?" ).."'. Replacement failed.");
return nil;
end
if meta.charge >= replacer_charge_per_node then
if not technic.creative_mode then
meta.charge = meta.charge - replacer_charge_per_node
itemstack:set_metadata(minetest.serialize(meta))
technic.set_RE_wear(itemstack, meta.charge, replacer_charge)
end
else
if not technic.creative_mode then
return itemstack
end
end
-- give the player the item by simulating digging if possible
if( node.name ~= "air"
and node.name ~= "ignore"
and node.name ~= "default:lava_source"
and node.name ~= "default:lava_flowing"
and node.name ~= "default:water_source"
and node.name ~= "default:water_flowing" ) then
minetest.node_dig( pos, node, user );
local digged_node = minetest.env:get_node_or_nil( pos );
if( not( digged_node )
or digged_node.name == node.name ) then
minetest.chat_send_player( name, "Replacing '"..( node.name or "air" ).."' with '"..( meta.item or "?" ).."' failed. Unable to remove old node.");
return nil;
end
end
-- consume the item
user:get_inventory():remove_item("main", daten[1].." 1");
--user:get_inventory():add_item( "main", node.name.." 1");
end
--minetest.chat_send_player( name, "Replacing node '"..( node.name or "air" ).."' with '"..( item[ "metadata"] or "?" ).."'.");
--minetest.env:place_node( pos, { name = item[ "metadata" ] } );
minetest.env:add_node( pos, { name = daten[1], param1 = daten[2], param2 = daten[3] } );
return itemstack
end
minetest.register_craft({
output = 'replacer:replacer',
recipe = {
{ 'default:chest', '', '' },
{ '', 'default:stick', '' },
{ '', '', 'default:chest' },
}
{'moreores:tin_ingot', 'technic:diamond_drill_head', 'moreores:tin_ingot'},
{'technic:stainless_steel_ingot', 'technic:motor', 'technic:stainless_steel_ingot'},
{'default:chest', 'technic:red_energy_crystal', 'default:copper_ingot'},
}
})

View File

@ -17,6 +17,16 @@ if( minetest.get_modpath("trees")
replacer.image_replacements[ "default:furnace_active" ] = "oven:oven_active";
end
function getblock(pos)
local function toblock(coord)
return math.floor(coord / 16)
end
if not pos then
return "(?)"
end
return minetest.pos_to_string({x=toblock(pos.x), y=toblock(pos.y), z=toblock(pos.z)})
end
minetest.register_tool( "replacer:inspect",
{
description = "Node inspection tool",
@ -119,6 +129,9 @@ replacer.inspect = function( itemstack, user, pointed_thing, mode, show_receipe
protected_info = 'INFO: You can dig this node, but others can\'t.';
end
text = text..' '..protected_info;
if pos then
text = text..' Block: '..getblock(pos)
end
-- no longer spam the chat; the craft guide is more informative
-- minetest.chat_send_player( name, text );
@ -139,7 +152,7 @@ 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:stick' ] = 'group:stick';
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';
@ -285,7 +298,7 @@ replacer.inspect_show_crafting = function( name, node_name, fields )
desc = ' - no description provided - ';
end
local formspec = "size[6,6]"..
local formspec = "size[8,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:]"..
@ -306,8 +319,12 @@ replacer.inspect_show_crafting = function( name, node_name, fields )
end
formspec = formspec..".]";
end
-- show information about protection
formspec = formspec.."label[0.0,4;Block coordinates "..
getblock(fields.pos)
formspec = formspec..".]";
-- 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
@ -365,19 +382,19 @@ replacer.inspect_show_crafting = function( name, node_name, fields )
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]"..
formspec = formspec.."item_image_button[1,1;2.4,2.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]"..
formspec = formspec.."item_image_button[1,1;2.4,2.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] ).."]";
elseif( receipe.type=='colormachine' and receipe.items and #receipe.items==1 ) then
formspec = formspec.."item_image_button[1,1;3.4,3.4;"..replacer.image_button_link( 'colormachine:colormachine' ).."]".. --colormachine_front.png]"..
formspec = formspec.."item_image_button[1,1;2.4,2.4;"..replacer.image_button_link( 'colormachine:colormachine' ).."]".. --colormachine_front.png]"..
"item_image_button[2,2;1.0,1.0;"..replacer.image_button_link( receipe.items[1] ).."]";
elseif( receipe.type=='saw' and receipe.items and #receipe.items==1 ) then
--formspec = formspec.."item_image[1,1;3.4,3.4;moreblocks:circular_saw]"..
formspec = formspec.."item_image_button[1,1;3.4,3.4;"..replacer.image_button_link( 'moreblocks:circular_saw' ).."]"..
formspec = formspec.."item_image_button[1,1;2.4,2.4;"..replacer.image_button_link( 'moreblocks:circular_saw' ).."]"..
"item_image_button[2,0.6;1.0,1.0;"..replacer.image_button_link( receipe.items[1] ).."]";
else
formspec = formspec..'label[3,1;Error: Unkown receipe.]';
@ -407,6 +424,6 @@ minetest.register_craft({
output = 'replacer:inspect',
recipe = {
{ 'default:torch' },
{ 'default:stick' },
{ 'group:stick' },
}
})

Binary file not shown.

Before

Width:  |  Height:  |  Size: 461 B

After

Width:  |  Height:  |  Size: 1.9 KiB