From 4e544c555c0be1db87e83781a6e6756de2dd9e01 Mon Sep 17 00:00:00 2001 From: Starbeamrainbowlabs Date: Tue, 11 May 2021 22:29:15 +0100 Subject: [PATCH] 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 --- .../commands/replacemix.lua | 14 +++++++------- 1 file changed, 7 insertions(+), 7 deletions(-) diff --git a/worldeditadditions_commands/commands/replacemix.lua b/worldeditadditions_commands/commands/replacemix.lua index 965cd2c..5eaa61a 100644 --- a/worldeditadditions_commands/commands/replacemix.lua +++ b/worldeditadditions_commands/commands/replacemix.lua @@ -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