Skip to content

Commit ea5d631

Browse files
authoredJan 21, 2021
ObjectRef: fix some v3f checks (#10602)
1 parent d92da47 commit ea5d631

File tree

2 files changed

+29
-31
lines changed

2 files changed

+29
-31
lines changed
 

Diff for: ‎doc/lua_api.txt

+12-11
Original file line numberDiff line numberDiff line change
@@ -6239,21 +6239,22 @@ object you are working with still exists.
62396239
`frame_loop`.
62406240
* `set_animation_frame_speed(frame_speed)`
62416241
* `frame_speed`: number, default: `15.0`
6242-
* `set_attach(parent, bone, position, rotation, forced_visible)`
6243-
* `bone`: string
6244-
* `position`: `{x=num, y=num, z=num}` (relative)
6245-
* `rotation`: `{x=num, y=num, z=num}` = Rotation on each axis, in degrees
6242+
* `set_attach(parent[, bone, position, rotation, forced_visible])`
6243+
* `bone`: string. Default is `""`, the root bone
6244+
* `position`: `{x=num, y=num, z=num}`, relative, default `{x=0, y=0, z=0}`
6245+
* `rotation`: `{x=num, y=num, z=num}` = Rotation on each axis, in degrees.
6246+
Default `{x=0, y=0, z=0}`
62466247
* `forced_visible`: Boolean to control whether the attached entity
6247-
should appear in first person.
6248+
should appear in first person. Default `false`.
62486249
* `get_attach()`: returns parent, bone, position, rotation, forced_visible,
62496250
or nil if it isn't attached.
62506251
* `get_children()`: returns a list of ObjectRefs that are attached to the
62516252
object.
62526253
* `set_detach()`
6253-
* `set_bone_position(bone, position, rotation)`
6254-
* `bone`: string
6255-
* `position`: `{x=num, y=num, z=num}` (relative)
6256-
* `rotation`: `{x=num, y=num, z=num}`
6254+
* `set_bone_position([bone, position, rotation])`
6255+
* `bone`: string. Default is `""`, the root bone
6256+
* `position`: `{x=num, y=num, z=num}`, relative, `default {x=0, y=0, z=0}`
6257+
* `rotation`: `{x=num, y=num, z=num}`, default `{x=0, y=0, z=0}`
62576258
* `get_bone_position(bone)`: returns position and rotation of the bone
62586259
* `set_properties(object property table)`
62596260
* `get_properties()`: returns object property table
@@ -6581,8 +6582,8 @@ object you are working with still exists.
65816582
* `frame_speed` sets the animations frame speed. Default is 30.
65826583
* `get_local_animation()`: returns idle, walk, dig, walk_while_dig tables and
65836584
`frame_speed`.
6584-
* `set_eye_offset(firstperson, thirdperson)`: defines offset vectors for camera
6585-
per player.
6585+
* `set_eye_offset([firstperson, thirdperson])`: defines offset vectors for
6586+
camera per player. An argument defaults to `{x=0, y=0, z=0}` if unspecified.
65866587
* in first person view
65876588
* in third person view (max. values `{x=-10/10,y=-10,15,z=-5/5}`)
65886589
* `get_eye_offset()`: returns first and third person offsets.

Diff for: ‎src/script/lua_api/l_object.cpp

+17-20
Original file line numberDiff line numberDiff line change
@@ -399,7 +399,7 @@ int ObjectRef::l_get_animation(lua_State *L)
399399
if (sao == nullptr)
400400
return 0;
401401

402-
v2f frames = v2f(1,1);
402+
v2f frames = v2f(1, 1);
403403
float frame_speed = 15;
404404
float frame_blend = 0;
405405
bool frame_loop = true;
@@ -463,8 +463,8 @@ int ObjectRef::l_set_eye_offset(lua_State *L)
463463
if (player == nullptr)
464464
return 0;
465465

466-
v3f offset_first = read_v3f(L, 2);
467-
v3f offset_third = read_v3f(L, 3);
466+
v3f offset_first = readParam<v3f>(L, 2, v3f(0, 0, 0));
467+
v3f offset_third = readParam<v3f>(L, 3, v3f(0, 0, 0));
468468

469469
// Prevent abuse of offset values (keep player always visible)
470470
offset_third.X = rangelim(offset_third.X,-10,10);
@@ -537,9 +537,9 @@ int ObjectRef::l_set_bone_position(lua_State *L)
537537
if (sao == nullptr)
538538
return 0;
539539

540-
std::string bone = readParam<std::string>(L, 2);
541-
v3f position = check_v3f(L, 3);
542-
v3f rotation = check_v3f(L, 4);
540+
std::string bone = readParam<std::string>(L, 2, "");
541+
v3f position = readParam<v3f>(L, 3, v3f(0, 0, 0));
542+
v3f rotation = readParam<v3f>(L, 4, v3f(0, 0, 0));
543543

544544
sao->setBonePosition(bone, position, rotation);
545545
return 0;
@@ -554,7 +554,7 @@ int ObjectRef::l_get_bone_position(lua_State *L)
554554
if (sao == nullptr)
555555
return 0;
556556

557-
std::string bone = readParam<std::string>(L, 2);
557+
std::string bone = readParam<std::string>(L, 2, "");
558558

559559
v3f position = v3f(0, 0, 0);
560560
v3f rotation = v3f(0, 0, 0);
@@ -578,10 +578,10 @@ int ObjectRef::l_set_attach(lua_State *L)
578578
if (sao == parent)
579579
throw LuaError("ObjectRef::set_attach: attaching object to itself is not allowed.");
580580

581-
int parent_id = 0;
581+
int parent_id;
582582
std::string bone;
583-
v3f position = v3f(0, 0, 0);
584-
v3f rotation = v3f(0, 0, 0);
583+
v3f position;
584+
v3f rotation;
585585
bool force_visible;
586586

587587
sao->getAttachment(&parent_id, &bone, &position, &rotation, &force_visible);
@@ -590,9 +590,9 @@ int ObjectRef::l_set_attach(lua_State *L)
590590
old_parent->removeAttachmentChild(sao->getId());
591591
}
592592

593-
bone = readParam<std::string>(L, 3, "");
594-
position = read_v3f(L, 4);
595-
rotation = read_v3f(L, 5);
593+
bone = readParam<std::string>(L, 3, "");
594+
position = readParam<v3f>(L, 4, v3f(0, 0, 0));
595+
rotation = readParam<v3f>(L, 5, v3f(0, 0, 0));
596596
force_visible = readParam<bool>(L, 6, false);
597597

598598
sao->setAttachment(parent->getId(), bone, position, rotation, force_visible);
@@ -609,10 +609,10 @@ int ObjectRef::l_get_attach(lua_State *L)
609609
if (sao == nullptr)
610610
return 0;
611611

612-
int parent_id = 0;
612+
int parent_id;
613613
std::string bone;
614-
v3f position = v3f(0, 0, 0);
615-
v3f rotation = v3f(0, 0, 0);
614+
v3f position;
615+
v3f rotation;
616616
bool force_visible;
617617

618618
sao->getAttachment(&parent_id, &bone, &position, &rotation, &force_visible);
@@ -892,9 +892,6 @@ int ObjectRef::l_set_yaw(lua_State *L)
892892
if (entitysao == nullptr)
893893
return 0;
894894

895-
if (isNaN(L, 2))
896-
throw LuaError("ObjectRef::set_yaw: NaN value is not allowed.");
897-
898895
float yaw = readParam<float>(L, 2) * core::RADTODEG;
899896

900897
entitysao->setRotation(v3f(0, yaw, 0));
@@ -2199,7 +2196,7 @@ int ObjectRef::l_set_minimap_modes(lua_State *L)
21992196

22002197
luaL_checktype(L, 2, LUA_TTABLE);
22012198
std::vector<MinimapMode> modes;
2202-
s16 selected_mode = luaL_checkint(L, 3);
2199+
s16 selected_mode = readParam<s16>(L, 3);
22032200

22042201
lua_pushnil(L);
22052202
while (lua_next(L, 2) != 0) {

0 commit comments

Comments
 (0)
Please sign in to comment.