Move hud over statbars
86
README.md
@ -1,34 +1,54 @@
|
|||||||
Replacement tool for creative building (Mod for MineTest)
|
## Replacer Tool
|
||||||
|
|
||||||
This tool is helpful for creative purposes (i.e. build a wall and "paint" windows into it).
|
Replacer tool for creative building in [Minetest](http://minetest.net) is helpful for copying, placing and replacing nodes. The tool can place or replace existing nodes with a previously selected other type of node (i.e. places said windows into a brick wall) preserving rotations of the copied node.
|
||||||
It replaces nodes with a previously selected other type of node (i.e. places said windows
|
|
||||||
into a brick wall).
|
|
||||||
|
|
||||||
Crafting: chest - -
|
### Crafting the replacer:
|
||||||
- stick -
|
chest | _____ | _____
|
||||||
- - chest
|
|
||||||
Or just use /giveme replacer:replacer
|
|
||||||
|
|
||||||
Usage: Right-click on a node of that type you want to replace other nodes with.
|
_____ | stick | _____
|
||||||
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.
|
_____ | _____ | chest
|
||||||
|
|
||||||
When not in creative mode, digging will be simulated and you will get what was there. In return, the replacement node
|
### Commands
|
||||||
will be taken from your inventory.
|
Give yourself a replacer (priv required) `/giveme replacer:replacer`
|
||||||
|
|
||||||
|
Set replacer modes (paint/legacy) `/replacer legacy` `/replacer paint`
|
||||||
|
|
||||||
The second tool included in this mod is the inspector.
|
### Paint mode controls (default)
|
||||||
|
The controls allow players continuously place or replace nodes by holding down right mouse key (Shift for replace)
|
||||||
|
|
||||||
Crafting: torch
|
`Shift + Left Mouse`: Set replacer's replacement node data (node to be placed)
|
||||||
stick
|
|
||||||
|
`Left Mouse`: Replace pointed node with replacement node.
|
||||||
|
|
||||||
|
`Right Mouse`: Place replacement node on pointed node (normal placement) continuously while keys are held.
|
||||||
|
|
||||||
|
`Shift + Right Mouse`: Replace pointed node with replacement node continuously while keys are held
|
||||||
|
|
||||||
|
### Legacy mode controls
|
||||||
|
`Right Mouse` Place replacement node on pointed face.
|
||||||
|
|
||||||
|
`Left Mouse`: Replace pointed node with replacement node.
|
||||||
|
|
||||||
|
`Shift + Right Mouse`: Set replacer's replacement node data (node to be placed)
|
||||||
|
|
||||||
|
### Inventory and Creative mode support
|
||||||
|
When not in creative mode, digging will be simulated when replacing nodes, giving the player any drops. In return, the replacement node will be taken from your inventory.
|
||||||
|
|
||||||
|
When in minetest game's creative mode, the node will just be replaced. Your inventory will not be changed.
|
||||||
|
|
||||||
|
## Inspector tool
|
||||||
|
The inspector tool shows information about the pointed node.
|
||||||
|
|
||||||
|
###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.
|
Just wield it and click on any node or entity you want to know more about. A limited craft-guide is included.
|
||||||
|
|
||||||
|
### License
|
||||||
|
-- Copyright 2021 Sokomine, lumberJack, Vanessa E
|
||||||
Copyright (C) 2013,2014,2015 Sokomine
|
|
||||||
|
|
||||||
This program is free software: you can redistribute it and/or modify
|
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
|
it under the terms of the GNU General Public License as published by
|
||||||
@ -42,4 +62,30 @@ Just wield it and click on any node or entity you want to know more about. A lim
|
|||||||
|
|
||||||
You should have received a copy of the GNU General Public License
|
You should have received a copy of the GNU General Public License
|
||||||
along with this program. If not, see <http://www.gnu.org/licenses/>.
|
along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||||
|
### Change log:
|
||||||
|
- 11.27.2021
|
||||||
|
- Add mode setting for paint and legacy keybindings
|
||||||
|
- Code and documentation cleaned up and updated.
|
||||||
|
- 2020
|
||||||
|
- Added HUD support and remove chat messages
|
||||||
|
- Added new keybinding to allow paint mechanic while replacing nodes
|
||||||
|
|
||||||
|
#### Forked from Sokomine
|
||||||
|
|
||||||
|
-- 09.12.2017 * Got rid of outdated minetest.env
|
||||||
|
-- * Fixed error in protection function.
|
||||||
|
-- * Fixed minor bugs.
|
||||||
|
-- * Added blacklist
|
||||||
|
-- 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
|
||||||
|
-- (instead of destroying the old node with its metadata; i.e. chests with content)
|
||||||
|
-- 20.11.2013 * if the server version is new enough, minetest.is_protected is used
|
||||||
|
-- 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
|
||||||
|
-- * receipe changed
|
||||||
|
-- * inventory image added
|
||||||
|
|
||||||
|
-- adds a function to check ownership of a node; taken from VanessaEs homedecor mod
|
@ -1,44 +0,0 @@
|
|||||||
-- taken from Vanessa Ezekowitz' homedecor mod
|
|
||||||
-- see http://forum.minetest.net/viewtopic.php?pid=26061 or https://github.com/VanessaE/homedecor for details!
|
|
||||||
function replacer_homedecor_node_is_owned(pos, placer)
|
|
||||||
|
|
||||||
if( not( placer ) or not(pos )) then
|
|
||||||
return true;
|
|
||||||
end
|
|
||||||
local pname = placer:get_player_name();
|
|
||||||
if (type( minetest.is_protected ) == "function") then
|
|
||||||
local res = minetest.is_protected( pos, pname );
|
|
||||||
if( res ) then
|
|
||||||
minetest.chat_send_player( pname, "Cannot replace node. It is protected." );
|
|
||||||
end
|
|
||||||
return res;
|
|
||||||
end
|
|
||||||
|
|
||||||
local ownername = false
|
|
||||||
if type(IsPlayerNodeOwner) == "function" then -- node_ownership mod
|
|
||||||
if HasOwner(pos, placer) then -- returns true if the node is owned
|
|
||||||
if not IsPlayerNodeOwner(pos, pname) then
|
|
||||||
if type(getLastOwner) == "function" then -- ...is an old version
|
|
||||||
ownername = getLastOwner(pos)
|
|
||||||
elseif type(GetNodeOwnerName) == "function" then -- ...is a recent version
|
|
||||||
ownername = GetNodeOwnerName(pos)
|
|
||||||
else
|
|
||||||
ownername = "someone"
|
|
||||||
end
|
|
||||||
end
|
|
||||||
end
|
|
||||||
|
|
||||||
elseif type(isprotect)=="function" then -- glomie's protection mod
|
|
||||||
if not isprotect(5, pos, placer) then
|
|
||||||
ownername = "someone"
|
|
||||||
end
|
|
||||||
end
|
|
||||||
|
|
||||||
if ownername ~= false then
|
|
||||||
minetest.chat_send_player( pname, "Sorry, "..ownername.." owns that spot." )
|
|
||||||
return true
|
|
||||||
else
|
|
||||||
return false
|
|
||||||
end
|
|
||||||
end
|
|
||||||
|
|
6
hud.lua
@ -1,4 +1,4 @@
|
|||||||
-- HUD support added by lumberJack
|
-- HUD support added by lumberJack 2021
|
||||||
|
|
||||||
-- store Hud ids by playername
|
-- store Hud ids by playername
|
||||||
replacer.hud_ids = {};
|
replacer.hud_ids = {};
|
||||||
@ -14,8 +14,8 @@ function replacer.set_hud(playername, message)
|
|||||||
hud_elem_type = "text",
|
hud_elem_type = "text",
|
||||||
name = "Replacer",
|
name = "Replacer",
|
||||||
number = 0xFFFFFF,
|
number = 0xFFFFFF,
|
||||||
position = {x=0.7, y=1},
|
position = {x=0.5, y=1},
|
||||||
offset = {x=0, y=-8},
|
offset = {x = (-10 * 24) - 25, y = -(64 + 24 + 16)},
|
||||||
text = message,
|
text = message,
|
||||||
scale = {x=200, y=60},
|
scale = {x=200, y=60},
|
||||||
alignment = {x=1, y=-1},
|
alignment = {x=1, y=-1},
|
||||||
|
522
init.lua
@ -1,271 +1,305 @@
|
|||||||
|
replacer = {}
|
||||||
|
replacer.blacklist = {}
|
||||||
--[[
|
|
||||||
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/>.
|
|
||||||
--]]
|
|
||||||
|
|
||||||
-- Version 3.0
|
|
||||||
|
|
||||||
-- Changelog:
|
|
||||||
-- 09.12.2017 * Got rid of outdated minetest.env
|
|
||||||
-- * Fixed error in protection function.
|
|
||||||
-- * Fixed minor bugs.
|
|
||||||
-- * Added blacklist
|
|
||||||
-- 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
|
|
||||||
-- (instead of destroying the old node with its metadata; i.e. chests with content)
|
|
||||||
-- 20.11.2013 * if the server version is new enough, minetest.is_protected is used
|
|
||||||
-- 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
|
|
||||||
-- * 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");
|
|
||||||
|
|
||||||
replacer = {};
|
|
||||||
|
|
||||||
replacer.blacklist = {};
|
|
||||||
|
|
||||||
-- playing with tnt and creative building are usually contradictory
|
-- playing with tnt and creative building are usually contradictory
|
||||||
-- (except when doing large-scale landscaping in singleplayer)
|
-- (except when doing large-scale landscaping in singleplayer)
|
||||||
replacer.blacklist[ "tnt:boom"] = true;
|
replacer.blacklist["tnt:boom"] = true
|
||||||
replacer.blacklist[ "tnt:gunpowder"] = true;
|
replacer.blacklist["tnt:gunpowder"] = true
|
||||||
replacer.blacklist[ "tnt:gunpowder_burning"] = true;
|
replacer.blacklist["tnt:gunpowder_burning"] = true
|
||||||
replacer.blacklist[ "tnt:tnt"] = true;
|
replacer.blacklist["tnt:tnt"] = true
|
||||||
|
|
||||||
-- prevent accidental replacement of your protector
|
-- prevent accidental replacement of your protector
|
||||||
replacer.blacklist[ "protector:protect"] = true;
|
replacer.blacklist["protector:protect"] = true
|
||||||
replacer.blacklist[ "protector:protect2"] = true;
|
replacer.blacklist["protector:protect2"] = true
|
||||||
|
|
||||||
-- adds a tool for inspecting nodes and entities
|
-- adds a tool for inspecting nodes and entities
|
||||||
dofile(minetest.get_modpath("replacer").."/inspect.lua");
|
dofile(minetest.get_modpath("replacer") .. "/inspect.lua")
|
||||||
-- add support for HUD messenges
|
-- add support for HUD messenges
|
||||||
dofile(minetest.get_modpath("replacer").."/hud.lua");
|
dofile(minetest.get_modpath("replacer") .. "/hud.lua")
|
||||||
|
|
||||||
|
minetest.register_tool("replacer:replacer", {
|
||||||
|
description = "Node replacement tool",
|
||||||
|
groups = {},
|
||||||
|
inventory_image = "replacer_replacer.png",
|
||||||
|
use_texture_alpha = true,
|
||||||
|
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 paint in/with water
|
||||||
|
node_placement_prediction = nil,
|
||||||
|
metadata = "default:dirt", -- default replacement: common dirt
|
||||||
|
|
||||||
minetest.register_tool( "replacer:replacer",
|
on_place = function(itemstack, placer, pointed_thing)
|
||||||
{
|
if (placer == nil or pointed_thing == nil) then
|
||||||
description = "Node replacement tool",
|
return itemstack -- nothing consumed
|
||||||
groups = {},
|
end
|
||||||
inventory_image = "replacer_replacer.png",
|
|
||||||
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
|
|
||||||
--[[
|
|
||||||
-- the tool_capabilities are of nearly no intrest here
|
|
||||||
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}
|
|
||||||
}
|
|
||||||
},
|
|
||||||
--]]
|
|
||||||
node_placement_prediction = nil,
|
|
||||||
metadata = "default:dirt", -- default replacement: common dirt
|
|
||||||
|
|
||||||
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 )..".");
|
|
||||||
|
|
||||||
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 );
|
|
||||||
else
|
|
||||||
return replacer.replace( itemstack, placer, pointed_thing, above );
|
|
||||||
end
|
|
||||||
end,
|
|
||||||
|
|
||||||
|
|
||||||
-- on_drop = func(itemstack, dropper, pos),
|
|
||||||
|
|
||||||
on_use = function(itemstack, user, pointed_thing)
|
|
||||||
name = user:get_player_name();
|
|
||||||
if( pointed_thing.type ~= "node" ) then
|
if( pointed_thing.type ~= "node" ) then
|
||||||
replacer.set_hud( name, " Error: No node selected.");
|
-- minetest.chat_send_player( name, " Error: No node selected.");
|
||||||
return nil;
|
replacer.set_hud(name, " Error: No node selected.");
|
||||||
|
return nil;
|
||||||
|
end
|
||||||
|
local name = placer:get_player_name()
|
||||||
|
local mode = replacer.get_mode(placer)
|
||||||
|
local keys = placer:get_player_control()
|
||||||
|
|
||||||
|
if mode == "legacy" then
|
||||||
|
if( not( keys["sneak"] )) then
|
||||||
|
return replacer.replace( itemstack, placer, pointed_thing, 0 ); end
|
||||||
|
|
||||||
|
local pos = minetest.get_pointed_thing_position( pointed_thing, under );
|
||||||
|
local node = minetest.get_node_or_nil( pos );
|
||||||
|
|
||||||
|
--minetest.chat_send_player( name, " Target node: "..minetest.serialize( node ).." at pos "..minetest.serialize( pos )..".");
|
||||||
|
local metadata = "default:dirt 0 0";
|
||||||
|
if( node ~= nil and node.name ) then
|
||||||
|
metadata = node.name..' '..node.param1..' '..node.param2;
|
||||||
|
end
|
||||||
|
itemstack:set_metadata( metadata );
|
||||||
|
|
||||||
|
--minetest.chat_send_player( name, "Node replacement tool set to: '"..metadata.."'.");
|
||||||
|
replacer.set_hud(name, "Node replacement tool set to: '"..metadata.."'.");
|
||||||
|
return itemstack; -- nothing consumed but data changed
|
||||||
end
|
end
|
||||||
|
|
||||||
local pos = minetest.get_pointed_thing_position( pointed_thing, under );
|
-- just place the stored node if now new one is to be selected
|
||||||
local node = minetest.get_node_or_nil( pos );
|
if (not (keys["sneak"])) then
|
||||||
|
|
||||||
--minetest.chat_send_player( name, " Target node: "..minetest.serialize( node ).." at pos "..minetest.serialize( pos )..".");
|
return replacer.replace(itemstack, placer, pointed_thing, 0)
|
||||||
local metadata = "default:dirt 0 0";
|
else
|
||||||
if( node ~= nil and node.name ) then
|
return replacer.replace(itemstack, placer, pointed_thing, above)
|
||||||
metadata = node.name..' '..node.param1..' '..node.param2;
|
|
||||||
end
|
end
|
||||||
itemstack:set_metadata( metadata );
|
end,
|
||||||
|
|
||||||
replacer.set_hud( name, "Node replacement tool set to: '"..metadata.."'.");
|
on_use = function(itemstack, user, pointed_thing)
|
||||||
|
local name = user:get_player_name()
|
||||||
|
local keys = user:get_player_control()
|
||||||
|
local mode = replacer.get_mode(user)
|
||||||
|
|
||||||
return itemstack; -- nothing consumed but data changed
|
if (pointed_thing.type ~= "node") then
|
||||||
end,
|
replacer.set_hud(name, " Error: No node selected.")
|
||||||
|
return nil
|
||||||
|
end
|
||||||
|
if mode == "legacy" then
|
||||||
|
return replacer.replace( itemstack, user, pointed_thing, above );
|
||||||
|
end
|
||||||
|
if (keys["sneak"]) then
|
||||||
|
local pos = minetest.get_pointed_thing_position(pointed_thing, under)
|
||||||
|
local node = minetest.get_node_or_nil(pos)
|
||||||
|
local metadata = "default:dirt 0 0"
|
||||||
|
if (node ~= nil and node.name) then
|
||||||
|
metadata = node.name .. ' ' .. node.param1 .. ' ' .. node.param2
|
||||||
|
end
|
||||||
|
itemstack:set_metadata(metadata)
|
||||||
|
|
||||||
|
replacer.set_hud(name, "Node replacement tool set to: '" .. metadata .. "'.")
|
||||||
|
|
||||||
|
return itemstack -- nothing consumed but data changed
|
||||||
|
else
|
||||||
|
return replacer.replace(itemstack, user, pointed_thing, above)
|
||||||
|
end
|
||||||
|
end
|
||||||
})
|
})
|
||||||
|
|
||||||
|
replacer.replace = function(itemstack, user, pointed_thing, mode)
|
||||||
|
|
||||||
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()
|
||||||
|
|
||||||
if( user == nil or pointed_thing == nil) then
|
if (pointed_thing.type ~= "node") then
|
||||||
return nil;
|
replacer.set_hud(name, " Error: No node.")
|
||||||
end
|
return nil
|
||||||
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
|
|
||||||
replacer.set_hud( name, " Error: No node.");
|
|
||||||
return nil;
|
|
||||||
end
|
|
||||||
|
|
||||||
local pos = minetest.get_pointed_thing_position( pointed_thing, mode );
|
|
||||||
local node = minetest.get_node_or_nil( pos );
|
|
||||||
|
|
||||||
--minetest.chat_send_player( name, " Target node: "..minetest.serialize( node ).." at pos "..minetest.serialize( pos )..".");
|
|
||||||
|
|
||||||
if( node == nil ) then
|
|
||||||
|
|
||||||
replacer.set_hud( 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
|
|
||||||
|
|
||||||
if( node.name and node.name ~= "" and replacer.blacklist[ node.name ]) then
|
|
||||||
replacer.set_hud( 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
|
|
||||||
replacer.set_hud( name, "Placing blocks of the type '"..( daten[1] or "?" )..
|
|
||||||
"' with the replacer is not allowed on this server. Replacement failed.");
|
|
||||||
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.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 place
|
|
||||||
if( not(minetest.settings:get_bool("creative_mode") )
|
|
||||||
and not( minetest.check_player_privs( name, {creative=true}))) then
|
|
||||||
|
|
||||||
-- 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";
|
|
||||||
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
|
|
||||||
|
|
||||||
|
|
||||||
replacer.set_hud( 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:river_water_source"
|
|
||||||
and node.name ~= "default:river_water_flowing"
|
|
||||||
and node.name ~= "default:water_source"
|
|
||||||
and node.name ~= "default:water_flowing" ) then
|
|
||||||
|
|
||||||
minetest.node_dig( pos, node, user );
|
|
||||||
|
|
||||||
local digged_node = minetest.get_node_or_nil( pos );
|
|
||||||
if( not( digged_node )
|
|
||||||
or digged_node.name == node.name ) then
|
|
||||||
|
|
||||||
replacer.set_hud( 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.place_node( pos, { name = item[ "metadata" ] } );
|
|
||||||
minetest.add_node( pos, { name = daten[1], param1 = daten[2], param2 = daten[3] } );
|
|
||||||
return nil; -- no item shall be removed from inventory
|
|
||||||
end
|
end
|
||||||
|
|
||||||
|
local pos = minetest.get_pointed_thing_position(pointed_thing, mode)
|
||||||
|
local node = minetest.get_node_or_nil(pos)
|
||||||
|
if (node == nil) then
|
||||||
|
replacer.set_hud(name, "Error: Target node not yet loaded. Please wait a moment for the server to catch up.")
|
||||||
|
return nil
|
||||||
|
end
|
||||||
|
|
||||||
minetest.register_craft({
|
local item = itemstack:to_table()
|
||||||
output = 'replacer:replacer',
|
|
||||||
recipe = {
|
-- make sure it is defined
|
||||||
{ 'default:chest', '', '' },
|
if (not (item["metadata"]) or item["metadata"] == "") then
|
||||||
{ '', 'default:stick', '' },
|
item["metadata"] = "default:dirt 0 0"
|
||||||
{ '', '', 'default:chest' },
|
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.node_is_owned(pos, user) then
|
||||||
|
return nil
|
||||||
|
end
|
||||||
|
|
||||||
|
if (node.name and node.name ~= "" and replacer.blacklist[node.name]) then
|
||||||
|
replacer.set_hud(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
|
||||||
|
replacer.set_hud(name, "Placing blocks of the type '" .. (daten[1] or "?") ..
|
||||||
|
"' with the replacer is not allowed on this server. Replacement failed.")
|
||||||
|
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.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 place
|
||||||
|
if (not (minetest.settings:get_bool("creative_mode")) and not (minetest.check_player_privs(name, {
|
||||||
|
creative = true
|
||||||
|
}))) then
|
||||||
|
|
||||||
|
-- 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"
|
||||||
|
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
|
||||||
|
replacer.set_hud(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:river_water_source" and node.name ~=
|
||||||
|
"default:river_water_flowing" and node.name ~= "default:water_source" and node.name ~=
|
||||||
|
"default:water_flowing") then
|
||||||
|
|
||||||
|
minetest.node_dig(pos, node, user)
|
||||||
|
|
||||||
|
local digged_node = minetest.get_node_or_nil(pos)
|
||||||
|
if (not (digged_node) or digged_node.name == node.name) then
|
||||||
|
|
||||||
|
replacer.set_hud(name,
|
||||||
|
"Replacing '" .. (node.name or "air") .. "' with '" .. (item["metadata"] or "?") ..
|
||||||
|
"' failed.\nUnable to remove old node.")
|
||||||
|
return nil
|
||||||
|
end
|
||||||
|
|
||||||
|
end
|
||||||
|
|
||||||
|
-- consume the item
|
||||||
|
user:get_inventory():remove_item("main", daten[1] .. " 1")
|
||||||
|
|
||||||
|
end
|
||||||
|
|
||||||
|
minetest.add_node(pos, {
|
||||||
|
name = daten[1],
|
||||||
|
param1 = daten[2],
|
||||||
|
param2 = daten[3]
|
||||||
|
})
|
||||||
|
return nil -- no item shall be removed from inventory
|
||||||
|
end
|
||||||
|
|
||||||
|
-- protection checking from Vanessa Ezekowitz' homedecor mod
|
||||||
|
-- see http://forum.minetest.net/viewtopic.php?pid=26061 or https://github.com/VanessaE/homedecor for details!
|
||||||
|
|
||||||
|
replacer.node_is_owned = function(pos, placer)
|
||||||
|
if (not (placer) or not (pos)) then
|
||||||
|
return true
|
||||||
|
end
|
||||||
|
local pname = placer:get_player_name()
|
||||||
|
if (type(minetest.is_protected) == "function") then
|
||||||
|
local res = minetest.is_protected(pos, pname)
|
||||||
|
if (res) then
|
||||||
|
|
||||||
|
replacer.set_hud(pname, "Cannot replace node. It is protected.")
|
||||||
|
end
|
||||||
|
return res
|
||||||
|
end
|
||||||
|
|
||||||
|
local ownername = false
|
||||||
|
if type(IsPlayerNodeOwner) == "function" then -- node_ownership mod
|
||||||
|
if HasOwner(pos, placer) then -- returns true if the node is owned
|
||||||
|
if not IsPlayerNodeOwner(pos, pname) then
|
||||||
|
if type(getLastOwner) == "function" then -- ...is an old version
|
||||||
|
ownername = getLastOwner(pos)
|
||||||
|
elseif type(GetNodeOwnerName) == "function" then -- ...is a recent version
|
||||||
|
ownername = GetNodeOwnerName(pos)
|
||||||
|
else
|
||||||
|
ownername = "someone"
|
||||||
|
end
|
||||||
|
end
|
||||||
|
end
|
||||||
|
|
||||||
|
elseif type(isprotect) == "function" then -- glomie's protection mod
|
||||||
|
if not isprotect(5, pos, placer) then
|
||||||
|
ownername = "someone"
|
||||||
|
end
|
||||||
|
end
|
||||||
|
|
||||||
|
if ownername ~= false then
|
||||||
|
minetest.chat_send_player(pname, "Sorry, " .. ownername .. " owns that spot.")
|
||||||
|
return true
|
||||||
|
else
|
||||||
|
return false
|
||||||
|
end
|
||||||
|
end
|
||||||
|
|
||||||
|
-- Handle mode setting/getting
|
||||||
|
replacer.set_mode = function(player, mode_name)
|
||||||
|
if mode_name ~= "legacy" and mode_name ~= "paint" then
|
||||||
|
return replacer.set_hud(player:get_player_name(), "Invalid replacer mode!")
|
||||||
|
end
|
||||||
|
local meta = player:get_meta()
|
||||||
|
meta:set_string('replacer_mode', mode_name)
|
||||||
|
replacer.set_hud(player:get_player_name(), "Replacer set to " .. mode_name .. " mode.")
|
||||||
|
end
|
||||||
|
|
||||||
|
replacer.get_mode = function(player)
|
||||||
|
local meta = player:get_meta()
|
||||||
|
local mode_name = meta:get_string("replacer_mode")
|
||||||
|
if mode_name == nil then
|
||||||
|
mode_name = "paint"
|
||||||
|
replacer.set_mode(player, mode_name)
|
||||||
|
end
|
||||||
|
return mode_name
|
||||||
|
end
|
||||||
|
|
||||||
|
-- Chat command to set mode
|
||||||
|
minetest.register_chatcommand("replacer_mode", {
|
||||||
|
params = "<mode_name>",
|
||||||
|
description = "Sets replacer mode. Modes include 'legacy' or 'paint'",
|
||||||
|
func = function(name, param)
|
||||||
|
if param ~= "legacy" and param ~= "paint" then
|
||||||
|
return minetest.chat_send_player(name, "Invalid replacer mode: 'legacy' or 'paint'")
|
||||||
|
end
|
||||||
|
replacer.set_mode(minetest.get_player_by_name(name), param)
|
||||||
|
end
|
||||||
})
|
})
|
||||||
|
|
||||||
|
-- Crafting
|
||||||
|
minetest.register_craft({
|
||||||
|
output = 'replacer:replacer',
|
||||||
|
recipe = {{'default:chest', '', ''}, {'', 'default:stick', ''}, {'', '', 'default:chest'}}
|
||||||
|
})
|
||||||
|
|
||||||
|
26
inspect.lua
@ -17,26 +17,13 @@ if( minetest.get_modpath("trees")
|
|||||||
replacer.image_replacements[ "default:furnace_active" ] = "oven:oven_active";
|
replacer.image_replacements[ "default:furnace_active" ] = "oven:oven_active";
|
||||||
end
|
end
|
||||||
|
|
||||||
minetest.register_tool( "replacer:inspect",
|
minetest.register_tool( "replacer:inspect", {
|
||||||
{
|
|
||||||
description = "Node inspection tool",
|
description = "Node inspection tool",
|
||||||
groups = {},
|
groups = {},
|
||||||
inventory_image = "replacer_inspect.png",
|
inventory_image = "replacer_inspect.png",
|
||||||
wield_image = "",
|
wield_image = "",
|
||||||
wield_scale = {x=1,y=1,z=1},
|
wield_scale = {x=1,y=1,z=1},
|
||||||
liquids_pointable = true, -- it is ok to request information about liquids
|
liquids_pointable = true, -- it is ok to request information about liquids
|
||||||
--[[
|
|
||||||
-- the tool_capabilities are of no intrest here; it is not for digging
|
|
||||||
tool_capabilities = {
|
|
||||||
full_punch_interval = 1.0,
|
|
||||||
max_drop_level=0,
|
|
||||||
groupcaps={
|
|
||||||
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}
|
|
||||||
}
|
|
||||||
},
|
|
||||||
--]]
|
|
||||||
node_placement_prediction = nil,
|
node_placement_prediction = nil,
|
||||||
|
|
||||||
on_use = function(itemstack, user, pointed_thing)
|
on_use = function(itemstack, user, pointed_thing)
|
||||||
@ -52,7 +39,6 @@ minetest.register_tool( "replacer:inspect",
|
|||||||
|
|
||||||
|
|
||||||
replacer.inspect = function( itemstack, user, pointed_thing, mode, show_receipe )
|
replacer.inspect = function( itemstack, user, pointed_thing, mode, show_receipe )
|
||||||
|
|
||||||
if( user == nil or pointed_thing == nil) then
|
if( user == nil or pointed_thing == nil) then
|
||||||
return nil;
|
return nil;
|
||||||
end
|
end
|
||||||
@ -367,19 +353,19 @@ replacer.inspect_show_crafting = function( name, node_name, fields )
|
|||||||
end
|
end
|
||||||
elseif( receipe.type=='cooking' and receipe.items and #receipe.items==1
|
elseif( receipe.type=='cooking' and receipe.items and #receipe.items==1
|
||||||
and receipe.output=="" ) then
|
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;1.0,1.0;"..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] ).."]"..
|
"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[1.0,0;"..tostring(receipe.items[1]).."]"..
|
||||||
"label[0,0.5;This can be used as a fuel.]";
|
"label[0,0.5;This can be used as a fuel.]";
|
||||||
elseif( receipe.type=='cooking' and receipe.items and #receipe.items==1 ) then
|
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;1.0,1.0;"..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] ).."]";
|
"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
|
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;1.0,1.0;"..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] ).."]";
|
"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
|
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[1,1;1.0,1.0;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;1.0,1.0;"..replacer.image_button_link( 'moreblocks:circular_saw' ).."]"..
|
||||||
"item_image_button[2,0.6;1.0,1.0;"..replacer.image_button_link( receipe.items[1] ).."]";
|
"item_image_button[2,0.6;1.0,1.0;"..replacer.image_button_link( receipe.items[1] ).."]";
|
||||||
else
|
else
|
||||||
formspec = formspec..'label[3,1;Error: Unkown receipe.]';
|
formspec = formspec..'label[3,1;Error: Unkown receipe.]';
|
||||||
|
BIN
textures/Gabosburg Mods/replacer/textures/replacer_inspect.png
Normal file
After Width: | Height: | Size: 594 B |
BIN
textures/Gabosburg Mods/replacer/textures/replacer_replacer.png
Normal file
After Width: | Height: | Size: 234 B |
BIN
textures/legacy_textures/replacer_replacer.png
Normal file
After Width: | Height: | Size: 461 B |
Before Width: | Height: | Size: 594 B After Width: | Height: | Size: 5.7 KiB |
Before Width: | Height: | Size: 461 B After Width: | Height: | Size: 5.7 KiB |