Merge branch 'main' of github.com:sbrl/Minetest-WorldEditAdditions into main

This commit is contained in:
Starbeamrainbowlabs 2021-05-21 02:11:11 +01:00
commit e3e5710217
No known key found for this signature in database
GPG Key ID: 1BE5172E637709C2
4 changed files with 42 additions and 21 deletions

@ -14,7 +14,8 @@ Note to self: See the bottom of this file for the release template text.
- Add new universal chance parsing
- Any `<chance>` can now either be a 1-in-N number (e.g. `4`, `10`), or a percentage chance (e.g. `50%`, `10%`).
- Caveat: Percentages are converted to a 1-in-N chance, but additionally that number is rounded down in some places
- `//torus`, `//hollowtorus`: Add optional new axes argument
- `//torus`, `//hollowtorus`: Add optional new axes
- `//torus`: Add optional hollow keyword
## v1.11: The big data update (25th January 2021)

@ -124,18 +124,20 @@ Creates a hollow ellipsoid at position 1 with the radius `(rx, ry, rz)`. Works t
//hollowellipsoid 21 11 41 stone
```
## `//torus <major_radius> <minor_radius> <node_name> [<axes=xy>]`
## `//torus <major_radius> <minor_radius> <node_name> [<axes=xy> [h[ollow]]]`
Creates a solid torus at position 1 with the specified major and minor radii. The major radius is the distance from the centre of the torus to the centre of the circle bit, and the minor radius is the radius of the circle bit.
The optional axes sets the axes upon which the torus will lay flat. Possible values: `xy` (the default), `xz`, `yz`.
The optional axes sets the axes upon which the torus will lay flat. Possible values: `xy` (the default), `xz`, `yz`. A single axis may also be specified (i.e. `x`, `y`, or `z`) - this will be interpreted as the axis that runs through the hole in the middle of the torus.
```
//torus 15 5 stone
//torus 5 3 meselamp
//hollowtorus 10 6 sandstone xz
//torus 10 6 sandstone xz
//torus 10 6 wool:red y
//torus 25 10 dirt xz hollow
```
## `//hollowtorus <major_radius> <minor_radius> <node_name>`
## `//hollowtorus <major_radius> <minor_radius> <node_name> [<axes=xy>]`
Creates a hollow torus at position 1 with the radius major and minor radii. Works the same way as `//torus` does.
```
@ -303,7 +305,7 @@ If you want to specify different scale factors for difference axes, then `//scal
This will scale the defined region by 2x in the positive x, 3x in the positive y, and 4x in the positive z. As these are all scale factors, we can also use the syntax described above to scale up and down in the same operation:
```
//scale 50% 2 1/4
//scale 50% 2 1/4
```
This will first scale in the positive y by 2x. Once that operation is completed, it will scale down to 50% size in the positive x and down to 25% size in the positive z. Note that if you want to scale down first and then scale up, you'll need to execute 2 separate commands.
@ -361,7 +363,7 @@ The above replaces 1 in 3 `dirt` nodes with a mix of `sandstone`, `dry_dirt`, an
Since WorldEditAdditions v1.12, you can also use percentages:
```
//replacemix dirt 33% sandstone 75% dry_dirt 10% cobble 15%
//replacemix dirt 33% sandstone 75% dry_dirt 10% cobble 15%
```
Note though that the percentages are internally converted to a 1-in-N chance and rounded down.
@ -379,7 +381,7 @@ Here are all the above examples together:
## `//convolve <kernel> [<width>[,<height>]] [<sigma>]`
Advanced version of `//smooth` from we_env, and one of the few WorldEditAdditions commands to have any aliases (`//smoothadv` and `//conv`).
Extracts a heightmap from the defined region and then proceeds to [convolve](https://en.wikipedia.org/wiki/Kernel_(image_processing)) over it with the specified kernel. The kernel can be thought of as the filter that will be applied to the heightmap. Once done, the newly convolved heightmap is applied to the terrain.
Extracts a heightmap from the defined region and then proceeds to [convolve](https://en.wikipedia.org/wiki/Kernel_(image_processing)) over it with the specified kernel. The kernel can be thought of as the filter that will be applied to the heightmap. Once done, the newly convolved heightmap is applied to the terrain.
Possible kernels:
@ -451,7 +453,7 @@ Counts all the nodes in the defined region and returns the result along with cal
```
## `//subdivide <size_x> <size_y> <size_z> <cmd_name> <args>`
Splits the current WorldEdit region into `(<size_x>, <size_y>, <size_z>)` sized chunks, and run `//<cmd_name> <args>` over each chunk.
Splits the current WorldEdit region into `(<size_x>, <size_y>, <size_z>)` sized chunks, and run `//<cmd_name> <args>` over each chunk.
Sometimes, we want to run a single command on a truly vast area. Usually, this results in running out of memory. If this was you, then this command is just what you need! It should be able to handle any sized region - the only limit is your patience for command to complete.....

@ -1,5 +1,5 @@
--- Overlap command. Places a specified node on top of
-- @module worldeditadditions.overlay
--- Generates torus shapes.
-- @module worldeditadditions.torus
--- Generates a torus shape at the given position with the given parameters.
-- @param position Vector The position at which to generate the torus.
@ -9,7 +9,9 @@
-- @param axes=xz string|nil The axes upon which the torus should lay flat.
-- @param hollow=false boolean Whether the generated torus should be hollow or not.
function worldeditadditions.torus(position, major_radius, minor_radius, target_node, axes, hollow)
local matrix = {x='yz', y='xz', z='xy'}
if type(axes) ~= "string" then axes = "xz" end
if #axes == 1 and axes:match('[xyz]') then axes = matrix[axes] end
-- position = { x, y, z }
local total_radius = major_radius + minor_radius
@ -55,8 +57,8 @@ function worldeditadditions.torus(position, major_radius, minor_radius, target_n
-- (x^2+y^2+z^2-(a^2+b^2))^2-4 a b (b^2-z^2)
-- Where:
-- (x, y, z) is the point
-- a is the major radius (centre to centre of circle)
-- b is the minor radius (radius of circle
-- a is the major radius (centre of the ring to the centre of the torus)
-- b is the minor radius (radius of the ring)
local comp_a = (sq.x+sq.y+sq.z - (major_radius_sq+minor_radius_sq))
local test_value = comp_a*comp_a - 4*major_radius*minor_radius*(minor_radius_sq-sq.z)

@ -35,21 +35,25 @@ local function parse_params_torus(params_text)
if axes:find("[^xyz]") then
return false, "Error: The axes may only contain the letters x, y, and z."
end
if #axes ~= 2 then
return false, "Error: Exactly 2 axes must be specified. For example, 'xy' is valid, but 'xyy' is not (both of course without quotes)."
if #axes > 2 then
return false, "Error: 2 or less axes must be specified. For example, xy is valid, but xzy is not."
end
local hollow = false
if parts[5] == "hollow" or parts[5] == "h" then
hollow = true
end
-- Sort the axis names (this is important to ensure we can identify the direction properly)
if axes == "yx" then axes = "xy" end
if axes == "zx" then axes = "xz" end
if axes == "zy" then axes = "yz" end
return true, replace_node, major_radius, minor_radius, axes
return true, replace_node, major_radius, minor_radius, axes, hollow
end
worldedit.register_command("torus", {
params = "<major_radius> <minor_radius> <replace_node> [<axes=xy>]",
params = "<major_radius> <minor_radius> <replace_node> [<axes=xy> [h[ollow]]]",
description = "Creates a 3D torus with a major radius of <major_radius> and a minor radius of <minor_radius> at pos1, filled with <replace_node>, on axes <axes> (i.e. 2 axis names: xz, zy, etc).",
privs = { worldedit = true },
require_pos = 1,
@ -60,9 +64,15 @@ worldedit.register_command("torus", {
nodes_needed = function(name, target_node, major_radius, minor_radius)
return math.ceil(2 * math.pi*math.pi * major_radius * minor_radius*minor_radius)
end,
func = function(name, target_node, major_radius, minor_radius, axes)
func = function(name, target_node, major_radius, minor_radius, axes, hollow)
local start_time = worldeditadditions.get_ms_time()
local replaced = worldeditadditions.torus(worldedit.pos1[name], major_radius, minor_radius, target_node, axes, false)
local replaced = worldeditadditions.torus(
worldedit.pos1[name],
major_radius, minor_radius,
target_node,
axes,
hollow
)
local time_taken = worldeditadditions.get_ms_time() - start_time
minetest.log("action", name .. " used //torus at " .. worldeditadditions.vector.tostring(worldedit.pos1[name]) .. ", replacing " .. replaced .. " nodes in " .. time_taken .. "s")
@ -83,9 +93,15 @@ worldedit.register_command("hollowtorus", {
nodes_needed = function(name, target_node, major_radius, minor_radius, axes)
return math.ceil(2 * math.pi*math.pi * major_radius * minor_radius*minor_radius)
end,
func = function(name, target_node, major_radius, minor_radius)
func = function(name, target_node, major_radius, minor_radius, axes)
local start_time = worldeditadditions.get_ms_time()
local replaced = worldeditadditions.torus(worldedit.pos1[name], major_radius, minor_radius, target_node, axes, true)
local replaced = worldeditadditions.torus(
worldedit.pos1[name],
major_radius, minor_radius,
target_node,
axes,
true -- hollow
)
local time_taken = worldeditadditions.get_ms_time() - start_time
minetest.log("action", name .. " used //hollowtorus at " .. worldeditadditions.vector.tostring(worldedit.pos1[name]) .. ", replacing " .. replaced .. " nodes in " .. time_taken .. "s")