2013-02-02 03:21:23 +01:00
|
|
|
|
2013-02-03 21:31:52 +01:00
|
|
|
|
|
|
|
--[[
|
|
|
|
Replacement tool for creative building (Mod for MineTest)
|
|
|
|
Copyright (C) 2013 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
|
|
|
|
the Free Software Foundation, either version 3 of the License, or
|
|
|
|
(at your option) any later version.
|
|
|
|
|
|
|
|
This program is distributed in the hope that it will be useful,
|
|
|
|
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
|
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
|
|
GNU General Public License for more details.
|
|
|
|
|
|
|
|
You should have received a copy of the GNU General Public License
|
|
|
|
along with this program. If not, see <http://www.gnu.org/licenses/>.
|
|
|
|
--]]
|
|
|
|
|
2014-10-02 18:18:35 +02:00
|
|
|
-- Version 3.0
|
2013-04-24 01:17:47 +02:00
|
|
|
|
|
|
|
-- Changelog:
|
2021-10-02 14:21:42 +02:00
|
|
|
-- 02.09.2021 * Added a history of stored patterns (not saved over server restart)
|
|
|
|
-- * Added a menu to select a history entry. It is accessable via AUX1 + left click.
|
2021-10-02 14:46:15 +02:00
|
|
|
-- * Removed deprecated functions get/set_metadata(..) and renamed metadata to pattern
|
2021-09-29 22:37:05 +02:00
|
|
|
-- 29.09.2021 * AUX1 key works now same as SNEAK key for storing new pattern (=easier when flying)
|
|
|
|
-- * The description of the tool now shows which pattern is stored
|
|
|
|
-- * The description of the stored pattern is more human readable
|
2017-12-09 20:20:43 +01:00
|
|
|
-- 09.12.2017 * Got rid of outdated minetest.env
|
|
|
|
-- * Fixed error in protection function.
|
|
|
|
-- * Fixed minor bugs.
|
|
|
|
-- * Added blacklist
|
2014-10-02 18:18:35 +02:00
|
|
|
-- 02.10.2014 * Some more improvements for inspect-tool. Added craft-guide.
|
2014-10-01 06:48:27 +02:00
|
|
|
-- 01.10.2014 * Added inspect-tool.
|
2014-01-12 13:19:26 +01:00
|
|
|
-- 12.01.2013 * If digging the node was unsuccessful, then the replacement will now fail
|
|
|
|
-- (instead of destroying the old node with its metadata; i.e. chests with content)
|
2013-11-20 21:50:38 +01:00
|
|
|
-- 20.11.2013 * if the server version is new enough, minetest.is_protected is used
|
|
|
|
-- in order to check if the replacement is allowed
|
2013-04-24 01:17:47 +02:00
|
|
|
-- 24.04.2013 * param1 and param2 are now stored
|
|
|
|
-- * hold sneak + right click to store new pattern
|
|
|
|
-- * right click: place one of the itmes
|
|
|
|
-- * receipe changed
|
|
|
|
-- * inventory image added
|
2013-02-03 21:31:52 +01:00
|
|
|
|
2013-02-02 03:21:23 +01:00
|
|
|
-- adds a function to check ownership of a node; taken from VanessaEs homedecor mod
|
|
|
|
dofile(minetest.get_modpath("replacer").."/check_owner.lua");
|
|
|
|
|
2013-04-24 01:17:47 +02:00
|
|
|
replacer = {};
|
|
|
|
|
2017-12-09 20:20:43 +01:00
|
|
|
replacer.blacklist = {};
|
|
|
|
|
|
|
|
-- playing with tnt and creative building are usually contradictory
|
|
|
|
-- (except when doing large-scale landscaping in singleplayer)
|
|
|
|
replacer.blacklist[ "tnt:boom"] = true;
|
|
|
|
replacer.blacklist[ "tnt:gunpowder"] = true;
|
|
|
|
replacer.blacklist[ "tnt:gunpowder_burning"] = true;
|
|
|
|
replacer.blacklist[ "tnt:tnt"] = true;
|
|
|
|
|
|
|
|
-- prevent accidental replacement of your protector
|
|
|
|
replacer.blacklist[ "protector:protect"] = true;
|
|
|
|
replacer.blacklist[ "protector:protect2"] = true;
|
|
|
|
|
2014-10-01 06:48:27 +02:00
|
|
|
-- adds a tool for inspecting nodes and entities
|
|
|
|
dofile(minetest.get_modpath("replacer").."/inspect.lua");
|
2013-02-02 03:21:23 +01:00
|
|
|
|
2021-10-02 14:21:42 +02:00
|
|
|
-- adds a formspec with a history function (accessible with AUX1 + left click)
|
|
|
|
dofile(minetest.get_modpath("replacer").."/fs_history.lua");
|
|
|
|
|
2013-02-02 03:21:23 +01:00
|
|
|
minetest.register_tool( "replacer:replacer",
|
|
|
|
{
|
|
|
|
description = "Node replacement tool",
|
|
|
|
groups = {},
|
2013-04-24 01:17:47 +02:00
|
|
|
inventory_image = "replacer_replacer.png",
|
2013-02-02 03:21:23 +01:00
|
|
|
wield_image = "",
|
|
|
|
wield_scale = {x=1,y=1,z=1},
|
|
|
|
stack_max = 1, -- it has to store information - thus only one can be stacked
|
|
|
|
liquids_pointable = true, -- it is ok to painit in/with water
|
2017-07-03 22:03:59 +02:00
|
|
|
--[[
|
2013-04-24 01:17:47 +02:00
|
|
|
-- the tool_capabilities are of nearly no intrest here
|
2013-02-02 03:21:23 +01:00
|
|
|
tool_capabilities = {
|
|
|
|
full_punch_interval = 1.0,
|
|
|
|
max_drop_level=0,
|
|
|
|
groupcaps={
|
|
|
|
-- For example:
|
|
|
|
fleshy={times={[2]=0.80, [3]=0.40}, maxwear=0.05, maxlevel=1},
|
|
|
|
snappy={times={[2]=0.80, [3]=0.40}, maxwear=0.05, maxlevel=1},
|
|
|
|
choppy={times={[3]=0.90}, maxwear=0.05, maxlevel=0}
|
|
|
|
}
|
|
|
|
},
|
2017-07-03 22:03:59 +02:00
|
|
|
--]]
|
2013-02-02 03:21:23 +01:00
|
|
|
node_placement_prediction = nil,
|
|
|
|
|
|
|
|
on_place = function(itemstack, placer, pointed_thing)
|
|
|
|
|
|
|
|
if( placer == nil or pointed_thing == nil) then
|
|
|
|
return itemstack; -- nothing consumed
|
|
|
|
end
|
|
|
|
local name = placer:get_player_name();
|
|
|
|
--minetest.chat_send_player( name, "You PLACED this on "..minetest.serialize( pointed_thing )..".");
|
2013-04-24 01:17:47 +02:00
|
|
|
|
|
|
|
local keys=placer:get_player_control();
|
|
|
|
|
|
|
|
-- just place the stored node if now new one is to be selected
|
2021-09-29 20:19:28 +02:00
|
|
|
if( not( keys["sneak"] ) and not( keys["aux1"])) then
|
2013-04-24 01:17:47 +02:00
|
|
|
|
|
|
|
return replacer.replace( itemstack, placer, pointed_thing, 0 ); end
|
|
|
|
|
2013-02-02 03:21:23 +01:00
|
|
|
|
|
|
|
if( pointed_thing.type ~= "node" ) then
|
|
|
|
minetest.chat_send_player( name, " Error: No node selected.");
|
|
|
|
return nil;
|
|
|
|
end
|
|
|
|
|
2019-02-28 15:48:29 +01:00
|
|
|
local pos = minetest.get_pointed_thing_position( pointed_thing, false ); -- node under
|
2017-12-08 22:25:35 +01:00
|
|
|
local node = minetest.get_node_or_nil( pos );
|
2013-02-02 03:21:23 +01:00
|
|
|
|
2021-10-02 14:46:15 +02:00
|
|
|
local pattern = "default:dirt 0 0";
|
2013-02-02 03:21:23 +01:00
|
|
|
if( node ~= nil and node.name ) then
|
2021-10-02 14:46:15 +02:00
|
|
|
pattern = node.name..' '..node.param1..' '..node.param2;
|
2013-02-02 03:21:23 +01:00
|
|
|
end
|
2021-09-29 22:37:05 +02:00
|
|
|
|
2021-10-02 14:46:15 +02:00
|
|
|
return replacer.set_to(name, pattern, placer, itemstack) -- nothing consumed but data changed
|
2013-02-02 03:21:23 +01:00
|
|
|
end,
|
|
|
|
|
|
|
|
|
|
|
|
on_use = function(itemstack, user, pointed_thing)
|
|
|
|
|
2019-02-28 15:48:29 +01:00
|
|
|
return replacer.replace( itemstack, user, pointed_thing, false );
|
2013-04-24 01:17:47 +02:00
|
|
|
end,
|
|
|
|
})
|
|
|
|
|
|
|
|
|
|
|
|
replacer.replace = function( itemstack, user, pointed_thing, mode )
|
|
|
|
|
2013-02-02 03:21:23 +01:00
|
|
|
if( user == nil or pointed_thing == nil) then
|
|
|
|
return nil;
|
|
|
|
end
|
|
|
|
local name = user:get_player_name();
|
|
|
|
|
|
|
|
if( pointed_thing.type ~= "node" ) then
|
|
|
|
minetest.chat_send_player( name, " Error: No node.");
|
|
|
|
return nil;
|
|
|
|
end
|
|
|
|
|
2013-04-24 01:17:47 +02:00
|
|
|
local pos = minetest.get_pointed_thing_position( pointed_thing, mode );
|
2017-12-08 22:25:35 +01:00
|
|
|
local node = minetest.get_node_or_nil( pos );
|
2013-02-02 03:21:23 +01:00
|
|
|
|
|
|
|
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
|
|
|
|
|
|
|
|
|
2021-10-02 14:46:15 +02:00
|
|
|
local meta = itemstack:get_meta()
|
|
|
|
local pattern = meta:get_string("pattern")
|
2013-02-02 03:21:23 +01:00
|
|
|
|
2013-04-24 01:17:47 +02:00
|
|
|
-- make sure it is defined
|
2021-10-02 14:46:15 +02:00
|
|
|
if(not(pattern) or pattern == "") then
|
|
|
|
pattern = "default:dirt 0 0";
|
2013-04-24 01:17:47 +02:00
|
|
|
end
|
2013-02-02 03:21:23 +01:00
|
|
|
|
2021-10-02 14:21:42 +02:00
|
|
|
local keys=user:get_player_control();
|
|
|
|
if( keys["aux1"]) then
|
2021-10-02 14:46:15 +02:00
|
|
|
minetest.show_formspec(name, "replacer:menu", replacer.get_formspec(name, pattern, user))
|
2021-10-02 14:21:42 +02:00
|
|
|
return nil
|
|
|
|
end
|
|
|
|
|
2013-04-24 01:17:47 +02:00
|
|
|
-- regain information about nodename, param1 and param2
|
2021-10-02 14:46:15 +02:00
|
|
|
local daten = pattern:split( " " );
|
2013-04-24 01:17:47 +02:00
|
|
|
-- the old format stored only the node name
|
|
|
|
if( #daten < 3 ) then
|
|
|
|
daten[2] = 0;
|
|
|
|
daten[3] = 0;
|
2013-02-02 03:21:23 +01:00
|
|
|
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
|
2013-04-24 01:17:47 +02:00
|
|
|
|
2017-12-09 20:20:43 +01:00
|
|
|
if( node.name and node.name ~= "" and replacer.blacklist[ node.name ]) then
|
|
|
|
minetest.chat_send_player( name, "Replacing blocks of the type '"..( node.name or "?" )..
|
|
|
|
"' is not allowed on this server. Replacement failed.");
|
|
|
|
return nil;
|
|
|
|
end
|
|
|
|
|
|
|
|
if( replacer.blacklist[ daten[1] ]) then
|
|
|
|
minetest.chat_send_player( name, "Placing blocks of the type '"..( daten[1] or "?" )..
|
|
|
|
"' with the replacer is not allowed on this server. Replacement failed.");
|
|
|
|
return nil;
|
|
|
|
end
|
|
|
|
|
2013-04-24 01:17:47 +02:00
|
|
|
-- 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
|
2017-12-08 22:25:35 +01:00
|
|
|
minetest.add_node( pos, { name = node.name, param1 = daten[2], param2 = daten[3] } );
|
2013-04-24 01:17:47 +02:00
|
|
|
end
|
|
|
|
|
|
|
|
return nil;
|
|
|
|
end
|
|
|
|
|
2013-02-02 03:21:23 +01:00
|
|
|
|
2017-12-09 20:20:43 +01:00
|
|
|
-- in survival mode, the player has to provide the node he wants to place
|
2019-03-11 23:47:05 +01:00
|
|
|
if( not(minetest.settings:get_bool("creative_mode") )
|
2017-11-03 03:07:20 +01:00
|
|
|
and not( minetest.check_player_privs( name, {creative=true}))) then
|
2013-02-02 03:21:23 +01:00
|
|
|
|
|
|
|
-- players usually don't carry dirt_with_grass around; it's safe to assume normal dirt here
|
2017-12-09 20:20:43 +01:00
|
|
|
-- fortunately, dirt and dirt_with_grass does not make use of rotation
|
2013-04-24 01:17:47 +02:00
|
|
|
if( daten[1] == "default:dirt_with_grass" ) then
|
|
|
|
daten[1] = "default:dirt";
|
2021-10-02 14:46:15 +02:00
|
|
|
pattern = "default:dirt 0 0";
|
2013-02-02 03:21:23 +01:00
|
|
|
end
|
|
|
|
|
|
|
|
-- does the player carry at least one of the desired nodes with him?
|
2013-04-24 01:17:47 +02:00
|
|
|
if( not( user:get_inventory():contains_item("main", daten[1]))) then
|
2013-02-02 03:21:23 +01:00
|
|
|
|
|
|
|
|
2013-04-24 01:17:47 +02:00
|
|
|
minetest.chat_send_player( name, "You have no further '"..( daten[1] or "?" ).."'. Replacement failed.");
|
2013-02-02 03:21:23 +01:00
|
|
|
return nil;
|
|
|
|
end
|
|
|
|
|
|
|
|
|
2013-02-02 03:42:02 +01:00
|
|
|
-- give the player the item by simulating digging if possible
|
|
|
|
if( node.name ~= "air"
|
2021-09-30 00:18:34 +02:00
|
|
|
and node.name ~= "ignore") then
|
2013-02-02 03:42:02 +01:00
|
|
|
|
|
|
|
minetest.node_dig( pos, node, user );
|
2014-01-12 13:19:26 +01:00
|
|
|
|
2017-12-08 22:25:35 +01:00
|
|
|
local digged_node = minetest.get_node_or_nil( pos );
|
2014-01-12 13:19:26 +01:00
|
|
|
if( not( digged_node )
|
|
|
|
or digged_node.name == node.name ) then
|
|
|
|
|
2021-09-30 00:18:34 +02:00
|
|
|
-- some nodes - like liquids - cannot be digged. but they are buildable_to and
|
|
|
|
-- thus can be replaced
|
|
|
|
local node_def = minetest.registered_nodes[node.name]
|
|
|
|
if(not(node_def) or not(node_def.buildable_to)) then
|
2021-10-02 14:46:15 +02:00
|
|
|
minetest.chat_send_player( name, "Replacing '"..( node.name or "air" ).."' with '"..( pattern or "?" ).."' failed. Unable to remove old node.");
|
2021-09-30 00:18:34 +02:00
|
|
|
return nil;
|
|
|
|
end
|
2014-01-12 13:19:26 +01:00
|
|
|
end
|
|
|
|
|
2013-02-02 03:42:02 +01:00
|
|
|
end
|
2014-01-12 13:19:26 +01:00
|
|
|
|
|
|
|
-- consume the item
|
|
|
|
user:get_inventory():remove_item("main", daten[1].." 1");
|
2013-02-02 03:21:23 +01:00
|
|
|
end
|
2017-12-08 22:25:35 +01:00
|
|
|
minetest.add_node( pos, { name = daten[1], param1 = daten[2], param2 = daten[3] } );
|
2013-02-02 03:21:23 +01:00
|
|
|
return nil; -- no item shall be removed from inventory
|
2013-04-24 01:17:47 +02:00
|
|
|
end
|
|
|
|
|
2013-02-02 03:21:23 +01:00
|
|
|
|
2013-02-02 04:12:00 +01:00
|
|
|
minetest.register_craft({
|
|
|
|
output = 'replacer:replacer',
|
|
|
|
recipe = {
|
2013-04-24 01:17:47 +02:00
|
|
|
{ 'default:chest', '', '' },
|
|
|
|
{ '', 'default:stick', '' },
|
|
|
|
{ '', '', 'default:chest' },
|
2013-02-02 04:12:00 +01:00
|
|
|
}
|
|
|
|
})
|
2014-10-01 06:48:27 +02:00
|
|
|
|