From cd34499c3c5b8bba843696de8b40656544e23437 Mon Sep 17 00:00:00 2001 From: Wuzzy Date: Sat, 16 Apr 2022 16:19:58 +0200 Subject: [PATCH] Do some simple noiseparams fixes --- init.lua | 17 +++++++++++++++-- 1 file changed, 15 insertions(+), 2 deletions(-) diff --git a/init.lua b/init.lua index af58063..c77e282 100644 --- a/init.lua +++ b/init.lua @@ -591,7 +591,7 @@ minetest.register_chatcommand("perlin_set_noise", { if not octaves or not offset or not sx or not sy or not sz or not persistence or not lacunarity or not seed then return false, S("Invalid parameter type.") end - set_perlin_noise({ + local noiseparams = { octaves = octaves, offset = offset, scale = scale, @@ -600,7 +600,9 @@ minetest.register_chatcommand("perlin_set_noise", { lacunarity = lacunarity, seed = seed, flags = flags, - }) + } + noiseparams = fix_noiseparams(noiseparams) + set_perlin_noise(noiseparams) loaded_areas = {} return true, S("Active Perlin noise parameters set!") end, @@ -829,6 +831,16 @@ local show_noise_formspec = function(player, noiseparams, profile_id) minetest.show_formspec(player:get_player_name(), "perlin_explorer:creator", form) end +-- Fix some errors in the noiseparams +local fix_noiseparams = function(noiseparams) + noiseparams.octaves = math.floor(math.max(1, noiseparams.octaves)) + noiseparams.lacunarity = math.max(1.0, noiseparams.lacunarity) + noiseparams.spread.x = math.floor(math.max(1, noiseparams.spread.x)) + noiseparams.spread.y = math.floor(math.max(1, noiseparams.spread.y)) + noiseparams.spread.z = math.floor(math.max(1, noiseparams.spread.z)) + return noiseparams +end + minetest.register_on_player_receive_fields(function(player, formname, fields) if formname == "perlin_explorer:analyze" and fields.done then local noiseparams = formspec_states[player:get_player_name()].noiseparams @@ -917,6 +929,7 @@ minetest.register_on_player_receive_fields(function(player, formname, fields) lacunarity = lacunarity, flags = build_flags_string(eased, absvalue), } + noiseparams = fix_noiseparams(noiseparams) -- Open analyze window if do_analyze then formspec_states[player:get_player_name()].noiseparams = noiseparams