From 630668f99ffb598286d62c1af0e0f3adc8e80cc7 Mon Sep 17 00:00:00 2001 From: Wuzzy Date: Wed, 20 Apr 2022 19:37:31 +0200 Subject: [PATCH] Validation check in perlin_set_noise command --- init.lua | 13 ++++++++++--- 1 file changed, 10 insertions(+), 3 deletions(-) diff --git a/init.lua b/init.lua index 2e5bc34..4e857ac 100644 --- a/init.lua +++ b/init.lua @@ -1,3 +1,6 @@ +local S = minetest.get_translator("perlin_explorer") +local F = minetest.formspec_escape + -- If true, the Perlin test nodes will support color -- (set to false in case of performance problems) local COLORIZE_NODES = true @@ -74,8 +77,8 @@ local STATISTICS_MAX_SIZE = math.floor((2^32-1)/1000) -- Used for triggering error message. local STATISTICS_MAX_SPREAD = math.floor(STATISTICS_MAX_SIZE / STATISTICS_SPREAD_FACTOR) -local S = minetest.get_translator("perlin_explorer") -local F = minetest.formspec_escape +-- Hardcoded message text +local TEXT_ERROR_BAD_WAVELENGTH = S("Bad noise parameters given. At least one of the resulting wavelengths got below 1, which is not allowed. Decrease the octaves or lacunarity, or increase the spread to reach valid wavelengths. Use the “Analyze” feature to see the wavelengths.") -- Per-player formspec states (mostly for remembering checkbox states) local formspec_states = {} @@ -942,6 +945,10 @@ minetest.register_chatcommand("perlin_set_noise", { flags = flags, } noiseparams = fix_noiseparams(noiseparams) + local _, _, _, badwaves = analyze_noiseparams(noiseparams) + if badwaves then + return false, TEXT_ERROR_BAD_WAVELENGTH + end set_perlin_noise(noiseparams) loaded_areas = {} return true, S("Active Perlin noise parameters set!") @@ -1518,7 +1525,7 @@ minetest.register_on_player_receive_fields(function(player, formname, fields) local _, _, _, badwaves = analyze_noiseparams(noiseparams) if badwaves then formspec_states[player:get_player_name()].noiseparams = noiseparams - show_error_formspec(player, S("Bad noise parameters given. At least one of the resulting wavelengths got below 1, which is not allowed. Decrease the octaves or lacunarity to reach valid wavelengths. Analyze the noise parameters to see the current wavelengths."), true) + show_error_formspec(player, TEXT_ERROR_BAD_WAVELENGTH) return end