ObjectRef: fix some v3f checks (#10602)

This commit is contained in:
Zughy 2021-01-21 17:37:38 +00:00 committed by GitHub
parent d92da47697
commit ea5d6312c1
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 29 additions and 31 deletions

@ -6239,21 +6239,22 @@ object you are working with still exists.
`frame_loop`.
* `set_animation_frame_speed(frame_speed)`
* `frame_speed`: number, default: `15.0`
* `set_attach(parent, bone, position, rotation, forced_visible)`
* `bone`: string
* `position`: `{x=num, y=num, z=num}` (relative)
* `rotation`: `{x=num, y=num, z=num}` = Rotation on each axis, in degrees
* `set_attach(parent[, bone, position, rotation, forced_visible])`
* `bone`: string. Default is `""`, the root bone
* `position`: `{x=num, y=num, z=num}`, relative, default `{x=0, y=0, z=0}`
* `rotation`: `{x=num, y=num, z=num}` = Rotation on each axis, in degrees.
Default `{x=0, y=0, z=0}`
* `forced_visible`: Boolean to control whether the attached entity
should appear in first person.
should appear in first person. Default `false`.
* `get_attach()`: returns parent, bone, position, rotation, forced_visible,
or nil if it isn't attached.
* `get_children()`: returns a list of ObjectRefs that are attached to the
object.
* `set_detach()`
* `set_bone_position(bone, position, rotation)`
* `bone`: string
* `position`: `{x=num, y=num, z=num}` (relative)
* `rotation`: `{x=num, y=num, z=num}`
* `set_bone_position([bone, position, rotation])`
* `bone`: string. Default is `""`, the root bone
* `position`: `{x=num, y=num, z=num}`, relative, `default {x=0, y=0, z=0}`
* `rotation`: `{x=num, y=num, z=num}`, default `{x=0, y=0, z=0}`
* `get_bone_position(bone)`: returns position and rotation of the bone
* `set_properties(object property table)`
* `get_properties()`: returns object property table
@ -6581,8 +6582,8 @@ object you are working with still exists.
* `frame_speed` sets the animations frame speed. Default is 30.
* `get_local_animation()`: returns idle, walk, dig, walk_while_dig tables and
`frame_speed`.
* `set_eye_offset(firstperson, thirdperson)`: defines offset vectors for camera
per player.
* `set_eye_offset([firstperson, thirdperson])`: defines offset vectors for
camera per player. An argument defaults to `{x=0, y=0, z=0}` if unspecified.
* in first person view
* in third person view (max. values `{x=-10/10,y=-10,15,z=-5/5}`)
* `get_eye_offset()`: returns first and third person offsets.

@ -399,7 +399,7 @@ int ObjectRef::l_get_animation(lua_State *L)
if (sao == nullptr)
return 0;
v2f frames = v2f(1,1);
v2f frames = v2f(1, 1);
float frame_speed = 15;
float frame_blend = 0;
bool frame_loop = true;
@ -463,8 +463,8 @@ int ObjectRef::l_set_eye_offset(lua_State *L)
if (player == nullptr)
return 0;
v3f offset_first = read_v3f(L, 2);
v3f offset_third = read_v3f(L, 3);
v3f offset_first = readParam<v3f>(L, 2, v3f(0, 0, 0));
v3f offset_third = readParam<v3f>(L, 3, v3f(0, 0, 0));
// Prevent abuse of offset values (keep player always visible)
offset_third.X = rangelim(offset_third.X,-10,10);
@ -537,9 +537,9 @@ int ObjectRef::l_set_bone_position(lua_State *L)
if (sao == nullptr)
return 0;
std::string bone = readParam<std::string>(L, 2);
v3f position = check_v3f(L, 3);
v3f rotation = check_v3f(L, 4);
std::string bone = readParam<std::string>(L, 2, "");
v3f position = readParam<v3f>(L, 3, v3f(0, 0, 0));
v3f rotation = readParam<v3f>(L, 4, v3f(0, 0, 0));
sao->setBonePosition(bone, position, rotation);
return 0;
@ -554,7 +554,7 @@ int ObjectRef::l_get_bone_position(lua_State *L)
if (sao == nullptr)
return 0;
std::string bone = readParam<std::string>(L, 2);
std::string bone = readParam<std::string>(L, 2, "");
v3f position = v3f(0, 0, 0);
v3f rotation = v3f(0, 0, 0);
@ -578,10 +578,10 @@ int ObjectRef::l_set_attach(lua_State *L)
if (sao == parent)
throw LuaError("ObjectRef::set_attach: attaching object to itself is not allowed.");
int parent_id = 0;
int parent_id;
std::string bone;
v3f position = v3f(0, 0, 0);
v3f rotation = v3f(0, 0, 0);
v3f position;
v3f rotation;
bool force_visible;
sao->getAttachment(&parent_id, &bone, &position, &rotation, &force_visible);
@ -591,8 +591,8 @@ int ObjectRef::l_set_attach(lua_State *L)
}
bone = readParam<std::string>(L, 3, "");
position = read_v3f(L, 4);
rotation = read_v3f(L, 5);
position = readParam<v3f>(L, 4, v3f(0, 0, 0));
rotation = readParam<v3f>(L, 5, v3f(0, 0, 0));
force_visible = readParam<bool>(L, 6, false);
sao->setAttachment(parent->getId(), bone, position, rotation, force_visible);
@ -609,10 +609,10 @@ int ObjectRef::l_get_attach(lua_State *L)
if (sao == nullptr)
return 0;
int parent_id = 0;
int parent_id;
std::string bone;
v3f position = v3f(0, 0, 0);
v3f rotation = v3f(0, 0, 0);
v3f position;
v3f rotation;
bool force_visible;
sao->getAttachment(&parent_id, &bone, &position, &rotation, &force_visible);
@ -892,9 +892,6 @@ int ObjectRef::l_set_yaw(lua_State *L)
if (entitysao == nullptr)
return 0;
if (isNaN(L, 2))
throw LuaError("ObjectRef::set_yaw: NaN value is not allowed.");
float yaw = readParam<float>(L, 2) * core::RADTODEG;
entitysao->setRotation(v3f(0, yaw, 0));
@ -2199,7 +2196,7 @@ int ObjectRef::l_set_minimap_modes(lua_State *L)
luaL_checktype(L, 2, LUA_TTABLE);
std::vector<MinimapMode> modes;
s16 selected_mode = luaL_checkint(L, 3);
s16 selected_mode = readParam<s16>(L, 3);
lua_pushnil(L);
while (lua_next(L, 2) != 0) {