diff options
author | Elias Fleckenstein <54945686+EliasFleckenstein03@users.noreply.github.com> | 2020-11-04 16:44:42 +0100 |
---|---|---|
committer | GitHub <noreply@github.com> | 2020-11-04 16:44:42 +0100 |
commit | 5d9ae5a91c544fc7fbd475decf47cef7e09ef8fc (patch) | |
tree | c980d614fec4a5495798be3e79e033229062c3cd /src/script/lua_api/l_object.cpp | |
parent | 28f6a79706b088c37268a59d90878220dc4ef9c7 (diff) | |
parent | 3af10766fd2b58b068e970266724d7eb10e9316b (diff) | |
download | dragonfireclient-5d9ae5a91c544fc7fbd475decf47cef7e09ef8fc.tar.xz |
Merge branch 'master' into master
Diffstat (limited to 'src/script/lua_api/l_object.cpp')
-rw-r--r-- | src/script/lua_api/l_object.cpp | 514 |
1 files changed, 260 insertions, 254 deletions
diff --git a/src/script/lua_api/l_object.cpp b/src/script/lua_api/l_object.cpp index e7394133a..5d48ee93d 100644 --- a/src/script/lua_api/l_object.cpp +++ b/src/script/lua_api/l_object.cpp @@ -39,16 +39,16 @@ with this program; if not, write to the Free Software Foundation, Inc., ObjectRef */ - -ObjectRef* ObjectRef::checkobject(lua_State *L, int narg) +ObjectRef *ObjectRef::checkobject(lua_State *L, int narg) { luaL_checktype(L, narg, LUA_TUSERDATA); void *ud = luaL_checkudata(L, narg, className); - if (!ud) luaL_typerror(L, narg, className); - return *(ObjectRef**)ud; // unbox pointer + if (!ud) + luaL_typerror(L, narg, className); + return *(ObjectRef **)ud; // unbox pointer } -ServerActiveObject* ObjectRef::getobject(ObjectRef *ref) +ServerActiveObject *ObjectRef::getobject(ObjectRef *ref) { ServerActiveObject *co = ref->m_object; if (co && co->isGone()) @@ -56,24 +56,24 @@ ServerActiveObject* ObjectRef::getobject(ObjectRef *ref) return co; } -LuaEntitySAO* ObjectRef::getluaobject(ObjectRef *ref) +LuaEntitySAO *ObjectRef::getluaobject(ObjectRef *ref) { ServerActiveObject *obj = getobject(ref); if (obj == NULL) return NULL; if (obj->getType() != ACTIVEOBJECT_TYPE_LUAENTITY) return NULL; - return (LuaEntitySAO*)obj; + return (LuaEntitySAO *)obj; } -PlayerSAO* ObjectRef::getplayersao(ObjectRef *ref) +PlayerSAO *ObjectRef::getplayersao(ObjectRef *ref) { ServerActiveObject *obj = getobject(ref); if (obj == NULL) return NULL; if (obj->getType() != ACTIVEOBJECT_TYPE_PLAYER) return NULL; - return (PlayerSAO*)obj; + return (PlayerSAO *)obj; } RemotePlayer *ObjectRef::getplayer(ObjectRef *ref) @@ -87,9 +87,10 @@ RemotePlayer *ObjectRef::getplayer(ObjectRef *ref) // Exported functions // garbage collector -int ObjectRef::gc_object(lua_State *L) { +int ObjectRef::gc_object(lua_State *L) +{ ObjectRef *o = *(ObjectRef **)(lua_touserdata(L, 1)); - //infostream<<"ObjectRef::gc_object: o="<<o<<std::endl; + // infostream<<"ObjectRef::gc_object: o="<<o<<std::endl; delete o; return 0; } @@ -121,7 +122,8 @@ int ObjectRef::l_get_pos(lua_State *L) NO_MAP_LOCK_REQUIRED; ObjectRef *ref = checkobject(L, 1); ServerActiveObject *co = getobject(ref); - if (co == NULL) return 0; + if (co == NULL) + return 0; push_v3f(L, co->getBasePosition() / BS); return 1; } @@ -132,7 +134,8 @@ int ObjectRef::l_set_pos(lua_State *L) NO_MAP_LOCK_REQUIRED; ObjectRef *ref = checkobject(L, 1); ServerActiveObject *co = getobject(ref); - if (co == NULL) return 0; + if (co == NULL) + return 0; // pos v3f pos = checkFloatPos(L, 2); // Do it @@ -146,7 +149,8 @@ int ObjectRef::l_move_to(lua_State *L) NO_MAP_LOCK_REQUIRED; ObjectRef *ref = checkobject(L, 1); ServerActiveObject *co = getobject(ref); - if (co == NULL) return 0; + if (co == NULL) + return 0; // pos v3f pos = checkFloatPos(L, 2); // continuous @@ -185,17 +189,18 @@ int ObjectRef::l_punch(lua_State *L) lua_pushnumber(L, wear); // If the punched is a player, and its HP changed - if (src_original_hp != co->getHP() && - co->getType() == ACTIVEOBJECT_TYPE_PLAYER) { + if (src_original_hp != co->getHP() && co->getType() == ACTIVEOBJECT_TYPE_PLAYER) { getServer(L)->SendPlayerHPOrDie((PlayerSAO *)co, - PlayerHPChangeReason(PlayerHPChangeReason::PLAYER_PUNCH, puncher)); + PlayerHPChangeReason(PlayerHPChangeReason::PLAYER_PUNCH, + puncher)); } // If the puncher is a player, and its HP changed if (dst_origin_hp != puncher->getHP() && puncher->getType() == ACTIVEOBJECT_TYPE_PLAYER) { getServer(L)->SendPlayerHPOrDie((PlayerSAO *)puncher, - PlayerHPChangeReason(PlayerHPChangeReason::PLAYER_PUNCH, co)); + PlayerHPChangeReason( + PlayerHPChangeReason::PLAYER_PUNCH, co)); } return 1; } @@ -208,8 +213,10 @@ int ObjectRef::l_right_click(lua_State *L) ObjectRef *ref2 = checkobject(L, 2); ServerActiveObject *co = getobject(ref); ServerActiveObject *co2 = getobject(ref2); - if (co == NULL) return 0; - if (co2 == NULL) return 0; + if (co == NULL) + return 0; + if (co2 == NULL) + return 0; // Do it co->rightClick(co2); return 0; @@ -240,7 +247,8 @@ int ObjectRef::l_set_hp(lua_State *L) lua_getfield(L, -1, "type"); if (lua_isstring(L, -1) && - !reason.setTypeFromString(readParam<std::string>(L, -1))) { + !reason.setTypeFromString( + readParam<std::string>(L, -1))) { errorstream << "Bad type given!" << std::endl; } lua_pop(L, 1); @@ -287,7 +295,8 @@ int ObjectRef::l_get_inventory(lua_State *L) NO_MAP_LOCK_REQUIRED; ObjectRef *ref = checkobject(L, 1); ServerActiveObject *co = getobject(ref); - if (co == NULL) return 0; + if (co == NULL) + return 0; // Do it InventoryLocation loc = co->getInventoryLocation(); if (getServerInventoryMgr(L)->getInventory(loc) != NULL) @@ -347,7 +356,8 @@ int ObjectRef::l_set_wielded_item(lua_State *L) NO_MAP_LOCK_REQUIRED; ObjectRef *ref = checkobject(L, 1); ServerActiveObject *co = getobject(ref); - if (co == NULL) return 0; + if (co == NULL) + return 0; // Do it ItemStack item = read_item(L, 2, getServer(L)->idef()); bool success = co->setWieldedItem(item); @@ -364,7 +374,8 @@ int ObjectRef::l_set_armor_groups(lua_State *L) NO_MAP_LOCK_REQUIRED; ObjectRef *ref = checkobject(L, 1); ServerActiveObject *co = getobject(ref); - if (co == NULL) return 0; + if (co == NULL) + return 0; // Do it ItemGroupList groups; read_groups(L, 2, groups); @@ -391,8 +402,9 @@ int ObjectRef::l_set_physics_override(lua_State *L) { NO_MAP_LOCK_REQUIRED; ObjectRef *ref = checkobject(L, 1); - PlayerSAO *co = (PlayerSAO *) getobject(ref); - if (co == NULL) return 0; + PlayerSAO *co = (PlayerSAO *)getobject(ref); + if (co == NULL) + return 0; // Do it if (lua_istable(L, 2)) { co->m_physics_override_speed = getfloatfield_default( @@ -403,8 +415,8 @@ int ObjectRef::l_set_physics_override(lua_State *L) L, 2, "gravity", co->m_physics_override_gravity); co->m_physics_override_sneak = getboolfield_default( L, 2, "sneak", co->m_physics_override_sneak); - co->m_physics_override_sneak_glitch = getboolfield_default( - L, 2, "sneak_glitch", co->m_physics_override_sneak_glitch); + co->m_physics_override_sneak_glitch = getboolfield_default(L, 2, + "sneak_glitch", co->m_physics_override_sneak_glitch); co->m_physics_override_new_move = getboolfield_default( L, 2, "new_move", co->m_physics_override_new_move); co->m_physics_override_sent = false; @@ -457,7 +469,8 @@ int ObjectRef::l_set_animation(lua_State *L) NO_MAP_LOCK_REQUIRED; ObjectRef *ref = checkobject(L, 1); ServerActiveObject *co = getobject(ref); - if (co == NULL) return 0; + if (co == NULL) + return 0; // Do it v2f frames = v2f(1, 1); if (!lua_isnil(L, 2)) @@ -484,7 +497,7 @@ int ObjectRef::l_get_animation(lua_State *L) if (co == NULL) return 0; // Do it - v2f frames = v2f(1,1); + v2f frames = v2f(1, 1); float frame_speed = 15; float frame_blend = 0; bool frame_loop = true; @@ -507,9 +520,9 @@ int ObjectRef::l_set_local_animation(lua_State *L) return 0; // Do it v2s32 frames[4]; - for (int i=0;i<4;i++) { - if (!lua_isnil(L, 2+1)) - frames[i] = read_v2s32(L, 2+i); + for (int i = 0; i < 4; i++) { + if (!lua_isnil(L, 2 + 1)) + frames[i] = read_v2s32(L, 2 + i); } float frame_speed = 30; if (!lua_isnil(L, 6)) @@ -559,10 +572,10 @@ int ObjectRef::l_set_eye_offset(lua_State *L) offset_third = read_v3f(L, 3); // Prevent abuse of offset values (keep player always visible) - offset_third.X = rangelim(offset_third.X,-10,10); - offset_third.Z = rangelim(offset_third.Z,-5,5); + offset_third.X = rangelim(offset_third.X, -10, 10); + offset_third.Z = rangelim(offset_third.Z, -5, 5); /* TODO: if possible: improve the camera colision detetion to allow Y <= -1.5) */ - offset_third.Y = rangelim(offset_third.Y,-10,15); //1.5*BS + offset_third.Y = rangelim(offset_third.Y, -10, 15); // 1.5*BS getServer(L)->setPlayerEyeOffset(player, offset_first, offset_third); lua_pushboolean(L, true); @@ -627,7 +640,8 @@ int ObjectRef::l_set_bone_position(lua_State *L) NO_MAP_LOCK_REQUIRED; ObjectRef *ref = checkobject(L, 1); ServerActiveObject *co = getobject(ref); - if (co == NULL) return 0; + if (co == NULL) + return 0; // Do it std::string bone; if (!lua_isnil(L, 2)) @@ -680,7 +694,8 @@ int ObjectRef::l_set_attach(lua_State *L) return 0; if (co == parent) - throw LuaError("ObjectRef::set_attach: attaching object to itself is not allowed."); + throw LuaError("ObjectRef::set_attach: attaching object to itself is not " + "allowed."); // Do it int parent_id = 0; @@ -851,7 +866,8 @@ int ObjectRef::l_set_velocity(lua_State *L) NO_MAP_LOCK_REQUIRED; ObjectRef *ref = checkobject(L, 1); LuaEntitySAO *co = getluaobject(ref); - if (co == NULL) return 0; + if (co == NULL) + return 0; v3f pos = checkFloatPos(L, 2); // Do it co->setVelocity(pos); @@ -878,7 +894,8 @@ int ObjectRef::l_get_velocity(lua_State *L) NO_MAP_LOCK_REQUIRED; ObjectRef *ref = checkobject(L, 1); LuaEntitySAO *co = getluaobject(ref); - if (co == NULL) return 0; + if (co == NULL) + return 0; // Do it v3f v = co->getVelocity(); pushFloatPos(L, v); @@ -891,7 +908,8 @@ int ObjectRef::l_set_acceleration(lua_State *L) NO_MAP_LOCK_REQUIRED; ObjectRef *ref = checkobject(L, 1); LuaEntitySAO *co = getluaobject(ref); - if (co == NULL) return 0; + if (co == NULL) + return 0; // pos v3f pos = checkFloatPos(L, 2); // Do it @@ -905,7 +923,8 @@ int ObjectRef::l_get_acceleration(lua_State *L) NO_MAP_LOCK_REQUIRED; ObjectRef *ref = checkobject(L, 1); LuaEntitySAO *co = getluaobject(ref); - if (co == NULL) return 0; + if (co == NULL) + return 0; // Do it v3f v = co->getAcceleration(); pushFloatPos(L, v); @@ -951,7 +970,8 @@ int ObjectRef::l_set_yaw(lua_State *L) ObjectRef *ref = checkobject(L, 1); LuaEntitySAO *co = getluaobject(ref); - if (co == NULL) return 0; + if (co == NULL) + return 0; if (isNaN(L, 2)) throw LuaError("ObjectRef::set_yaw: NaN value is not allowed."); @@ -980,7 +1000,8 @@ int ObjectRef::l_set_texture_mod(lua_State *L) NO_MAP_LOCK_REQUIRED; ObjectRef *ref = checkobject(L, 1); LuaEntitySAO *co = getluaobject(ref); - if (co == NULL) return 0; + if (co == NULL) + return 0; // Do it std::string mod = luaL_checkstring(L, 2); co->setTextureMod(mod); @@ -993,7 +1014,8 @@ int ObjectRef::l_get_texture_mod(lua_State *L) NO_MAP_LOCK_REQUIRED; ObjectRef *ref = checkobject(L, 1); LuaEntitySAO *co = getluaobject(ref); - if (co == NULL) return 0; + if (co == NULL) + return 0; // Do it std::string mod = co->getTextureMod(); lua_pushstring(L, mod.c_str()); @@ -1007,9 +1029,10 @@ int ObjectRef::l_set_sprite(lua_State *L) NO_MAP_LOCK_REQUIRED; ObjectRef *ref = checkobject(L, 1); LuaEntitySAO *co = getluaobject(ref); - if (co == NULL) return 0; + if (co == NULL) + return 0; // Do it - v2s16 p(0,0); + v2s16 p(0, 0); if (!lua_isnil(L, 2)) p = readParam<v2s16>(L, 2); int num_frames = 1; @@ -1032,8 +1055,9 @@ int ObjectRef::l_get_entity_name(lua_State *L) NO_MAP_LOCK_REQUIRED; ObjectRef *ref = checkobject(L, 1); LuaEntitySAO *co = getluaobject(ref); - log_deprecated(L,"Deprecated call to \"get_entity_name"); - if (co == NULL) return 0; + log_deprecated(L, "Deprecated call to \"get_entity_name"); + if (co == NULL) + return 0; // Do it std::string name = co->getName(); lua_pushstring(L, name.c_str()); @@ -1046,7 +1070,8 @@ int ObjectRef::l_get_luaentity(lua_State *L) NO_MAP_LOCK_REQUIRED; ObjectRef *ref = checkobject(L, 1); LuaEntitySAO *co = getluaobject(ref); - if (co == NULL) return 0; + if (co == NULL) + return 0; // Do it luaentity_get(L, co->getId()); return 1; @@ -1060,7 +1085,7 @@ int ObjectRef::l_is_player_connected(lua_State *L) NO_MAP_LOCK_REQUIRED; // This method was once added for a bugfix, but never documented log_deprecated(L, "is_player_connected is undocumented and " - "will be removed in a future release"); + "will be removed in a future release"); ObjectRef *ref = checkobject(L, 1); RemotePlayer *player = getplayer(ref); lua_pushboolean(L, (player != NULL && player->getPeerId() != PEER_ID_INEXISTENT)); @@ -1119,13 +1144,14 @@ int ObjectRef::l_get_look_dir(lua_State *L) { NO_MAP_LOCK_REQUIRED; ObjectRef *ref = checkobject(L, 1); - PlayerSAO* co = getplayersao(ref); - if (co == NULL) return 0; + PlayerSAO *co = getplayersao(ref); + if (co == NULL) + return 0; // Do it float pitch = co->getRadLookPitchDep(); float yaw = co->getRadYawDep(); - v3f v(std::cos(pitch) * std::cos(yaw), std::sin(pitch), std::cos(pitch) * - std::sin(yaw)); + v3f v(std::cos(pitch) * std::cos(yaw), std::sin(pitch), + std::cos(pitch) * std::sin(yaw)); push_v3f(L, v); return 1; } @@ -1136,12 +1162,13 @@ int ObjectRef::l_get_look_pitch(lua_State *L) { NO_MAP_LOCK_REQUIRED; - log_deprecated(L, - "Deprecated call to get_look_pitch, use get_look_vertical instead"); + log_deprecated(L, "Deprecated call to get_look_pitch, use get_look_vertical " + "instead"); ObjectRef *ref = checkobject(L, 1); - PlayerSAO* co = getplayersao(ref); - if (co == NULL) return 0; + PlayerSAO *co = getplayersao(ref); + if (co == NULL) + return 0; // Do it lua_pushnumber(L, co->getRadLookPitchDep()); return 1; @@ -1153,12 +1180,13 @@ int ObjectRef::l_get_look_yaw(lua_State *L) { NO_MAP_LOCK_REQUIRED; - log_deprecated(L, - "Deprecated call to get_look_yaw, use get_look_horizontal instead"); + log_deprecated(L, "Deprecated call to get_look_yaw, use get_look_horizontal " + "instead"); ObjectRef *ref = checkobject(L, 1); - PlayerSAO* co = getplayersao(ref); - if (co == NULL) return 0; + PlayerSAO *co = getplayersao(ref); + if (co == NULL) + return 0; // Do it lua_pushnumber(L, co->getRadYawDep()); return 1; @@ -1169,8 +1197,9 @@ int ObjectRef::l_get_look_vertical(lua_State *L) { NO_MAP_LOCK_REQUIRED; ObjectRef *ref = checkobject(L, 1); - PlayerSAO* co = getplayersao(ref); - if (co == NULL) return 0; + PlayerSAO *co = getplayersao(ref); + if (co == NULL) + return 0; // Do it lua_pushnumber(L, co->getRadLookPitch()); return 1; @@ -1181,8 +1210,9 @@ int ObjectRef::l_get_look_horizontal(lua_State *L) { NO_MAP_LOCK_REQUIRED; ObjectRef *ref = checkobject(L, 1); - PlayerSAO* co = getplayersao(ref); - if (co == NULL) return 0; + PlayerSAO *co = getplayersao(ref); + if (co == NULL) + return 0; // Do it lua_pushnumber(L, co->getRadRotation().Y); return 1; @@ -1193,8 +1223,9 @@ int ObjectRef::l_set_look_vertical(lua_State *L) { NO_MAP_LOCK_REQUIRED; ObjectRef *ref = checkobject(L, 1); - PlayerSAO* co = getplayersao(ref); - if (co == NULL) return 0; + PlayerSAO *co = getplayersao(ref); + if (co == NULL) + return 0; float pitch = readParam<float>(L, 2) * core::RADTODEG; // Do it co->setLookPitchAndSend(pitch); @@ -1206,8 +1237,9 @@ int ObjectRef::l_set_look_horizontal(lua_State *L) { NO_MAP_LOCK_REQUIRED; ObjectRef *ref = checkobject(L, 1); - PlayerSAO* co = getplayersao(ref); - if (co == NULL) return 0; + PlayerSAO *co = getplayersao(ref); + if (co == NULL) + return 0; float yaw = readParam<float>(L, 2) * core::RADTODEG; // Do it co->setPlayerYawAndSend(yaw); @@ -1220,12 +1252,13 @@ int ObjectRef::l_set_look_pitch(lua_State *L) { NO_MAP_LOCK_REQUIRED; - log_deprecated(L, - "Deprecated call to set_look_pitch, use set_look_vertical instead."); + log_deprecated(L, "Deprecated call to set_look_pitch, use set_look_vertical " + "instead."); ObjectRef *ref = checkobject(L, 1); - PlayerSAO* co = getplayersao(ref); - if (co == NULL) return 0; + PlayerSAO *co = getplayersao(ref); + if (co == NULL) + return 0; float pitch = readParam<float>(L, 2) * core::RADTODEG; // Do it co->setLookPitchAndSend(pitch); @@ -1238,12 +1271,13 @@ int ObjectRef::l_set_look_yaw(lua_State *L) { NO_MAP_LOCK_REQUIRED; - log_deprecated(L, - "Deprecated call to set_look_yaw, use set_look_horizontal instead."); + log_deprecated(L, "Deprecated call to set_look_yaw, use set_look_horizontal " + "instead."); ObjectRef *ref = checkobject(L, 1); - PlayerSAO* co = getplayersao(ref); - if (co == NULL) return 0; + PlayerSAO *co = getplayersao(ref); + if (co == NULL) + return 0; float yaw = readParam<float>(L, 2) * core::RADTODEG; // Do it co->setPlayerYawAndSend(yaw); @@ -1259,11 +1293,10 @@ int ObjectRef::l_set_fov(lua_State *L) if (!player) return 0; - player->setFov({ - static_cast<f32>(luaL_checknumber(L, 2)), - readParam<bool>(L, 3, false), - lua_isnumber(L, 4) ? static_cast<f32>(luaL_checknumber(L, 4)) : 0.0f - }); + player->setFov({static_cast<f32>(luaL_checknumber(L, 2)), + readParam<bool>(L, 3, false), + lua_isnumber(L, 4) ? static_cast<f32>(luaL_checknumber(L, 4)) + : 0.0f}); getServer(L)->SendPlayerFov(player->getPeerId()); return 0; @@ -1291,8 +1324,9 @@ int ObjectRef::l_set_breath(lua_State *L) { NO_MAP_LOCK_REQUIRED; ObjectRef *ref = checkobject(L, 1); - PlayerSAO* co = getplayersao(ref); - if (co == NULL) return 0; + PlayerSAO *co = getplayersao(ref); + if (co == NULL) + return 0; u16 breath = luaL_checknumber(L, 2); co->setBreath(breath); @@ -1304,22 +1338,23 @@ int ObjectRef::l_get_breath(lua_State *L) { NO_MAP_LOCK_REQUIRED; ObjectRef *ref = checkobject(L, 1); - PlayerSAO* co = getplayersao(ref); - if (co == NULL) return 0; + PlayerSAO *co = getplayersao(ref); + if (co == NULL) + return 0; // Do it u16 breath = co->getBreath(); - lua_pushinteger (L, breath); + lua_pushinteger(L, breath); return 1; } // set_attribute(self, attribute, value) int ObjectRef::l_set_attribute(lua_State *L) { - log_deprecated(L, - "Deprecated call to set_attribute, use MetaDataRef methods instead."); + log_deprecated(L, "Deprecated call to set_attribute, use MetaDataRef methods " + "instead."); ObjectRef *ref = checkobject(L, 1); - PlayerSAO* co = getplayersao(ref); + PlayerSAO *co = getplayersao(ref); if (co == NULL) return 0; @@ -1336,11 +1371,11 @@ int ObjectRef::l_set_attribute(lua_State *L) // get_attribute(self, attribute) int ObjectRef::l_get_attribute(lua_State *L) { - log_deprecated(L, - "Deprecated call to get_attribute, use MetaDataRef methods instead."); + log_deprecated(L, "Deprecated call to get_attribute, use MetaDataRef methods " + "instead."); ObjectRef *ref = checkobject(L, 1); - PlayerSAO* co = getplayersao(ref); + PlayerSAO *co = getplayersao(ref); if (co == NULL) return 0; @@ -1355,7 +1390,6 @@ int ObjectRef::l_get_attribute(lua_State *L) return 0; } - // get_meta(self, attribute) int ObjectRef::l_get_meta(lua_State *L) { @@ -1368,14 +1402,14 @@ int ObjectRef::l_get_meta(lua_State *L) return 1; } - // set_inventory_formspec(self, formspec) int ObjectRef::l_set_inventory_formspec(lua_State *L) { NO_MAP_LOCK_REQUIRED; ObjectRef *ref = checkobject(L, 1); RemotePlayer *player = getplayer(ref); - if (player == NULL) return 0; + if (player == NULL) + return 0; std::string formspec = luaL_checkstring(L, 2); player->inventory_formspec = formspec; @@ -1390,7 +1424,8 @@ int ObjectRef::l_get_inventory_formspec(lua_State *L) NO_MAP_LOCK_REQUIRED; ObjectRef *ref = checkobject(L, 1); RemotePlayer *player = getplayer(ref); - if (player == NULL) return 0; + if (player == NULL) + return 0; std::string formspec = player->inventory_formspec; lua_pushlstring(L, formspec.c_str(), formspec.size()); @@ -1421,7 +1456,7 @@ int ObjectRef::l_get_formspec_prepend(lua_State *L) ObjectRef *ref = checkobject(L, 1); RemotePlayer *player = getplayer(ref); if (player == NULL) - return 0; + return 0; std::string formspec = player->formspec_prepend; lua_pushlstring(L, formspec.c_str(), formspec.size()); @@ -1573,14 +1608,14 @@ int ObjectRef::l_hud_set_flags(lua_State *L) return 0; u32 flags = 0; - u32 mask = 0; + u32 mask = 0; bool flag; const EnumString *esp = es_HudBuiltinElement; for (int i = 0; esp[i].str; i++) { if (getboolfield(L, 2, esp[i].str, flag)) { flags |= esp[i].num * flag; - mask |= esp[i].num; + mask |= esp[i].num; } } if (!getServer(L)->hudSetFlags(player, flags, mask)) @@ -1735,7 +1770,8 @@ int ObjectRef::l_set_sky(lua_State *L) lua_pushnil(L); while (lua_next(L, -2) != 0) { // Key is at index -2 and value at index -1 - skybox_params.textures.emplace_back(readParam<std::string>(L, -1)); + skybox_params.textures.emplace_back( + readParam<std::string>(L, -1)); // Removes the value, but keeps the key for iteration lua_pop(L, 1); } @@ -1748,11 +1784,12 @@ int ObjectRef::l_set_sky(lua_State *L) using "regular" or "plain" skybox modes as textures aren't needed. */ - if (skybox_params.textures.size() != 6 && skybox_params.textures.size() > 0) + if (skybox_params.textures.size() != 6 && + skybox_params.textures.size() > 0) throw LuaError("Skybox expects 6 textures!"); - skybox_params.clouds = getboolfield_default(L, 2, - "clouds", skybox_params.clouds); + skybox_params.clouds = getboolfield_default( + L, 2, "clouds", skybox_params.clouds); lua_getfield(L, 2, "sky_color"); if (lua_istable(L, -1)) { @@ -1836,9 +1873,10 @@ int ObjectRef::l_set_sky(lua_State *L) if (lua_istable(L, 4)) { lua_pushnil(L); while (lua_next(L, 4) != 0) { - // Key at index -2, and value at index -1 + // Key at index -2, and value at index -1 if (lua_isstring(L, -1)) - skybox_params.textures.emplace_back(readParam<std::string>(L, -1)); + skybox_params.textures.emplace_back( + readParam<std::string>(L, -1)); else skybox_params.textures.emplace_back(""); // Remove the value, keep the key for the next iteration @@ -1878,7 +1916,7 @@ int ObjectRef::l_get_sky(lua_State *L) lua_newtable(L); s16 i = 1; - for (const std::string& texture : skybox_params.textures) { + for (const std::string &texture : skybox_params.textures) { lua_pushlstring(L, texture.c_str(), texture.size()); lua_rawseti(L, -2, i++); } @@ -1896,7 +1934,7 @@ int ObjectRef::l_get_sky_color(lua_State *L) if (!player) return 0; - const SkyboxParams& skybox_params = player->getSkyParams(); + const SkyboxParams &skybox_params = player->getSkyParams(); lua_newtable(L); if (skybox_params.type == "regular") { @@ -1938,25 +1976,20 @@ int ObjectRef::l_set_sun(lua_State *L) SunParams sun_params = player->getSunParams(); - sun_params.visible = getboolfield_default(L, 2, - "visible", sun_params.visible); - sun_params.texture = getstringfield_default(L, 2, - "texture", sun_params.texture); - sun_params.tonemap = getstringfield_default(L, 2, - "tonemap", sun_params.tonemap); - sun_params.sunrise = getstringfield_default(L, 2, - "sunrise", sun_params.sunrise); - sun_params.sunrise_visible = getboolfield_default(L, 2, - "sunrise_visible", sun_params.sunrise_visible); - sun_params.scale = getfloatfield_default(L, 2, - "scale", sun_params.scale); + sun_params.visible = getboolfield_default(L, 2, "visible", sun_params.visible); + sun_params.texture = getstringfield_default(L, 2, "texture", sun_params.texture); + sun_params.tonemap = getstringfield_default(L, 2, "tonemap", sun_params.tonemap); + sun_params.sunrise = getstringfield_default(L, 2, "sunrise", sun_params.sunrise); + sun_params.sunrise_visible = getboolfield_default( + L, 2, "sunrise_visible", sun_params.sunrise_visible); + sun_params.scale = getfloatfield_default(L, 2, "scale", sun_params.scale); getServer(L)->setSun(player, sun_params); lua_pushboolean(L, true); return 1; } -//get_sun(self) +// get_sun(self) int ObjectRef::l_get_sun(lua_State *L) { NO_MAP_LOCK_REQUIRED; @@ -1996,14 +2029,12 @@ int ObjectRef::l_set_moon(lua_State *L) MoonParams moon_params = player->getMoonParams(); - moon_params.visible = getboolfield_default(L, 2, - "visible", moon_params.visible); - moon_params.texture = getstringfield_default(L, 2, - "texture", moon_params.texture); - moon_params.tonemap = getstringfield_default(L, 2, - "tonemap", moon_params.tonemap); - moon_params.scale = getfloatfield_default(L, 2, - "scale", moon_params.scale); + moon_params.visible = getboolfield_default(L, 2, "visible", moon_params.visible); + moon_params.texture = + getstringfield_default(L, 2, "texture", moon_params.texture); + moon_params.tonemap = + getstringfield_default(L, 2, "tonemap", moon_params.tonemap); + moon_params.scale = getfloatfield_default(L, 2, "scale", moon_params.scale); getServer(L)->setMoon(player, moon_params); lua_pushboolean(L, true); @@ -2046,18 +2077,15 @@ int ObjectRef::l_set_stars(lua_State *L) StarParams star_params = player->getStarParams(); - star_params.visible = getboolfield_default(L, 2, - "visible", star_params.visible); - star_params.count = getintfield_default(L, 2, - "count", star_params.count); + star_params.visible = getboolfield_default(L, 2, "visible", star_params.visible); + star_params.count = getintfield_default(L, 2, "count", star_params.count); lua_getfield(L, 2, "star_color"); if (!lua_isnil(L, -1)) read_color(L, -1, &star_params.starcolor); lua_pop(L, 1); - star_params.scale = getfloatfield_default(L, 2, - "scale", star_params.scale); + star_params.scale = getfloatfield_default(L, 2, "scale", star_params.scale); getServer(L)->setStars(player, star_params); lua_pushboolean(L, true); @@ -2100,7 +2128,8 @@ int ObjectRef::l_set_clouds(lua_State *L) CloudParams cloud_params = player->getCloudParams(); - cloud_params.density = getfloatfield_default(L, 2, "density", cloud_params.density); + cloud_params.density = + getfloatfield_default(L, 2, "density", cloud_params.density); lua_getfield(L, 2, "color"); if (!lua_isnil(L, -1)) @@ -2111,8 +2140,9 @@ int ObjectRef::l_set_clouds(lua_State *L) read_color(L, -1, &cloud_params.color_ambient); lua_pop(L, 1); - cloud_params.height = getfloatfield_default(L, 2, "height", cloud_params.height ); - cloud_params.thickness = getfloatfield_default(L, 2, "thickness", cloud_params.thickness); + cloud_params.height = getfloatfield_default(L, 2, "height", cloud_params.height); + cloud_params.thickness = + getfloatfield_default(L, 2, "thickness", cloud_params.thickness); lua_getfield(L, 2, "speed"); if (lua_istable(L, -1)) { @@ -2158,7 +2188,6 @@ int ObjectRef::l_get_clouds(lua_State *L) return 1; } - // override_day_night_ratio(self, brightness=0...1) int ObjectRef::l_override_day_night_ratio(lua_State *L) { @@ -2201,10 +2230,9 @@ int ObjectRef::l_get_day_night_ratio(lua_State *L) return 1; } -ObjectRef::ObjectRef(ServerActiveObject *object): - m_object(object) +ObjectRef::ObjectRef(ServerActiveObject *object) : m_object(object) { - //infostream<<"ObjectRef created for id="<<m_object->getId()<<std::endl; + // infostream<<"ObjectRef created for id="<<m_object->getId()<<std::endl; } // Creates an ObjectRef and leaves it on top of stack @@ -2212,7 +2240,7 @@ ObjectRef::ObjectRef(ServerActiveObject *object): void ObjectRef::create(lua_State *L, ServerActiveObject *object) { ObjectRef *o = new ObjectRef(object); - //infostream<<"ObjectRef::create: o="<<o<<std::endl; + // infostream<<"ObjectRef::create: o="<<o<<std::endl; *(void **)(lua_newuserdata(L, sizeof(void *))) = o; luaL_getmetatable(L, className); lua_setmetatable(L, -2); @@ -2233,7 +2261,7 @@ void ObjectRef::Register(lua_State *L) lua_pushliteral(L, "__metatable"); lua_pushvalue(L, methodtable); - lua_settable(L, metatable); // hide metatable from Lua getmetatable() + lua_settable(L, metatable); // hide metatable from Lua getmetatable() lua_pushliteral(L, "__index"); lua_pushvalue(L, methodtable); @@ -2243,119 +2271,97 @@ void ObjectRef::Register(lua_State *L) lua_pushcfunction(L, gc_object); lua_settable(L, metatable); - lua_pop(L, 1); // drop metatable + lua_pop(L, 1); // drop metatable markAliasDeprecated(methods); - luaL_openlib(L, 0, methods, 0); // fill methodtable - lua_pop(L, 1); // drop methodtable + luaL_openlib(L, 0, methods, 0); // fill methodtable + lua_pop(L, 1); // drop methodtable // Cannot be created from Lua - //lua_register(L, className, create_object); + // lua_register(L, className, create_object); } const char ObjectRef::className[] = "ObjectRef"; luaL_Reg ObjectRef::methods[] = { - // ServerActiveObject - luamethod(ObjectRef, remove), - luamethod_aliased(ObjectRef, get_pos, getpos), - luamethod_aliased(ObjectRef, set_pos, setpos), - luamethod_aliased(ObjectRef, move_to, moveto), - luamethod(ObjectRef, punch), - luamethod(ObjectRef, right_click), - luamethod(ObjectRef, set_hp), - luamethod(ObjectRef, get_hp), - luamethod(ObjectRef, get_inventory), - luamethod(ObjectRef, get_wield_list), - luamethod(ObjectRef, get_wield_index), - luamethod(ObjectRef, get_wielded_item), - luamethod(ObjectRef, set_wielded_item), - luamethod(ObjectRef, set_armor_groups), - luamethod(ObjectRef, get_armor_groups), - luamethod(ObjectRef, set_animation), - luamethod(ObjectRef, get_animation), - luamethod(ObjectRef, set_animation_frame_speed), - luamethod(ObjectRef, set_bone_position), - luamethod(ObjectRef, get_bone_position), - luamethod(ObjectRef, set_attach), - luamethod(ObjectRef, get_attach), - luamethod(ObjectRef, set_detach), - luamethod(ObjectRef, set_properties), - luamethod(ObjectRef, get_properties), - luamethod(ObjectRef, set_nametag_attributes), - luamethod(ObjectRef, get_nametag_attributes), - // LuaEntitySAO-only - luamethod_aliased(ObjectRef, set_velocity, setvelocity), - luamethod(ObjectRef, add_velocity), - luamethod_aliased(ObjectRef, get_velocity, getvelocity), - luamethod_aliased(ObjectRef, set_acceleration, setacceleration), - luamethod_aliased(ObjectRef, get_acceleration, getacceleration), - luamethod_aliased(ObjectRef, set_yaw, setyaw), - luamethod_aliased(ObjectRef, get_yaw, getyaw), - luamethod(ObjectRef, set_rotation), - luamethod(ObjectRef, get_rotation), - luamethod_aliased(ObjectRef, set_texture_mod, settexturemod), - luamethod_aliased(ObjectRef, set_sprite, setsprite), - luamethod(ObjectRef, get_entity_name), - luamethod(ObjectRef, get_luaentity), - // Player-only - luamethod(ObjectRef, is_player), - luamethod(ObjectRef, is_player_connected), - luamethod(ObjectRef, get_player_name), - luamethod(ObjectRef, get_player_velocity), - luamethod(ObjectRef, add_player_velocity), - luamethod(ObjectRef, get_look_dir), - luamethod(ObjectRef, get_look_pitch), - luamethod(ObjectRef, get_look_yaw), - luamethod(ObjectRef, get_look_vertical), - luamethod(ObjectRef, get_look_horizontal), - luamethod(ObjectRef, set_look_horizontal), - luamethod(ObjectRef, set_look_vertical), - luamethod(ObjectRef, set_look_yaw), - luamethod(ObjectRef, set_look_pitch), - luamethod(ObjectRef, get_fov), - luamethod(ObjectRef, set_fov), - luamethod(ObjectRef, get_breath), - luamethod(ObjectRef, set_breath), - luamethod(ObjectRef, get_attribute), - luamethod(ObjectRef, set_attribute), - luamethod(ObjectRef, get_meta), - luamethod(ObjectRef, set_inventory_formspec), - luamethod(ObjectRef, get_inventory_formspec), - luamethod(ObjectRef, set_formspec_prepend), - luamethod(ObjectRef, get_formspec_prepend), - luamethod(ObjectRef, get_player_control), - luamethod(ObjectRef, get_player_control_bits), - luamethod(ObjectRef, set_physics_override), - luamethod(ObjectRef, get_physics_override), - luamethod(ObjectRef, hud_add), - luamethod(ObjectRef, hud_remove), - luamethod(ObjectRef, hud_change), - luamethod(ObjectRef, hud_get), - luamethod(ObjectRef, hud_set_flags), - luamethod(ObjectRef, hud_get_flags), - luamethod(ObjectRef, hud_set_hotbar_itemcount), - luamethod(ObjectRef, hud_get_hotbar_itemcount), - luamethod(ObjectRef, hud_set_hotbar_image), - luamethod(ObjectRef, hud_get_hotbar_image), - luamethod(ObjectRef, hud_set_hotbar_selected_image), - luamethod(ObjectRef, hud_get_hotbar_selected_image), - luamethod(ObjectRef, set_sky), - luamethod(ObjectRef, get_sky), - luamethod(ObjectRef, get_sky_color), - luamethod(ObjectRef, set_sun), - luamethod(ObjectRef, get_sun), - luamethod(ObjectRef, set_moon), - luamethod(ObjectRef, get_moon), - luamethod(ObjectRef, set_stars), - luamethod(ObjectRef, get_stars), - luamethod(ObjectRef, set_clouds), - luamethod(ObjectRef, get_clouds), - luamethod(ObjectRef, override_day_night_ratio), - luamethod(ObjectRef, get_day_night_ratio), - luamethod(ObjectRef, set_local_animation), - luamethod(ObjectRef, get_local_animation), - luamethod(ObjectRef, set_eye_offset), - luamethod(ObjectRef, get_eye_offset), - luamethod(ObjectRef, send_mapblock), - {0,0} -}; + // ServerActiveObject + luamethod(ObjectRef, remove), + luamethod_aliased(ObjectRef, get_pos, getpos), + luamethod_aliased(ObjectRef, set_pos, setpos), + luamethod_aliased(ObjectRef, move_to, moveto), + luamethod(ObjectRef, punch), luamethod(ObjectRef, right_click), + luamethod(ObjectRef, set_hp), luamethod(ObjectRef, get_hp), + luamethod(ObjectRef, get_inventory), luamethod(ObjectRef, get_wield_list), + luamethod(ObjectRef, get_wield_index), + luamethod(ObjectRef, get_wielded_item), + luamethod(ObjectRef, set_wielded_item), + luamethod(ObjectRef, set_armor_groups), + luamethod(ObjectRef, get_armor_groups), + luamethod(ObjectRef, set_animation), luamethod(ObjectRef, get_animation), + luamethod(ObjectRef, set_animation_frame_speed), + luamethod(ObjectRef, set_bone_position), + luamethod(ObjectRef, get_bone_position), luamethod(ObjectRef, set_attach), + luamethod(ObjectRef, get_attach), luamethod(ObjectRef, set_detach), + luamethod(ObjectRef, set_properties), + luamethod(ObjectRef, get_properties), + luamethod(ObjectRef, set_nametag_attributes), + luamethod(ObjectRef, get_nametag_attributes), + // LuaEntitySAO-only + luamethod_aliased(ObjectRef, set_velocity, setvelocity), + luamethod(ObjectRef, add_velocity), + luamethod_aliased(ObjectRef, get_velocity, getvelocity), + luamethod_aliased(ObjectRef, set_acceleration, setacceleration), + luamethod_aliased(ObjectRef, get_acceleration, getacceleration), + luamethod_aliased(ObjectRef, set_yaw, setyaw), + luamethod_aliased(ObjectRef, get_yaw, getyaw), + luamethod(ObjectRef, set_rotation), luamethod(ObjectRef, get_rotation), + luamethod_aliased(ObjectRef, set_texture_mod, settexturemod), + luamethod_aliased(ObjectRef, set_sprite, setsprite), + luamethod(ObjectRef, get_entity_name), + luamethod(ObjectRef, get_luaentity), + // Player-only + luamethod(ObjectRef, is_player), + luamethod(ObjectRef, is_player_connected), + luamethod(ObjectRef, get_player_name), + luamethod(ObjectRef, get_player_velocity), + luamethod(ObjectRef, add_player_velocity), + luamethod(ObjectRef, get_look_dir), luamethod(ObjectRef, get_look_pitch), + luamethod(ObjectRef, get_look_yaw), + luamethod(ObjectRef, get_look_vertical), + luamethod(ObjectRef, get_look_horizontal), + luamethod(ObjectRef, set_look_horizontal), + luamethod(ObjectRef, set_look_vertical), + luamethod(ObjectRef, set_look_yaw), luamethod(ObjectRef, set_look_pitch), + luamethod(ObjectRef, get_fov), luamethod(ObjectRef, set_fov), + luamethod(ObjectRef, get_breath), luamethod(ObjectRef, set_breath), + luamethod(ObjectRef, get_attribute), luamethod(ObjectRef, set_attribute), + luamethod(ObjectRef, get_meta), + luamethod(ObjectRef, set_inventory_formspec), + luamethod(ObjectRef, get_inventory_formspec), + luamethod(ObjectRef, set_formspec_prepend), + luamethod(ObjectRef, get_formspec_prepend), + luamethod(ObjectRef, get_player_control), + luamethod(ObjectRef, get_player_control_bits), + luamethod(ObjectRef, set_physics_override), + luamethod(ObjectRef, get_physics_override), luamethod(ObjectRef, hud_add), + luamethod(ObjectRef, hud_remove), luamethod(ObjectRef, hud_change), + luamethod(ObjectRef, hud_get), luamethod(ObjectRef, hud_set_flags), + luamethod(ObjectRef, hud_get_flags), + luamethod(ObjectRef, hud_set_hotbar_itemcount), + luamethod(ObjectRef, hud_get_hotbar_itemcount), + luamethod(ObjectRef, hud_set_hotbar_image), + luamethod(ObjectRef, hud_get_hotbar_image), + luamethod(ObjectRef, hud_set_hotbar_selected_image), + luamethod(ObjectRef, hud_get_hotbar_selected_image), + luamethod(ObjectRef, set_sky), luamethod(ObjectRef, get_sky), + luamethod(ObjectRef, get_sky_color), luamethod(ObjectRef, set_sun), + luamethod(ObjectRef, get_sun), luamethod(ObjectRef, set_moon), + luamethod(ObjectRef, get_moon), luamethod(ObjectRef, set_stars), + luamethod(ObjectRef, get_stars), luamethod(ObjectRef, set_clouds), + luamethod(ObjectRef, get_clouds), + luamethod(ObjectRef, override_day_night_ratio), + luamethod(ObjectRef, get_day_night_ratio), + luamethod(ObjectRef, set_local_animation), + luamethod(ObjectRef, get_local_animation), + luamethod(ObjectRef, set_eye_offset), + luamethod(ObjectRef, get_eye_offset), luamethod(ObjectRef, send_mapblock), + {0, 0}}; |