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
88function 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)
4243end
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
4748function 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)
5557end
5658
5759--- Sets an entity's rotation
58- --- @param obj minetest .ObjectRef| any
60+ --- @param obj core .ObjectRef| any
5961--- @param rotation vector.Vector
6062function 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)
6870end
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
7476function 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
8892--- @return contextTable ?
8993function 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)
98102end
99103
100104function 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
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)
188194end
189195
190196--- Gets a player's gamemode
191- --- @param player minetest .Player
197+ --- @param player core .Player
192198--- @return string ?
193199function 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
0 commit comments