replacemix: add support for wea.parse.chance

TODO: use wea.parse.weighted_nodes

The problem here is that we have a target_node with an optional chance 
too, so a finite state machine is needed to parse it currently

Once we've extracted the target_node and it's optional chance though, we 
should be able to use wea.parse.weighted_nodes in theory
This commit is contained in:
Starbeamrainbowlabs 2021-05-11 22:29:15 +01:00
parent ea05d5f559
commit 4e544c555c
No known key found for this signature in database
GPG Key ID: 1BE5172E637709C2

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