Skip to content

Commit 6df3fb7

Browse files
Add weather and stop commands
1 parent 4d6fad6 commit 6df3fb7

File tree

9 files changed

+161
-7
lines changed

9 files changed

+161
-7
lines changed

.vscode/settings.json

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,10 @@
11
{
22
"Lua.workspace.library": [
3-
"/home/nolan/.config/Code/User/globalStorage/sumneko.lua/addonManager/addons/minetest/module/library"
3+
"C:/Users/Nolan/AppData/Roaming/Code/User/globalStorage/sumneko.lua/addonManager/addons/minetest/module/library"
44
],
55
"Lua.diagnostics.disable": [
6-
"undefined-field",
76
"cast-local-type",
7+
"undefined-field"
88
],
99
"Lua.diagnostics.globals": [
1010
"mcl_formspec",
@@ -30,7 +30,10 @@
3030
"better_command_blocks",
3131
"mcl_gamemode",
3232
"mcl_experience",
33-
"awards"
33+
"awards",
34+
"mcl_weather",
35+
"weather",
36+
"weather_mod"
3437
],
3538
"Lua.workspace.checkThirdParty": false,
3639
}

API/parsing.lua

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -596,8 +596,8 @@ function better_commands.parse_time_string(time, absolute)
596596
-- The pattern shouldn't let through any negative numbers... but just in case
597597
if amount < 0 then return nil, S("Amount must not be negative") end
598598
if unit == "s" then
599-
local second_multiplier = tonumber(minetest.settings:get("time_speed")) or 72
600-
amount = amount * second_multiplier / 3.6 -- (3.6s = 1 millihour)
599+
local tps = tonumber(minetest.settings:get("time_speed")) or 72
600+
amount = amount * tps / 3.6 -- (3.6s = 1 millihour)
601601
elseif unit == "d" then
602602
amount = amount * 24000
603603
elseif unit ~= "t" then

API/register.lua

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -36,6 +36,8 @@ function better_commands.register_command(name, def)
3636
end
3737
end
3838
end
39+
else
40+
return success, nil, count
3941
end
4042
return success, "", count --don't actually send messages
4143
end

CHANGELOG.md

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,13 @@
11
# Changelog
22

3+
## v3.0
4+
### New features
5+
* Added `/stop` command
6+
* Added `/weather` command
7+
* Added `/toggledownfall` command
8+
### Bugfixes
9+
* Leaving out arguments no longer fails to show the `params` string.
10+
311
## v2.0 (May 31, 2024)
412
### New features
513
* Added `gamemode`/`m` selector argument

COMMANDS/COMMANDS.lua

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,8 @@ local command_files = {
1818
"spawnpoint",
1919
"clear",
2020
"settings",
21+
"stop",
22+
"weather",
2123
}
2224

2325
local mcl_only = {

COMMANDS/clear.lua

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -126,7 +126,7 @@ better_commands.register_command("clear", {
126126
end
127127
end
128128
if count < 1 then
129-
return false, better_commands.error(S("No player was found"))
129+
return false, better_commands.error(S("No player was found")), 0
130130
elseif count == 1 then
131131
if all and remove_max == -1 then
132132
return true, S("Removed all items from player @1", last), 1

COMMANDS/stop.lua

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
local S = minetest.get_translator(minetest.get_current_modname())
2+
3+
better_commands.register_command("stop", {
4+
description = "Stops the server",
5+
privs = {server = true},
6+
func = function(name, param, context)
7+
minetest.request_shutdown(S("Server stopping."), true, 0)
8+
return true, "", 1
9+
end
10+
})

COMMANDS/weather.lua

Lines changed: 119 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,119 @@
1+
local S = minetest.get_translator(minetest.get_current_modname())
2+
3+
local set_weather, get_weather, validate_weather
4+
5+
if better_commands.mcl and minetest.settings:get_bool("mcl_doWeatherCycle", true) and mcl_weather then
6+
---@param w string
7+
---@param end_time? integer
8+
---@return boolean, string?
9+
set_weather = function(w, end_time)
10+
if w == "clear" then w = "none" end
11+
return mcl_weather.change_weather(w or "none", end_time)
12+
end
13+
14+
---@return string
15+
get_weather = mcl_weather.get_weather
16+
17+
---@param w string
18+
---@return string?
19+
validate_weather = function (w)
20+
if mcl_weather.reg_weathers and mcl_weather.reg_weathers[w] then
21+
return w
22+
else
23+
return
24+
end
25+
end
26+
elseif minetest.get_modpath("weather") and weather and weather_mod then
27+
---@param w string
28+
---@return boolean
29+
set_weather = function(w)
30+
if w == "clear" then w = "none" end
31+
weather.type = w or "none"
32+
weather_mod.handle_lightning()
33+
weather_mod.handle_weather_change({type = w or "none"})
34+
return true
35+
end
36+
37+
---@return string
38+
get_weather = function() return weather.type end
39+
40+
---@param w string
41+
---@return string?
42+
validate_weather = function (w)
43+
if w == "clear" then return "none" end
44+
if not weather_mod.registered_downfalls[w] then
45+
for downfall in pairs(weather_mod.registered_downfalls) do
46+
if downfall:match("[%w_]+:"..w) then
47+
return downfall
48+
end
49+
end
50+
return
51+
end
52+
return w
53+
end
54+
else -- Don't bother registering the commands if there's no weather mod.
55+
return
56+
end
57+
58+
better_commands.register_command("weather", {
59+
description = "Sets or outputs the current weather",
60+
privs = {server = true},
61+
params = "query|"..
62+
(better_commands.mcl and "(" or "")..
63+
"<weather>"..
64+
(better_commands.mcl and " [<duration>])" or ""),
65+
func = function (name, param, context)
66+
local split_param, err = better_commands.parse_params(param)
67+
if err or not split_param then return false, err, 0 end
68+
if not split_param[1] then
69+
return false, nil, 0
70+
end
71+
if split_param[1][3] == "query" then
72+
if split_param[2] then
73+
return false, better_commands.error(S("Unexpected argument: @1", split_param[2][3])), 0
74+
end
75+
local w = get_weather()
76+
if w == "none" then w = "clear" end
77+
return true, S("Weather state is: @1", w), 1
78+
end
79+
local w = validate_weather(split_param[1][3])
80+
if w then
81+
local end_time
82+
if split_param[2] then
83+
if not better_commands.mcl then
84+
return false, better_commands.error(S("Unexpected argument: @1", split_param[2][3])), 0
85+
else
86+
local duration, err = better_commands.parse_time_string(split_param[2][3], true)
87+
if err or not duration then return false, err, 0 end
88+
local tps = tonumber(minetest.settings:get("time_speed"))
89+
-- Don't ask how the math works; I already forgot.
90+
local duration_s = duration*24000/(tps/3.6)
91+
end_time = minetest.get_gametime() + duration_s
92+
end
93+
end
94+
set_weather(w, end_time)
95+
return true, S("Set weather to @1", split_param[1][3])
96+
else
97+
return false, S("Invalid weather: @1", split_param[1][3])
98+
end
99+
end
100+
})
101+
102+
better_commands.register_command("toggledownfall", {
103+
description = "Toggles weather",
104+
privs = {server = true},
105+
func = function (name, param, context)
106+
local w = get_weather()
107+
if w == "none" or w == "clear" then
108+
local new_weather = validate_weather("rain")
109+
if new_weather then
110+
set_weather(new_weather)
111+
else
112+
return false, S("No weather called 'rain'"), 0
113+
end
114+
else
115+
set_weather("none")
116+
end
117+
return true, S("Toggled downfall"), 1
118+
end
119+
})

TODO.md

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,16 @@
11
# TODO
22
A place for me to write out my future plans. I decide what to do next [randomly](https://wheelofnames.com/24r-ygp) (yes, this is genuinely how I do it).
33

4+
## Short-term goals
5+
Things that *must* be done before the next release
6+
- [ ] `/give <player> <item_without_metadata> <count>` only gives 1 item.
7+
- Items with metadata work fine.
8+
9+
10+
11+
12+
## Long-term goals
13+
Things that I hope to do *eventually*.
414
- [ ] Add scoreboard playerlist
515
- [x] Add scoreboard nametags
616
- [ ] Make output match ACOVG's (error messages, number results, etc.)
@@ -84,7 +94,7 @@ A place for me to write out my future plans. I decide what to do next [randomly]
8494
- [ ] `ride`?
8595
- [ ] `seed`
8696
- [ ] `setidletimeout`?
87-
- [ ] `stop`
97+
- [x] `stop`
8898
- [ ] `structure`?
8999
- [x] `summon`
90100
- [ ] `tag`

0 commit comments

Comments
 (0)