Skip to content

Commit 835c9ce

Browse files
Changed way too much before committing
1 parent b0012da commit 835c9ce

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

43 files changed

+343
-238
lines changed

.gitignore

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
.qodo

.vscode/settings.json

Lines changed: 30 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,5 @@
11
{
2-
"Lua.workspace.library": [
3-
"C:/Users/Nolan/AppData/Roaming/Code/User/globalStorage/sumneko.lua/addonManager/addons/minetest/module/library"
4-
],
5-
"Lua.diagnostics.disable": [
6-
"cast-local-type",
7-
"undefined-field"
8-
],
2+
"editor.inlineSuggest.showToolbar": "always",
93
"Lua.diagnostics.globals": [
104
"mcl_formspec",
115
"mcl_item_id",
@@ -28,12 +22,36 @@
2822
"core",
2923
"better_commands",
3024
"better_command_blocks",
31-
"mcl_gamemode",
32-
"mcl_experience",
33-
"awards",
25+
"nether",
26+
"vector",
27+
"pipeworks",
28+
"mcl_burning",
29+
"fire_plus",
3430
"mcl_weather",
31+
"weather_mod",
32+
"mcl_damage",
3533
"weather",
36-
"weather_mod"
34+
"awards",
35+
"mcl_craftguide",
36+
"mcl_particles",
37+
"screwdriver",
38+
"mcl_autogroup",
39+
"farming",
40+
"hopper",
41+
"stamina",
42+
"mcl_banners",
43+
"mcl_hunger",
44+
"mcl_experience",
45+
"mcl_gamemode"
46+
],
47+
"Lua.diagnostics.disable": [
48+
"undefined-field"
49+
],
50+
"Lua.workspace.userThirdParty": [
51+
"C:\\Portable\\LuaLSAddons"
52+
],
53+
"Lua.workspace.library": [
54+
"C:/Portable/LuaLSAddons/luanti-lls-definitions/library"
3755
],
38-
"Lua.workspace.checkThirdParty": false,
56+
"Lua.workspace.checkThirdParty": false
3957
}

API/API.lua

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,12 @@
1-
---@alias contextTable {executor: minetest.ObjectRef, pos: vector.Vector, rot: vector.Vector, anchor: string, origin: string, [any]: any}
1+
---@alias contextTable {executor: core.ObjectRef, pos: vector.Vector, rot: vector.Vector, anchor: string, origin: string, [any]: any}
22
---@alias splitParam {[1]: integer, [2]: integer, [3]: string, type: string, any: string}
33
---@alias betterCommandFunc fun(name: string, param: string, context: contextTable): success: boolean, message: string?, count: number
44
---@alias betterCommandDef {description: string, param?: string, privs: table<string, boolean>, func: betterCommandFunc, real_func: betterCommandFunc?}
55

66
--local bc = better_commands
77

88

9-
local modpath = minetest.get_modpath("better_commands")
9+
local modpath = core.get_modpath("better_commands")
1010

1111
---Runs a file
1212
---@param file string
@@ -37,7 +37,7 @@ end
3737

3838
better_commands.paused = false
3939
local timer = 0
40-
minetest.register_globalstep(function(dtime)
40+
core.register_globalstep(function(dtime)
4141
if better_commands.paused then return end
4242
timer = timer + dtime
4343
if timer > better_commands.settings.save_interval then
@@ -48,7 +48,7 @@ minetest.register_globalstep(function(dtime)
4848
end
4949
end)
5050

51-
minetest.register_on_joinplayer(function(player)
51+
core.register_on_joinplayer(function(player)
5252
better_commands.sidebars[player:get_player_name()] = {}
5353
end)
5454

API/damage.lua

Lines changed: 10 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,31 +1,32 @@
11
--local bc = better_commands
22

33
---Deals damage; copied from Mineclonia's mcl_util.deal_damage
4-
---@param target minetest.ObjectRef
4+
---@param target core.ObjectRef
55
---@param damage integer
66
---@param reason table?
77
---@param damage_immortal? boolean
88
function better_commands.deal_damage(target, damage, reason, damage_immortal)
9+
910
local luaentity = target:get_luaentity()
1011

1112
if luaentity then
1213
if luaentity.deal_damage then -- Mobs Redo/Mobs MC
13-
--minetest.log("deal_damage")
14+
--core.log("deal_damage")
1415
luaentity:deal_damage(damage, reason or {type = "generic"})
1516
return
1617
elseif luaentity.hurt then -- Animalia
17-
--minetest.log("hurt/indicate_damage")
18+
--core.log("hurt/indicate_damage")
1819
luaentity:hurt(damage)
1920
luaentity:indicate_damage()
2021
return
2122
elseif luaentity.health then -- Mobs Redo/Mobs MC/NSSM
2223
-- local puncher = mcl_reason and mcl_reason.direct or target
2324
-- target:punch(puncher, 1.0, {full_punch_interval = 1.0, damage_groups = {fleshy = damage}}, vector.direction(puncher:get_pos(), target:get_pos()), damage)
2425
if luaentity.health > 0 then
25-
--minetest.log("luaentity.health")
26+
--core.log("luaentity.health")
2627
luaentity.health = luaentity.health - damage
2728
luaentity:check_for_death(reason)
28-
--minetest.log(luaentity.health)
29+
--core.log(luaentity.health)
2930
end
3031
return
3132
end
@@ -35,15 +36,16 @@ function better_commands.deal_damage(target, damage, reason, damage_immortal)
3536
local armorgroups = target:get_armor_groups()
3637

3738
if hp > 0 and armorgroups and (damage_immortal or not armorgroups.immortal) then
38-
--minetest.log("set_hp")
39+
--core.log("set_hp")
3940
target:set_hp(hp - damage, reason)
4041
end
41-
--minetest.log("nothing")
42+
--core.log("nothing")
4243
end
4344

4445
-- Make sure players always die when /killed
45-
minetest.register_on_player_hpchange(function(player, hp_change, reason)
46+
core.register_on_player_hpchange(function(player, hp_change, reason)
4647
if reason.better_commands == "kill" then
48+
---@diagnostic disable-next-line: redundant-return-value
4749
return math.min(hp_change, -1000000000), true
4850
end
4951
return hp_change

API/entity.lua

Lines changed: 17 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,15 @@
11
--local bc = better_commands
2-
local S = minetest.get_translator(minetest.get_current_modname())
2+
local S = core.get_translator(core.get_current_modname())
33

44
---Gets the name of an entity
5-
---@param obj minetest.ObjectRef|vector.Vector
5+
---@param obj core.ObjectRef|vector.Vector
66
---@param no_id? boolean
77
---@return string
88
function better_commands.get_entity_name(obj, no_id, no_format)
99
if not obj.is_player then
1010
return S("Command Block")
1111
end
12+
---@cast obj -vector.Vector
1213
if obj:is_player() then
1314
local player_name = obj:get_player_name()
1415
if no_format then return player_name end
@@ -42,9 +43,10 @@ function better_commands.get_entity_name(obj, no_id, no_format)
4243
end
4344

4445
---Gets an entity's current rotation
45-
---@param obj minetest.ObjectRef|vector.Vector
46+
---@param obj core.ObjectRef|vector.Vector
4647
---@return vector.Vector
4748
function better_commands.get_entity_rotation(obj)
49+
---@diagnostic disable-next-line: param-type-mismatch
4850
if obj.is_player and obj:is_player() then
4951
return {x = obj:get_look_vertical(), y = obj:get_look_horizontal(), z = 0}
5052
elseif obj.get_rotation then
@@ -55,7 +57,7 @@ function better_commands.get_entity_rotation(obj)
5557
end
5658

5759
---Sets an entity's rotation
58-
---@param obj minetest.ObjectRef|any
60+
---@param obj core.ObjectRef|any
5961
---@param rotation vector.Vector
6062
function better_commands.set_entity_rotation(obj, rotation)
6163
if not obj.is_player then return end
@@ -68,11 +70,13 @@ function better_commands.set_entity_rotation(obj, rotation)
6870
end
6971

7072
---Takes an object and a position, returns the rotation at which the object points at the position
71-
---@param obj minetest.ObjectRef|vector.Vector
73+
---@param obj core.ObjectRef|vector.Vector
7274
---@param pos vector.Vector
7375
---@return vector.Vector
7476
function better_commands.point_at_pos(obj, pos)
77+
---@diagnostic disable-next-line: param-type-mismatch
7578
local obj_pos = obj.get_pos and obj:get_pos() or obj
79+
---@diagnostic disable-next-line: param-type-mismatch
7680
if obj:is_player() then
7781
obj_pos.y = obj_pos.y + obj:get_properties().eye_height
7882
end
@@ -88,8 +92,8 @@ end
8892
---@return contextTable?
8993
function better_commands.complete_context(name, context)
9094
if not context then context = {} end
91-
context.executor = context.executor or minetest.get_player_by_name(name)
92-
if not context.executor then minetest.log("error", "Missing executor") return end
95+
context.executor = context.executor or core.get_player_by_name(name)
96+
if not context.executor then core.log("error", "Missing executor") return end
9397
context.pos = context.pos or context.executor:get_pos()
9498
context.rot = context.rot or better_commands.get_entity_rotation(context.executor)
9599
--context.anchor = context.anchor or "feet"
@@ -98,7 +102,7 @@ function better_commands.complete_context(name, context)
98102
end
99103

100104
function better_commands.entity_from_alias(alias, list)
101-
if minetest.registered_entities[alias] then return alias end
105+
if core.registered_entities[alias] then return alias end
102106
local entities = better_commands.unique_entities[alias]
103107
if not entities then return end
104108
if list then return entities end
@@ -139,7 +143,7 @@ end
139143

140144
---Handles rotation in various commands
141145
---@param context contextTable
142-
---@param victim minetest.ObjectRef|vector.Vector
146+
---@param victim core.ObjectRef|vector.Vector
143147
---@param split_param splitParam[]
144148
---@param i integer
145149
---@return vector.Vector? result
@@ -165,12 +169,14 @@ function better_commands.get_tp_rot(context, victim, split_param, i)
165169
if split_param[i+1].type == "selector" then
166170
local targets, err = better_commands.parse_selector(split_param[i+1], context, true)
167171
if err or not targets then return nil, err end
172+
---@diagnostic disable-next-line: param-type-mismatch
168173
local target_pos = targets[1].is_player and targets[1]:get_pos() or targets[1]
169174
---@diagnostic disable-next-line: param-type-mismatch
170175
victim_rot = better_commands.point_at_pos(victim, target_pos)
171176
elseif split_param[i+1][3] == "entity" and split_param[i+2].type == "selector" then
172177
local targets, err = better_commands.parse_selector(split_param[i+2], context, true)
173178
if err or not targets then return nil, err end
179+
---@diagnostic disable-next-line: param-type-mismatch
174180
local target_pos = targets[1].is_player and targets[1]:get_pos() or targets[1]
175181
---@diagnostic disable-next-line: param-type-mismatch
176182
victim_rot = better_commands.point_at_pos(victim, target_pos)
@@ -188,15 +194,15 @@ function better_commands.get_tp_rot(context, victim, split_param, i)
188194
end
189195

190196
---Gets a player's gamemode
191-
---@param player minetest.Player
197+
---@param player core.Player
192198
---@return string?
193199
function better_commands.get_gamemode(player)
194200
if player.is_player and player:is_player() then
195201
local gamemode
196202
if better_commands.mcl then
197203
gamemode = mcl_gamemode.get_gamemode(player)
198204
else
199-
gamemode = minetest.is_creative_enabled(player:get_player_name()) and "creative" or "survival"
205+
gamemode = core.is_creative_enabled(player:get_player_name()) and "creative" or "survival"
200206
end
201207
return gamemode
202208
end

API/parsing.lua

Lines changed: 14 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -1,15 +1,17 @@
11
--local bc = better_commands
2-
local S = minetest.get_translator(minetest.get_current_modname())
2+
local S = core.get_translator(core.get_current_modname())
33

44
---Parses parameters out of a string
55
---@param str string
66
---@return splitParam[] split_param
77
function better_commands.parse_params(str)
8+
str = " "..str -- Don't ask
89
local i = 1
910
local tmp
1011
local found = {}
1112
-- selectors, @?[data]
1213
repeat
14+
-- p, a, r, s, e, and n are obviously the selectors but I just like the fact that they include the word "parse" (it was even better before I added @n)
1315
tmp = {str:find("(@[parsen])%s*(%[.-%])", i)}
1416
if tmp[1] then
1517
i = tmp[2] + 1
@@ -54,7 +56,7 @@ function better_commands.parse_params(str)
5456
i = 1
5557
repeat
5658
-- modname:id count wear (everything but id optional)
57-
tmp = {str:find("(%s[_%w]*:?[_%w]+)%s*(%d*)%s*(%d*)", i)}
59+
tmp = {str:find("%s([_%w]*:?[_%w]+)%s*(%d*)%s*(%d*)", i)}
5860
if tmp[1] then
5961
tmp[1] = tmp[1] + 1 -- ignore the space
6062
local overlap
@@ -172,15 +174,15 @@ end
172174
---@param selector_data splitParam
173175
---@param context contextTable
174176
---@param require_one? boolean
175-
---@return (minetest.ObjectRef|vector.Vector)[]? results
177+
---@return (core.ObjectRef|vector.Vector)[]? results
176178
---@return string? err
177179
---@nodiscard
178180
function better_commands.parse_selector(selector_data, context, require_one)
179181
local caller = context.executor
180182
local pos = table.copy(context.pos)
181183
local result = {}
182184
if selector_data[3]:sub(1,1) ~= "@" then
183-
local player = minetest.get_player_by_name(selector_data[3])
185+
local player = core.get_player_by_name(selector_data[3])
184186
if not player then
185187
return nil, S("No player was found")
186188
else
@@ -204,13 +206,13 @@ function better_commands.parse_selector(selector_data, context, require_one)
204206
return {caller}
205207
end
206208
-- Always include players
207-
for _, player in pairs(minetest.get_connected_players()) do
209+
for _, player in pairs(core.get_connected_players()) do
208210
if player:get_pos() then
209211
table.insert(objects, player)
210212
end
211213
end
212214
if selector == "@e" or selector == "@n" then
213-
for _, luaentity in pairs(minetest.luaentities) do
215+
for _, luaentity in pairs(core.luaentities) do
214216
if luaentity.object:get_pos() then
215217
table.insert(objects, luaentity.object)
216218
end
@@ -220,7 +222,7 @@ function better_commands.parse_selector(selector_data, context, require_one)
220222
if selector == "@r" or selector == "@p" then
221223
for _, arg in ipairs(arg_table) do
222224
if arg[1] == "type" and arg[2]:lower() ~= "player" then
223-
for _, luaentity in pairs(minetest.luaentities) do
225+
for _, luaentity in pairs(core.luaentities) do
224226
if luaentity.object:get_pos() then
225227
table.insert(objects, luaentity.object)
226228
end
@@ -491,7 +493,7 @@ end
491493

492494
---Parses item data, returning an itemstack or err message
493495
---@param item_data splitParam
494-
---@return minetest.ItemStack? result
496+
---@return core.ItemStack? result
495497
---@return string? err
496498
---@nodiscard
497499
function better_commands.parse_item(item_data, ignore_count)
@@ -535,7 +537,7 @@ end
535537

536538
---Parses node data, returns node and metadata table
537539
---@param item_data splitParam
538-
---@return minetest.Node? node
540+
---@return core.Node? node
539541
---@return table? metadata
540542
---@return string? err
541543
---@nodiscard
@@ -547,7 +549,7 @@ function better_commands.parse_node(item_data)
547549
if not itemstring then
548550
return nil, nil, S("Unknown node '@1'", item_data[3])
549551
end
550-
if not minetest.registered_nodes[itemstring] then
552+
if not core.registered_nodes[itemstring] then
551553
return nil, nil, S("'@1' is not a node", itemstring)
552554
end
553555
if item_data.type == "item" and not item_data.extra_data then
@@ -595,7 +597,7 @@ function better_commands.parse_time_string(time, absolute)
595597
-- The pattern shouldn't let through any negative numbers... but just in case
596598
if amount < 0 then return nil, S("Amount must not be negative") end
597599
if unit == "s" then
598-
local tps = tonumber(minetest.settings:get("time_speed")) or 72
600+
local tps = tonumber(core.settings:get("time_speed")) or 72
599601
amount = amount * tps / 3.6 -- (3.6s = 1 millihour)
600602
elseif unit == "d" then
601603
amount = amount * 24000
@@ -604,7 +606,7 @@ function better_commands.parse_time_string(time, absolute)
604606
end
605607

606608
if not absolute then
607-
result = (minetest.get_timeofday() + (amount/24000)) % 1
609+
result = (core.get_timeofday() + (amount/24000)) % 1
608610
elseif better_commands.settings.acovg_time then
609611
result = ((amount + 6000)/24000) % 1
610612
else

0 commit comments

Comments
 (0)