2012-10-14 03:45:50 +02:00
minetest.register_privilege ( " worldedit " , " Can use WorldEdit commands " )
worldedit.set_pos = { }
2013-07-29 18:43:24 +02:00
worldedit.inspect = { }
2012-10-14 03:45:50 +02:00
worldedit.pos1 = { }
worldedit.pos2 = { }
2013-06-22 08:24:54 +02:00
if minetest.place_schematic then
worldedit.prob_pos = { }
worldedit.prob_list = { }
end
2012-10-14 03:45:50 +02:00
2015-01-06 14:20:58 +01:00
dofile ( minetest.get_modpath ( " worldedit_commands " ) .. " /cuboid.lua " )
2012-10-14 03:45:50 +02:00
dofile ( minetest.get_modpath ( " worldedit_commands " ) .. " /mark.lua " )
2016-12-10 21:43:38 +01:00
dofile ( minetest.get_modpath ( " worldedit_commands " ) .. " /wand.lua " )
2017-01-31 19:52:54 +01:00
local safe_region , check_region , reset_pending = dofile ( minetest.get_modpath ( " worldedit_commands " ) .. " /safe.lua " )
2012-10-14 03:45:50 +02:00
2015-05-17 01:46:33 +02:00
local function get_position ( name ) --position 1 retrieval function for when not using `safe_region`
2014-03-10 22:57:49 +01:00
local pos1 = worldedit.pos1 [ name ]
if pos1 == nil then
worldedit.player_notify ( name , " no position 1 selected " )
end
return pos1
end
2015-05-17 01:46:33 +02:00
local function get_node ( name , nodename )
2014-03-10 22:57:49 +01:00
local node = worldedit.normalize_nodename ( nodename )
if not node then
worldedit.player_notify ( name , " invalid node name: " .. nodename )
return nil
end
return node
end
2015-05-17 01:46:33 +02:00
function worldedit . player_notify ( name , message )
2013-05-15 23:52:12 +02:00
minetest.chat_send_player ( name , " WorldEdit -!- " .. message , false )
end
2012-10-14 03:45:50 +02:00
--determines whether `nodename` is a valid node name, returning a boolean
2013-06-13 01:59:13 +02:00
worldedit.normalize_nodename = function ( nodename )
2014-07-18 22:09:57 +02:00
nodename = nodename : gsub ( " ^%s*(.-)%s*$ " , " %1 " )
2014-03-10 22:57:49 +01:00
if nodename == " " then return nil end
2013-06-24 23:13:10 +02:00
local fullname = ItemStack ( { name = nodename } ) : get_name ( ) --resolve aliases of node names to full names
2013-12-12 21:34:05 +01:00
if minetest.registered_nodes [ fullname ] or fullname == " air " then --directly found node name or alias of nodename
2013-06-24 23:13:10 +02:00
return fullname
2013-06-13 01:59:13 +02:00
end
for key , value in pairs ( minetest.registered_nodes ) do
if key : find ( " : " .. nodename , 1 , true ) then --found in mod
return key
end
end
2013-06-24 23:13:10 +02:00
nodename = nodename : lower ( ) --lowercase both for case insensitive comparison
2013-06-13 01:59:13 +02:00
for key , value in pairs ( minetest.registered_nodes ) do
2013-06-24 23:13:10 +02:00
if value.description : lower ( ) == nodename then --found in description
2013-06-13 01:59:13 +02:00
return key
end
end
return nil
2012-10-14 03:45:50 +02:00
end
2015-05-17 01:46:33 +02:00
-- Determines the axis in which a player is facing, returning an axis ("x", "y", or "z") and the sign (1 or -1)
function worldedit . player_axis ( name )
2013-07-31 06:02:37 +02:00
local dir = minetest.get_player_by_name ( name ) : get_look_dir ( )
2012-10-14 03:45:50 +02:00
local x , y , z = math.abs ( dir.x ) , math.abs ( dir.y ) , math.abs ( dir.z )
if x > y then
if x > z then
return " x " , dir.x > 0 and 1 or - 1
end
elseif y > z then
return " y " , dir.y > 0 and 1 or - 1
end
return " z " , dir.z > 0 and 1 or - 1
end
2015-06-01 22:53:03 +02:00
local function mkdir ( path )
2015-05-17 01:46:33 +02:00
if minetest.mkdir then
minetest.mkdir ( path )
else
os.execute ( ' mkdir " ' .. path .. ' " ' )
end
end
2015-06-01 23:08:43 +02:00
local function check_filename ( name )
return name : find ( " ^[%w%s%^&'@{}%[%],%$=!%-#%(%)%%%.%+~_]+$ " ) ~= nil
end
2015-05-17 01:46:33 +02:00
2014-10-25 07:53:20 +02:00
minetest.register_chatcommand ( " /about " , {
2013-08-29 02:28:49 +02:00
params = " " ,
description = " Get information about the mod " ,
func = function ( name , param )
2013-12-10 07:47:32 +01:00
worldedit.player_notify ( name , " WorldEdit " .. worldedit.version_string .. " is available on this server. Type /help to get a list of commands, or get more information at https://github.com/Uberi/MineTest-WorldEdit/ " )
2013-08-29 02:28:49 +02:00
end ,
} )
2017-01-01 22:26:58 +01:00
-- mostly copied from builtin/chatcommands.lua with minor modifications
minetest.register_chatcommand ( " /help " , {
privs = { } ,
params = " [all/<cmd>] " ,
description = " Get help for WorldEdit commands " ,
func = function ( name , param )
local function is_we_command ( cmd )
return cmd : sub ( 0 , 1 ) == " / "
end
local function format_help_line ( cmd , def )
local msg = minetest.colorize ( " #00ffff " , " / " .. cmd )
if def.params and def.params ~= " " then
msg = msg .. " " .. def.params
end
if def.description and def.description ~= " " then
msg = msg .. " : " .. def.description
end
return msg
end
if not minetest.check_player_privs ( name , " worldedit " ) then
return false , " You are not allowed to use any WorldEdit commands. "
end
if param == " " then
local msg = " "
local cmds = { }
for cmd , def in pairs ( minetest.chatcommands ) do
if is_we_command ( cmd ) and minetest.check_player_privs ( name , def.privs ) then
cmds [ # cmds + 1 ] = cmd : sub ( 2 ) -- strip the /
end
end
table.sort ( cmds )
return true , " Available commands: " .. table.concat ( cmds , " " ) .. " \n "
.. " Use '//help <cmd>' to get more information, "
.. " or '//help all' to list everything. "
elseif param == " all " then
local cmds = { }
for cmd , def in pairs ( minetest.chatcommands ) do
if is_we_command ( cmd ) and minetest.check_player_privs ( name , def.privs ) then
cmds [ # cmds + 1 ] = format_help_line ( cmd , def )
end
end
table.sort ( cmds )
return true , " Available commands: \n " .. table.concat ( cmds , " \n " )
else
return minetest.chatcommands [ " help " ] . func ( name , " / " .. param )
end
end ,
} )
2014-10-25 07:53:20 +02:00
minetest.register_chatcommand ( " /inspect " , {
2013-12-21 00:41:13 +01:00
params = " on/off/1/0/true/false/yes/no/enable/disable/<blank> " ,
2013-07-21 23:16:29 +02:00
description = " Enable or disable node inspection " ,
privs = { worldedit = true } ,
func = function ( name , param )
2013-12-21 00:41:13 +01:00
if param == " on " or param == " 1 " or param == " true " or param == " yes " or param == " enable " or param == " " then
2013-07-29 18:43:24 +02:00
worldedit.inspect [ name ] = true
2013-12-21 00:41:13 +01:00
local axis , sign = worldedit.player_axis ( name )
worldedit.player_notify ( name , string.format ( " inspector: inspection enabled for %s, currently facing the %s axis " ,
name , axis .. ( sign > 0 and " + " or " - " ) ) )
2013-07-21 23:16:29 +02:00
elseif param == " off " or param == " 0 " or param == " false " or param == " no " or param == " disable " then
2013-07-29 18:43:24 +02:00
worldedit.inspect [ name ] = nil
2013-12-21 00:41:13 +01:00
worldedit.player_notify ( name , " inspector: inspection disabled " )
2013-07-21 23:16:29 +02:00
else
worldedit.player_notify ( name , " invalid usage: " .. param )
end
end ,
} )
2017-01-26 22:26:45 +01:00
local function get_node_rlight ( pos )
local vecs = { -- neighboring nodes
{ x = 1 , y = 0 , z = 0 } ,
{ x =- 1 , y = 0 , z = 0 } ,
{ x = 0 , y = 1 , z = 0 } ,
{ x = 0 , y =- 1 , z = 0 } ,
{ x = 0 , y = 0 , z = 1 } ,
{ x = 0 , y = 0 , z =- 1 } ,
}
local ret = 0
for _ , v in ipairs ( vecs ) do
ret = math.max ( ret , minetest.get_node_light ( vector.add ( pos , v ) ) )
end
return ret
end
2013-07-21 23:16:29 +02:00
minetest.register_on_punchnode ( function ( pos , node , puncher )
2013-07-29 18:43:24 +02:00
local name = puncher : get_player_name ( )
if worldedit.inspect [ name ] then
2017-01-03 17:11:38 +01:00
local axis , sign = worldedit.player_axis ( name )
2017-01-26 22:26:45 +01:00
message = string.format ( " inspector: %s at %s (param1=%d, param2=%d, received light=%d) punched facing the %s axis " ,
node.name , minetest.pos_to_string ( pos ) , node.param1 , node.param2 , get_node_rlight ( pos ) , axis .. ( sign > 0 and " + " or " - " ) )
2013-07-29 18:43:24 +02:00
worldedit.player_notify ( name , message )
2013-07-21 23:16:29 +02:00
end
end )
2014-10-25 07:53:20 +02:00
minetest.register_chatcommand ( " /reset " , {
2012-10-14 03:45:50 +02:00
params = " " ,
description = " Reset the region so that it is empty " ,
privs = { worldedit = true } ,
func = function ( name , param )
worldedit.pos1 [ name ] = nil
worldedit.pos2 [ name ] = nil
worldedit.mark_pos1 ( name )
worldedit.mark_pos2 ( name )
2013-05-15 23:03:26 +02:00
worldedit.set_pos [ name ] = nil
2017-01-31 19:52:54 +01:00
--make sure the user does not try to confirm an operation after resetting pos:
reset_pending ( name )
2013-05-15 23:52:12 +02:00
worldedit.player_notify ( name , " region reset " )
2012-10-14 03:45:50 +02:00
end ,
} )
2014-10-25 07:53:20 +02:00
minetest.register_chatcommand ( " /mark " , {
2012-10-14 03:45:50 +02:00
params = " " ,
description = " Show markers at the region positions " ,
privs = { worldedit = true } ,
func = function ( name , param )
worldedit.mark_pos1 ( name )
worldedit.mark_pos2 ( name )
2013-05-15 23:52:12 +02:00
worldedit.player_notify ( name , " region marked " )
2012-10-14 03:45:50 +02:00
end ,
} )
2014-10-25 07:53:20 +02:00
minetest.register_chatcommand ( " /unmark " , {
2013-05-15 23:03:26 +02:00
params = " " ,
description = " Hide markers if currently shown " ,
privs = { worldedit = true } ,
func = function ( name , param )
local pos1 , pos2 = worldedit.pos1 [ name ] , worldedit.pos2 [ name ]
worldedit.pos1 [ name ] = nil
worldedit.pos2 [ name ] = nil
worldedit.mark_pos1 ( name )
worldedit.mark_pos2 ( name )
worldedit.pos1 [ name ] = pos1
worldedit.pos2 [ name ] = pos2
2013-05-15 23:52:12 +02:00
worldedit.player_notify ( name , " region unmarked " )
2013-05-15 23:03:26 +02:00
end ,
} )
2014-10-25 07:53:20 +02:00
minetest.register_chatcommand ( " /pos1 " , {
2012-10-14 03:45:50 +02:00
params = " " ,
description = " Set WorldEdit region position 1 to the player's location " ,
privs = { worldedit = true } ,
func = function ( name , param )
2013-07-31 06:02:37 +02:00
local pos = minetest.get_player_by_name ( name ) : getpos ( )
2013-02-17 03:14:44 +01:00
pos.x , pos.y , pos.z = math.floor ( pos.x + 0.5 ) , math.floor ( pos.y + 0.5 ) , math.floor ( pos.z + 0.5 )
2012-10-14 03:45:50 +02:00
worldedit.pos1 [ name ] = pos
worldedit.mark_pos1 ( name )
2013-05-15 23:52:12 +02:00
worldedit.player_notify ( name , " position 1 set to " .. minetest.pos_to_string ( pos ) )
2012-10-14 03:45:50 +02:00
end ,
} )
2014-10-25 07:53:20 +02:00
minetest.register_chatcommand ( " /pos2 " , {
2012-10-14 03:45:50 +02:00
params = " " ,
description = " Set WorldEdit region position 2 to the player's location " ,
privs = { worldedit = true } ,
func = function ( name , param )
2013-07-31 06:02:37 +02:00
local pos = minetest.get_player_by_name ( name ) : getpos ( )
2013-02-17 03:14:44 +01:00
pos.x , pos.y , pos.z = math.floor ( pos.x + 0.5 ) , math.floor ( pos.y + 0.5 ) , math.floor ( pos.z + 0.5 )
2012-10-14 03:45:50 +02:00
worldedit.pos2 [ name ] = pos
worldedit.mark_pos2 ( name )
2013-05-15 23:52:12 +02:00
worldedit.player_notify ( name , " position 2 set to " .. minetest.pos_to_string ( pos ) )
2012-10-14 03:45:50 +02:00
end ,
} )
2014-10-25 07:53:20 +02:00
minetest.register_chatcommand ( " /p " , {
2012-10-19 03:28:58 +02:00
params = " set/set1/set2/get " ,
description = " Set WorldEdit region, WorldEdit position 1, or WorldEdit position 2 by punching nodes, or display the current WorldEdit region " ,
2012-10-14 03:45:50 +02:00
privs = { worldedit = true } ,
func = function ( name , param )
if param == " set " then --set both WorldEdit positions
2012-10-19 03:28:58 +02:00
worldedit.set_pos [ name ] = " pos1 "
2013-05-15 23:52:12 +02:00
worldedit.player_notify ( name , " select positions by punching two nodes " )
2012-10-19 03:28:58 +02:00
elseif param == " set1 " then --set WorldEdit position 1
worldedit.set_pos [ name ] = " pos1only "
2013-05-15 23:52:12 +02:00
worldedit.player_notify ( name , " select position 1 by punching a node " )
2012-10-19 03:28:58 +02:00
elseif param == " set2 " then --set WorldEdit position 2
worldedit.set_pos [ name ] = " pos2 "
2013-05-15 23:52:12 +02:00
worldedit.player_notify ( name , " select position 2 by punching a node " )
2012-10-14 03:45:50 +02:00
elseif param == " get " then --display current WorldEdit positions
if worldedit.pos1 [ name ] ~= nil then
2013-05-15 23:52:12 +02:00
worldedit.player_notify ( name , " position 1: " .. minetest.pos_to_string ( worldedit.pos1 [ name ] ) )
2012-10-14 03:45:50 +02:00
else
2013-05-15 23:52:12 +02:00
worldedit.player_notify ( name , " position 1 not set " )
2012-10-14 03:45:50 +02:00
end
if worldedit.pos2 [ name ] ~= nil then
2013-05-15 23:52:12 +02:00
worldedit.player_notify ( name , " position 2: " .. minetest.pos_to_string ( worldedit.pos2 [ name ] ) )
2012-10-14 03:45:50 +02:00
else
2013-05-15 23:52:12 +02:00
worldedit.player_notify ( name , " position 2 not set " )
2012-10-14 03:45:50 +02:00
end
else
2013-05-15 23:52:12 +02:00
worldedit.player_notify ( name , " unknown subcommand: " .. param )
2012-10-14 03:45:50 +02:00
end
end ,
} )
2014-10-25 07:53:20 +02:00
minetest.register_chatcommand ( " /fixedpos " , {
2013-07-28 23:07:47 +02:00
params = " set1/set2 x y z " ,
description = " Set a WorldEdit region position to the position at (<x>, <y>, <z>) " ,
privs = { worldedit = true } ,
func = function ( name , param )
local found , _ , flag , x , y , z = param : find ( " ^(set[12])%s+([+-]?%d+)%s+([+-]?%d+)%s+([+-]?%d+)$ " )
if found == nil then
worldedit.player_notify ( name , " invalid usage: " .. param )
return
end
2013-07-29 00:15:46 +02:00
local pos = { x = tonumber ( x ) , y = tonumber ( y ) , z = tonumber ( z ) }
2013-07-28 23:07:47 +02:00
if flag == " set1 " then
worldedit.pos1 [ name ] = pos
worldedit.mark_pos1 ( name )
worldedit.player_notify ( name , " position 1 set to " .. minetest.pos_to_string ( pos ) )
else --flag == "set2"
worldedit.pos2 [ name ] = pos
worldedit.mark_pos2 ( name )
worldedit.player_notify ( name , " position 2 set to " .. minetest.pos_to_string ( pos ) )
end
end ,
} )
2012-10-14 03:45:50 +02:00
minetest.register_on_punchnode ( function ( pos , node , puncher )
local name = puncher : get_player_name ( )
if name ~= " " and worldedit.set_pos [ name ] ~= nil then --currently setting position
2012-10-19 03:28:58 +02:00
if worldedit.set_pos [ name ] == " pos1 " then --setting position 1
2012-10-14 03:45:50 +02:00
worldedit.pos1 [ name ] = pos
worldedit.mark_pos1 ( name )
2012-10-19 03:28:58 +02:00
worldedit.set_pos [ name ] = " pos2 " --set position 2 on the next invocation
2013-05-15 23:52:12 +02:00
worldedit.player_notify ( name , " position 1 set to " .. minetest.pos_to_string ( pos ) )
2012-10-19 03:28:58 +02:00
elseif worldedit.set_pos [ name ] == " pos1only " then --setting position 1 only
worldedit.pos1 [ name ] = pos
worldedit.mark_pos1 ( name )
2012-10-14 03:45:50 +02:00
worldedit.set_pos [ name ] = nil --finished setting positions
2013-05-15 23:52:12 +02:00
worldedit.player_notify ( name , " position 1 set to " .. minetest.pos_to_string ( pos ) )
2012-10-19 03:28:58 +02:00
elseif worldedit.set_pos [ name ] == " pos2 " then --setting position 2
2012-10-14 03:45:50 +02:00
worldedit.pos2 [ name ] = pos
worldedit.mark_pos2 ( name )
2012-10-19 03:28:58 +02:00
worldedit.set_pos [ name ] = nil --finished setting positions
2013-05-15 23:52:12 +02:00
worldedit.player_notify ( name , " position 2 set to " .. minetest.pos_to_string ( pos ) )
2013-06-22 08:24:54 +02:00
elseif worldedit.set_pos [ name ] == " prob " then --setting Minetest schematic node probabilities
worldedit.prob_pos [ name ] = pos
minetest.show_formspec ( puncher : get_player_name ( ) , " prob_val_enter " , " field[text;;] " )
2012-10-14 03:45:50 +02:00
end
end
end )
2014-10-25 07:53:20 +02:00
minetest.register_chatcommand ( " /volume " , {
2012-10-14 03:45:50 +02:00
params = " " ,
description = " Display the volume of the current WorldEdit region " ,
privs = { worldedit = true } ,
func = function ( name , param )
local pos1 , pos2 = worldedit.pos1 [ name ] , worldedit.pos2 [ name ]
if pos1 == nil or pos2 == nil then
2013-05-15 23:52:12 +02:00
worldedit.player_notify ( name , " no region selected " )
2014-03-10 22:57:49 +01:00
return nil
2012-10-14 03:45:50 +02:00
end
local volume = worldedit.volume ( pos1 , pos2 )
2013-07-28 03:34:42 +02:00
local abs = math.abs
worldedit.player_notify ( name , " current region has a volume of " .. volume .. " nodes ( "
2013-12-10 07:47:32 +01:00
.. abs ( pos2.x - pos1.x ) + 1 .. " * "
.. abs ( pos2.y - pos1.y ) + 1 .. " * "
.. abs ( pos2.z - pos1.z ) + 1 .. " ) " )
2012-10-14 03:45:50 +02:00
end ,
} )
2015-02-08 01:38:05 +01:00
minetest.register_chatcommand ( " /deleteblocks " , {
params = " " ,
description = " remove all MapBlocks (16x16x16) containing the selected area from the map " ,
privs = { worldedit = true } ,
func = safe_region ( function ( name , param )
local pos1 , pos2 = worldedit.pos1 [ name ] , worldedit.pos2 [ name ]
local success = minetest.delete_area ( pos1 , pos2 )
if success then
worldedit.player_notify ( name , " Area deleted. " )
else
worldedit.player_notify ( name , " There was an error during deletion of the area. " )
end
end ) ,
} )
2014-10-25 07:53:20 +02:00
minetest.register_chatcommand ( " /set " , {
2014-07-18 21:51:09 +02:00
params = " <node> " ,
description = " Set the current WorldEdit region to <node> " ,
privs = { worldedit = true } ,
func = safe_region ( function ( name , param )
local node = get_node ( name , param )
if not node then
worldedit.player_notify ( name , " Could not identify node \" " .. param .. " \" " )
return
end
local count = worldedit.set ( worldedit.pos1 [ name ] , worldedit.pos2 [ name ] , node )
worldedit.player_notify ( name , count .. " nodes set " )
end , check_region ) ,
} )
2017-08-31 01:06:14 +02:00
minetest.register_chatcommand ( " /param2 " , {
params = " <param2> " ,
description = " Set param2 of all nodes in the current WorldEdit region to <param2> " ,
privs = { worldedit = true } ,
func = safe_region ( function ( name , param )
local param2 = tonumber ( param )
if not param2 then
worldedit.player_notify ( name , " Invalid or missing param2 argument " )
return
elseif param2 < 0 or param2 > 255 then
worldedit.player_notify ( name , " Param2 is out of range (must be between 0 and 255 inclusive)! " )
return
end
local count = worldedit.set_param2 ( worldedit.pos1 [ name ] , worldedit.pos2 [ name ] , param2 )
worldedit.player_notify ( name , count .. " nodes set " )
end , check_region ) ,
} )
2014-10-25 07:53:20 +02:00
minetest.register_chatcommand ( " /mix " , {
2014-07-07 01:42:02 +02:00
params = " <node1> ... " ,
2014-07-18 21:51:09 +02:00
description = " Fill the current WorldEdit region with a random mix of <node1>, ... " ,
2012-10-14 03:45:50 +02:00
privs = { worldedit = true } ,
2014-03-12 21:11:00 +01:00
func = safe_region ( function ( name , param )
2014-07-18 21:51:09 +02:00
local nodes = { }
2014-07-18 22:09:57 +02:00
for nodename in param : gmatch ( " [^%s]+ " ) do
2014-07-18 21:51:09 +02:00
local node = get_node ( name , nodename )
if not node then
worldedit.player_notify ( name , " Could not identify node \" " .. name .. " \" " )
return
end
nodes [ # nodes + 1 ] = node
end
2014-07-01 01:13:44 +02:00
2014-03-12 21:11:00 +01:00
local pos1 , pos2 = worldedit.pos1 [ name ] , worldedit.pos2 [ name ]
2014-07-01 01:13:44 +02:00
local count = worldedit.set ( pos1 , pos2 , nodes )
2013-05-15 23:52:12 +02:00
worldedit.player_notify ( name , count .. " nodes set " )
2014-07-01 01:13:44 +02:00
end , check_region ) ,
2012-10-14 03:45:50 +02:00
} )
2014-03-12 21:11:00 +01:00
local check_replace = function ( name , param )
local found , _ , searchnode , replacenode = param : find ( " ^([^%s]+)%s+(.+)$ " )
if found == nil then
worldedit.player_notify ( name , " invalid usage: " .. param )
return nil
end
local newsearchnode = worldedit.normalize_nodename ( searchnode )
if not newsearchnode then
worldedit.player_notify ( name , " invalid search node name: " .. searchnode )
return nil
end
local newreplacenode = worldedit.normalize_nodename ( replacenode )
if not newreplacenode then
worldedit.player_notify ( name , " invalid replace node name: " .. replacenode )
return nil
end
return check_region ( name , param )
end
2014-10-25 07:53:20 +02:00
minetest.register_chatcommand ( " /replace " , {
2012-10-14 03:45:50 +02:00
params = " <search node> <replace node> " ,
2013-01-13 00:20:41 +01:00
description = " Replace all instances of <search node> with <replace node> in the current WorldEdit region " ,
2012-10-14 03:45:50 +02:00
privs = { worldedit = true } ,
2014-03-12 21:11:00 +01:00
func = safe_region ( function ( name , param )
2014-10-30 03:47:08 +01:00
local found , _ , search_node , replace_node = param : find ( " ^([^%s]+)%s+(.+)$ " )
local norm_search_node = worldedit.normalize_nodename ( search_node )
local norm_replace_node = worldedit.normalize_nodename ( replace_node )
local count = worldedit.replace ( worldedit.pos1 [ name ] , worldedit.pos2 [ name ] ,
norm_search_node , norm_replace_node )
2013-05-15 23:52:12 +02:00
worldedit.player_notify ( name , count .. " nodes replaced " )
2014-03-12 21:11:00 +01:00
end , check_replace ) ,
2012-10-14 03:45:50 +02:00
} )
2014-10-25 07:53:20 +02:00
minetest.register_chatcommand ( " /replaceinverse " , {
2013-01-13 00:29:57 +01:00
params = " <search node> <replace node> " ,
description = " Replace all nodes other than <search node> with <replace node> in the current WorldEdit region " ,
2013-01-13 00:20:41 +01:00
privs = { worldedit = true } ,
2014-03-12 21:11:00 +01:00
func = safe_region ( function ( name , param )
2014-10-30 03:47:08 +01:00
local found , _ , search_node , replace_node = param : find ( " ^([^%s]+)%s+(.+)$ " )
local norm_search_node = worldedit.normalize_nodename ( search_node )
local norm_replace_node = worldedit.normalize_nodename ( replace_node )
local count = worldedit.replace ( worldedit.pos1 [ name ] , worldedit.pos2 [ name ] ,
norm_search_node , norm_replace_node , true )
2013-05-15 23:52:12 +02:00
worldedit.player_notify ( name , count .. " nodes replaced " )
2014-03-12 21:11:00 +01:00
end , check_replace ) ,
2013-01-13 00:20:41 +01:00
} )
2014-03-12 21:11:00 +01:00
local check_sphere = function ( name , param )
if worldedit.pos1 [ name ] == nil then
worldedit.player_notify ( name , " no position 1 selected " )
return nil
end
local found , _ , radius , nodename = param : find ( " ^(%d+)%s+(.+)$ " )
if found == nil then
worldedit.player_notify ( name , " invalid usage: " .. param )
return nil
end
local node = get_node ( name , nodename )
if not node then return nil end
return math.ceil ( ( 4 * math.pi * ( tonumber ( radius ) ^ 3 ) ) / 3 ) --volume of sphere
end
2014-10-25 07:53:20 +02:00
minetest.register_chatcommand ( " /hollowsphere " , {
2012-10-14 03:45:50 +02:00
params = " <radius> <node> " ,
2013-06-23 05:05:34 +02:00
description = " Add hollow sphere centered at WorldEdit position 1 with radius <radius>, composed of <node> " ,
2012-10-14 03:45:50 +02:00
privs = { worldedit = true } ,
2014-03-12 21:11:00 +01:00
func = safe_region ( function ( name , param )
2013-06-13 01:59:13 +02:00
local found , _ , radius , nodename = param : find ( " ^(%d+)%s+(.+)$ " )
2014-03-10 22:57:49 +01:00
local node = get_node ( name , nodename )
2014-10-30 03:47:08 +01:00
local count = worldedit.sphere ( worldedit.pos1 [ name ] , tonumber ( radius ) , node , true )
2013-05-15 23:52:12 +02:00
worldedit.player_notify ( name , count .. " nodes added " )
2014-03-12 21:11:00 +01:00
end , check_sphere ) ,
2012-10-14 03:45:50 +02:00
} )
2014-10-25 07:53:20 +02:00
minetest.register_chatcommand ( " /sphere " , {
2012-10-14 03:45:50 +02:00
params = " <radius> <node> " ,
2013-06-23 05:05:34 +02:00
description = " Add sphere centered at WorldEdit position 1 with radius <radius>, composed of <node> " ,
2012-10-14 03:45:50 +02:00
privs = { worldedit = true } ,
2014-03-12 21:11:00 +01:00
func = safe_region ( function ( name , param )
2013-06-13 01:59:13 +02:00
local found , _ , radius , nodename = param : find ( " ^(%d+)%s+(.+)$ " )
2014-03-10 22:57:49 +01:00
local node = get_node ( name , nodename )
2014-07-18 21:51:09 +02:00
local count = worldedit.sphere ( worldedit.pos1 [ name ] , tonumber ( radius ) , node )
2013-05-15 23:52:12 +02:00
worldedit.player_notify ( name , count .. " nodes added " )
2014-03-12 21:11:00 +01:00
end , check_sphere ) ,
2012-10-14 03:45:50 +02:00
} )
2014-03-12 21:11:00 +01:00
local check_dome = function ( name , param )
if worldedit.pos1 [ name ] == nil then
worldedit.player_notify ( name , " no position 1 selected " )
return nil
end
local found , _ , radius , nodename = param : find ( " ^(%d+)%s+(.+)$ " )
if found == nil then
worldedit.player_notify ( name , " invalid usage: " .. param )
return nil
end
local node = get_node ( name , nodename )
if not node then return nil end
return math.ceil ( ( 2 * math.pi * ( tonumber ( radius ) ^ 3 ) ) / 3 ) --volume of dome
end
2014-10-25 07:53:20 +02:00
minetest.register_chatcommand ( " /hollowdome " , {
2013-04-28 00:28:20 +02:00
params = " <radius> <node> " ,
2013-06-23 05:05:34 +02:00
description = " Add hollow dome centered at WorldEdit position 1 with radius <radius>, composed of <node> " ,
2013-04-28 00:28:20 +02:00
privs = { worldedit = true } ,
2014-03-12 21:11:00 +01:00
func = safe_region ( function ( name , param )
local found , _ , radius , nodename = param : find ( " ^(%d+)%s+(.+)$ " )
2014-03-10 22:57:49 +01:00
local node = get_node ( name , nodename )
2014-10-30 03:47:08 +01:00
local count = worldedit.dome ( worldedit.pos1 [ name ] , tonumber ( radius ) , node , true )
2013-05-15 23:52:12 +02:00
worldedit.player_notify ( name , count .. " nodes added " )
2014-03-12 21:11:00 +01:00
end , check_dome ) ,
2013-04-28 00:28:20 +02:00
} )
2014-10-25 07:53:20 +02:00
minetest.register_chatcommand ( " /dome " , {
2013-04-28 00:28:20 +02:00
params = " <radius> <node> " ,
2013-06-23 05:05:34 +02:00
description = " Add dome centered at WorldEdit position 1 with radius <radius>, composed of <node> " ,
2013-04-28 00:28:20 +02:00
privs = { worldedit = true } ,
2014-03-12 21:11:00 +01:00
func = safe_region ( function ( name , param )
local found , _ , radius , nodename = param : find ( " ^(%d+)%s+(.+)$ " )
2014-03-10 22:57:49 +01:00
local node = get_node ( name , nodename )
2014-07-18 21:51:09 +02:00
local count = worldedit.dome ( worldedit.pos1 [ name ] , tonumber ( radius ) , node )
2013-05-15 23:52:12 +02:00
worldedit.player_notify ( name , count .. " nodes added " )
2014-03-12 21:11:00 +01:00
end , check_dome ) ,
2013-04-28 00:28:20 +02:00
} )
2014-03-12 21:11:00 +01:00
local check_cylinder = function ( name , param )
if worldedit.pos1 [ name ] == nil then
worldedit.player_notify ( name , " no position 1 selected " )
return nil
end
local found , _ , axis , length , radius , nodename = param : find ( " ^([xyz%?])%s+([+-]?%d+)%s+(%d+)%s+(.+)$ " )
if found == nil then
worldedit.player_notify ( name , " invalid usage: " .. param )
return nil
end
local node = get_node ( name , nodename )
if not node then return nil end
return math.ceil ( math.pi * ( tonumber ( radius ) ^ 2 ) * tonumber ( length ) )
end
2014-10-25 07:53:20 +02:00
minetest.register_chatcommand ( " /hollowcylinder " , {
2012-10-14 03:45:50 +02:00
params = " x/y/z/? <length> <radius> <node> " ,
description = " Add hollow cylinder at WorldEdit position 1 along the x/y/z/? axis with length <length> and radius <radius>, composed of <node> " ,
privs = { worldedit = true } ,
2014-03-12 21:11:00 +01:00
func = safe_region ( function ( name , param )
2013-06-13 01:59:13 +02:00
local found , _ , axis , length , radius , nodename = param : find ( " ^([xyz%?])%s+([+-]?%d+)%s+(%d+)%s+(.+)$ " )
2014-03-12 21:11:00 +01:00
length = tonumber ( length )
2012-10-14 03:45:50 +02:00
if axis == " ? " then
axis , sign = worldedit.player_axis ( name )
length = length * sign
end
2014-03-10 22:57:49 +01:00
local node = get_node ( name , nodename )
2014-10-30 03:47:08 +01:00
local count = worldedit.cylinder ( worldedit.pos1 [ name ] , axis , length , tonumber ( radius ) , node , true )
2013-05-15 23:52:12 +02:00
worldedit.player_notify ( name , count .. " nodes added " )
2014-03-12 21:11:00 +01:00
end , check_cylinder ) ,
2012-10-14 03:45:50 +02:00
} )
2014-10-25 07:53:20 +02:00
minetest.register_chatcommand ( " /cylinder " , {
2012-10-14 03:45:50 +02:00
params = " x/y/z/? <length> <radius> <node> " ,
description = " Add cylinder at WorldEdit position 1 along the x/y/z/? axis with length <length> and radius <radius>, composed of <node> " ,
privs = { worldedit = true } ,
2014-03-12 21:11:00 +01:00
func = safe_region ( function ( name , param )
2013-06-13 01:59:13 +02:00
local found , _ , axis , length , radius , nodename = param : find ( " ^([xyz%?])%s+([+-]?%d+)%s+(%d+)%s+(.+)$ " )
2014-03-12 21:11:00 +01:00
length = tonumber ( length )
2012-10-14 03:45:50 +02:00
if axis == " ? " then
axis , sign = worldedit.player_axis ( name )
length = length * sign
end
2014-03-10 22:57:49 +01:00
local node = get_node ( name , nodename )
2014-07-18 21:51:09 +02:00
local count = worldedit.cylinder ( worldedit.pos1 [ name ] , axis , length , tonumber ( radius ) , node )
2013-05-15 23:52:12 +02:00
worldedit.player_notify ( name , count .. " nodes added " )
2014-03-12 21:11:00 +01:00
end , check_cylinder ) ,
2012-10-14 03:45:50 +02:00
} )
2015-09-13 11:31:47 +02:00
local check_pyramid = function ( name , param )
if worldedit.pos1 [ name ] == nil then
worldedit.player_notify ( name , " no position 1 selected " )
return nil
end
local found , _ , axis , height , nodename = param : find ( " ^([xyz%?])%s+([+-]?%d+)%s+(.+)$ " )
if found == nil then
worldedit.player_notify ( name , " invalid usage: " .. param )
return nil
end
local node = get_node ( name , nodename )
if not node then return nil end
height = tonumber ( height )
return math.ceil ( ( ( height * 2 + 1 ) ^ 2 ) * height / 3 )
end
minetest.register_chatcommand ( " /hollowpyramid " , {
2013-07-29 18:43:24 +02:00
params = " x/y/z/? <height> <node> " ,
2015-09-13 11:31:47 +02:00
description = " Add hollow pyramid centered at WorldEdit position 1 along the x/y/z/? axis with height <height>, composed of <node> " ,
2012-10-14 03:45:50 +02:00
privs = { worldedit = true } ,
2014-03-12 21:11:00 +01:00
func = safe_region ( function ( name , param )
2013-07-29 18:43:24 +02:00
local found , _ , axis , height , nodename = param : find ( " ^([xyz%?])%s+([+-]?%d+)%s+(.+)$ " )
height = tonumber ( height )
if axis == " ? " then
axis , sign = worldedit.player_axis ( name )
height = height * sign
end
2014-03-10 22:57:49 +01:00
local node = get_node ( name , nodename )
2015-09-13 11:31:47 +02:00
local count = worldedit.pyramid ( worldedit.pos1 [ name ] , axis , height , node , true )
2013-05-15 23:52:12 +02:00
worldedit.player_notify ( name , count .. " nodes added " )
2015-09-13 11:31:47 +02:00
end , check_pyramid ) ,
} )
minetest.register_chatcommand ( " /pyramid " , {
params = " x/y/z/? <height> <node> " ,
description = " Add pyramid centered at WorldEdit position 1 along the x/y/z/? axis with height <height>, composed of <node> " ,
privs = { worldedit = true } ,
func = safe_region ( function ( name , param )
2014-03-12 21:11:00 +01:00
local found , _ , axis , height , nodename = param : find ( " ^([xyz%?])%s+([+-]?%d+)%s+(.+)$ " )
2015-09-13 11:31:47 +02:00
height = tonumber ( height )
if axis == " ? " then
axis , sign = worldedit.player_axis ( name )
height = height * sign
2014-03-12 21:11:00 +01:00
end
local node = get_node ( name , nodename )
2015-09-13 11:31:47 +02:00
local count = worldedit.pyramid ( worldedit.pos1 [ name ] , axis , height , node )
worldedit.player_notify ( name , count .. " nodes added " )
end , check_pyramid ) ,
2012-10-14 03:45:50 +02:00
} )
2014-10-25 07:53:20 +02:00
minetest.register_chatcommand ( " /spiral " , {
2013-08-01 04:15:08 +02:00
params = " <length> <height> <space> <node> " ,
description = " Add spiral centered at WorldEdit position 1 with side length <length>, height <height>, space between walls <space>, composed of <node> " ,
2012-10-14 03:45:50 +02:00
privs = { worldedit = true } ,
2014-03-12 21:11:00 +01:00
func = safe_region ( function ( name , param )
2013-08-01 04:15:08 +02:00
local found , _ , length , height , space , nodename = param : find ( " ^(%d+)%s+(%d+)%s+(%d+)%s+(.+)$ " )
2014-03-10 22:57:49 +01:00
local node = get_node ( name , nodename )
2014-07-18 21:51:09 +02:00
local count = worldedit.spiral ( worldedit.pos1 [ name ] , tonumber ( length ) , tonumber ( height ) , tonumber ( space ) , node )
2013-05-15 23:52:12 +02:00
worldedit.player_notify ( name , count .. " nodes added " )
2012-10-14 03:45:50 +02:00
end ,
2014-03-12 21:11:00 +01:00
function ( name , param )
if worldedit.pos1 [ name ] == nil then
worldedit.player_notify ( name , " no position 1 selected " )
return nil
end
local found , _ , length , height , space , nodename = param : find ( " ^(%d+)%s+(%d+)%s+(%d+)%s+(.+)$ " )
if found == nil then
worldedit.player_notify ( name , " invalid usage: " .. param )
return nil
end
local node = get_node ( name , nodename )
if not node then return nil end
2016-10-12 19:45:38 +02:00
return 1 -- TODO: return an useful value
2014-03-12 21:11:00 +01:00
end ) ,
2012-10-14 03:45:50 +02:00
} )
2014-10-25 07:53:20 +02:00
minetest.register_chatcommand ( " /copy " , {
2012-10-14 03:45:50 +02:00
params = " x/y/z/? <amount> " ,
description = " Copy the current WorldEdit region along the x/y/z/? axis by <amount> nodes " ,
privs = { worldedit = true } ,
2014-03-12 21:11:00 +01:00
func = safe_region ( function ( name , param )
2012-10-14 03:45:50 +02:00
local found , _ , axis , amount = param : find ( " ^([xyz%?])%s+([+-]?%d+)$ " )
if found == nil then
2013-05-15 23:52:12 +02:00
worldedit.player_notify ( name , " invalid usage: " .. param )
2012-10-14 03:45:50 +02:00
return
end
2013-07-29 18:43:24 +02:00
amount = tonumber ( amount )
2012-10-14 03:45:50 +02:00
if axis == " ? " then
axis , sign = worldedit.player_axis ( name )
amount = amount * sign
end
2014-07-18 21:51:09 +02:00
local count = worldedit.copy ( worldedit.pos1 [ name ] , worldedit.pos2 [ name ] , axis , amount )
2013-05-15 23:52:12 +02:00
worldedit.player_notify ( name , count .. " nodes copied " )
2014-03-12 21:11:00 +01:00
end ,
function ( name , param )
local volume = check_region ( name , param )
return volume and volume * 2 or volume
2014-03-10 22:57:49 +01:00
end ) ,
2012-10-14 03:45:50 +02:00
} )
2014-10-25 07:53:20 +02:00
minetest.register_chatcommand ( " /move " , {
2012-10-14 03:45:50 +02:00
params = " x/y/z/? <amount> " ,
description = " Move the current WorldEdit region along the x/y/z/? axis by <amount> nodes " ,
privs = { worldedit = true } ,
2014-03-12 21:11:00 +01:00
func = safe_region ( function ( name , param )
local pos1 , pos2 = worldedit.pos1 [ name ] , worldedit.pos2 [ name ]
2012-10-14 03:45:50 +02:00
local found , _ , axis , amount = param : find ( " ^([xyz%?])%s+([+-]?%d+)$ " )
if found == nil then
2013-05-15 23:52:12 +02:00
worldedit.player_notify ( name , " invalid usage: " .. param )
2012-10-14 03:45:50 +02:00
return
end
2013-07-29 18:43:24 +02:00
amount = tonumber ( amount )
2012-10-14 03:45:50 +02:00
if axis == " ? " then
axis , sign = worldedit.player_axis ( name )
amount = amount * sign
end
2013-07-31 06:02:37 +02:00
local count = worldedit.move ( pos1 , pos2 , axis , amount )
2012-10-14 03:45:50 +02:00
pos1 [ axis ] = pos1 [ axis ] + amount
pos2 [ axis ] = pos2 [ axis ] + amount
worldedit.mark_pos1 ( name )
worldedit.mark_pos2 ( name )
2013-05-15 23:52:12 +02:00
worldedit.player_notify ( name , count .. " nodes moved " )
2014-03-12 21:11:00 +01:00
end , check_region ) ,
2012-10-14 03:45:50 +02:00
} )
2014-10-25 07:53:20 +02:00
minetest.register_chatcommand ( " /stack " , {
2012-10-14 03:45:50 +02:00
params = " x/y/z/? <count> " ,
description = " Stack the current WorldEdit region along the x/y/z/? axis <count> times " ,
privs = { worldedit = true } ,
2014-03-12 21:11:00 +01:00
func = safe_region ( function ( name , param )
2014-03-10 22:57:49 +01:00
local found , _ , axis , repetitions = param : find ( " ^([xyz%?])%s+([+-]?%d+)$ " )
repetitions = tonumber ( repetitions )
2012-10-14 03:45:50 +02:00
if axis == " ? " then
axis , sign = worldedit.player_axis ( name )
2014-03-10 22:57:49 +01:00
repetitions = repetitions * sign
2012-10-14 03:45:50 +02:00
end
2014-07-18 21:51:09 +02:00
local count = worldedit.stack ( worldedit.pos1 [ name ] , worldedit.pos2 [ name ] , axis , repetitions )
2013-05-15 23:52:12 +02:00
worldedit.player_notify ( name , count .. " nodes stacked " )
2012-10-14 03:45:50 +02:00
end ,
2014-03-12 21:11:00 +01:00
function ( name , param )
2014-03-10 22:57:49 +01:00
local found , _ , axis , repetitions = param : find ( " ^([xyz%?])%s+([+-]?%d+)$ " )
2014-03-12 21:11:00 +01:00
if found == nil then
worldedit.player_notify ( name , " invalid usage: " .. param )
2014-08-16 01:23:23 +02:00
return
2014-03-10 22:57:49 +01:00
end
2014-03-12 21:11:00 +01:00
local count = check_region ( name , param )
if count then return ( tonumber ( repetitions ) + 1 ) * count end
return nil
2014-03-10 22:57:49 +01:00
end ) ,
2012-10-14 03:45:50 +02:00
} )
2014-10-25 07:53:20 +02:00
minetest.register_chatcommand ( " /stack2 " , {
2014-07-07 01:42:02 +02:00
params = " <count> <x> <y> <z> " ,
description = " Stack the current WorldEdit region <count> times by offset <x>, <y>, <z> " ,
2014-07-01 01:14:14 +02:00
privs = { worldedit = true } ,
func = function ( name , param )
local pos1 , pos2 = worldedit.pos1 [ name ] , worldedit.pos2 [ name ]
2014-07-18 21:51:09 +02:00
if pos1 == nil or pos2 == nil then
2014-07-07 01:42:02 +02:00
worldedit.player_notify ( name , " Select a position first! " )
2014-07-18 21:51:09 +02:00
return
end
local repetitions , incs = param : match ( " (%d+)%s*(.+) " )
if repetitions == nil then
2014-07-01 01:14:14 +02:00
worldedit.player_notify ( name , " invalid count: " .. param )
2014-07-18 21:51:09 +02:00
return
end
2014-07-07 01:42:02 +02:00
repetitions = tonumber ( repetitions )
2014-07-01 01:14:14 +02:00
2014-12-16 07:44:22 +01:00
local x , y , z = incs : match ( " ([+-]?%d+) ([+-]?%d+) ([+-]?%d+) " )
2014-07-18 21:51:09 +02:00
if x == nil then
worldedit.player_notify ( name , " invalid increments: " .. param )
return
end
x , y , z = tonumber ( x ) , tonumber ( y ) , tonumber ( z )
2014-07-01 01:14:14 +02:00
2014-07-18 21:51:09 +02:00
local count = worldedit.volume ( pos1 , pos2 ) * repetitions
2014-07-01 01:14:14 +02:00
2014-07-18 21:51:09 +02:00
return safe_region ( function ( )
2014-07-07 01:42:02 +02:00
worldedit.stack2 ( pos1 , pos2 , { x = x , y = y , z = z } , repetitions ,
function ( ) worldedit.player_notify ( name , count .. " nodes stacked " ) end )
end , function ( )
return count
2014-07-18 21:51:09 +02:00
end ) ( name , param ) -- more hax --wip: clean this up a little bit
2014-07-01 01:14:14 +02:00
end
} )
2014-10-25 07:53:20 +02:00
minetest.register_chatcommand ( " /stretch " , {
2013-12-21 00:41:13 +01:00
params = " <stretchx> <stretchy> <stretchz> " ,
description = " Scale the current WorldEdit positions and region by a factor of <stretchx>, <stretchy>, <stretchz> along the X, Y, and Z axes, repectively, with position 1 as the origin " ,
2013-06-18 21:05:49 +02:00
privs = { worldedit = true } ,
2014-03-12 21:11:00 +01:00
func = safe_region ( function ( name , param )
local pos1 , pos2 = worldedit.pos1 [ name ] , worldedit.pos2 [ name ]
2013-12-21 00:41:13 +01:00
local found , _ , stretchx , stretchy , stretchz = param : find ( " ^(%d+)%s+(%d+)%s+(%d+)$ " )
stretchx , stretchy , stretchz = tonumber ( stretchx ) , tonumber ( stretchy ) , tonumber ( stretchz )
local count , pos1 , pos2 = worldedit.stretch ( pos1 , pos2 , stretchx , stretchy , stretchz )
2013-06-18 21:05:49 +02:00
--reset markers to scaled positions
worldedit.pos1 [ name ] = pos1
worldedit.pos2 [ name ] = pos2
worldedit.mark_pos1 ( name )
worldedit.mark_pos2 ( name )
2013-12-21 00:41:13 +01:00
worldedit.player_notify ( name , count .. " nodes stretched " )
2013-06-18 21:05:49 +02:00
end ,
2014-03-12 21:11:00 +01:00
function ( name , param )
2014-03-10 22:57:49 +01:00
local found , _ , stretchx , stretchy , stretchz = param : find ( " ^(%d+)%s+(%d+)%s+(%d+)$ " )
2014-03-12 21:11:00 +01:00
if found == nil then
worldedit.player_notify ( name , " invalid usage: " .. param )
return nil
2014-03-10 22:57:49 +01:00
end
2014-03-12 21:11:00 +01:00
stretchx , stretchy , stretchz = tonumber ( stretchx ) , tonumber ( stretchy ) , tonumber ( stretchz )
if stretchx == 0 or stretchy == 0 or stretchz == 0 then
worldedit.player_notify ( name , " invalid scaling factors: " .. param )
end
local count = check_region ( name , param )
if count then return tonumber ( stretchx ) * tonumber ( stretchy ) * tonumber ( stretchz ) * count end
return nil
2014-03-10 22:57:49 +01:00
end ) ,
2013-06-18 21:05:49 +02:00
} )
2014-10-25 07:53:20 +02:00
minetest.register_chatcommand ( " /transpose " , {
2012-10-14 03:45:50 +02:00
params = " x/y/z/? x/y/z/? " ,
description = " Transpose the current WorldEdit region along the x/y/z/? and x/y/z/? axes " ,
privs = { worldedit = true } ,
2014-03-12 21:11:00 +01:00
func = safe_region ( function ( name , param )
local pos1 , pos2 = worldedit.pos1 [ name ] , worldedit.pos2 [ name ]
2012-10-14 03:45:50 +02:00
local found , _ , axis1 , axis2 = param : find ( " ^([xyz%?])%s+([xyz%?])$ " )
2014-03-12 21:11:00 +01:00
if axis1 == " ? " then axis1 = worldedit.player_axis ( name ) end
if axis2 == " ? " then axis2 = worldedit.player_axis ( name ) end
2013-07-31 06:02:37 +02:00
local count , pos1 , pos2 = worldedit.transpose ( pos1 , pos2 , axis1 , axis2 )
2012-12-12 23:17:56 +01:00
--reset markers to transposed positions
worldedit.pos1 [ name ] = pos1
worldedit.pos2 [ name ] = pos2
worldedit.mark_pos1 ( name )
worldedit.mark_pos2 ( name )
2013-05-15 23:52:12 +02:00
worldedit.player_notify ( name , count .. " nodes transposed " )
2014-03-12 21:11:00 +01:00
end ,
function ( name , param )
local found , _ , axis1 , axis2 = param : find ( " ^([xyz%?])%s+([xyz%?])$ " )
if found == nil then
worldedit.player_notify ( name , " invalid usage: " .. param )
return nil
end
if axis1 == axis2 then
worldedit.player_notify ( name , " invalid usage: axes must be different " )
return nil
end
return check_region ( name , param )
2014-03-10 22:57:49 +01:00
end ) ,
2012-10-14 03:45:50 +02:00
} )
2014-10-25 07:53:20 +02:00
minetest.register_chatcommand ( " /flip " , {
2012-10-14 03:45:50 +02:00
params = " x/y/z/? " ,
description = " Flip the current WorldEdit region along the x/y/z/? axis " ,
privs = { worldedit = true } ,
2014-03-12 21:11:00 +01:00
func = safe_region ( function ( name , param )
if param == " ? " then param = worldedit.player_axis ( name ) end
2014-07-18 21:51:09 +02:00
local count = worldedit.flip ( worldedit.pos1 [ name ] , worldedit.pos2 [ name ] , param )
2013-05-15 23:52:12 +02:00
worldedit.player_notify ( name , count .. " nodes flipped " )
2014-03-12 21:11:00 +01:00
end ,
function ( name , param )
if param ~= " x " and param ~= " y " and param ~= " z " and param ~= " ? " then
worldedit.player_notify ( name , " invalid usage: " .. param )
return nil
end
return check_region ( name , param )
2014-03-10 22:57:49 +01:00
end ) ,
2012-10-14 03:45:50 +02:00
} )
2014-10-25 07:53:20 +02:00
minetest.register_chatcommand ( " /rotate " , {
2012-10-14 03:45:50 +02:00
params = " <axis> <angle> " ,
description = " Rotate the current WorldEdit region around the axis <axis> by angle <angle> (90 degree increment) " ,
privs = { worldedit = true } ,
2014-03-12 21:11:00 +01:00
func = safe_region ( function ( name , param )
local pos1 , pos2 = worldedit.pos1 [ name ] , worldedit.pos2 [ name ]
2012-10-14 03:45:50 +02:00
local found , _ , axis , angle = param : find ( " ^([xyz%?])%s+([+-]?%d+)$ " )
2014-03-12 21:11:00 +01:00
if axis == " ? " then axis = worldedit.player_axis ( name ) end
2013-06-02 23:50:14 +02:00
local count , pos1 , pos2 = worldedit.rotate ( pos1 , pos2 , axis , angle )
2012-12-12 23:17:56 +01:00
--reset markers to rotated positions
worldedit.pos1 [ name ] = pos1
worldedit.pos2 [ name ] = pos2
worldedit.mark_pos1 ( name )
worldedit.mark_pos2 ( name )
2013-05-15 23:52:12 +02:00
worldedit.player_notify ( name , count .. " nodes rotated " )
2014-03-12 21:11:00 +01:00
end ,
function ( name , param )
local found , _ , axis , angle = param : find ( " ^([xyz%?])%s+([+-]?%d+)$ " )
if found == nil then
worldedit.player_notify ( name , " invalid usage: " .. param )
return nil
end
if angle % 90 ~= 0 then
worldedit.player_notify ( name , " invalid usage: angle must be multiple of 90 " )
return nil
end
return check_region ( name , param )
2014-03-10 22:57:49 +01:00
end ) ,
2012-10-14 03:45:50 +02:00
} )
2014-10-25 07:53:20 +02:00
minetest.register_chatcommand ( " /orient " , {
2013-01-12 22:46:40 +01:00
params = " <angle> " ,
description = " Rotate oriented nodes in the current WorldEdit region around the Y axis by angle <angle> (90 degree increment) " ,
privs = { worldedit = true } ,
2014-03-12 21:11:00 +01:00
func = safe_region ( function ( name , param )
local found , _ , angle = param : find ( " ^([+-]?%d+)$ " )
2014-07-18 21:51:09 +02:00
local count = worldedit.orient ( worldedit.pos1 [ name ] , worldedit.pos2 [ name ] , angle )
2014-03-12 21:11:00 +01:00
worldedit.player_notify ( name , count .. " nodes oriented " )
end ,
function ( name , param )
2013-01-12 22:46:40 +01:00
local found , _ , angle = param : find ( " ^([+-]?%d+)$ " )
if found == nil then
2013-05-15 23:52:12 +02:00
worldedit.player_notify ( name , " invalid usage: " .. param )
2014-03-12 21:11:00 +01:00
return nil
2013-01-12 22:46:40 +01:00
end
if angle % 90 ~= 0 then
2013-05-15 23:52:12 +02:00
worldedit.player_notify ( name , " invalid usage: angle must be multiple of 90 " )
2014-03-12 21:11:00 +01:00
return nil
2013-01-12 22:46:40 +01:00
end
2014-03-12 21:11:00 +01:00
return check_region ( name , param )
2014-03-10 22:57:49 +01:00
end ) ,
2013-01-12 22:46:40 +01:00
} )
2014-10-25 07:53:20 +02:00
minetest.register_chatcommand ( " /fixlight " , {
2012-10-14 03:45:50 +02:00
params = " " ,
2013-01-12 22:02:23 +01:00
description = " Fix the lighting in the current WorldEdit region " ,
2012-10-14 03:45:50 +02:00
privs = { worldedit = true } ,
2014-03-12 21:11:00 +01:00
func = safe_region ( function ( name , param )
2014-07-18 21:51:09 +02:00
local count = worldedit.fixlight ( worldedit.pos1 [ name ] , worldedit.pos2 [ name ] )
2013-05-15 23:52:12 +02:00
worldedit.player_notify ( name , count .. " nodes updated " )
2014-03-10 22:57:49 +01:00
end ) ,
2012-10-14 03:45:50 +02:00
} )
2016-03-23 22:09:55 +01:00
minetest.register_chatcommand ( " /drain " , {
params = " " ,
description = " Remove any fluid node within the current WorldEdit region " ,
privs = { worldedit = true } ,
func = safe_region ( function ( name , param )
-- TODO: make an API function for this
local count = 0
local pos1 , pos2 = worldedit.sort_pos ( worldedit.pos1 [ name ] , worldedit.pos2 [ name ] )
for x = pos1.x , pos2.x do
for y = pos1.y , pos2.y do
for z = pos1.z , pos2.z do
local n = minetest.get_node ( { x = x , y = y , z = z } ) . name
local d = minetest.registered_nodes [ n ]
if d ~= nil and ( d [ " drawtype " ] == " liquid " or d [ " drawtype " ] == " flowingliquid " ) then
minetest.remove_node ( { x = x , y = y , z = z } )
count = count + 1
end
end
end
end
worldedit.player_notify ( name , count .. " nodes updated " )
end ) ,
} )
2014-10-25 07:53:20 +02:00
minetest.register_chatcommand ( " /hide " , {
2012-12-12 23:17:56 +01:00
params = " " ,
description = " Hide all nodes in the current WorldEdit region non-destructively " ,
privs = { worldedit = true } ,
2014-03-12 21:11:00 +01:00
func = safe_region ( function ( name , param )
2014-07-18 21:51:09 +02:00
local count = worldedit.hide ( worldedit.pos1 [ name ] , worldedit.pos2 [ name ] )
2013-05-15 23:52:12 +02:00
worldedit.player_notify ( name , count .. " nodes hidden " )
2014-03-10 22:57:49 +01:00
end ) ,
2012-12-12 23:17:56 +01:00
} )
2014-10-25 07:53:20 +02:00
minetest.register_chatcommand ( " /suppress " , {
2012-10-14 03:45:50 +02:00
params = " <node> " ,
2012-12-12 23:17:56 +01:00
description = " Suppress all <node> in the current WorldEdit region non-destructively " ,
2012-10-14 03:45:50 +02:00
privs = { worldedit = true } ,
2014-03-12 21:11:00 +01:00
func = safe_region ( function ( name , param )
2014-03-10 22:57:49 +01:00
local node = get_node ( name , param )
2014-07-18 21:51:09 +02:00
local count = worldedit.suppress ( worldedit.pos1 [ name ] , worldedit.pos2 [ name ] , node )
2013-05-15 23:52:12 +02:00
worldedit.player_notify ( name , count .. " nodes suppressed " )
2014-12-30 00:16:36 +01:00
end , check_region ) ,
2012-10-14 03:45:50 +02:00
} )
2014-10-25 07:53:20 +02:00
minetest.register_chatcommand ( " /highlight " , {
2012-10-14 03:45:50 +02:00
params = " <node> " ,
2012-10-21 23:49:43 +02:00
description = " Highlight <node> in the current WorldEdit region by hiding everything else non-destructively " ,
2012-10-14 03:45:50 +02:00
privs = { worldedit = true } ,
2014-03-12 21:11:00 +01:00
func = safe_region ( function ( name , param )
2014-03-10 22:57:49 +01:00
local node = get_node ( name , param )
2014-07-18 21:51:09 +02:00
local count = worldedit.highlight ( worldedit.pos1 [ name ] , worldedit.pos2 [ name ] , node )
2013-05-15 23:52:12 +02:00
worldedit.player_notify ( name , count .. " nodes highlighted " )
2014-12-30 00:16:36 +01:00
end , check_region ) ,
2012-10-14 03:45:50 +02:00
} )
2014-10-25 07:53:20 +02:00
minetest.register_chatcommand ( " /restore " , {
2012-10-14 03:45:50 +02:00
params = " " ,
description = " Restores nodes hidden with WorldEdit in the current WorldEdit region " ,
privs = { worldedit = true } ,
2014-03-12 21:11:00 +01:00
func = safe_region ( function ( name , param )
2014-07-18 21:51:09 +02:00
local count = worldedit.restore ( worldedit.pos1 [ name ] , worldedit.pos2 [ name ] )
2013-05-15 23:52:12 +02:00
worldedit.player_notify ( name , count .. " nodes restored " )
2014-03-10 22:57:49 +01:00
end ) ,
2012-10-14 03:45:50 +02:00
} )
2014-10-25 07:53:20 +02:00
minetest.register_chatcommand ( " /save " , {
2012-10-14 03:45:50 +02:00
params = " <file> " ,
description = " Save the current WorldEdit region to \" (world folder)/schems/<file>.we \" " ,
privs = { worldedit = true } ,
2014-03-12 21:11:00 +01:00
func = safe_region ( function ( name , param )
2012-10-14 03:45:50 +02:00
if param == " " then
2013-05-15 23:52:12 +02:00
worldedit.player_notify ( name , " invalid usage: " .. param )
2012-10-14 03:45:50 +02:00
return
end
2015-06-01 23:08:43 +02:00
if not check_filename ( param ) then
2015-05-17 01:46:33 +02:00
worldedit.player_notify ( name , " Disallowed file name: " .. param )
2013-12-21 00:41:13 +01:00
return
end
2015-05-17 01:46:33 +02:00
local result , count = worldedit.serialize ( worldedit.pos1 [ name ] ,
worldedit.pos2 [ name ] )
2012-10-14 03:45:50 +02:00
local path = minetest.get_worldpath ( ) .. " /schems "
2015-05-17 01:46:33 +02:00
-- Create directory if it does not already exist
2015-06-01 22:53:03 +02:00
mkdir ( path )
2015-05-17 01:46:33 +02:00
2012-10-14 03:45:50 +02:00
local filename = path .. " / " .. param .. " .we "
local file , err = io.open ( filename , " wb " )
if err ~= nil then
2015-05-17 01:46:33 +02:00
worldedit.player_notify ( name , " Could not save file to \" " .. filename .. " \" " )
2012-10-14 03:45:50 +02:00
return
end
file : write ( result )
file : flush ( )
file : close ( )
2013-05-15 23:52:12 +02:00
worldedit.player_notify ( name , count .. " nodes saved " )
2014-03-10 22:57:49 +01:00
end ) ,
2012-10-14 03:45:50 +02:00
} )
2014-10-25 07:53:20 +02:00
minetest.register_chatcommand ( " /allocate " , {
2012-10-21 23:49:43 +02:00
params = " <file> " ,
description = " Set the region defined by nodes from \" (world folder)/schems/<file>.we \" as the current WorldEdit region " ,
privs = { worldedit = true } ,
func = function ( name , param )
2014-03-10 22:57:49 +01:00
local pos = get_position ( name )
if pos == nil then return end
2012-10-21 23:49:43 +02:00
if param == " " then
2013-05-15 23:52:12 +02:00
worldedit.player_notify ( name , " invalid usage: " .. param )
2012-10-21 23:49:43 +02:00
return
end
2015-06-01 23:08:43 +02:00
if not check_filename ( param ) then
worldedit.player_notify ( name , " Disallowed file name: " .. param )
2013-12-21 00:41:13 +01:00
return
end
2012-10-21 23:49:43 +02:00
local filename = minetest.get_worldpath ( ) .. " /schems/ " .. param .. " .we "
local file , err = io.open ( filename , " rb " )
if err ~= nil then
2013-05-15 23:52:12 +02:00
worldedit.player_notify ( name , " could not open file \" " .. filename .. " \" " )
2012-10-21 23:49:43 +02:00
return
end
local value = file : read ( " *a " )
file : close ( )
2014-10-24 21:01:46 +02:00
local version = worldedit.read_header ( value )
if version == 0 then
worldedit.player_notify ( name , " File is invalid! " )
2013-03-20 22:12:48 +01:00
return
2014-10-24 21:01:46 +02:00
elseif version > worldedit.LATEST_SERIALIZATION_VERSION then
worldedit.player_notify ( name , " File was created with newer version of WorldEdit! " )
2012-10-23 05:17:37 +02:00
end
2014-03-10 22:57:49 +01:00
local nodepos1 , nodepos2 , count = worldedit.allocate ( pos , value )
2012-10-21 23:49:43 +02:00
worldedit.pos1 [ name ] = nodepos1
worldedit.mark_pos1 ( name )
worldedit.pos2 [ name ] = nodepos2
worldedit.mark_pos2 ( name )
2013-05-15 23:52:12 +02:00
worldedit.player_notify ( name , count .. " nodes allocated " )
2012-10-21 23:49:43 +02:00
end ,
} )
2014-10-25 07:53:20 +02:00
minetest.register_chatcommand ( " /load " , {
2012-10-14 03:45:50 +02:00
params = " <file> " ,
2013-03-20 22:12:48 +01:00
description = " Load nodes from \" (world folder)/schems/<file>[.we[m]] \" with position 1 of the current WorldEdit region as the origin " ,
2012-10-14 03:45:50 +02:00
privs = { worldedit = true } ,
func = function ( name , param )
2014-03-10 22:57:49 +01:00
local pos = get_position ( name )
if pos == nil then return end
2012-10-14 03:45:50 +02:00
if param == " " then
2013-05-15 23:52:12 +02:00
worldedit.player_notify ( name , " invalid usage: " .. param )
2012-10-14 03:45:50 +02:00
return
end
2013-12-21 00:41:13 +01:00
if not string.find ( param , " ^[%w \t .,+-_=!@#$%%^&*()%[%]{};' \" ]+$ " ) then
worldedit.player_notify ( name , " invalid file name: " .. param )
return
end
2012-10-14 03:45:50 +02:00
2013-03-20 22:12:48 +01:00
--find the file in the world path
local testpaths = {
minetest.get_worldpath ( ) .. " /schems/ " .. param ,
minetest.get_worldpath ( ) .. " /schems/ " .. param .. " .we " ,
minetest.get_worldpath ( ) .. " /schems/ " .. param .. " .wem " ,
}
local file , err
for index , path in ipairs ( testpaths ) do
file , err = io.open ( path , " rb " )
if not err then
break
end
end
if err then
2013-05-15 23:52:12 +02:00
worldedit.player_notify ( name , " could not open file \" " .. param .. " \" " )
2012-10-14 03:45:50 +02:00
return
end
local value = file : read ( " *a " )
file : close ( )
2014-10-24 21:01:46 +02:00
local version = worldedit.read_header ( value )
if version == 0 then
worldedit.player_notify ( name , " File is invalid! " )
return
elseif version > worldedit.LATEST_SERIALIZATION_VERSION then
worldedit.player_notify ( name , " File was created with newer version of WorldEdit! " )
2012-10-14 03:45:50 +02:00
return
end
2013-04-28 19:08:09 +02:00
2014-03-10 22:57:49 +01:00
local count = worldedit.deserialize ( pos , value )
2012-10-14 03:45:50 +02:00
2013-05-15 23:52:12 +02:00
worldedit.player_notify ( name , count .. " nodes loaded " )
2012-10-14 03:45:50 +02:00
end ,
} )
2013-01-13 00:20:41 +01:00
2014-10-25 07:53:20 +02:00
minetest.register_chatcommand ( " /lua " , {
2013-01-13 00:20:41 +01:00
params = " <code> " ,
description = " Executes <code> as a Lua chunk in the global namespace " ,
2013-01-14 22:14:54 +01:00
privs = { worldedit = true , server = true } ,
2013-01-13 00:20:41 +01:00
func = function ( name , param )
local err = worldedit.lua ( param )
if err then
2013-05-15 23:52:12 +02:00
worldedit.player_notify ( name , " code error: " .. err )
2017-05-21 17:31:59 +02:00
minetest.log ( " action " , name .. " tried to execute " .. param )
2013-01-13 00:20:41 +01:00
else
2013-05-15 23:52:12 +02:00
worldedit.player_notify ( name , " code successfully executed " , false )
2017-05-21 17:31:59 +02:00
minetest.log ( " action " , name .. " executed " .. param )
2013-01-13 00:20:41 +01:00
end
end ,
} )
2014-10-25 07:53:20 +02:00
minetest.register_chatcommand ( " /luatransform " , {
2013-01-13 00:20:41 +01:00
params = " <code> " ,
description = " Executes <code> as a Lua chunk in the global namespace with the variable pos available, for each node in the current WorldEdit region " ,
2013-01-14 22:14:54 +01:00
privs = { worldedit = true , server = true } ,
2014-03-12 21:11:00 +01:00
func = safe_region ( function ( name , param )
2014-07-18 21:51:09 +02:00
local err = worldedit.luatransform ( worldedit.pos1 [ name ] , worldedit.pos2 [ name ] , param )
2013-01-13 00:20:41 +01:00
if err then
2013-05-15 23:52:12 +02:00
worldedit.player_notify ( name , " code error: " .. err , false )
2017-05-21 17:31:59 +02:00
minetest.log ( " action " , name .. " tried to execute luatransform " .. param )
2013-01-13 00:20:41 +01:00
else
2013-05-15 23:52:12 +02:00
worldedit.player_notify ( name , " code successfully executed " , false )
2017-05-21 17:31:59 +02:00
minetest.log ( " action " , name .. " executed luatransform " .. param )
2013-01-13 00:20:41 +01:00
end
2014-03-10 22:57:49 +01:00
end ) ,
2013-04-28 19:08:09 +02:00
} )
2013-06-22 08:24:54 +02:00
2014-10-25 07:53:20 +02:00
minetest.register_chatcommand ( " /mtschemcreate " , {
2013-07-29 18:43:24 +02:00
params = " <file> " ,
2015-05-17 01:46:33 +02:00
description = " Save the current WorldEdit region using the Minetest " ..
" Schematic format to \" (world folder)/schems/<filename>.mts \" " ,
2013-06-22 08:24:54 +02:00
privs = { worldedit = true } ,
2014-03-12 21:11:00 +01:00
func = safe_region ( function ( name , param )
2013-06-22 08:24:54 +02:00
if param == nil then
worldedit.player_notify ( name , " No filename specified " )
return
end
2015-06-01 23:08:43 +02:00
if not check_filename ( param ) then
2015-05-17 01:46:33 +02:00
worldedit.player_notify ( name , " Disallowed file name: " .. param )
return
end
2013-06-22 08:24:54 +02:00
local path = minetest.get_worldpath ( ) .. " /schems "
2015-05-17 01:46:33 +02:00
-- Create directory if it does not already exist
2015-06-01 22:53:03 +02:00
mkdir ( path )
2013-06-22 08:24:54 +02:00
2015-05-17 01:46:33 +02:00
local filename = path .. " / " .. param .. " .mts "
local ret = minetest.create_schematic ( worldedit.pos1 [ name ] ,
worldedit.pos2 [ name ] , worldedit.prob_list [ name ] ,
filename )
2013-06-22 08:24:54 +02:00
if ret == nil then
2015-05-17 01:46:33 +02:00
worldedit.player_notify ( name , " Failed to create Minetest schematic " , false )
2013-06-22 08:24:54 +02:00
else
2015-05-17 01:46:33 +02:00
worldedit.player_notify ( name , " Saved Minetest schematic to " .. param , false )
2013-06-22 08:24:54 +02:00
end
worldedit.prob_list [ name ] = { }
2014-03-10 22:57:49 +01:00
end ) ,
2013-06-22 08:24:54 +02:00
} )
2014-10-25 07:53:20 +02:00
minetest.register_chatcommand ( " /mtschemplace " , {
2013-07-29 18:43:24 +02:00
params = " <file> " ,
description = " Load nodes from \" (world folder)/schems/<file>.mts \" with position 1 of the current WorldEdit region as the origin " ,
2013-06-22 08:24:54 +02:00
privs = { worldedit = true } ,
func = function ( name , param )
2015-06-01 23:08:43 +02:00
if param == " " then
2014-03-10 22:57:49 +01:00
worldedit.player_notify ( name , " no filename specified " )
2013-06-22 08:24:54 +02:00
return
end
2015-06-01 23:08:43 +02:00
if not check_filename ( param ) then
worldedit.player_notify ( name , " Disallowed file name: " .. param )
return
end
2013-06-22 08:24:54 +02:00
2014-03-10 22:57:49 +01:00
local pos = get_position ( name )
if pos == nil then return end
2013-06-22 08:24:54 +02:00
local path = minetest.get_worldpath ( ) .. " /schems/ " .. param .. " .mts "
if minetest.place_schematic ( pos , path ) == nil then
2014-03-10 22:57:49 +01:00
worldedit.player_notify ( name , " failed to place Minetest schematic " , false )
2013-06-22 08:24:54 +02:00
else
2014-03-10 22:57:49 +01:00
worldedit.player_notify ( name , " placed Minetest schematic " .. param ..
2013-06-22 08:24:54 +02:00
" at " .. minetest.pos_to_string ( pos ) , false )
end
end ,
} )
2014-10-25 07:53:20 +02:00
minetest.register_chatcommand ( " /mtschemprob " , {
2013-06-22 08:24:54 +02:00
params = " start/finish/get " ,
description = " Begins node probability entry for Minetest schematics, gets the nodes that have probabilities set, or ends node probability entry " ,
privs = { worldedit = true } ,
func = function ( name , param )
if param == " start " then --start probability setting
worldedit.set_pos [ name ] = " prob "
worldedit.prob_list [ name ] = { }
worldedit.player_notify ( name , " select Minetest schematic probability values by punching nodes " )
elseif param == " finish " then --finish probability setting
worldedit.set_pos [ name ] = nil
worldedit.player_notify ( name , " finished Minetest schematic probability selection " )
elseif param == " get " then --get all nodes that had probabilities set on them
local text = " "
local problist = worldedit.prob_list [ name ]
if problist == nil then
return
end
for k , v in pairs ( problist ) do
2016-08-05 16:41:37 +02:00
local prob = math.floor ( ( ( v.prob / 256 ) * 100 ) * 100 + 0.5 ) / 100
text = text .. minetest.pos_to_string ( v.pos ) .. " : " .. prob .. " % | "
2013-06-22 08:24:54 +02:00
end
2014-03-10 22:57:49 +01:00
worldedit.player_notify ( name , " currently set node probabilities: " )
2013-06-22 08:24:54 +02:00
worldedit.player_notify ( name , text )
else
worldedit.player_notify ( name , " unknown subcommand: " .. param )
end
end ,
} )
2016-08-05 16:41:37 +02:00
minetest.register_on_player_receive_fields ( function ( player , formname , fields )
if formname == " prob_val_enter " and not ( fields.text == " " or fields.text == nil ) then
local name = player : get_player_name ( )
local prob_entry = { pos = worldedit.prob_pos [ name ] , prob = tonumber ( fields.text ) }
local index = table.getn ( worldedit.prob_list [ name ] ) + 1
worldedit.prob_list [ name ] [ index ] = prob_entry
2013-06-22 08:24:54 +02:00
end
2016-08-05 16:41:37 +02:00
end )
2013-07-29 18:43:24 +02:00
2014-10-25 07:53:20 +02:00
minetest.register_chatcommand ( " /clearobjects " , {
2013-07-29 18:43:24 +02:00
params = " " ,
description = " Clears all objects within the WorldEdit region " ,
privs = { worldedit = true } ,
2014-03-12 21:11:00 +01:00
func = safe_region ( function ( name , param )
2014-10-30 03:47:08 +01:00
local count = worldedit.clear_objects ( worldedit.pos1 [ name ] , worldedit.pos2 [ name ] )
2013-07-29 18:43:24 +02:00
worldedit.player_notify ( name , count .. " objects cleared " )
2014-03-10 22:57:49 +01:00
end ) ,
2016-08-05 16:41:37 +02:00
} )