port everything else

phew!
This commit is contained in:
Starbeamrainbowlabs 2022-09-19 01:16:22 +01:00
parent 41e3ebc7dd
commit 2af1226b49
Signed by: sbrl
GPG key ID: 1BE5172E637709C2
35 changed files with 186 additions and 160 deletions

View file

@ -1,3 +1,4 @@
local wea_c = worldeditadditions_core
--[[ --[[
This file contains sapling alias definitions for a number of different mods. This file contains sapling alias definitions for a number of different mods.
If your mod is not listed here, please open a pull request to add it :-) If your mod is not listed here, please open a pull request to add it :-)
@ -7,15 +8,16 @@ This mod's repository can be found here: https://github.com/sbrl/Minetest-WorldE
Adding support for your mod is a 2 step process: Adding support for your mod is a 2 step process:
1. Update this file with your definitions 1. Update this file with your definitions
2. Update depends.txt to add a soft dependency on your mod. Find that file here: https://github.com/sbrl/Minetest-WorldEditAdditions/blob/master/worldeditadditions/depends.txt - for example, add something line "my_awesome_mod?" (note the question mark at the end) on a new line(without quotes). 2. Update depends.txt to add a soft dependency on your mod. Find that file here: https://github.com/sbrl/Minetest-WorldEditAdditions/blob/main/worldeditadditions/depends.txt - for example, add something line "my_awesome_mod?" (note the question mark at the end) on a new line(without quotes).
Alternatively, you can register support in your mod directly. Do that by adding a soft dependency on worldeditadditions, and then calling worldeditadditions.normalise_saplingname if worldeditadditions is loaded. Alternatively, you can register support in your mod directly. Do that by adding a soft dependency on worldeditadditions_core, and then calling worldeditadditions_core.normalise_saplingname if worldeditadditions is loaded.
]]-- ]]--
-- worldeditadditions.register_sapling_alias("") -- TODO: MOVE register_sapling_alias & register_sapling_alias_many back to worldeditadditions from worldeditadditions_core!!!!
-- wea_c.register_sapling_alias("")
if minetest.get_modpath("default") then if minetest.get_modpath("default") then
worldeditadditions.register_sapling_alias_many({ wea_c.register_sapling_alias_many({
{ "default:sapling", "apple" }, { "default:sapling", "apple" },
{ "default:bush_sapling", "bush" }, { "default:bush_sapling", "bush" },
{ "default:pine_sapling", "pine" }, { "default:pine_sapling", "pine" },
@ -31,7 +33,7 @@ if minetest.get_modpath("default") then
end end
if minetest.get_modpath("moretrees") then if minetest.get_modpath("moretrees") then
worldeditadditions.register_sapling_alias_many({ wea_c.register_sapling_alias_many({
{ "moretrees:spruce_sapling_ongen", "spruce" }, { "moretrees:spruce_sapling_ongen", "spruce" },
{ "moretrees:rubber_tree_sapling_ongen", "rubber" }, { "moretrees:rubber_tree_sapling_ongen", "rubber" },
{ "moretrees:beech_sapling_ongen", "beech" }, { "moretrees:beech_sapling_ongen", "beech" },
@ -51,7 +53,7 @@ if minetest.get_modpath("moretrees") then
end end
if minetest.get_modpath("ethereal") then if minetest.get_modpath("ethereal") then
worldeditadditions.register_sapling_alias_many({ wea_c.register_sapling_alias_many({
{ "ethereal:mushroom_sapling", "mushroom" }, { "ethereal:mushroom_sapling", "mushroom" },
{ "ethereal:sakura_sapling", "sakura" }, { "ethereal:sakura_sapling", "sakura" },
{ "ethereal:birch_sapling", "birch" }, { "ethereal:birch_sapling", "birch" },
@ -75,56 +77,56 @@ end
-- ██████ ██████ ██████ ███████ ███████ ██ ██ ██ ███████ ███████ ███████ -- ██████ ██████ ██████ ███████ ███████ ██ ██ ██ ███████ ███████ ███████
if minetest.get_modpath("lemontree") then if minetest.get_modpath("lemontree") then
worldeditadditions.register_sapling_alias("lemontree:sapling", "lemon") wea_c.register_sapling_alias("lemontree:sapling", "lemon")
end end
if minetest.get_modpath("pineapple") then if minetest.get_modpath("pineapple") then
worldeditadditions.register_sapling_alias("pineapple:sapling", "pineapple") wea_c.register_sapling_alias("pineapple:sapling", "pineapple")
end end
if minetest.get_modpath("baldcypress") then if minetest.get_modpath("baldcypress") then
worldeditadditions.register_sapling_alias("baldcypress:sapling", "baldcypress") wea_c.register_sapling_alias("baldcypress:sapling", "baldcypress")
end end
if minetest.get_modpath("bamboo") then if minetest.get_modpath("bamboo") then
worldeditadditions.register_sapling_alias("bamboo:sprout", "bamboo") wea_c.register_sapling_alias("bamboo:sprout", "bamboo")
end end
if minetest.get_modpath("birch") then if minetest.get_modpath("birch") then
worldeditadditions.register_sapling_alias("birch:sapling", "birch") wea_c.register_sapling_alias("birch:sapling", "birch")
end end
if minetest.get_modpath("cherrytree") then if minetest.get_modpath("cherrytree") then
worldeditadditions.register_sapling_alias("cherrytree:sapling", "cherry") wea_c.register_sapling_alias("cherrytree:sapling", "cherry")
end end
if minetest.get_modpath("clementinetree") then if minetest.get_modpath("clementinetree") then
worldeditadditions.register_sapling_alias("clementinetree:sapling", "clementine") wea_c.register_sapling_alias("clementinetree:sapling", "clementine")
end end
if minetest.get_modpath("ebony") then if minetest.get_modpath("ebony") then
worldeditadditions.register_sapling_alias("ebony:sapling", "ebony") wea_c.register_sapling_alias("ebony:sapling", "ebony")
end end
if minetest.get_modpath("jacaranda") then if minetest.get_modpath("jacaranda") then
worldeditadditions.register_sapling_alias("jacaranda:sapling", "jacaranda") wea_c.register_sapling_alias("jacaranda:sapling", "jacaranda")
end end
if minetest.get_modpath("larch") then if minetest.get_modpath("larch") then
worldeditadditions.register_sapling_alias("larch:sapling", "larch") wea_c.register_sapling_alias("larch:sapling", "larch")
end end
if minetest.get_modpath("maple") then if minetest.get_modpath("maple") then
worldeditadditions.register_sapling_alias("maple:sapling", "maple") wea_c.register_sapling_alias("maple:sapling", "maple")
end end
if minetest.get_modpath("palm") then if minetest.get_modpath("palm") then
worldeditadditions.register_sapling_alias("palm:sapling", "palm") wea_c.register_sapling_alias("palm:sapling", "palm")
end end
if minetest.get_modpath("plumtree") then if minetest.get_modpath("plumtree") then
worldeditadditions.register_sapling_alias("plumtree:sapling", "plum") wea_c.register_sapling_alias("plumtree:sapling", "plum")
end end
if minetest.get_modpath("hollytree") then if minetest.get_modpath("hollytree") then
worldeditadditions.register_sapling_alias("hollytree:sapling", "holly") wea_c.register_sapling_alias("hollytree:sapling", "holly")
end end
if minetest.get_modpath("pomegranate") then if minetest.get_modpath("pomegranate") then
worldeditadditions.register_sapling_alias("pomegranate:sapling", "pomegranate") wea_c.register_sapling_alias("pomegranate:sapling", "pomegranate")
end end
if minetest.get_modpath("willow") then if minetest.get_modpath("willow") then
worldeditadditions.register_sapling_alias("willow:sapling", "willow") wea_c.register_sapling_alias("willow:sapling", "willow")
end end
if minetest.get_modpath("mahogany") then if minetest.get_modpath("mahogany") then
worldeditadditions.register_sapling_alias("mahogany:sapling", "mahogany") wea_c.register_sapling_alias("mahogany:sapling", "mahogany")
end end
if minetest.get_modpath("chestnuttree") then if minetest.get_modpath("chestnuttree") then
worldeditadditions.register_sapling_alias("chestnuttree:sapling", "chestnut") wea_c.register_sapling_alias("chestnuttree:sapling", "chestnut")
end end

View file

@ -1,5 +1,6 @@
local wea = worldeditadditions local wea = worldeditadditions
local Vector3 = wea.Vector3 local wea_c = worldeditadditions_core
local Vector3 = wea_c.Vector3
wea.conv = {} wea.conv = {}
@ -62,8 +63,8 @@ function wea.convolve(pos1, pos2, kernel, kernel_size)
local node_id_air = minetest.get_content_id("air") local node_id_air = minetest.get_content_id("air")
local heightmap, heightmap_size = wea.terrain.make_heightmap(pos1, pos2, manip, area, data) local heightmap, heightmap_size = wea_c.terrain.make_heightmap(pos1, pos2, manip, area, data)
local heightmap_conv = wea.table.shallowcopy(heightmap) local heightmap_conv = wea_c.table.shallowcopy(heightmap)
wea.conv.convolve( wea.conv.convolve(
heightmap_conv, heightmap_conv,
@ -77,7 +78,7 @@ function wea.convolve(pos1, pos2, kernel, kernel_size)
-- print("transformed") -- print("transformed")
-- wea.format.array_2d(heightmap_conv, (pos2.z - pos1.z) + 1) -- wea.format.array_2d(heightmap_conv, (pos2.z - pos1.z) + 1)
wea.terrain.apply_heightmap_changes( wea_c.terrain.apply_heightmap_changes(
pos1, pos2, area, data, pos1, pos2, area, data,
heightmap, heightmap_conv, heightmap_size heightmap, heightmap_conv, heightmap_size
) )

View file

@ -1,5 +1,5 @@
local wea = worldeditadditions local wea_c = worldeditadditions_core
local Vector3 = wea.Vector3 local Vector3 = wea_c.Vector3
--[[ --[[
Convolves over a given 2D heightmap with a given matrix. Convolves over a given 2D heightmap with a given matrix.
Note that this *mutates* the given heightmap. Note that this *mutates* the given heightmap.
@ -17,7 +17,7 @@ function worldeditadditions.conv.convolve(heightmap, heightmap_size, matrix, mat
-- We need to reference a *copy* of the heightmap when convolving -- We need to reference a *copy* of the heightmap when convolving
-- This is because we need the original values when we perform a -- This is because we need the original values when we perform a
-- convolution on a given pixel -- convolution on a given pixel
local heightmap_copy = wea.table.shallowcopy(heightmap) local heightmap_copy = wea_c.table.shallowcopy(heightmap)
local border_size = Vector3.new( local border_size = Vector3.new(
(matrix_size.x-1) / 2, -- x = height (matrix_size.x-1) / 2, -- x = height

View file

@ -1,3 +1,4 @@
local wea_c = worldeditadditions_core
-- Ported from Javascript by Starbeamrainbowlabs -- Ported from Javascript by Starbeamrainbowlabs
-- Original source: https://github.com/sidorares/gaussian-convolution-kernel/ -- Original source: https://github.com/sidorares/gaussian-convolution-kernel/
-- From -- From
@ -27,7 +28,7 @@ function worldeditadditions.conv.kernel_gaussian(dimension, sigma)
local sum = 0 local sum = 0
for i = 0, dimension-1 do for i = 0, dimension-1 do
for j = 0, dimension-1 do for j = 0, dimension-1 do
local distance = worldeditadditions.hypotenuse(i, j, centre, centre) local distance = wea_c.hypotenuse(i, j, centre, centre)
-- The following is an algorithm that came from the gaussian blur -- The following is an algorithm that came from the gaussian blur
-- wikipedia page [1]. -- wikipedia page [1].

View file

@ -1,4 +1,5 @@
local wea = worldeditadditions local wea = worldeditadditions
local wea_c = worldeditadditions_core
wea.erode = {} wea.erode = {}
dofile(wea.modpath.."/lib/erode/snowballs.lua") dofile(wea.modpath.."/lib/erode/snowballs.lua")
@ -18,12 +19,12 @@ function wea.erode.run(pos1, pos2, algorithm, params)
local region_height = (pos2.y - pos1.y) + 1 local region_height = (pos2.y - pos1.y) + 1
local heightmap = wea.terrain.make_heightmap(pos1, pos2, manip, area, data) local heightmap = wea_c.terrain.make_heightmap(pos1, pos2, manip, area, data)
local heightmap_eroded = wea.table.shallowcopy(heightmap) local heightmap_eroded = wea_c.table.shallowcopy(heightmap)
-- print("[erode.run] algorithm: "..algorithm..", params:"); -- print("[erode.run] algorithm: "..algorithm..", params:");
-- print(wea.format.map(params)) -- print(wea_c.format.map(params))
-- wea.format.array_2d(heightmap, heightmap_size.x) -- wea_c.format.array_2d(heightmap, heightmap_size.x)
local success, msg, stats local success, msg, stats
if algorithm == "snowballs" then if algorithm == "snowballs" then
success, msg = wea.erode.snowballs( success, msg = wea.erode.snowballs(
@ -49,7 +50,7 @@ function wea.erode.run(pos1, pos2, algorithm, params)
return false, "Error: Unknown algorithm '"..algorithm.."'. Currently implemented algorithms: snowballs (2d; hydraulic-like), river (2d; cellular automata-like; fills potholes and lowers towers). Ideas for algorithms to implement are welcome!" return false, "Error: Unknown algorithm '"..algorithm.."'. Currently implemented algorithms: snowballs (2d; hydraulic-like), river (2d; cellular automata-like; fills potholes and lowers towers). Ideas for algorithms to implement are welcome!"
end end
success, stats = wea.terrain.apply_heightmap_changes( success, stats = wea_c.terrain.apply_heightmap_changes(
pos1, pos2, area, data, pos1, pos2, area, data,
heightmap, heightmap_eroded, heightmap_size heightmap, heightmap_eroded, heightmap_size
) )

View file

@ -1,12 +1,13 @@
local wea = worldeditadditions local wea = worldeditadditions
local wea_c = worldeditadditions_core
--- Parses a comma-separated side numbers list out into a list of numbers. --- Parses a comma-separated side numbers list out into a list of numbers.
-- @param list string The command separated list to parse. -- @param list string The command separated list to parse.
-- @returns number[] A list of side numbers. -- @returns number[] A list of side numbers.
local function parse_sides_list(list) local function parse_sides_list(list)
list = list:gsub("%s", "") -- Spaces are not permitted list = list:gsub("%s", "") -- Spaces are not permitted
return wea.table.unique(wea.table.map( return wea_c.table.unique(wea_c.table.map(
wea.split(list, ","), wea_c.split(list, ","),
function(value) return tonumber(value) end function(value) return tonumber(value) end
)) ))
end end
@ -20,7 +21,7 @@ function worldeditadditions.erode.river(heightmap_initial, heightmap, heightmap_
dolower = true -- Whether to do lower operations or not dolower = true -- Whether to do lower operations or not
} }
-- Apply the custom settings -- Apply the custom settings
wea.table.apply(params_custom, params) wea_c.table.apply(params_custom, params)
params.lower_sides = parse_sides_list(params.lower_sides) params.lower_sides = parse_sides_list(params.lower_sides)
params.raise_sides = parse_sides_list(params.raise_sides) params.raise_sides = parse_sides_list(params.raise_sides)
@ -30,8 +31,8 @@ function worldeditadditions.erode.river(heightmap_initial, heightmap, heightmap_
local removed = 0 local removed = 0
for i=1,params.steps do for i=1,params.steps do
-- print("[DEBUG:river] step ", i) -- print("[DEBUG:river] step ", i)
-- wea.format.array_2d(heightmap, heightmap_size.x) -- wea_c.format.array_2d(heightmap, heightmap_size.x)
local time_start = wea.get_ms_time() local time_start = wea_c.get_ms_time()
-- Store up changes to make and make them at the end of the step -- Store up changes to make and make them at the end of the step
-- This is important, because decisions -- This is important, because decisions
@ -105,7 +106,7 @@ function worldeditadditions.erode.river(heightmap_initial, heightmap, heightmap_
removed = removed + 1 removed = removed + 1
end end
-- print("[DEBUG:river] sides_higher", sides_higher, "sides_lower", sides_lower, "action", action) -- print("[DEBUG:river] sides_higher", sides_higher, "sides_lower", sides_lower, "action", action)
-- wea.format.array_2d(heightmap, heightmap_size.x) -- wea_c.format.array_2d(heightmap, heightmap_size.x)
end end
end end
@ -116,8 +117,8 @@ function worldeditadditions.erode.river(heightmap_initial, heightmap, heightmap_
heightmap[hi] = heightmap[hi] - 1 heightmap[hi] = heightmap[hi] - 1
end end
table.insert(timings, wea.get_ms_time() - time_start) table.insert(timings, wea_c.get_ms_time() - time_start)
end end
return true, params.steps.." steps made, raising "..filled.." and lowering "..removed.." columns in "..wea.format.human_time(wea.sum(timings)).." (~"..wea.format.human_time(wea.average(timings)).." per step)" return true, params.steps.." steps made, raising "..filled.." and lowering "..removed.." columns in "..wea_c.format.human_time(wea_c.sum(timings)).." (~"..wea_c.format.human_time(wea_c.average(timings)).." per step)"
end end

View file

@ -1,16 +1,19 @@
local wea = worldeditadditions local wea = worldeditadditions
local Vector3 = wea.Vector3 local wea_c = worldeditadditions_core
local Vector3 = wea_c.Vector3
-- Test command: //multi //fp set1 1313 6 5540 //fp set2 1338 17 5521 //erode snowballs -- Test command: //multi //fp set1 1313 6 5540 //fp set2 1338 17 5521 //erode snowballs
local function snowball(heightmap, normalmap, heightmap_size, startpos, params) local function snowball(heightmap, normalmap, heightmap_size, startpos, params)
local sediment = 0 local sediment = 0
local pos = { x = startpos.x, z = startpos.z } local pos = Vector3.new(startpos.x, 0, startpos.z) -- X/Z
local pos_prev = { x = pos.x, z = pos.z } local pos_prev = Vector3.new(pos.x, 0, pos.z) -- X/Z
local velocity = { local velocity = Vector3.new(
x = (math.random() * 2 - 1) * params.init_velocity, (math.random() * 2 - 1) * params.init_velocity,
z = (math.random() * 2 - 1) * params.init_velocity 0,
} (math.random() * 2 - 1) * params.init_velocity
) -- X/Z
local heightmap_length = #heightmap local heightmap_length = #heightmap
-- print("[snowball] startpos ("..pos.x..", "..pos.z.."), velocity: ("..velocity.x..", "..velocity.z..")") -- print("[snowball] startpos ("..pos.x..", "..pos.z.."), velocity: ("..velocity.x..", "..velocity.z..")")
@ -29,7 +32,7 @@ local function snowball(heightmap, normalmap, heightmap_size, startpos, params)
end end
if #hist_velocity > 0 and i > 5 if #hist_velocity > 0 and i > 5
and wea.average(hist_velocity) < 0.03 then and wea_c.average(hist_velocity) < 0.03 then
-- print("[snowball] It looks like we've stopped") -- print("[snowball] It looks like we've stopped")
return true, i return true, i
end end
@ -50,13 +53,13 @@ local function snowball(heightmap, normalmap, heightmap_size, startpos, params)
end end
velocity.x = params.friction * velocity.x + normalmap[hi].x * params.speed velocity.x = params.friction * velocity.x + normalmap[hi].x * params.speed
velocity.y = 0 -- Just in case
velocity.z = params.friction * velocity.z + normalmap[hi].y * params.speed velocity.z = params.friction * velocity.z + normalmap[hi].y * params.speed
-- print("[snowball] now at ("..x..", "..z..") velocity "..wea.vector.lengthsquared(velocity)..", sediment "..sediment) -- print("[snowball] now at ("..x..", "..z..") velocity "..wea.vector.lengthsquared(velocity)..", sediment "..sediment)
local new_vel_sq = wea.vector.lengthsquared(velocity) local new_vel_sq = velocity:length_squared()
if new_vel_sq > 1 then if new_vel_sq > 1 then
-- print("[snowball] velocity squared over 1, normalising") -- print("[snowball] velocity squared over 1, normalising")
velocity = wea.vector.normalize(velocity) velocity = velocity:normalise()
end end
table.insert(hist_velocity, new_vel_sq) table.insert(hist_velocity, new_vel_sq)
if #hist_velocity > params.velocity_hist_count then table.remove(hist_velocity, 1) end if #hist_velocity > params.velocity_hist_count then table.remove(hist_velocity, 1) end
@ -89,12 +92,12 @@ function wea.erode.snowballs(heightmap_initial, heightmap, heightmap_size, regio
count = 25000 count = 25000
} }
-- Apply the custom settings -- Apply the custom settings
wea.table.apply(params_custom, params) wea_c.table.apply(params_custom, params)
-- print("[erode/snowballs] params: ") -- print("[erode/snowballs] params: ")
-- print(wea.format.map(params)) -- print(wea_c.format.map(params))
local normals = wea.terrain.calculate_normals(heightmap, heightmap_size) local normals = wea_c.terrain.calculate_normals(heightmap, heightmap_size)
local stats_steps = {} local stats_steps = {}
for i = 1, params.count do for i = 1, params.count do
@ -142,5 +145,5 @@ function wea.erode.snowballs(heightmap_initial, heightmap, heightmap_size, regio
) )
end end
return true, ""..#stats_steps.." snowballs simulated, max "..params.max_steps.." steps (averaged ~"..wea.average(stats_steps).." steps)" return true, ""..#stats_steps.." snowballs simulated, max "..params.max_steps.." steps (averaged ~"..wea_c.average(stats_steps).." steps)"
end end

View file

@ -1,5 +1,7 @@
local wea = worldeditadditions local wea_c = worldeditadditions_core
local Vector3 = wea.Vector3 local Vector3 = wea_c.Vector3
local metaballdata = {} local metaballdata = {}
@ -9,7 +11,7 @@ local metaballdata = {}
-- @param radius number The radius of the metaball. -- @param radius number The radius of the metaball.
-- @returns bool,number The number of metaballs now defined for the given player. -- @returns bool,number The number of metaballs now defined for the given player.
local function add(player_name, pos, radius) local function add(player_name, pos, radius)
local pos = Vector3.clone(pos) pos = Vector3.clone(pos)
if type(player_name) ~= "string" then if type(player_name) ~= "string" then
return false, "Error: Invalid player name specified." return false, "Error: Invalid player name specified."
@ -63,7 +65,7 @@ local function list_pretty(player_name)
}) })
end end
return true, wea.format.make_ascii_table(rows).."\n---------------------------\nTotal "..tostring(#metaball_list).." metaballs" return true, wea_c.format.make_ascii_table(rows).."\n---------------------------\nTotal "..tostring(#metaball_list).." metaballs"
end end
--- Removes the metaball with the specified index for a given player. --- Removes the metaball with the specified index for a given player.

View file

@ -1,5 +1,6 @@
local wea = worldeditadditions local wea_c = worldeditadditions_core
local Vector3 = wea.Vector3 local Vector3 = wea_c.Vector3
-- ███ ███ ███████ ████████ █████ ██████ █████ ██ ██ ███████ -- ███ ███ ███████ ████████ █████ ██████ █████ ██ ██ ███████
-- ████ ████ ██ ██ ██ ██ ██ ██ ██ ██ ██ ██ ██ -- ████ ████ ██ ██ ██ ██ ██ ██ ██ ██ ██ ██ ██

View file

@ -1,9 +1,10 @@
local wea = worldeditadditions local wea = worldeditadditions
local wea_c = worldeditadditions_core
--- Applies the given noise field to the given heightmap. --- Applies the given noise field to the given heightmap.
-- Mutates the given heightmap. -- Mutates the given heightmap.
-- @param heightmap number[] A table of ZERO indexed numbers representing the heghtmap - see worldeditadditions.terrain.make_heightmap(). -- @param heightmap number[] A table of ZERO indexed numbers representing the heghtmap - see wea_c.terrain.make_heightmap().
-- @param noise number[] An table identical in structure to the heightmap containing the noise values to apply. -- @param noise number[] An table identical in structure to the heightmap containing the noise values to apply.
-- @param heightmap_size {x:number,z:number} A 2d vector representing the size of the heightmap. -- @param heightmap_size {x:number,z:number} A 2d vector representing the size of the heightmap.
-- @param region_height number The height of the defined region. -- @param region_height number The height of the defined region.
@ -18,7 +19,7 @@ function wea.noise.apply_2d(heightmap, noise, heightmap_size, pos1, pos2, apply_
-- print("NOISE APPLY_2D\n") -- print("NOISE APPLY_2D\n")
wea.format.array_2d(noise, heightmap_size.x) wea_c.format.array_2d(noise, heightmap_size.x)
local height = tonumber(apply_mode) local height = tonumber(apply_mode)
@ -29,15 +30,15 @@ function wea.noise.apply_2d(heightmap, noise, heightmap_size, pos1, pos2, apply_
local i = (z * heightmap_size.x) + x local i = (z * heightmap_size.x) + x
if apply_mode == "add" then if apply_mode == "add" then
heightmap[i] = wea.round(heightmap[i] + noise[i]) heightmap[i] = wea_c.round(heightmap[i] + noise[i])
elseif apply_mode == "multiply" then elseif apply_mode == "multiply" then
heightmap[i] = wea.round(heightmap[i] * noise[i]) heightmap[i] = wea_c.round(heightmap[i] * noise[i])
elseif height then elseif height then
-- Rescale from 0 - 1 to -1 - +1 -- Rescale from 0 - 1 to -1 - +1
local rescaled = (noise[i] * 2) - 1 local rescaled = (noise[i] * 2) - 1
-- Rescale to match the height specified -- Rescale to match the height specified
rescaled = rescaled * height rescaled = rescaled * height
rescaled = math.floor(wea.clamp( rescaled = math.floor(wea_c.clamp(
heightmap[i] + rescaled, heightmap[i] + rescaled,
0, region_height 0, region_height
)) ))
@ -54,7 +55,7 @@ function wea.noise.apply_2d(heightmap, noise, heightmap_size, pos1, pos2, apply_
-- end -- end
-- print("HEIGHTMAP\n") -- print("HEIGHTMAP\n")
-- worldeditadditions.format.array_2d(heightmap, heightmap_size.x) -- wea_c.format.array_2d(heightmap, heightmap_size.x)
return true return true

View file

@ -1,4 +1,6 @@
local wea = worldeditadditions local wea = worldeditadditions
local wea_c = worldeditadditions_core
local Vector3 = wea_c.Vector3
local White = dofile(wea.modpath.."/lib/noise/engines/white.lua") local White = dofile(wea.modpath.."/lib/noise/engines/white.lua")
@ -25,7 +27,7 @@ function Infrared:noise( x, y, z )
end end
end end
end end
return wea.average(values) return wea_c.average(values)
end end
return Infrared return Infrared

View file

@ -1,4 +1,6 @@
local wea = worldeditadditions local wea = worldeditadditions
local wea_c = worldeditadditions_core
local Vector3 = wea_c.Vector3
--- Perlin noise generation engine. --- Perlin noise generation engine.
-- Original code by Ken Perlin: http://mrl.nyu.edu/~perlin/noise/ -- Original code by Ken Perlin: http://mrl.nyu.edu/~perlin/noise/
@ -58,9 +60,9 @@ end
function Perlin:noise( x, y, z ) function Perlin:noise( x, y, z )
y = y or 0 y = y or 0
z = z or 0 z = z or 0
local xi = wea.bit.band(math.floor(x), 255) local xi = wea_c.bit.band(math.floor(x), 255)
local yi = wea.bit.band(math.floor(y), 255) local yi = wea_c.bit.band(math.floor(y), 255)
local zi = wea.bit.band(math.floor(z), 255) local zi = wea_c.bit.band(math.floor(z), 255)
-- print("x", x, "y", y, "z", z, "xi", xi, "yi", yi, "zi", zi) -- print("x", x, "y", y, "z", z, "xi", xi, "yi", yi, "zi", zi)
-- print("p[xi]", self.p[xi]) -- print("p[xi]", self.p[xi])
@ -118,7 +120,7 @@ function Perlin:lerp(t, a, b)
end end
function Perlin:grad(hash, x, y, z) function Perlin:grad(hash, x, y, z)
local h = wea.bit.band(hash, 15) local h = wea_c.bit.band(hash, 15)
local u = h < 8 and x or y local u = h < 8 and x or y
local v = h < 4 and y or ((h == 12 or h == 14) and x or z) local v = h < 4 and y or ((h == 12 or h == 14) and x or z)
return ((h and 1) == 0 and u or - u) + ((h and 2) == 0 and v or - v) return ((h and 1) == 0 and u or - u) + ((h and 2) == 0 and v or - v)

View file

@ -1,4 +1,5 @@
local wea = worldeditadditions local wea_c = worldeditadditions_core
local Vector3 = wea_c.Vector3
local PerlinMT = {} local PerlinMT = {}
@ -25,7 +26,7 @@ function PerlinMT.new(seed, params)
end end
function PerlinMT:noise( x, y, z ) function PerlinMT:noise( x, y, z )
local value = self.engine:get_3d(wea.Vector3.new(x, y, z)) local value = self.engine:get_3d(Vector3.new(x, y, z))
return value return value
end end

View file

@ -1,4 +1,5 @@
local wea = worldeditadditions local wea = worldeditadditions
local wea_c = worldeditadditions_core
local White = dofile(wea.modpath.."/lib/noise/engines/white.lua") local White = dofile(wea.modpath.."/lib/noise/engines/white.lua")
@ -33,7 +34,7 @@ function Red:noise( x, y, z )
self.white:noise(x + 1, y + 1, z), self.white:noise(x + 1, y + 1, z),
self.white:noise(x + 1, y + 1, z + 1), self.white:noise(x + 1, y + 1, z + 1),
} }
return wea.average(values) return wea_c.average(values)
end end
return Red return Red

View file

@ -1,5 +1,3 @@
local wea = worldeditadditions
local Sin = {} local Sin = {}
Sin.__index = Sin Sin.__index = Sin

View file

@ -1,4 +1,3 @@
local wea = worldeditadditions
local White = {} local White = {}

View file

@ -1,10 +1,11 @@
local wea = worldeditadditions
local wea_c = worldeditadditions_core
-- ███ ███ █████ ██ ██ ███████ ██████ ██████ -- ███ ███ █████ ██ ██ ███████ ██████ ██████
-- ████ ████ ██ ██ ██ ██ ██ ██ ██ ██ -- ████ ████ ██ ██ ██ ██ ██ ██ ██ ██
-- ██ ████ ██ ███████ █████ █████ █████ ██ ██ -- ██ ████ ██ ███████ █████ █████ █████ ██ ██
-- ██ ██ ██ ██ ██ ██ ██ ██ ██ ██ ██ -- ██ ██ ██ ██ ██ ██ ██ ██ ██ ██ ██
-- ██ ██ ██ ██ ██ ██ ███████ ███████ ███████ ██████ -- ██ ██ ██ ██ ██ ██ ███████ ███████ ███████ ██████
local wea = worldeditadditions
-- Generate a flat array of 2D noise. -- Generate a flat array of 2D noise.
-- Written with help from https://www.redblobgames.com/maps/terrain-from-noise/ -- Written with help from https://www.redblobgames.com/maps/terrain-from-noise/
@ -55,7 +56,7 @@ function worldeditadditions.noise.make_2d(size, start_pos, params)
print("NOISE MAKE_2D\n") print("NOISE MAKE_2D\n")
worldeditadditions.format.array_2d(result, size.x) wea_c.format.array_2d(result, size.x)
-- We don't round here, because otherwise when we apply it it'll be inaccurate -- We don't round here, because otherwise when we apply it it'll be inaccurate

View file

@ -1,4 +1,6 @@
local wea = worldeditadditions local wea = worldeditadditions
local wea_c = worldeditadditions_core
local Vector3 = wea_c.Vector3
--- Makes sure that the default settings are all present in the given params table. --- Makes sure that the default settings are all present in the given params table.
-- This way not all params have to be specified by the user. -- This way not all params have to be specified by the user.
@ -15,9 +17,9 @@ function worldeditadditions.noise.params_apply_default(params)
-- The backend noise algorithm to use -- The backend noise algorithm to use
algorithm = "perlinmt", algorithm = "perlinmt",
-- Zooms in and out -- Zooms in and out
scale = wea.Vector3.new(1, 1, 1), scale = Vector3.new(1, 1, 1),
-- Offset the generated noise by this vector. -- Offset the generated noise by this vector.
offset = wea.Vector3.new(0, 0, 0), offset = Vector3.new(0, 0, 0),
-- Apply this exponent to the resulting noise value -- Apply this exponent to the resulting noise value
exponent = 1, exponent = 1,
-- Multiply the resulting noise value by this number. Changes the "strength" of the noise -- Multiply the resulting noise value by this number. Changes the "strength" of the noise
@ -34,7 +36,7 @@ function worldeditadditions.noise.params_apply_default(params)
-- If params[1] is thing, this is a list of params -- If params[1] is thing, this is a list of params
-- This might be a thing if we're dealing with multiple octaves -- This might be a thing if we're dealing with multiple octaves
for i,params_el in ipairs(params) do for i,params_el in ipairs(params) do
local default_copy = wea.table.shallowcopy(params_default) local default_copy = wea_c.table.shallowcopy(params_default)
-- Keyword support -- Keyword support
for _i, keyword in ipairs(wea.noise.engines.available) do for _i, keyword in ipairs(wea.noise.engines.available) do
@ -44,7 +46,7 @@ function worldeditadditions.noise.params_apply_default(params)
end end
-- Apply this table to fill in the gaps -- Apply this table to fill in the gaps
wea.table.apply( wea_c.table.apply(
params_el, params_el,
default_copy default_copy
) )

View file

@ -1,7 +1,10 @@
local wea = worldeditadditions
local wea_c = worldeditadditions_core
local Vector3 = wea_c.Vector3
--- Applies a layer of 2D noise over the terrain in the defined region. --- Applies a layer of 2D noise over the terrain in the defined region.
-- @module worldeditadditions.noise2d -- @module worldeditadditions.noise2d
local wea = worldeditadditions
-- ███ ██ ██████ ██ ███████ ███████ ██████ ██████ -- ███ ██ ██████ ██ ███████ ███████ ██████ ██████
-- ████ ██ ██ ██ ██ ██ ██ ██ ██ ██ -- ████ ██ ██ ██ ██ ██ ██ ██ ██ ██
@ -13,24 +16,24 @@ local wea = worldeditadditions
-- @param pos2 Vector pos2 of the defined region -- @param pos2 Vector pos2 of the defined region
-- @param noise_params table A noise parameters table. -- @param noise_params table A noise parameters table.
function wea.noise.run2d(pos1, pos2, noise_params) function wea.noise.run2d(pos1, pos2, noise_params)
pos1, pos2 = worldedit.sort_pos(pos1, pos2) pos1, pos2 = Vector3.sort(pos1, pos2)
-- pos2 will always have the highest co-ordinates now -- pos2 will always have the highest co-ordinates now
-- Fill in the default params -- Fill in the default params
-- print("DEBUG noise_params_custom ", wea.format.map(noise_params)) -- print("DEBUG noise_params_custom ", wea_c.format.map(noise_params))
noise_params = wea.noise.params_apply_default(noise_params) noise_params = wea.noise.params_apply_default(noise_params)
-- print("DEBUG noise_params[1] ", wea.format.map(noise_params[1])) -- print("DEBUG noise_params[1] ", wea_c.format.map(noise_params[1]))
-- Fetch the nodes in the specified area -- Fetch the nodes in the specified area
local manip, area = worldedit.manip_helpers.init(pos1, pos2) local manip, area = worldedit.manip_helpers.init(pos1, pos2)
local data = manip:get_data() local data = manip:get_data()
local heightmap_old, heightmap_size = wea.terrain.make_heightmap( local heightmap_old, heightmap_size = wea_c.terrain.make_heightmap(
pos1, pos2, pos1, pos2,
manip, area, manip, area,
data data
) )
local heightmap_new = wea.table.shallowcopy(heightmap_old) local heightmap_new = wea_c.table.shallowcopy(heightmap_old)
local success, noisemap = wea.noise.make_2d( local success, noisemap = wea.noise.make_2d(
heightmap_size, heightmap_size,
@ -49,7 +52,7 @@ function wea.noise.run2d(pos1, pos2, noise_params)
if not success then return success, message end if not success then return success, message end
local stats local stats
success, stats = wea.terrain.apply_heightmap_changes( success, stats = wea_c.terrain.apply_heightmap_changes(
pos1, pos2, pos1, pos2,
area, data, area, data,
heightmap_old, heightmap_new, heightmap_old, heightmap_new,

View file

@ -1,5 +1,6 @@
local wea = worldeditadditions local wea = worldeditadditions
local Vector3 = wea.Vector3 local wea_c = worldeditadditions_core
local Vector3 = wea_c.Vector3
--- Applies the given brush with the given height and size to the given position. --- Applies the given brush with the given height and size to the given position.
-- @param pos1 Vector3 The position at which to apply the brush. -- @param pos1 Vector3 The position at which to apply the brush.
@ -36,12 +37,12 @@ local function apply(pos1, brush_name, height, brush_size)
local manip, area = worldedit.manip_helpers.init(pos1_compute, pos2_compute) local manip, area = worldedit.manip_helpers.init(pos1_compute, pos2_compute)
local data = manip:get_data() local data = manip:get_data()
local heightmap, heightmap_size = wea.terrain.make_heightmap( local heightmap, heightmap_size = wea_c.terrain.make_heightmap(
pos1_compute, pos2_compute, pos1_compute, pos2_compute,
manip, area, manip, area,
data data
) )
local heightmap_orig = wea.table.shallowcopy(heightmap) local heightmap_orig = wea_c.table.shallowcopy(heightmap)
local success2, added, removed = wea.sculpt.apply_heightmap( local success2, added, removed = wea.sculpt.apply_heightmap(
brush, brush_size_actual, brush, brush_size_actual,
@ -52,7 +53,7 @@ local function apply(pos1, brush_name, height, brush_size)
if not success2 then return success2, added end if not success2 then return success2, added end
-- 3: Save back to disk & return -- 3: Save back to disk & return
local success3, stats = wea.terrain.apply_heightmap_changes( local success3, stats = wea_c.terrain.apply_heightmap_changes(
pos1_compute, pos2_compute, pos1_compute, pos2_compute,
area, data, area, data,
heightmap_orig, heightmap, heightmap_orig, heightmap,

View file

@ -1,5 +1,5 @@
local wea = worldeditadditions local wea_c = worldeditadditions_core
local Vector3 = wea.Vector3 local Vector3 = wea_c.Vector3
--- Applies the given brush at the given x/z position to the given heightmap. --- Applies the given brush at the given x/z position to the given heightmap.
-- Important: Where a Vector3 is mentioned in the parameter list, it reall MUST -- Important: Where a Vector3 is mentioned in the parameter list, it reall MUST
@ -26,6 +26,7 @@ local function apply_heightmap(brush, brush_size, height, position, heightmap, h
local added = 0 local added = 0
local removed = 0 local removed = 0
-- TODO: Make the strength of the brush depend on the height of the nodes in the heightmap?
-- Iterate over the heightmap and apply the brush -- Iterate over the heightmap and apply the brush
-- Note that we do not iterate over the brush, because we don't know if the -- Note that we do not iterate over the brush, because we don't know if the

View file

@ -1,20 +1,22 @@
local wea = worldeditadditions local wea = worldeditadditions
local Vector3 = wea.Vector3 local wea_c = worldeditadditions
local Vector3 = wea_c.Vector3
--- Returns a smooth gaussian brush. --- Returns a smooth gaussian brush.
-- @param size Vector3 The target size of the brush. Note that the actual size of the brush will be different, as the gaussian function has some limitations. -- @param size Vector3 The target size of the brush. Note that the actual size of the brush will be different, as the gaussian function has some limitations.
-- @param sigma=2 number The 'smoothness' of the brush. Higher values are more smooth. -- @param sigma=2 number The 'smoothness' of the brush. Higher values are more smooth.
return function(size, sigma) return function(size, sigma)
local size = math.min(size.x, size.y) size = math.min(size.x, size.y)
if size % 2 == 0 then size = size - 1 end if size % 2 == 0 then size = size - 1 end -- Gaussian runs on odd numbers
if size < 1 then if size < 1 then
return false, "Error: Invalid brush size." return false, "Error: Invalid brush size (brushes must be at least 1 node in size)."
end end
local success, gaussian = wea.conv.kernel_gaussian(size, sigma) local success, gaussian = wea.conv.kernel_gaussian(size, sigma)
-- Normalise values to fill the range 0 - 1 -- Normalise values to fill the range 0 - 1
-- By default, wea.conv.kernel_gaussian values add up to 1 in total -- By default, wea.conv.kernel_gaussian values add up to 1 in total
local max = wea.max(gaussian) local max = wea_c.max(gaussian)
for i=0,size*size-1 do for i=0,size*size-1 do
gaussian[i] = gaussian[i] / max gaussian[i] = gaussian[i] / max
end end

View file

@ -1,7 +1,9 @@
local wea = worldeditadditions local wea_c = worldeditadditions_core
local Vector3 = wea.Vector3 local Vector3 = wea_c.Vector3
--- Makes a circle brush of a given size.
-- @param size Vector3 The desired sizez of the brush (only X and Y are considered; Z is ignored).
-- @returns bool,brush,Vector3 Success bool, then the brush, then finally the actual size of the brush generated.
return function(size) return function(size)
local brush = {} local brush = {}

View file

@ -1,5 +1,6 @@
local wea = worldeditadditions local wea = worldeditadditions
local Vector3 = wea.Vector3 local wea_c = worldeditadditions_core
local Vector3 = wea_c.Vector3
return function(size) return function(size)
@ -30,14 +31,14 @@ return function(size)
local success, kernel = wea.conv.kernel_gaussian(kernel_size, 2) local success, kernel = wea.conv.kernel_gaussian(kernel_size, 2)
if not success then return success, kernel end if not success then return success, kernel end
local success2, msg = worldeditadditions.conv.convolve( local success2, msg = wea.conv.convolve(
brush, Vector3.new(size.x, 0, size.y), brush, Vector3.new(size.x, 0, size.y),
kernel, Vector3.new(kernel_size, 0, kernel_size) kernel, Vector3.new(kernel_size, 0, kernel_size)
) )
if not success2 then return success2, msg end if not success2 then return success2, msg end
-- Rescale to be between 0 and 1 -- Rescale to be between 0 and 1
local max_value = wea.max(brush) local max_value = wea_c.max(brush)
for i,value in pairs(brush) do for i,value in pairs(brush) do
brush[i] = brush[i] / max_value brush[i] = brush[i] / max_value
end end

View file

@ -1,5 +1,4 @@
local wea = worldeditadditions local wea = worldeditadditions
local Vector3 = wea.Vector3
local parse_static = dofile(wea.modpath.."/lib/sculpt/parse_static.lua") local parse_static = dofile(wea.modpath.."/lib/sculpt/parse_static.lua")
@ -8,8 +7,9 @@ local parse_static = dofile(wea.modpath.."/lib/sculpt/parse_static.lua")
-- @returns true,table,Vector3|false,string A success boolean, followed either by an error message as a string or the brush (as a table) and it's size (as an X/Y Vector3) -- @returns true,table,Vector3|false,string A success boolean, followed either by an error message as a string or the brush (as a table) and it's size (as an X/Y Vector3)
return function(filepath) return function(filepath)
local handle = io.open(filepath) local handle = io.open(filepath)
if not handle then if not handle then
handle:close() if handle ~= nil then handle:close() end
return false, "Error: Failed to open the static brush file at '"..filepath.."'." return false, "Error: Failed to open the static brush file at '"..filepath.."'."
end end

View file

@ -12,7 +12,6 @@ local sculpt = {
make_brush = dofile(wea.modpath.."/lib/sculpt/make_brush.lua"), make_brush = dofile(wea.modpath.."/lib/sculpt/make_brush.lua"),
make_preview = dofile(wea.modpath.."/lib/sculpt/make_preview.lua"), make_preview = dofile(wea.modpath.."/lib/sculpt/make_preview.lua"),
preview_brush = dofile(wea.modpath.."/lib/sculpt/preview_brush.lua"), preview_brush = dofile(wea.modpath.."/lib/sculpt/preview_brush.lua"),
read_brush_static = dofile(wea.modpath.."/lib/sculpt/read_brush_static.lua"),
apply_heightmap = dofile(wea.modpath.."/lib/sculpt/apply_heightmap.lua"), apply_heightmap = dofile(wea.modpath.."/lib/sculpt/apply_heightmap.lua"),
apply = dofile(wea.modpath.."/lib/sculpt/apply.lua"), apply = dofile(wea.modpath.."/lib/sculpt/apply.lua"),
scan_static = dofile(wea.modpath.."/lib/sculpt/scan_static.lua"), scan_static = dofile(wea.modpath.."/lib/sculpt/scan_static.lua"),

View file

@ -1,5 +1,4 @@
local wea = worldeditadditions local wea = worldeditadditions
local Vector3 = wea.Vector3
local make_brush = dofile(wea.modpath.."/lib/sculpt/make_brush.lua") local make_brush = dofile(wea.modpath.."/lib/sculpt/make_brush.lua")

View file

@ -1,5 +1,6 @@
local wea = worldeditadditions local wea = worldeditadditions
local Vector3 = wea.Vector3 local wea_c = worldeditadditions_core
local Vector3 = wea_c.Vector3
--- Parses a static brush definition. --- Parses a static brush definition.
-- @param source string The source string that contains the static brush, formatted as TSV. -- @param source string The source string that contains the static brush, formatted as TSV.
@ -11,12 +12,12 @@ return function(source)
-- Parse out the TSV into a table of tables, while also parsing values as numbers -- Parse out the TSV into a table of tables, while also parsing values as numbers
-- Also keeps track of the maximum/minimum values found for rescaling later. -- Also keeps track of the maximum/minimum values found for rescaling later.
local values = wea.table.map( local values = wea_c.table.map(
wea.split(source, "\n", false), wea_c.split(source, "\n", false),
function(line) function(line)
local row = wea.split(line, "%s+", false) local row = wea_c.split(line, "%s+", false)
width = math.max(width, #row) width = math.max(width, #row)
return wea.table.map( return wea_c.table.map(
row, row,
function(pixel) function(pixel)
local value = tonumber(pixel) local value = tonumber(pixel)

View file

@ -1,5 +1,6 @@
local wea = worldeditadditions local wea = worldeditadditions
local Vector3 = wea.Vector3 local wea_c = worldeditadditions_core
local Vector3 = wea_c.Vector3
local make_brush = dofile(wea.modpath.."/lib/sculpt/make_brush.lua") local make_brush = dofile(wea.modpath.."/lib/sculpt/make_brush.lua")
local make_preview = dofile(wea.modpath.."/lib/sculpt/make_preview.lua") local make_preview = dofile(wea.modpath.."/lib/sculpt/make_preview.lua")

View file

@ -1,11 +0,0 @@
return function(filepath)
local brush_size = { x = 0, y = 0 }
local brush = { }
-- TODO: Import brush here
return false, "Error: Not implemented yet"
-- return true, brush, brush_size
end

View file

@ -1,5 +1,6 @@
local wea = worldeditadditions local wea = worldeditadditions
local Vector3 = wea.Vector3 local wea_c = worldeditadditions_core
local Vector3 = wea_c.Vector3
local import_static = dofile(wea.modpath.."/lib/sculpt/import_static.lua") local import_static = dofile(wea.modpath.."/lib/sculpt/import_static.lua")
@ -25,14 +26,14 @@ end
-- @returns bool,loaded,errors A success boolean, followed by the number of brushes loaded, followed by the number of errors encountered while loading brushes (errors are logged as warnings with Minetest) -- @returns bool,loaded,errors A success boolean, followed by the number of brushes loaded, followed by the number of errors encountered while loading brushes (errors are logged as warnings with Minetest)
return function(dirpath, overwrite_existing) return function(dirpath, overwrite_existing)
if overwrite_existing == nil then overwrite_existing = false end if overwrite_existing == nil then overwrite_existing = false end
local files = wea.io.scandir_files(dirpath) local files = wea_c.io.scandir_files(dirpath)
local brushes_loaded = 0 local brushes_loaded = 0
local errors = 0 local errors = 0
for i, filename in pairs(files) do for i, filename in pairs(files) do
if wea.str_ends(filename, ".brush.tsv") then if wea_c.str_ends(filename, ".brush.tsv") then
local filepath = dirpath.."/"..filename local filepath = dirpath.."/"..filename
local name = filename:gsub(".brush.tsv", "") local name = filename:gsub(".brush.tsv", "")

View file

@ -1,3 +1,6 @@
local wea_c = worldeditadditions_core
local Vector3 = wea_c.Vector3
-- ██████ ██████ ██████ ███ ██ ███████ ██████ ███████ ███████ ████████ -- ██████ ██████ ██████ ███ ██ ███████ ██████ ███████ ███████ ████████
-- ██ ██ ██ ██ ██ ████ ██ ██ ██ ██ ██ ██ ██ -- ██ ██ ██ ██ ██ ████ ██ ██ ██ ██ ██ ██ ██
-- ██ ██ ██ ██████ ██ ██ ██ █████ ██████ ███████ █████ ██ -- ██ ██ ██ ██████ ██ ██ ██ █████ ██████ ███████ █████ ██
@ -5,9 +8,9 @@
-- ██████ ██████ ██ ██ ██ ████ ███████ ██ ██ ███████ ███████ ██ -- ██████ ██████ ██ ██ ██ ████ ███████ ██ ██ ███████ ███████ ██
--- Puts a node at each corner of selection box. --- Puts a node at each corner of selection box.
-- @param {Position} pos1 The 1st position defining the WorldEdit selection -- @param pos1 Vector3 The 1st position defining the WorldEdit selection
-- @param {Position} pos2 The 2nd positioon defining the WorldEdit selection -- @param pos2 Vector3 The 2nd positioon defining the WorldEdit selection
-- @param {string} node Name of the node to place -- @param node string Name of the node to place
function worldeditadditions.corner_set(pos1, pos2, node) function worldeditadditions.corner_set(pos1, pos2, node)
-- z y x is the preferred loop order (because CPU cache I'd guess, since then we're iterating linearly through the data array) -- z y x is the preferred loop order (because CPU cache I'd guess, since then we're iterating linearly through the data array)
@ -15,7 +18,7 @@ function worldeditadditions.corner_set(pos1,pos2,node)
for i, z in pairs({pos1.z, pos2.z}) do for i, z in pairs({pos1.z, pos2.z}) do
for j, y in pairs({pos1.y, pos2.y}) do for j, y in pairs({pos1.y, pos2.y}) do
for k, x in pairs({pos1.x, pos2.x}) do for k, x in pairs({pos1.x, pos2.x}) do
minetest.set_node(vector.new(x,y,z), {name=node}) minetest.set_node(Vector3.new(x, y, z), {name = node})
counts.replaced = counts.replaced + 1 counts.replaced = counts.replaced + 1
end end
end end

View file

@ -1,3 +1,6 @@
local wea_c = worldeditadditions_core
local Vector3 = wea_c.Vector3
-- ███ ███ █████ ██ ██ ███████ ██████ ██████ ███ ███ ██████ █████ ███████ ███████ -- ███ ███ █████ ██ ██ ███████ ██████ ██████ ███ ███ ██████ █████ ███████ ███████
-- ████ ████ ██ ██ ██ ██ ██ ██ ██ ██ ████ ████ ██ ██ ██ ██ ██ ██ -- ████ ████ ██ ██ ██ ██ ██ ██ ██ ██ ████ ████ ██ ██ ██ ██ ██ ██
-- ██ ████ ██ ███████ █████ █████ ██ ██ ██ ██ ████ ██ ██████ ███████ ███████ ███████ -- ██ ████ ██ ███████ █████ █████ ██ ██ ██ ██ ████ ██ ██████ ███████ ███████ ███████
@ -9,20 +12,20 @@
-- @param {string} node1 Name of the node to place -- @param {string} node1 Name of the node to place
-- @param {string} node2 Name of the node of the bead -- @param {string} node2 Name of the node of the bead
function worldeditadditions.make_compass(pos1,node1,node2) function worldeditadditions.make_compass(pos1,node1,node2)
pos1 = Vector3.clone(pos1)
minetest.set_node(vector.add(pos1,vector.new(0,1,3)), {name=node2}) minetest.set_node(pos1 + Vector3.new(0,1,3), { name = node2 })
local counts = { replaced = 1 } local counts = { replaced = 1 }
-- z y x is the preferred loop order (because CPU cache I'd guess, since then we're iterating linearly through the data array) -- z y x is the preferred loop order (because CPU cache I'd guess, since then we're iterating linearly through the data array)
for z = -3,3 do for z = -3,3 do
if z ~= 0 then if z ~= 0 then
for k,x in pairs({math.floor(-3/math.abs(z)),0,math.ceil(3/math.abs(z))}) do for k,x in pairs({math.floor(-3/math.abs(z)),0,math.ceil(3/math.abs(z))}) do
minetest.set_node(vector.new(pos1.x+x,pos1.y,pos1.z+z), {name=node1}) minetest.set_node(Vector3.new(pos1.x+x,pos1.y,pos1.z+z), {name=node1})
counts.replaced = counts.replaced + 1 counts.replaced = counts.replaced + 1
end end
else else
for x = -3,3 do for x = -3,3 do
minetest.set_node(vector.new(pos1.x+x,pos1.y,pos1.z), {name=node1}) minetest.set_node(Vector3.new(pos1.x+x,pos1.y,pos1.z), {name=node1})
counts.replaced = counts.replaced + 1 counts.replaced = counts.replaced + 1
end end
end end

View file

@ -1,3 +1,5 @@
local v3 = worldeditadditions_core.Vector3
-- ██ ██ ██ ██████ ███████ ██████ ██████ ██ ██ -- ██ ██ ██ ██████ ███████ ██████ ██████ ██ ██
-- ██ ██ ██ ██ ██ ██ ██ ██ ██ ██ ██ ██ -- ██ ██ ██ ██ ██ ██ ██ ██ ██ ██ ██ ██
-- ██ █ ██ ██ ██████ █████ ██████ ██ ██ ███ -- ██ █ ██ ██ ██████ █████ ██████ ██ ██ ███
@ -8,7 +10,6 @@
-- @param {Position} pos1 The 1st position defining the WorldEdit selection -- @param {Position} pos1 The 1st position defining the WorldEdit selection
-- @param {Position} pos2 The 2nd positioon defining the WorldEdit selection -- @param {Position} pos2 The 2nd positioon defining the WorldEdit selection
-- @param {string} node Name of the node to place -- @param {string} node Name of the node to place
local v3 = worldeditadditions.Vector3
function worldeditadditions.wire_box(pos1,pos2,node) function worldeditadditions.wire_box(pos1,pos2,node)
local node_id_replace = minetest.get_content_id(node) local node_id_replace = minetest.get_content_id(node)
local ps1, ps2 = v3.sort(pos1,pos2) local ps1, ps2 = v3.sort(pos1,pos2)

View file

@ -56,7 +56,7 @@ worldeditadditions_core.register_command("convolve", {
func = function(name, kernel_name, kernel_width, kernel_height, sigma) func = function(name, kernel_name, kernel_width, kernel_height, sigma)
local start_time = wea_c.get_ms_time() local start_time = wea_c.get_ms_time()
local success, kernel = wea_c.get_conv_kernel( local success, kernel = wea.get_conv_kernel(
kernel_name, kernel_name,
kernel_width, kernel_height, kernel_width, kernel_height,
sigma sigma