Fix default value handling during set (allows bool settings to be set to false), add game rules: doMobSpawning, disableRaids, doWeatherCycle, doFireTick

This commit is contained in:
teknomunk 2024-05-30 21:36:16 -05:00
parent d02ddae55b
commit 25e4aa5983
9 changed files with 38 additions and 7 deletions

@ -30,7 +30,11 @@ local tunable_class = {}
function tunable_class:set(value)
local self_type = self.type
if type(value) == "string" then
self[1] = self_type.from_string(value) or self.default
local new_value = self_type.from_string(value)
if new_value == nil then new_value = self.default end
minetest.log("action","new_value="..dump(new_value))
self[1] = new_value
else
self[1] = value
end

@ -1,5 +1,5 @@
name = mcl_mobs
author = PilzAdam
description = Adds a mob API for mods to add animals or monsters, etc.
depends = mcl_particles, mcl_luck
depends = mcl_particles, mcl_luck, vl_tuning
optional_depends = mcl_weather, mcl_explosions, mcl_hunger, mcl_worlds, invisibility, lucky_block, cmi, doc_identifier, mcl_armor, mcl_portals, mcl_experience, mcl_sculk

@ -1,7 +1,12 @@
--lua locals
local S = minetest.get_translator("mcl_mobs")
local math, vector, minetest, mcl_mobs = math, vector, minetest, mcl_mobs
local mob_class = mcl_mobs.mob_class
local gamerule_doMobSpawning = vl_tuning.setting("gamerule:doMobSpawning", "bool", {
description = S("Whether mobs should spawn naturally, or via global spawning logic, such as for cats, phantoms, patrols, wandering traders, or zombie sieges. Does not affect special spawning attempts, like monster spawners, raids, or iron golems."), default = true
})
local modern_lighting = minetest.settings:get_bool("mcl_mobs_modern_lighting", true)
local nether_threshold = tonumber(minetest.settings:get("mcl_mobs_nether_threshold")) or 11
local end_threshold = tonumber(minetest.settings:get("mcl_mobs_end_threshold")) or 0
@ -905,8 +910,6 @@ end
mcl_mobs.spawn_group = spawn_group
local S = minetest.get_translator("mcl_mobs")
minetest.register_chatcommand("spawn_mob",{
privs = { debug = true },
description=S("spawn_mob is a chatcommand that allows you to type in the name of a mob without 'typing mobs_mc:' all the time like so; 'spawn_mob spider'. however, there is more you can do with this special command, currently you can edit any number, boolean, and string variable you choose with this format: spawn_mob 'any_mob:var<mobs_variable=variable_value>:'. any_mob being your mob of choice, mobs_variable being the variable, and variable value being the value of the chosen variable. and example of this format: \n spawn_mob skeleton:var<passive=true>:\n this would spawn a skeleton that wouldn't attack you. REMEMBER-THIS> when changing a number value always prefix it with 'NUM', example: \n spawn_mob skeleton:var<jump_height=NUM10>:\n this setting the skelly's jump height to 10. if you want to make multiple changes to a mob, you can, example: \n spawn_mob skeleton:var<passive=true>::var<jump_height=NUM10>::var<fly_in=air>::var<fly=true>:\n etc."),
@ -1187,6 +1190,7 @@ if mobs_spawn then
local timer = 0
minetest.register_globalstep(function(dtime)
if not gamerule_doMobSpawning[1] then return end
timer = timer + dtime
if timer < WAIT_FOR_SPAWN_ATTEMPT then return end

@ -2,6 +2,10 @@
mcl_raids = {}
local S = minetest.get_translator(minetest.get_current_modname())
local gamerule_disableRaids = vl_tuning.setting("gamerule:disableRaids", "bool", {
description = S("Whether raids are disabled"), default = false,
})
-- Define the amount of illagers to spawn each wave.
local waves = {
{
@ -291,6 +295,8 @@ mcl_events.register_event("raid",{
exclusive_to_area = 128,
enable_bossbar = true,
cond_start = function(self)
if gamerule_disableRaids[1] then return false end
--minetest.log("Cond start raid")
local r = {}
for _,p in pairs(minetest.get_connected_players()) do

@ -1,3 +1,3 @@
name = mcl_raids
author = PrairieWind
depends = mcl_events, mobs_mc, mcl_potions, mcl_bells, mcl_achievements
depends = mcl_events, mobs_mc, mcl_potions, mcl_bells, mcl_achievements, vl_tuning

@ -1,5 +1,5 @@
name = mcl_weather
author = xeranas
description = Weather and sky handling: Rain, snow, thunderstorm, End and Nether ambience
depends = mcl_init, mcl_worlds
depends = mcl_init, mcl_worlds, vl_tuning
optional_depends = lightning

@ -2,6 +2,10 @@ local S = minetest.get_translator(minetest.get_current_modname())
local math = math
local gamerule_doWeatherCycle = vl_tuning.setting("gamerule:doWeatherCycle", "bool", {
description = S("Whether the weather can change naturally. The /weather command can still change weather."), default = true
})
-- weather states, 'none' is default, other states depends from active mods
mcl_weather.state = "none"
@ -126,6 +130,8 @@ end
local t, wci = 0, mcl_weather.check_interval
minetest.register_globalstep(function(dtime)
if not gamerule_doWeatherCycle[1] then return end
t = t + dtime
if t < wci then return end
t = 0

@ -7,6 +7,9 @@ local modpath = minetest.get_modpath(modname)
local S = minetest.get_translator(modname)
local has_mcl_portals = minetest.get_modpath("mcl_portals")
local gamerule_doFireTick = vl_tuning.setting("gamerule:doFireTick", "bool", {
description = S("Whether fire should spread and naturally extinguish"), default = true
})
local set_node = minetest.set_node
local get_node = minetest.get_node
@ -366,6 +369,8 @@ else -- Fire enabled
chance = 12,
catch_up = false,
action = function(pos)
if not gamerule_doFireTick[1] then return end
local p = get_ignitable(pos)
if p then
spawn_fire(p)
@ -383,6 +388,8 @@ else -- Fire enabled
chance = 9,
catch_up = false,
action = function(pos)
if not gamerule_doFireTick[1] then return end
local p=get_ignitable_by_lava(pos)
if p then
spawn_fire(p)
@ -397,6 +404,8 @@ else -- Fire enabled
chance = 3,
catch_up = false,
action = function(pos)
if not gamerule_doFireTick[1] then return end
local p=has_flammable(pos)
if p then
local n=minetest.get_node_or_nil(p)
@ -418,6 +427,8 @@ else -- Fire enabled
chance = 18,
catch_up = false,
action = function(pos)
if not gamerule_doFireTick[1] then return end
local p = has_flammable(pos)
if not p then
return

@ -1,3 +1,3 @@
name = mcl_fire
depends = mcl_core, mcl_worlds, mcl_sounds, mcl_particles, mcl_util
optional_depends = mcl_portals
optional_depends = mcl_portals, vl_tuning