X-Git-Url: https://git.lizzy.rs/?a=blobdiff_plain;f=worldedit_commands%2Finit.lua;h=a102dbcbf43b7bcb96e699d5204cbabd36d3c6ac;hb=283f47f10d1bb4f119a2021404ff49c2f32065f5;hp=424082fdaf33d58aefeed44702ee292c06ac7e08;hpb=bb8456b71119ca6303b9e9706829a84dc7f81ab3;p=worldedit.git diff --git a/worldedit_commands/init.lua b/worldedit_commands/init.lua index 424082f..a102dbc 100644 --- a/worldedit_commands/init.lua +++ b/worldedit_commands/init.lua @@ -10,10 +10,12 @@ if minetest.place_schematic then worldedit.prob_list = {} end +dofile(minetest.get_modpath("worldedit_commands") .. "/cuboid.lua") dofile(minetest.get_modpath("worldedit_commands") .. "/mark.lua") -dofile(minetest.get_modpath("worldedit_commands") .. "/safe.lua"); safe_region = safe_region or function(callback) return callback end +dofile(minetest.get_modpath("worldedit_commands") .. "/wand.lua") +local safe_region, check_region, reset_pending = dofile(minetest.get_modpath("worldedit_commands") .. "/safe.lua") -local get_position = function(name) --position 1 retrieval function for when not using `safe_region` +local function get_position(name) --position 1 retrieval function for when not using `safe_region` local pos1 = worldedit.pos1[name] if pos1 == nil then worldedit.player_notify(name, "no position 1 selected") @@ -21,7 +23,8 @@ local get_position = function(name) --position 1 retrieval function for when not return pos1 end -local get_node = function(name, nodename) +-- normalize_nodename wrapper for convenience purposes +local function get_node(name, nodename) local node = worldedit.normalize_nodename(nodename) if not node then worldedit.player_notify(name, "invalid node name: " .. nodename) @@ -30,34 +33,54 @@ local get_node = function(name, nodename) return node end -worldedit.player_notify = function(name, message) +function worldedit.player_notify(name, message) minetest.chat_send_player(name, "WorldEdit -!- " .. message, false) end ---determines whether `nodename` is a valid node name, returning a boolean +local function string_endswith(full, part) + return full:find(part, 1, true) == #full - #part + 1 +end + +-- normalizes node "description" `nodename`, returning a string (or nil) worldedit.normalize_nodename = function(nodename) - nodename = nodename:gsub("^%s*(.-)%s*$", "%1") + nodename = nodename:gsub("^%s*(.-)%s*$", "%1") -- strip spaces if nodename == "" then return nil end - local fullname = ItemStack({name=nodename}):get_name() --resolve aliases of node names to full names - if minetest.registered_nodes[fullname] or fullname == "air" then --directly found node name or alias of nodename + + local fullname = ItemStack({name=nodename}):get_name() -- resolve aliases + if minetest.registered_nodes[fullname] or fullname == "air" then -- full name return fullname end for key, value in pairs(minetest.registered_nodes) do - if key:find(":" .. nodename, 1, true) then --found in mod + if string_endswith(key, ":" .. nodename) then -- matches name (w/o mod part) return key end end - nodename = nodename:lower() --lowercase both for case insensitive comparison + nodename = nodename:lower() -- lowercase both for case insensitive comparison for key, value in pairs(minetest.registered_nodes) do - if value.description:lower() == nodename then --found in description + local desc = value.description:lower() + if desc == nodename then -- matches description + return key + end + if string_endswith(desc, " block") and desc == nodename.." block" then + -- fuzzy description match (e.g. "Steel" == "Steel Block") return key end end - return nil + + local match = nil + for key, value in pairs(minetest.registered_nodes) do + if value.description:lower():find(nodename, 1, true) ~= nil then + if match ~= nil then + return nil + end + match = key -- substring description match (only if no ambiguities) + end + end + return match end ---determines the axis in which a player is facing, returning an axis ("x", "y", or "z") and the sign (1 or -1) -worldedit.player_axis = function(name) +-- 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) local dir = minetest.get_player_by_name(name):get_look_dir() local x, y, z = math.abs(dir.x), math.abs(dir.y), math.abs(dir.z) if x > y then @@ -70,6 +93,19 @@ worldedit.player_axis = function(name) return "z", dir.z > 0 and 1 or -1 end +local function mkdir(path) + if minetest.mkdir then + minetest.mkdir(path) + else + os.execute('mkdir "' .. path .. '"') + end +end + +local function check_filename(name) + return name:find("^[%w%s%^&'@{}%[%],%$=!%-#%(%)%%%.%+~_]+$") ~= nil +end + + minetest.register_chatcommand("/about", { params = "", description = "Get information about the mod", @@ -78,6 +114,56 @@ minetest.register_chatcommand("/about", { end, }) +-- mostly copied from builtin/chatcommands.lua with minor modifications +minetest.register_chatcommand("/help", { + privs = {}, + params = "[all/]", + 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 ' 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, +}) + minetest.register_chatcommand("/inspect", { params = "on/off/1/0/true/false/yes/no/enable/disable/", description = "Enable or disable node inspection", @@ -97,16 +183,28 @@ minetest.register_chatcommand("/inspect", { end, }) +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 + minetest.register_on_punchnode(function(pos, node, puncher) local name = puncher:get_player_name() if worldedit.inspect[name] then - if minetest.check_player_privs(name, {worldedit=true}) then - local axis, sign = worldedit.player_axis(name) - message = string.format("inspector: %s at %s (param1=%d, param2=%d) punched by %s facing the %s axis", - node.name, minetest.pos_to_string(pos), node.param1, node.param2, name, axis .. (sign > 0 and "+" or "-")) - else - message = "inspector: worldedit privileges required" - end + local axis, sign = worldedit.player_axis(name) + 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 "-")) worldedit.player_notify(name, message) end end) @@ -121,6 +219,8 @@ minetest.register_chatcommand("/reset", { worldedit.mark_pos1(name) worldedit.mark_pos2(name) worldedit.set_pos[name] = nil + --make sure the user does not try to confirm an operation after resetting pos: + reset_pending(name) worldedit.player_notify(name, "region reset") end, }) @@ -277,22 +377,53 @@ minetest.register_chatcommand("/volume", { end, }) +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), +}) + minetest.register_chatcommand("/set", { params = "", description = "Set the current WorldEdit region to ", 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 + if not node then return end local count = worldedit.set(worldedit.pos1[name], worldedit.pos2[name], node) worldedit.player_notify(name, count .. " nodes set") end, check_region), }) +minetest.register_chatcommand("/param2", { + params = "", + description = "Set param2 of all nodes in the current WorldEdit region to ", + 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 altered") + end, check_region), +}) + minetest.register_chatcommand("/mix", { params = " ...", description = "Fill the current WorldEdit region with a random mix of , ...", @@ -301,10 +432,7 @@ minetest.register_chatcommand("/mix", { local nodes = {} for nodename in param:gmatch("[^%s]+") do local node = get_node(name, nodename) - if not node then - worldedit.player_notify(name, "Could not identify node \"" .. name .. "\"") - return - end + if not node then return end nodes[#nodes + 1] = node end @@ -361,6 +489,45 @@ minetest.register_chatcommand("/replaceinverse", { end, check_replace), }) +local check_cube = function(name, param) + if worldedit.pos1[name] == nil then + worldedit.player_notify(name, "no position 1 selected") + return nil + end + local found, _, w, h, l, 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 + return tonumber(w) * tonumber(h) * tonumber(l) +end + +minetest.register_chatcommand("/hollowcube", { + params = " ", + description = "Add a hollow cube with its ground level centered at WorldEdit position 1 with dimensions x x , composed of .", + privs = {worldedit=true}, + func = safe_region(function(name, param) + local found, _, w, h, l, nodename = param:find("^(%d+)%s+(%d+)%s+(%d+)%s+(.+)$") + local node = get_node(name, nodename) + local count = worldedit.cube(worldedit.pos1[name], tonumber(w), tonumber(h), tonumber(l), node, true) + worldedit.player_notify(name, count .. " nodes added") + end, check_cube), +}) + +minetest.register_chatcommand("/cube", { + params = " ", + description = "Add a cube with its ground level centered at WorldEdit position 1 with dimensions x x , composed of .", + privs = {worldedit=true}, + func = safe_region(function(name, param) + local found, _, w, h, l, nodename = param:find("^(%d+)%s+(%d+)%s+(%d+)%s+(.+)$") + local node = get_node(name, nodename) + local count = worldedit.cube(worldedit.pos1[name], tonumber(w), tonumber(h), tonumber(l), node) + worldedit.player_notify(name, count .. " nodes added") + end, check_cube), +}) + local check_sphere = function(name, param) if worldedit.pos1[name] == nil then worldedit.player_notify(name, "no position 1 selected") @@ -444,53 +611,88 @@ local check_cylinder = function(name, param) 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+(.+)$") + -- two radii + local found, _, axis, length, radius1, radius2, nodename = param:find("^([xyz%?])%s+([+-]?%d+)%s+(%d+)%s+(%d+)%s+(.+)$") + if found == nil then + -- single radius + found, _, axis, length, radius1, nodename = param:find("^([xyz%?])%s+([+-]?%d+)%s+(%d+)%s+(.+)$") + radius2 = radius1 + end 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)) + local radius = math.max(tonumber(radius1), tonumber(radius2)) + return math.ceil(math.pi * (radius ^ 2) * tonumber(length)) end minetest.register_chatcommand("/hollowcylinder", { - params = "x/y/z/? ", - description = "Add hollow cylinder at WorldEdit position 1 along the x/y/z/? axis with length and radius , composed of ", + params = "x/y/z/? [radius2] ", + description = "Add hollow cylinder at WorldEdit position 1 along the x/y/z/? axis with length , base radius (and top radius [radius2]), composed of ", privs = {worldedit=true}, func = safe_region(function(name, param) - local found, _, axis, length, radius, nodename = param:find("^([xyz%?])%s+([+-]?%d+)%s+(%d+)%s+(.+)$") + -- two radii + local found, _, axis, length, radius1, radius2, nodename = param:find("^([xyz%?])%s+([+-]?%d+)%s+(%d+)%s+(%d+)%s+(.+)$") + if found == nil then + -- single radius + found, _, axis, length, radius1, nodename = param:find("^([xyz%?])%s+([+-]?%d+)%s+(%d+)%s+(.+)$") + radius2 = radius1 + end length = tonumber(length) if axis == "?" then axis, sign = worldedit.player_axis(name) length = length * sign end local node = get_node(name, nodename) - local count = worldedit.cylinder(worldedit.pos1[name], axis, length, tonumber(radius), node, true) + local count = worldedit.cylinder(worldedit.pos1[name], axis, length, tonumber(radius1), tonumber(radius2), node, true) worldedit.player_notify(name, count .. " nodes added") end, check_cylinder), }) minetest.register_chatcommand("/cylinder", { - params = "x/y/z/? ", - description = "Add cylinder at WorldEdit position 1 along the x/y/z/? axis with length and radius , composed of ", + params = "x/y/z/? [radius2] ", + description = "Add cylinder at WorldEdit position 1 along the x/y/z/? axis with length , base radius (and top radius [radius2]), composed of ", privs = {worldedit=true}, func = safe_region(function(name, param) - local found, _, axis, length, radius, nodename = param:find("^([xyz%?])%s+([+-]?%d+)%s+(%d+)%s+(.+)$") + -- two radii + local found, _, axis, length, radius1, radius2, nodename = param:find("^([xyz%?])%s+([+-]?%d+)%s+(%d+)%s+(%d+)%s+(.+)$") + if found == nil then + -- single radius + found, _, axis, length, radius1, nodename = param:find("^([xyz%?])%s+([+-]?%d+)%s+(%d+)%s+(.+)$") + radius2 = radius1 + end length = tonumber(length) if axis == "?" then axis, sign = worldedit.player_axis(name) length = length * sign end local node = get_node(name, nodename) - local count = worldedit.cylinder(worldedit.pos1[name], axis, length, tonumber(radius), node) + local count = worldedit.cylinder(worldedit.pos1[name], axis, length, tonumber(radius1), tonumber(radius2), node) worldedit.player_notify(name, count .. " nodes added") end, check_cylinder), }) -minetest.register_chatcommand("/pyramid", { +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", { params = "x/y/z/? ", - description = "Add pyramid centered at WorldEdit position 1 along the x/y/z/? axis with height , composed of ", + description = "Add hollow pyramid centered at WorldEdit position 1 along the x/y/z/? axis with height , composed of ", privs = {worldedit=true}, func = safe_region(function(name, param) local found, _, axis, height, nodename = param:find("^([xyz%?])%s+([+-]?%d+)%s+(.+)$") @@ -500,24 +702,26 @@ minetest.register_chatcommand("/pyramid", { height = height * sign end local node = get_node(name, nodename) - local count = worldedit.pyramid(worldedit.pos1[name], axis, height, node) + local count = worldedit.pyramid(worldedit.pos1[name], axis, height, node, true) worldedit.player_notify(name, count .. " nodes added") - end, - function(name, param) - if worldedit.pos1[name] == nil then - worldedit.player_notify(name, "no position 1 selected") - return nil - end + end, check_pyramid), +}) + +minetest.register_chatcommand("/pyramid", { + params = "x/y/z/? ", + description = "Add pyramid centered at WorldEdit position 1 along the x/y/z/? axis with height , composed of ", + privs = {worldedit=true}, + func = safe_region(function(name, param) local found, _, axis, height, nodename = param:find("^([xyz%?])%s+([+-]?%d+)%s+(.+)$") - if found == nil then - worldedit.player_notify(name, "invalid usage: " .. param) - return nil + height = tonumber(height) + if axis == "?" then + axis, sign = worldedit.player_axis(name) + height = height * sign 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), + local count = worldedit.pyramid(worldedit.pos1[name], axis, height, node) + worldedit.player_notify(name, count .. " nodes added") + end, check_pyramid), }) minetest.register_chatcommand("/spiral", { @@ -542,7 +746,7 @@ minetest.register_chatcommand("/spiral", { end local node = get_node(name, nodename) if not node then return nil end - return check_region(name, param) + return 1 -- TODO: return an useful value end), }) @@ -810,6 +1014,30 @@ minetest.register_chatcommand("/fixlight", { end), }) +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), +}) + minetest.register_chatcommand("/hide", { params = "", description = "Hide all nodes in the current WorldEdit region non-destructively", @@ -861,20 +1089,21 @@ minetest.register_chatcommand("/save", { worldedit.player_notify(name, "invalid usage: " .. param) return end - if not string.find(param, "^[%w \t.,+-_=!@#$%%^&*()%[%]{};'\"]+$") then - worldedit.player_notify(name, "invalid file name: " .. param) + if not check_filename(param) then + worldedit.player_notify(name, "Disallowed file name: " .. param) return end - - local result, count = worldedit.serialize(worldedit.pos1[name], worldedit.pos2[name]) + local result, count = worldedit.serialize(worldedit.pos1[name], + worldedit.pos2[name]) local path = minetest.get_worldpath() .. "/schems" + -- Create directory if it does not already exist + mkdir(path) + local filename = path .. "/" .. param .. ".we" - filename = filename:gsub("\"", "\\\""):gsub("\\", "\\\\") --escape any nasty characters - os.execute("mkdir \"" .. path .. "\"") --create directory if it does not already exist local file, err = io.open(filename, "wb") if err ~= nil then - worldedit.player_notify(name, "could not save file to \"" .. filename .. "\"") + worldedit.player_notify(name, "Could not save file to \"" .. filename .. "\"") return end file:write(result) @@ -897,8 +1126,8 @@ minetest.register_chatcommand("/allocate", { worldedit.player_notify(name, "invalid usage: " .. param) return end - if not string.find(param, "^[%w \t.,+-_=!@#$%%^&*()%[%]{};'\"]+$") then - worldedit.player_notify(name, "invalid file name: " .. param) + if not check_filename(param) then + worldedit.player_notify(name, "Disallowed file name: " .. param) return end @@ -986,16 +1215,13 @@ minetest.register_chatcommand("/lua", { description = "Executes as a Lua chunk in the global namespace", privs = {worldedit=true, server=true}, func = function(name, param) - local admin = minetest.setting_get("name") - if not admin or not name == admin then - worldedit.player_notify(name, "this command can only be run by the server administrator") - return - end local err = worldedit.lua(param) if err then worldedit.player_notify(name, "code error: " .. err) + minetest.log("action", name.." tried to execute "..param) else worldedit.player_notify(name, "code successfully executed", false) + minetest.log("action", name.." executed "..param) end end, }) @@ -1005,41 +1231,44 @@ minetest.register_chatcommand("/luatransform", { description = "Executes as a Lua chunk in the global namespace with the variable pos available, for each node in the current WorldEdit region", privs = {worldedit=true, server=true}, func = safe_region(function(name, param) - local admin = minetest.setting_get("name") - if not admin or not name == admin then - worldedit.player_notify(name, "this command can only be run by the server administrator") - return - end - local err = worldedit.luatransform(worldedit.pos1[name], worldedit.pos2[name], param) if err then worldedit.player_notify(name, "code error: " .. err, false) + minetest.log("action", name.." tried to execute luatransform "..param) else worldedit.player_notify(name, "code successfully executed", false) + minetest.log("action", name.." executed luatransform "..param) end end), }) minetest.register_chatcommand("/mtschemcreate", { params = "", - description = "Save the current WorldEdit region using the Minetest Schematic format to \"(world folder)/schems/.mts\"", + description = "Save the current WorldEdit region using the Minetest ".. + "Schematic format to \"(world folder)/schems/.mts\"", privs = {worldedit=true}, func = safe_region(function(name, param) if param == nil then worldedit.player_notify(name, "No filename specified") return end + if not check_filename(param) then + worldedit.player_notify(name, "Disallowed file name: " .. param) + return + end local path = minetest.get_worldpath() .. "/schems" - local filename = path .. "/" .. param .. ".mts" - filename = filename:gsub("\"", "\\\""):gsub("\\", "\\\\") --escape any nasty characters - os.execute("mkdir \"" .. path .. "\"") --create directory if it does not already exist + -- Create directory if it does not already exist + mkdir(path) - local ret = minetest.create_schematic(worldedit.pos1[name], worldedit.pos2[name], worldedit.prob_list[name], filename) + local filename = path .. "/" .. param .. ".mts" + local ret = minetest.create_schematic(worldedit.pos1[name], + worldedit.pos2[name], worldedit.prob_list[name], + filename) if ret == nil then - worldedit.player_notify(name, "failed to create Minetest schematic", false) + worldedit.player_notify(name, "Failed to create Minetest schematic", false) else - worldedit.player_notify(name, "saved Minetest schematic to " .. param, false) + worldedit.player_notify(name, "Saved Minetest schematic to " .. param, false) end worldedit.prob_list[name] = {} end), @@ -1050,10 +1279,14 @@ minetest.register_chatcommand("/mtschemplace", { description = "Load nodes from \"(world folder)/schems/.mts\" with position 1 of the current WorldEdit region as the origin", privs = {worldedit=true}, func = function(name, param) - if param == nil then + if param == "" then worldedit.player_notify(name, "no filename specified") return end + if not check_filename(param) then + worldedit.player_notify(name, "Disallowed file name: " .. param) + return + end local pos = get_position(name) if pos == nil then return end @@ -1087,8 +1320,8 @@ minetest.register_chatcommand("/mtschemprob", { return end for k,v in pairs(problist) do - local prob = math.floor(((v["prob"] / 256) * 100) * 100 + 0.5) / 100 - text = text .. minetest.pos_to_string(v["pos"]) .. ": " .. prob .. "% | " + local prob = math.floor(((v.prob / 256) * 100) * 100 + 0.5) / 100 + text = text .. minetest.pos_to_string(v.pos) .. ": " .. prob .. "% | " end worldedit.player_notify(name, "currently set node probabilities:") worldedit.player_notify(name, text) @@ -1098,16 +1331,14 @@ minetest.register_chatcommand("/mtschemprob", { end, }) -minetest.register_on_player_receive_fields( - function(player, formname, fields) - if (formname == "prob_val_enter") and (fields.text ~= "") 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 - end +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 end -) +end) minetest.register_chatcommand("/clearobjects", { params = "",