mirror of
https://github.com/sbrl/Minetest-WorldEditAdditions.git
synced 2024-11-27 17:43:53 +01:00
Merge pull request #34 from VorTechnix/master
Added //srect and //basename
This commit is contained in:
commit
2acc6b3470
@ -15,6 +15,7 @@ dofile(worldeditadditions.modpath.."/utils/node_identification.lua")
|
||||
dofile(worldeditadditions.modpath.."/utils/tables.lua")
|
||||
dofile(worldeditadditions.modpath.."/utils/terrain.lua")
|
||||
dofile(worldeditadditions.modpath.."/utils/raycast_adv.lua") -- For the farwand
|
||||
dofile(worldeditadditions.modpath.."/utils/selector_helps.lua")
|
||||
|
||||
dofile(worldeditadditions.modpath.."/lib/compat/saplingnames.lua")
|
||||
|
||||
|
@ -1,7 +1,7 @@
|
||||
-- From http://lua-users.org/wiki/SimpleRound
|
||||
function worldeditadditions.round(num, numDecimalPlaces)
|
||||
local mult = 10^(numDecimalPlaces or 0)
|
||||
return math.floor(num * mult + 0.5) / mult
|
||||
local mult = 10^(numDecimalPlaces or 0)
|
||||
return math.floor(num * mult + 0.5) / mult
|
||||
end
|
||||
|
||||
function worldeditadditions.hypotenuse(x1, y1, x2, y2)
|
||||
@ -11,17 +11,17 @@ function worldeditadditions.hypotenuse(x1, y1, x2, y2)
|
||||
end
|
||||
|
||||
function worldeditadditions.sum(list)
|
||||
if #list == 0 then return 0 end
|
||||
if #list == 0 then return 0 end
|
||||
local sum = 0
|
||||
for i,value in ipairs(list) do
|
||||
sum = sum + value
|
||||
end
|
||||
return sum
|
||||
return sum
|
||||
end
|
||||
|
||||
|
||||
function worldeditadditions.average(list)
|
||||
if #list == 0 then return 0 end
|
||||
if #list == 0 then return 0 end
|
||||
return worldeditadditions.sum(list) / #list
|
||||
end
|
||||
|
||||
@ -32,11 +32,33 @@ function worldeditadditions.get_ms_time()
|
||||
end
|
||||
|
||||
function worldeditadditions.eta(existing_times, done_count, total_count)
|
||||
local max = 100
|
||||
local average = worldeditadditions.average(
|
||||
worldeditadditions.table_get_last(existing_times, max)
|
||||
)
|
||||
local times_left = total_count - done_count
|
||||
if times_left == 0 then return 0 end
|
||||
return average * times_left
|
||||
local max = 100
|
||||
local average = worldeditadditions.average(
|
||||
worldeditadditions.table_get_last(existing_times, max)
|
||||
)
|
||||
local times_left = total_count - done_count
|
||||
if times_left == 0 then return 0 end
|
||||
return average * times_left
|
||||
end
|
||||
|
||||
--- Returns the sign (+ or -) at the beginning of a string if present.
|
||||
-- @param str string Input string.
|
||||
-- @param type string The type of value to return. Valid values: "string" (default), "int"
|
||||
-- @return string|int Returns the sign string or signed multiplier (1|-1).
|
||||
function worldeditadditions.getsign(str, type)
|
||||
if not type then type = "string" end
|
||||
if not (type == "string" or type == "int") then
|
||||
return false, "Error: Unknown type '"..type.."'."
|
||||
end
|
||||
if str:sub(1, 1) == "-" then
|
||||
if type == "int" then return true, -1
|
||||
else return true, "-" end
|
||||
else
|
||||
if type == "int" then return true, 1
|
||||
else return true, "+" end
|
||||
end
|
||||
end
|
||||
|
||||
-- For Testing:
|
||||
-- worldeditadditions = {}
|
||||
-- print(worldeditadditions.getsign('-y'))
|
||||
|
12
worldeditadditions/utils/selector_helps.lua
Normal file
12
worldeditadditions/utils/selector_helps.lua
Normal file
@ -0,0 +1,12 @@
|
||||
-- Returns the player's facing direction on the horizontal axes only.
|
||||
-- @param name string The name of the player to return facing direction of.
|
||||
-- @return table Returns axis name and sign multiplyer.
|
||||
function worldeditadditions.player_axis2d(name)
|
||||
-- minetest.get_player_by_name("singleplayer"):
|
||||
local dir = math.floor(minetest.get_player_by_name(name):get_look_horizontal() / math.pi * 2 + 0.5) % 4
|
||||
local crdnl = { {1,"z"},{-1,"x"},{-1,"z"},{1,"x"} }
|
||||
return crdnl[dir+1]
|
||||
end
|
||||
|
||||
-- Tests
|
||||
-- /lua print(unpack(worldeditadditions.player_axis2d(myname)))
|
20
worldeditadditions_commands/commands/extra/basename.lua
Normal file
20
worldeditadditions_commands/commands/extra/basename.lua
Normal file
@ -0,0 +1,20 @@
|
||||
-- ██████ █████ ███████ ███████ ███ ██ █████ ███ ███ ███████
|
||||
-- ██ ██ ██ ██ ██ ██ ████ ██ ██ ██ ████ ████ ██
|
||||
-- ██████ ███████ ███████ █████ ██ ██ ██ ███████ ██ ████ ██ █████
|
||||
-- ██ ██ ██ ██ ██ ██ ██ ██ ██ ██ ██ ██ ██ ██ ██
|
||||
-- ██████ ██ ██ ███████ ███████ ██ ████ ██ ██ ██ ██ ███████
|
||||
worldedit.register_command("basename", {
|
||||
params = "<nodealias>",
|
||||
description = "Returns the base name of nodes that use a given alias.",
|
||||
privs = {worldedit = true},
|
||||
parse = function(params_text)
|
||||
if params_text == "" or not params_text then
|
||||
return false, "Node not specified."
|
||||
end
|
||||
return true, params_text
|
||||
end,
|
||||
func = function(name, params_text)
|
||||
if name == nil then return end
|
||||
worldedit.player_notify(name, worldedit.normalize_nodename(params_text) or 'Error 404: "'..params_text..'" not found!')
|
||||
end
|
||||
})
|
@ -1,3 +1,8 @@
|
||||
-- ███████ █████ ██████ ██ ██ ███ ██ ██████ █████ ██ ██ █████ ███████ ███████ ███████
|
||||
-- ██ ██ ██ ██ ██ ██ ██ ████ ██ ██ ██ ██ ██ ██ ██ ██ ██ ██ ██
|
||||
-- ███████ ███████ ██████ ██ ██ ██ ██ ██ ██ ███ ███████ ██ ██ ███████ ███████ █████ ███████
|
||||
-- ██ ██ ██ ██ ██ ██ ██ ██ ██ ██ ██ ██ ██ ██ ██ ██ ██ ██ ██ ██
|
||||
-- ███████ ██ ██ ██ ███████ ██ ██ ████ ██████ ██ ██ ███████ ██ ██ ██ ███████ ███████ ███████
|
||||
minetest.register_chatcommand("/saplingaliases", {
|
||||
params = "[aliases|all_saplings]",
|
||||
description = "Lists all the currently registered sapling aliases (default). A single argument is taken as the mode of operation. Current modes: aliases (default; as described previously), all_saplings (lists all node names with the group \"sapling\")",
|
@ -1,8 +1,9 @@
|
||||
-- ██████ ██ ██ ███████ ██████ ██ █████ ██ ██
|
||||
-- ██ ██ ██ ██ ██ ██ ██ ██ ██ ██ ██ ██
|
||||
-- ██ ██ ██ ██ █████ ██████ ██ ███████ ████
|
||||
-- ██ ██ ██ ██ ██ ██ ██ ██ ██ ██ ██
|
||||
-- ██████ ████ ███████ ██ ██ ███████ ██ ██ ██
|
||||
-- ███████ ██████ ██████ ███████ ███████ ████████
|
||||
-- ██ ██ ██ ██ ██ ██ ██ ██
|
||||
-- █████ ██ ██ ██████ █████ ███████ ██
|
||||
-- ██ ██ ██ ██ ██ ██ ██ ██
|
||||
-- ██ ██████ ██ ██ ███████ ███████ ██
|
||||
|
||||
worldedit.register_command("forest", {
|
||||
params = "[<density>] <sapling_a> [<chance_a>] <sapling_b> [<chance_b>] [<sapling_N> [<chance_N>]] ...",
|
||||
description = "Plants and grows trees in the defined region according to the given list of sapling names and chances and density factor. The density controls the relative density of the resulting forest, and defaults to 1 (floating-point numbers allowed). Higher chance numbers result in a lower relative chance with respect to other saplings in the list. Saplings that fail to grow are subsequently removed (this will affect pre-existing saplings too).",
|
||||
|
64
worldeditadditions_commands/commands/selectors/srect.lua
Normal file
64
worldeditadditions_commands/commands/selectors/srect.lua
Normal file
@ -0,0 +1,64 @@
|
||||
-- ███████ ██████ ███████ ██████ ████████
|
||||
-- ██ ██ ██ ██ ██ ██
|
||||
-- ███████ ██████ █████ ██ ██
|
||||
-- ██ ██ ██ ██ ██ ██
|
||||
-- ███████ ██ ██ ███████ ██████ ██
|
||||
-- local -- TODO: set this to local once development is finished
|
||||
function parse_params_srect(params_text)
|
||||
local wea = worldeditadditions
|
||||
local find = wea.split(params_text, "%s", false)
|
||||
local ax1, ax2, len = find[1], find[2], find[table.maxn(find)]
|
||||
|
||||
-- If ax1 is bad set to player facing dir
|
||||
if ax1 == len or not ax1:match('[xyz]') then ax1 = "get"
|
||||
else
|
||||
local success, value = wea.getsign(ax1, "int")
|
||||
if not success then return success, value
|
||||
else ax1 = { value, ax1:gsub('[^xyz]',''):sub(1,1) }
|
||||
end
|
||||
end
|
||||
-- If ax2 is bad set to +y
|
||||
if not ax2 or ax2 == len or not ax2:match('[xyz]') then ax2 = "y" end
|
||||
local success, value = wea.getsign(ax2, "int")
|
||||
if not success then return success, value end
|
||||
ax2 = { value, ax2:gsub('[^xyz]',''):sub(1,1) }
|
||||
|
||||
len = tonumber(len)
|
||||
-- If len == nill cancel the operation
|
||||
if len == nil then
|
||||
return false, "No length specified."
|
||||
end
|
||||
|
||||
return true, ax1, ax2, len
|
||||
end
|
||||
worldedit.register_command("srect", {
|
||||
params = "[<axis1> [<axis2>]] <length>",
|
||||
description = "Set WorldEdit region position 2 at a set distance along 2 axes.",
|
||||
privs = {worldedit=true},
|
||||
require_pos = 1,
|
||||
parse = function(params_text)
|
||||
local values = {parse_params_srect(params_text)}
|
||||
return unpack(values)
|
||||
end,
|
||||
func = function(name, axis1, axis2, len)
|
||||
if axis1 == "get" then axis1 = worldeditadditions.player_axis2d(name) end
|
||||
|
||||
local p2 = vector.new(worldedit.pos1[name])
|
||||
|
||||
p2[axis1[2]] = p2[axis1[2]] + tonumber(len) * axis1[1]
|
||||
p2[axis2[2]] = p2[axis2[2]] + tonumber(len) * axis2[1]
|
||||
|
||||
worldedit.pos2[name] = p2
|
||||
worldedit.mark_pos2(name)
|
||||
return true, "position 2 set to " .. minetest.pos_to_string(p2)
|
||||
end,
|
||||
})
|
||||
|
||||
-- Tests
|
||||
-- /multi //fp set1 -63 19 -20 //srect 5
|
||||
-- /multi //fp set1 -63 19 -20 //srect z 5
|
||||
-- /multi //fp set1 -63 19 -20 //srect a z 5
|
||||
-- /multi //fp set1 -63 19 -20 //srect z a 5
|
||||
-- /multi //fp set1 -63 19 -20 //srect -z 5
|
||||
-- /multi //fp set1 -63 19 -20 //srect a -x 5
|
||||
-- /multi //fp set1 -63 19 -20 //srect -x -a 5
|
@ -35,13 +35,19 @@ dofile(we_c.modpath.."/commands/hollow.lua")
|
||||
dofile(we_c.modpath.."/commands/scale.lua")
|
||||
|
||||
dofile(we_c.modpath.."/commands/count.lua")
|
||||
dofile(we_c.modpath.."/commands/saplingaliases.lua")
|
||||
|
||||
dofile(we_c.modpath.."/commands/meta/multi.lua")
|
||||
dofile(we_c.modpath.."/commands/meta/many.lua")
|
||||
dofile(we_c.modpath.."/commands/meta/subdivide.lua")
|
||||
dofile(we_c.modpath.."/commands/meta/ellipsoidapply.lua")
|
||||
|
||||
-- dofile(we_c.modpath.."/commands/selectors/scol.lua")
|
||||
dofile(we_c.modpath.."/commands/selectors/srect.lua")
|
||||
-- dofile(we_c.modpath.."/commands/selectors/scube.lua")
|
||||
|
||||
dofile(we_c.modpath.."/commands/extra/saplingaliases.lua")
|
||||
dofile(we_c.modpath.."/commands/extra/basename.lua")
|
||||
|
||||
-- Don't registry the //bonemeal command if the bonemeal mod isn't present
|
||||
if minetest.get_modpath("bonemeal") then
|
||||
dofile(we_c.modpath.."/commands/bonemeal.lua")
|
||||
|
Loading…
Reference in New Issue
Block a user