Merge branch 'main' into vortechnix

This commit is contained in:
VorTechnix 2021-05-17 20:45:28 -07:00 committed by GitHub
commit d4b457f85d
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
5 changed files with 26 additions and 57 deletions

View file

@ -37,7 +37,6 @@ Note also that columns without any air nodes in them at all are also skipped, so
//overlay grass_with_dirt 10 dirt //overlay grass_with_dirt 10 dirt
//overlay grass_with_dirt 10 dirt 2 sand 1 //overlay grass_with_dirt 10 dirt 2 sand 1
//overlay sandstone dirt 2 sand 5 //overlay sandstone dirt 2 sand 5
//overlay dirt 90% stone 10%
``` ```
## `//layers [<node_name_1> [<layer_count_1>]] [<node_name_2> [<layer_count_2>]] ...` ## `//layers [<node_name_1> [<layer_count_1>]] [<node_name_2> [<layer_count_2>]] ...`
@ -127,8 +126,6 @@ Creates a hollow ellipsoid at position 1 with the radius `(rx, ry, rz)`. Works t
## `//torus <major_radius> <minor_radius> <node_name> [<axes=xy> [h[ollow]]]` ## `//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. 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`.
``` ```
//torus 15 5 stone //torus 15 5 stone
//torus 5 3 meselamp x //torus 5 3 meselamp x
@ -142,7 +139,6 @@ Creates a hollow torus at position 1 with the radius major and minor radii. Work
``` ```
//hollowtorus 10 5 glass //hollowtorus 10 5 glass
//hollowtorus 21 11 stone //hollowtorus 21 11 stone
//hollowtorus 18 6 dirt xz
``` ```
## `//line [<replace_node> [<radius>]]` ## `//line [<replace_node> [<radius>]]`
@ -218,15 +214,12 @@ Also optionally takes a chance number. This is the chance that an eligible node
For example, a chance number of 2 would mean a 50% chance that any given eligible node will get bonemealed. A chance number of 16 would be a 6.25% chance, and a chance number of 25 would be 2%. For example, a chance number of 2 would mean a 50% chance that any given eligible node will get bonemealed. A chance number of 16 would be a 6.25% chance, and a chance number of 25 would be 2%.
Since WorldEditAdditions v1.12, a percentage chance is also supported. This is denoted by suffixing a number with a percent sign (e.g. `//bonemeal 1 25%`).
``` ```
//bonemeal //bonemeal
//bonemeal 3 25 //bonemeal 3 25
//bonemeal 4 //bonemeal 4
//bonemeal 1 10 //bonemeal 1 10
//bonemeal 2 15 //bonemeal 2 15
//bonemeal 2 10%
``` ```
## `//walls <replace_node>` ## `//walls <replace_node>`

View file

@ -1,4 +1,4 @@
--- Overlap command. Places a specified node on top of --- Overlap command. Places a specified node on top of
-- @module worldeditadditions.overlay -- @module worldeditadditions.overlay
--- Generates a torus shape at the given position with the given parameters. --- Generates a torus shape at the given position with the given parameters.
@ -12,7 +12,7 @@ function worldeditadditions.torus(position, major_radius, minor_radius, target_n
local matrix = {x='yz', y='xz', z='xy'} local matrix = {x='yz', y='xz', z='xy'}
if type(axes) ~= "string" then axes = "xz" end if type(axes) ~= "string" then axes = "xz" end
if #axes == 1 and axes:match('[xyz]') then axes = matrix[axes] end if #axes == 1 and axes:match('[xyz]') then axes = matrix[axes] end
-- position = { x, y, z } -- position = { x, y, z }
local total_radius = major_radius + minor_radius local total_radius = major_radius + minor_radius
local inner_minor_radius = minor_radius - 2 local inner_minor_radius = minor_radius - 2
@ -22,7 +22,6 @@ function worldeditadditions.torus(position, major_radius, minor_radius, target_n
-- Fetch the nodes in the specified area -- Fetch the nodes in the specified area
-- OPTIMIZE: We should be able to calculate a more efficient box-area here -- OPTIMIZE: We should be able to calculate a more efficient box-area here
-- This is complicated by the multiple possible axes though
local manip, area = worldedit.manip_helpers.init_radius(position, total_radius) local manip, area = worldedit.manip_helpers.init_radius(position, total_radius)
local data = manip:get_data() local data = manip:get_data()
@ -45,15 +44,6 @@ function worldeditadditions.torus(position, major_radius, minor_radius, target_n
for x = -total_radius, total_radius do for x = -total_radius, total_radius do
local x_sq = x*x local x_sq = x*x
local sq = vector.new(x_sq, y_sq, z_sq)
-- Default: xy
if axes == "xz" then
sq.x, sq.y, sq.z = sq.x, sq.z, sq.y
elseif axes == "yz" then
sq.x, sq.y, sq.z = sq.y, sq.z, sq.x
end
-- (x^2+y^2+z^2-(a^2+b^2))^2-4 a b (b^2-z^2) -- (x^2+y^2+z^2-(a^2+b^2))^2-4 a b (b^2-z^2)
-- Where: -- Where:
-- (x, y, z) is the point -- (x, y, z) is the point
@ -68,8 +58,8 @@ function worldeditadditions.torus(position, major_radius, minor_radius, target_n
if not place_ok then if not place_ok then
-- It must be hollow! Do some additional calculations. -- It must be hollow! Do some additional calculations.
local inner_comp_a = (sq.x+sq.y+sq.z - (major_radius_sq+inner_minor_radius_sq)) local inner_comp_a = (x_sq+y_sq+z_sq - (major_radius_sq+inner_minor_radius_sq))
local inner_test_value = inner_comp_a*inner_comp_a - 4*major_radius*inner_minor_radius*(inner_minor_radius_sq-sq.z) local inner_test_value = inner_comp_a*inner_comp_a - 4*major_radius*inner_minor_radius*(inner_minor_radius_sq-z_sq)
-- It's only ok to place it if it's outside our inner torus -- It's only ok to place it if it's outside our inner torus
place_ok = inner_test_value >= 0 place_ok = inner_test_value >= 0

View file

@ -27,7 +27,7 @@ worldedit.register_command("bonemeal", {
end end
end end
if #parts >= 2 then if #parts >= 2 then
chance = worldeditadditions.parse.chance(parts[2]) chance = tonumber(parts[2])
if not chance then if not chance then
return false, "Invalid chance value (must be a positive integer)" return false, "Invalid chance value (must be a positive integer)"
end end

View file

@ -1,4 +1,4 @@
local wea = worldeditadditions local we_c = worldeditadditions_commands
-- ██████ ███████ ██████ ██ █████ ██████ ███████ ███ ███ ██ ██ ██ -- ██████ ███████ ██████ ██ █████ ██████ ███████ ███ ███ ██ ██ ██
-- ██ ██ ██ ██ ██ ██ ██ ██ ██ ██ ████ ████ ██ ██ ██ -- ██ ██ ██ ██ ██ ██ ██ ██ ██ ██ ████ ████ ██ ██ ██
@ -15,7 +15,7 @@ worldedit.register_command("replacemix", {
return false, "Error: No arguments specified" return false, "Error: No arguments specified"
end end
local parts = wea.split(params_text, "%s+", false) local parts = worldeditadditions.split(params_text, "%s+", false)
local target_node = nil local target_node = nil
local target_node_chance = 1 local target_node_chance = 1
@ -30,16 +30,16 @@ worldedit.register_command("replacemix", {
return false, "Error: Invalid target_node name" return false, "Error: Invalid target_node name"
end end
mode = "target_chance" mode = "target_chance"
elseif mode == "target_chance" and wea.parse.chance(part) then elseif mode == "target_chance" and tonumber(part) then
target_node_chance = wea.parse.chance(part) target_node_chance = tonumber(part)
mode = "replace_node" mode = "replace_node"
elseif (mode == "target_chance" and not wea.parse.chance(part, "weight")) or mode == "replace_node" then elseif (mode == "target_chance" and not tonumber(part)) or mode == "replace_node" then
mode = "replace_node" mode = "replace_node"
if wea.parse.chance(part, "weight") then if tonumber(part) then
if not last_node_name then if not last_node_name then
return false, "Error: No previous node name was found (this is a probably a bug)." return false, "Error: No previous node name was found (this is a probably a bug)."
end end
replace_nodes[last_node_name] = math.floor(wea.parse.chance(part, "weight")) replace_nodes[last_node_name] = math.floor(tonumber(part))
else else
if last_node_name and not replace_nodes[last_node_name] then if last_node_name and not replace_nodes[last_node_name] then
replace_nodes[last_node_name] = 1 replace_nodes[last_node_name] = 1

View file

@ -4,36 +4,22 @@
-- ██ ██ ██ ██ ██ ██ ██ ██ -- ██ ██ ██ ██ ██ ██ ██ ██
-- ██ ██████ ██ ██ ██████ ███████ -- ██ ██████ ██ ██ ██████ ███████
local function parse_params_torus(params_text) local function parse_params_torus(params_text)
local parts = worldeditadditions.split(params_text, "%s+", false) local found, _, major_radius, minor_radius, replace_node = params_text:find("([0-9]+)%s+([0-9]+)%s+([a-z:_\\-]+)")
if #parts < 1 then if found == nil then
return false, "Error: No replace_node specified." return nil, nil
end
if #parts < 2 then
return false, "Error: No major radius specified (expected integer greater than 0)."
end
if #parts < 3 then
return false, "Error: No minor radius specified (expected integer greater than 0)."
end end
local major_radius = tonumber(parts[1]) major_radius = tonumber(major_radius)
local minor_radius = tonumber(parts[2]) minor_radius = tonumber(minor_radius)
local replace_node = worldedit.normalize_nodename(parts[3])
local axes replace_node = worldedit.normalize_nodename(replace_node)
if #parts > 3 then axes = parts[4] end
if not axes then axes = "xy" end
if major_radius < 1 then
return false, "Error: The major radius must be greater than 0."
end
if minor_radius < 1 then
return false, "Error: The minor radius must be greater than 0."
end
if not replace_node then if not replace_node then
return false, "Error: Invalid node name." return false, "Error: Invalid replace_node."
end end
if axes:find("[^xyz]") then if not major_radius or major_radius < 1 then
return false, "Error: The axes may only contain the letters x, y, and z." return false, "Error: Invalid major radius (expected integer greater than 0)"
end end
if #axes > 2 then if #axes > 2 then
return false, "Error: 2 or less axes must be specified. For example, xy is valid, but xzy is not." return false, "Error: 2 or less axes must be specified. For example, xy is valid, but xzy is not."
@ -74,20 +60,20 @@ worldedit.register_command("torus", {
-- TODO: This duplicates a lot of code. Perhaps we can trim it down a bit? -- TODO: This duplicates a lot of code. Perhaps we can trim it down a bit?
worldedit.register_command("hollowtorus", { worldedit.register_command("hollowtorus", {
params = "<major_radius> <minor_radius> <replace_node> [<axes=xy>]", params = "<major_radius> <minor_radius> <replace_node>",
description = "Creates a 3D hollow torus with a major radius of <major_radius> and a minor radius of <minor_radius> at pos1, made out of <replace_node>, on axes <axes> (i.e. 2 axis names: xz, zy, etc).", description = "Creates a 3D hollow torus with a major radius of <major_radius> and a minor radius of <minor_radius> at pos1, made out of <replace_node>.",
privs = { worldedit = true }, privs = { worldedit = true },
require_pos = 1, require_pos = 1,
parse = function(params_text) parse = function(params_text)
local values = {parse_params_torus(params_text)} local values = {parse_params_torus(params_text)}
return unpack(values) return unpack(values)
end, end,
nodes_needed = function(name, target_node, major_radius, minor_radius, axes) nodes_needed = function(name, target_node, major_radius, minor_radius)
return math.ceil(2 * math.pi*math.pi * major_radius * minor_radius*minor_radius) return math.ceil(2 * math.pi*math.pi * major_radius * minor_radius*minor_radius)
end, end,
func = function(name, target_node, major_radius, minor_radius) func = function(name, target_node, major_radius, minor_radius)
local start_time = worldeditadditions.get_ms_time() 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, true)
local time_taken = worldeditadditions.get_ms_time() - start_time 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") minetest.log("action", name .. " used //hollowtorus at " .. worldeditadditions.vector.tostring(worldedit.pos1[name]) .. ", replacing " .. replaced .. " nodes in " .. time_taken .. "s")