Validation check in perlin_set_noise command
This commit is contained in:
parent
f9c206409b
commit
630668f99f
13
init.lua
13
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
|
||||
|
||||
|
Loading…
x
Reference in New Issue
Block a user