end,
})
+core.register_chatcommand("days", {
+ description = "Display day count",
+ func = function(name, param)
+ return true, "Current day is " .. core.get_day_count()
+ end
+})
+
core.register_chatcommand("shutdown", {
description = "shutdown server",
privs = {server=true},
* `val` is between `0` and `1`; `0` for midnight, `0.5` for midday
* `minetest.get_timeofday()`
* `minetest.get_gametime()`: returns the time, in seconds, since the world was created
+* `minetest.get_day_count()`: returns number days elapsed since world was created,
+ * accounting for time changes.
* `minetest.find_node_near(pos, radius, nodenames)`: returns pos or `nil`
* `radius`: using a maximum metric
* `nodenames`: e.g. `{"ignore", "group:tree"}` or `"default:dirt"`
void Environment::setTimeOfDay(u32 time)
{
MutexAutoLock lock(this->m_time_lock);
+ if (m_time_of_day > time)
+ m_day_count++;
m_time_of_day = time;
m_time_of_day_f = (float)time / 24000.0;
}
bool sync_f = false;
if (units > 0) {
// Sync at overflow
- if (m_time_of_day + units >= 24000)
+ if (m_time_of_day + units >= 24000) {
sync_f = true;
+ m_day_count++;
+ }
m_time_of_day = (m_time_of_day + units) % 24000;
if (sync_f)
m_time_of_day_f = (float)m_time_of_day / 24000.0;
}
}
+u32 Environment::getDayCount()
+{
+ // Atomic<u32> counter
+ return m_day_count;
+}
+
+
/*
ABMWithState
*/
args.setU64("lbm_introduction_times_version", 1);
args.set("lbm_introduction_times",
m_lbm_mgr.createIntroductionTimesString());
+ args.setU64("day_count", m_day_count);
args.writeLines(ss);
ss<<"EnvArgsEnd\n";
}
m_lbm_mgr.loadIntroductionTimes(lbm_introduction_times, m_gamedef, m_game_time);
+ try {
+ m_day_count = args.getU64("day_count");
+ } catch (SettingNotFoundException &e) {
+ // If missing, start the day counter
+ m_day_count = 0;
+ }
}
void ServerEnvironment::loadDefaultMeta()
void setDayNightRatioOverride(bool enable, u32 value);
+ u32 getDayCount();
+
// counter used internally when triggering ABMs
u32 m_added_objects;
// Overriding the day-night ratio is useful for custom sky visuals
bool m_enable_day_night_ratio_override;
u32 m_day_night_ratio_override;
+ // Days from the server start, accounts for time shift
+ // in game (e.g. /time or bed usage)
+ Atomic<u32> m_day_count;
/*
* Above: values managed by m_time_lock
*/
return 1;
}
+// get_day_count() -> int
+int ModApiEnvMod::l_get_day_count(lua_State *L)
+{
+ GET_ENV_PTR;
+
+ lua_pushnumber(L, env->getDayCount());
+ return 1;
+}
+
// get_gametime()
int ModApiEnvMod::l_get_gametime(lua_State *L)
{
API_FCT(set_timeofday);
API_FCT(get_timeofday);
API_FCT(get_gametime);
+ API_FCT(get_day_count);
API_FCT(find_node_near);
API_FCT(find_nodes_in_area);
API_FCT(find_nodes_in_area_under_air);
// get_gametime()
static int l_get_gametime(lua_State *L);
+ // get_day_count() -> int
+ static int l_get_day_count(lua_State *L);
+
// find_node_near(pos, radius, nodenames) -> pos or nil
// nodenames: eg. {"ignore", "group:tree"} or "default:dirt"
static int l_find_node_near(lua_State *L);