mirror of
https://github.com/sbrl/Minetest-WorldEditAdditions.git
synced 2024-08-21 05:54:06 +02:00
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:
parent
ea05d5f559
commit
4e544c555c
@ -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"
|
return false, "Error: No arguments specified"
|
||||||
end
|
end
|
||||||
|
|
||||||
local parts = worldeditadditions.split(params_text, "%s+", false)
|
local parts = wea.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 tonumber(part) then
|
elseif mode == "target_chance" and wea.parse.chance(part) then
|
||||||
target_node_chance = tonumber(part)
|
target_node_chance = wea.parse.chance(part)
|
||||||
mode = "replace_node"
|
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"
|
mode = "replace_node"
|
||||||
if tonumber(part) then
|
if wea.parse.chance(part, "weight") 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(tonumber(part))
|
replace_nodes[last_node_name] = math.floor(wea.parse.chance(part, "weight"))
|
||||||
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
|
||||||
|
Loading…
Reference in New Issue
Block a user