sao->clearParentAttachment();
verbosestream << "ObjectRef::l_remove(): id=" << sao->getId() << std::endl;
- sao->m_pending_removal = true;
+ sao->markForRemoval();
return 0;
}
if (sao == nullptr || puncher == nullptr)
return 0;
- float time_from_last_punch = lua_isnil(L, 3) ?
- 1000000.0f : readParam<float>(L,3);
+ float time_from_last_punch = readParam<float>(L, 3, 1000000.0f);
ToolCapabilities toolcap = read_tool_capabilities(L, 4);
- v3f dir = lua_isnil(L, 5) ?
- sao->getBasePosition() - puncher->getBasePosition() : check_v3f(L, 5);
-
+ v3f dir = readParam<v3f>(L, 5, sao->getBasePosition() - puncher->getBasePosition());
dir.normalize();
- u16 src_original_hp = sao->getHP();
- u16 dst_origin_hp = puncher->getHP();
- u16 wear = sao->punch(dir, &toolcap, puncher, time_from_last_punch);
+ u32 wear = sao->punch(dir, &toolcap, puncher, time_from_last_punch);
lua_pushnumber(L, wear);
- // If the punched is a player, and its HP changed
- if (src_original_hp != sao->getHP() &&
- sao->getType() == ACTIVEOBJECT_TYPE_PLAYER) {
- getServer(L)->SendPlayerHPOrDie((PlayerSAO *)sao,
- 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, sao));
- }
return 1;
}
}
sao->setHP(hp, reason);
- if (sao->getType() == ACTIVEOBJECT_TYPE_PLAYER)
- getServer(L)->SendPlayerHPOrDie((PlayerSAO *)sao, reason);
if (reason.hasLuaReference())
luaL_unref(L, LUA_REGISTRYINDEX, reason.lua_reference);
return 0;
ItemGroupList groups;
read_groups(L, 2, groups);
+ if (sao->getType() == ACTIVEOBJECT_TYPE_PLAYER) {
+ if (!g_settings->getBool("enable_damage") && !itemgroup_get(groups, "immortal")) {
+ warningstream << "Mod tried to enable damage for a player, but it's "
+ "disabled globally. Ignoring." << std::endl;
+ infostream << script_get_backtrace(L) << std::endl;
+ groups["immortal"] = 1;
+ }
+ }
+
sao->setArmorGroups(groups);
return 0;
}
if (sao == nullptr)
return 0;
- v2f frames = v2f(1, 1);
- if (!lua_isnil(L, 2))
- frames = readParam<v2f>(L, 2);
- float frame_speed = 15;
- if (!lua_isnil(L, 3))
- frame_speed = lua_tonumber(L, 3);
- float frame_blend = 0;
- if (!lua_isnil(L, 4))
- frame_blend = lua_tonumber(L, 4);
- bool frame_loop = true;
- if (lua_isboolean(L, 5))
- frame_loop = readParam<bool>(L, 5);
+ v2f frame_range = readParam<v2f>(L, 2, v2f(1, 1));
+ float frame_speed = readParam<float>(L, 3, 15.0f);
+ float frame_blend = readParam<float>(L, 4, 0.0f);
+ bool frame_loop = readParam<bool>(L, 5, true);
- sao->setAnimation(frames, frame_speed, frame_blend, frame_loop);
+ sao->setAnimation(frame_range, frame_speed, frame_blend, frame_loop);
return 0;
}
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;
if (!lua_isnil(L, 2+1))
frames[i] = read_v2s32(L, 2+i);
}
- float frame_speed = lua_isnil(L, 6) ? 30 : readParam<float>(L, 6);
+ float frame_speed = readParam<float>(L, 6, 30.0f);
getServer(L)->setLocalPlayerAnimations(player, frames, frame_speed);
- lua_pushboolean(L, true);
- return 1;
+ return 0;
}
// get_local_animation(self)
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);
offset_third.Y = rangelim(offset_third.Y,-10,15); //1.5*BS
getServer(L)->setPlayerEyeOffset(player, offset_first, offset_third);
- lua_pushboolean(L, true);
- return 1;
+ return 0;
}
// get_eye_offset(self)
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;
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);
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);
old_parent->removeAttachmentChild(sao->getId());
}
- bone = readParam<std::string>(L, 3, "");
- position = read_v3f(L, 4);
- rotation = read_v3f(L, 5);
+ bone = readParam<std::string>(L, 3, "");
+ 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);
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);
return 0;
read_object_properties(L, 2, sao, prop, getServer(L)->idef());
+ prop->validate();
sao->notifyObjectPropertiesModified();
return 0;
}
}
lua_pop(L, 1);
+ lua_getfield(L, -1, "bgcolor");
+ if (!lua_isnil(L, -1)) {
+ if (lua_toboolean(L, -1)) {
+ video::SColor color;
+ if (read_color(L, -1, &color))
+ prop->nametag_bgcolor = color;
+ } else {
+ prop->nametag_bgcolor = nullopt;
+ }
+ }
+ lua_pop(L, 1);
+
std::string nametag = getstringfield_default(L, 2, "text", "");
prop->nametag = nametag;
+ prop->validate();
sao->notifyObjectPropertiesModified();
- lua_pushboolean(L, true);
- return 1;
+ return 0;
}
// get_nametag_attributes(self)
if (!prop)
return 0;
- video::SColor color = prop->nametag_color;
-
lua_newtable(L);
- push_ARGB8(L, color);
+
+ push_ARGB8(L, prop->nametag_color);
lua_setfield(L, -2, "color");
+
+ if (prop->nametag_bgcolor) {
+ push_ARGB8(L, prop->nametag_bgcolor.value());
+ lua_setfield(L, -2, "bgcolor");
+ } else {
+ lua_pushboolean(L, false);
+ lua_setfield(L, -2, "bgcolor");
+ }
+
lua_pushstring(L, prop->nametag.c_str());
lua_setfield(L, -2, "text");
+
+
+
return 1;
}
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));
if (entitysao == nullptr)
return 0;
- v2s16 start_frame = lua_isnil(L, 2) ? v2s16(0,0) : readParam<v2s16>(L, 2);
- int num_frames = lua_isnil(L, 3) ? 1 : luaL_checkint(L, 3);
- float framelength = lua_isnil(L, 4) ? 0.2 : lua_tonumber(L, 4);
+ v2s16 start_frame = readParam<v2s16>(L, 2, v2s16(0,0));
+ int num_frames = readParam<int>(L, 3, 1);
+ float framelength = readParam<float>(L, 4, 0.2f);
bool select_x_by_camera = readParam<bool>(L, 5, false);
entitysao->setSprite(start_frame, num_frames, framelength, select_x_by_camera);
float pitch = readParam<float>(L, 2) * core::RADTODEG;
playersao->setLookPitchAndSend(pitch);
- return 1;
+ return 0;
}
// set_look_horizontal(self, radians)
float yaw = readParam<float>(L, 2) * core::RADTODEG;
playersao->setPlayerYawAndSend(yaw);
- return 1;
+ return 0;
}
// DEPRECATED
float pitch = readParam<float>(L, 2) * core::RADTODEG;
playersao->setLookPitchAndSend(pitch);
- return 1;
+ return 0;
}
// DEPRECATED
float yaw = readParam<float>(L, 2) * core::RADTODEG;
playersao->setPlayerYawAndSend(yaw);
- return 1;
+ return 0;
}
// set_fov(self, degrees, is_multiplier, transition_time)
player->inventory_formspec = formspec;
getServer(L)->reportInventoryFormspecModified(player->getName());
- lua_pushboolean(L, true);
- return 1;
+ return 0;
}
// get_inventory_formspec(self) -> formspec
player->formspec_prepend = formspec;
getServer(L)->reportFormspecPrependModified(player->getName());
- lua_pushboolean(L, true);
- return 1;
+ return 0;
}
// get_formspec_prepend(self)
NO_MAP_LOCK_REQUIRED;
ObjectRef *ref = checkobject(L, 1);
RemotePlayer *player = getplayer(ref);
- if (player == nullptr) {
- lua_pushlstring(L, "", 0);
- return 1;
- }
- const PlayerControl &control = player->getPlayerControl();
lua_newtable(L);
- lua_pushboolean(L, control.up);
+ if (player == nullptr)
+ return 1;
+
+ const PlayerControl &control = player->getPlayerControl();
+ lua_pushboolean(L, control.direction_keys & (1 << 0));
lua_setfield(L, -2, "up");
- lua_pushboolean(L, control.down);
+ lua_pushboolean(L, control.direction_keys & (1 << 1));
lua_setfield(L, -2, "down");
- lua_pushboolean(L, control.left);
+ lua_pushboolean(L, control.direction_keys & (1 << 2));
lua_setfield(L, -2, "left");
- lua_pushboolean(L, control.right);
+ lua_pushboolean(L, control.direction_keys & (1 << 3));
lua_setfield(L, -2, "right");
lua_pushboolean(L, control.jump);
lua_setfield(L, -2, "jump");
ObjectRef *ref = checkobject(L, 1);
RemotePlayer *player = getplayer(ref);
if (player == nullptr) {
- lua_pushlstring(L, "", 0);
+ lua_pushinteger(L, 0);
return 1;
}
- lua_pushnumber(L, player->keyPressed);
+ const auto &c = player->getPlayerControl();
+
+ // This is very close to PlayerControl::getKeysPressed() but duplicated
+ // here so the encoding in the API is not inadvertedly changed.
+ u32 keypress_bits =
+ c.direction_keys |
+ ( (u32)(c.jump & 1) << 4) |
+ ( (u32)(c.aux1 & 1) << 5) |
+ ( (u32)(c.sneak & 1) << 6) |
+ ( (u32)(c.dig & 1) << 7) |
+ ( (u32)(c.place & 1) << 8) |
+ ( (u32)(c.zoom & 1) << 9)
+ ;
+
+ lua_pushinteger(L, keypress_bits);
return 1;
}
{
NO_MAP_LOCK_REQUIRED;
ObjectRef *ref = checkobject(L, 1);
- PlayerSAO *playersao = (PlayerSAO *) getobject(ref);
+ PlayerSAO *playersao = getplayersao(ref);
if (playersao == nullptr)
return 0;
- luaL_checktype(L, 2, LUA_TTABLE);
- playersao->m_physics_override_speed = getfloatfield_default(
- L, 2, "speed", playersao->m_physics_override_speed);
- playersao->m_physics_override_jump = getfloatfield_default(
- L, 2, "jump", playersao->m_physics_override_jump);
- playersao->m_physics_override_gravity = getfloatfield_default(
- L, 2, "gravity", playersao->m_physics_override_gravity);
- playersao->m_physics_override_sneak = getboolfield_default(
- L, 2, "sneak", playersao->m_physics_override_sneak);
- playersao->m_physics_override_sneak_glitch = getboolfield_default(
- L, 2, "sneak_glitch", playersao->m_physics_override_sneak_glitch);
- playersao->m_physics_override_new_move = getboolfield_default(
- L, 2, "new_move", playersao->m_physics_override_new_move);
- playersao->m_physics_override_sent = false;
+ if (lua_istable(L, 2)) {
+ bool modified = false;
+ modified |= getfloatfield(L, 2, "speed", playersao->m_physics_override_speed);
+ modified |= getfloatfield(L, 2, "jump", playersao->m_physics_override_jump);
+ modified |= getfloatfield(L, 2, "gravity", playersao->m_physics_override_gravity);
+ modified |= getboolfield(L, 2, "sneak", playersao->m_physics_override_sneak);
+ modified |= getboolfield(L, 2, "sneak_glitch", playersao->m_physics_override_sneak_glitch);
+ modified |= getboolfield(L, 2, "new_move", playersao->m_physics_override_new_move);
+ if (modified)
+ playersao->m_physics_override_sent = false;
+ } else {
+ // old, non-table format
+ // TODO: Remove this code after version 5.4.0
+ log_deprecated(L, "Deprecated use of set_physics_override(num, num, num)");
+
+ if (!lua_isnil(L, 2)) {
+ playersao->m_physics_override_speed = lua_tonumber(L, 2);
+ playersao->m_physics_override_sent = false;
+ }
+ if (!lua_isnil(L, 3)) {
+ playersao->m_physics_override_jump = lua_tonumber(L, 3);
+ playersao->m_physics_override_sent = false;
+ }
+ if (!lua_isnil(L, 4)) {
+ playersao->m_physics_override_gravity = lua_tonumber(L, 4);
+ playersao->m_physics_override_sent = false;
+ }
+ }
return 0;
}
{
NO_MAP_LOCK_REQUIRED;
ObjectRef *ref = checkobject(L, 1);
- PlayerSAO *playersao = (PlayerSAO *)getobject(ref);
+ PlayerSAO *playersao = getplayersao(ref);
if (playersao == nullptr)
return 0;
if (elem == nullptr)
return 0;
+ HudElementStat stat;
void *value = nullptr;
- HudElementStat stat = read_hud_change(L, elem, &value);
+ bool ok = read_hud_change(L, stat, elem, &value);
- getServer(L)->hudChange(player, id, stat, value);
+ if (ok)
+ getServer(L)->hudChange(player, id, stat, value);
- lua_pushboolean(L, true);
+ lua_pushboolean(L, ok);
return 1;
}
if (!getServer(L)->hudSetFlags(player, flags, mask))
return 0;
- lua_pushboolean(L, true);
- return 1;
+ return 0;
}
// hud_get_flags(self)
return 0;
lua_newtable(L);
- lua_pushboolean(L, player->hud_flags & HUD_FLAG_HOTBAR_VISIBLE);
- lua_setfield(L, -2, "hotbar");
- lua_pushboolean(L, player->hud_flags & HUD_FLAG_HEALTHBAR_VISIBLE);
- lua_setfield(L, -2, "healthbar");
- lua_pushboolean(L, player->hud_flags & HUD_FLAG_CROSSHAIR_VISIBLE);
- lua_setfield(L, -2, "crosshair");
- lua_pushboolean(L, player->hud_flags & HUD_FLAG_WIELDITEM_VISIBLE);
- lua_setfield(L, -2, "wielditem");
- lua_pushboolean(L, player->hud_flags & HUD_FLAG_BREATHBAR_VISIBLE);
- lua_setfield(L, -2, "breathbar");
- lua_pushboolean(L, player->hud_flags & HUD_FLAG_MINIMAP_VISIBLE);
- lua_setfield(L, -2, "minimap");
- lua_pushboolean(L, player->hud_flags & HUD_FLAG_MINIMAP_RADAR_VISIBLE);
- lua_setfield(L, -2, "minimap_radar");
+ const EnumString *esp = es_HudBuiltinElement;
+ for (int i = 0; esp[i].str; i++) {
+ lua_pushboolean(L, (player->hud_flags & esp[i].num) != 0);
+ lua_setfield(L, -2, esp[i].str);
+ }
return 1;
}
return 0;
SkyboxParams sky_params = player->getSkyParams();
- bool is_colorspec = is_color_table(L, 2);
- if (lua_istable(L, 2) && !is_colorspec) {
+ // reset if empty
+ if (lua_isnoneornil(L, 2) && lua_isnone(L, 3)) {
+ sky_params = SkyboxDefaults::getSkyDefaults();
+ } else if (lua_istable(L, 2) && !is_color_table(L, 2)) {
lua_getfield(L, 2, "base_color");
if (!lua_isnil(L, -1))
read_color(L, -1, &sky_params.bgcolor);
}
lua_pop(L, 1);
- /*
- We want to avoid crashes, so we're checking even if we're not using them.
- However, we want to ensure that the skybox can be set to nil when
- using "regular" or "plain" skybox modes as textures aren't needed.
- */
-
- if (sky_params.textures.size() != 6 && sky_params.textures.size() > 0)
+ // Validate that we either have six or zero textures
+ if (sky_params.textures.size() != 6 && !sky_params.textures.empty())
throw LuaError("Skybox expects 6 textures!");
- sky_params.clouds = getboolfield_default(L, 2,
- "clouds", sky_params.clouds);
+ sky_params.clouds = getboolfield_default(L, 2, "clouds", sky_params.clouds);
lua_getfield(L, 2, "sky_color");
if (lua_istable(L, -1)) {
sky_params.fog_tint_type = luaL_checkstring(L, -1);
lua_pop(L, 1);
- // Because we need to leave the "sky_color" table.
+ // pop "sky_color" table
lua_pop(L, 1);
}
} else {
if (lua_istable(L, 4)) {
lua_pushnil(L);
while (lua_next(L, 4) != 0) {
- // Key at index -2, and value at index -1
- if (lua_isstring(L, -1))
- sky_params.textures.emplace_back(readParam<std::string>(L, -1));
- else
- sky_params.textures.emplace_back("");
+ // Key at index -2, and value at index -1
+ sky_params.textures.emplace_back(readParam<std::string>(L, -1));
// Remove the value, keep the key for the next iteration
lua_pop(L, 1);
}
getServer(L)->setMoon(player, moon_params);
getServer(L)->setStars(player, star_params);
}
+
getServer(L)->setSky(player, sky_params);
- lua_pushboolean(L, true);
- return 1;
+ return 0;
+}
+
+static void push_sky_color(lua_State *L, const SkyboxParams ¶ms)
+{
+ lua_newtable(L);
+ if (params.type == "regular") {
+ push_ARGB8(L, params.sky_color.day_sky);
+ lua_setfield(L, -2, "day_sky");
+ push_ARGB8(L, params.sky_color.day_horizon);
+ lua_setfield(L, -2, "day_horizon");
+ push_ARGB8(L, params.sky_color.dawn_sky);
+ lua_setfield(L, -2, "dawn_sky");
+ push_ARGB8(L, params.sky_color.dawn_horizon);
+ lua_setfield(L, -2, "dawn_horizon");
+ push_ARGB8(L, params.sky_color.night_sky);
+ lua_setfield(L, -2, "night_sky");
+ push_ARGB8(L, params.sky_color.night_horizon);
+ lua_setfield(L, -2, "night_horizon");
+ push_ARGB8(L, params.sky_color.indoors);
+ lua_setfield(L, -2, "indoors");
+ }
+ push_ARGB8(L, params.fog_sun_tint);
+ lua_setfield(L, -2, "fog_sun_tint");
+ push_ARGB8(L, params.fog_moon_tint);
+ lua_setfield(L, -2, "fog_moon_tint");
+ lua_pushstring(L, params.fog_tint_type.c_str());
+ lua_setfield(L, -2, "fog_tint_type");
}
-// get_sky(self)
+// get_sky(self, as_table)
int ObjectRef::l_get_sky(lua_State *L)
{
NO_MAP_LOCK_REQUIRED;
if (player == nullptr)
return 0;
- SkyboxParams skybox_params = player->getSkyParams();
+ const SkyboxParams &skybox_params = player->getSkyParams();
+
+ // handle the deprecated version
+ if (!readParam<bool>(L, 2, false)) {
+ log_deprecated(L, "Deprecated call to get_sky, please check lua_api.txt");
+ push_ARGB8(L, skybox_params.bgcolor);
+ lua_pushlstring(L, skybox_params.type.c_str(), skybox_params.type.size());
+
+ lua_newtable(L);
+ s16 i = 1;
+ for (const std::string &texture : skybox_params.textures) {
+ lua_pushlstring(L, texture.c_str(), texture.size());
+ lua_rawseti(L, -2, i++);
+ }
+ lua_pushboolean(L, skybox_params.clouds);
+ return 4;
+ }
+
+ lua_newtable(L);
push_ARGB8(L, skybox_params.bgcolor);
+ lua_setfield(L, -2, "base_color");
lua_pushlstring(L, skybox_params.type.c_str(), skybox_params.type.size());
+ lua_setfield(L, -2, "type");
lua_newtable(L);
s16 i = 1;
lua_pushlstring(L, texture.c_str(), texture.size());
lua_rawseti(L, -2, i++);
}
+ lua_setfield(L, -2, "textures");
lua_pushboolean(L, skybox_params.clouds);
- return 4;
+ lua_setfield(L, -2, "clouds");
+
+ push_sky_color(L, skybox_params);
+ lua_setfield(L, -2, "sky_color");
+ return 1;
}
+// DEPRECATED
// get_sky_color(self)
int ObjectRef::l_get_sky_color(lua_State *L)
{
NO_MAP_LOCK_REQUIRED;
+
+ log_deprecated(L, "Deprecated call to get_sky_color, use get_sky instead");
+
ObjectRef *ref = checkobject(L, 1);
RemotePlayer *player = getplayer(ref);
if (player == nullptr)
return 0;
const SkyboxParams &skybox_params = player->getSkyParams();
-
- lua_newtable(L);
- if (skybox_params.type == "regular") {
- push_ARGB8(L, skybox_params.sky_color.day_sky);
- lua_setfield(L, -2, "day_sky");
- push_ARGB8(L, skybox_params.sky_color.day_horizon);
- lua_setfield(L, -2, "day_horizon");
- push_ARGB8(L, skybox_params.sky_color.dawn_sky);
- lua_setfield(L, -2, "dawn_sky");
- push_ARGB8(L, skybox_params.sky_color.dawn_horizon);
- lua_setfield(L, -2, "dawn_horizon");
- push_ARGB8(L, skybox_params.sky_color.night_sky);
- lua_setfield(L, -2, "night_sky");
- push_ARGB8(L, skybox_params.sky_color.night_horizon);
- lua_setfield(L, -2, "night_horizon");
- push_ARGB8(L, skybox_params.sky_color.indoors);
- lua_setfield(L, -2, "indoors");
- }
- push_ARGB8(L, skybox_params.fog_sun_tint);
- lua_setfield(L, -2, "fog_sun_tint");
- push_ARGB8(L, skybox_params.fog_moon_tint);
- lua_setfield(L, -2, "fog_moon_tint");
- lua_pushstring(L, skybox_params.fog_tint_type.c_str());
- lua_setfield(L, -2, "fog_tint_type");
+ push_sky_color(L, skybox_params);
return 1;
}
if (player == nullptr)
return 0;
- luaL_checktype(L, 2, LUA_TTABLE);
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);
+ // reset if empty
+ if (lua_isnoneornil(L, 2)) {
+ sun_params = SkyboxDefaults::getSunDefaults();
+ } else {
+ luaL_checktype(L, 2, LUA_TTABLE);
+ 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;
+ return 0;
}
//get_sun(self)
if (player == nullptr)
return 0;
- luaL_checktype(L, 2, LUA_TTABLE);
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);
+ // reset if empty
+ if (lua_isnoneornil(L, 2)) {
+ moon_params = SkyboxDefaults::getMoonDefaults();
+ } else {
+ luaL_checktype(L, 2, LUA_TTABLE);
+ 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);
- return 1;
+ return 0;
}
// get_moon(self)
if (player == nullptr)
return 0;
- luaL_checktype(L, 2, LUA_TTABLE);
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);
+ // reset if empty
+ if (lua_isnoneornil(L, 2)) {
+ star_params = SkyboxDefaults::getStarDefaults();
+ } else {
+ luaL_checktype(L, 2, LUA_TTABLE);
+ 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);
+ 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);
- return 1;
+ return 0;
}
// get_stars(self)
if (player == nullptr)
return 0;
- luaL_checktype(L, 2, LUA_TTABLE);
CloudParams cloud_params = player->getCloudParams();
- cloud_params.density = getfloatfield_default(L, 2, "density", cloud_params.density);
+ // reset if empty
+ if (lua_isnoneornil(L, 2)) {
+ cloud_params = SkyboxDefaults::getCloudDefaults();
+ } else {
+ luaL_checktype(L, 2, LUA_TTABLE);
+ cloud_params.density = getfloatfield_default(L, 2, "density", cloud_params.density);
- lua_getfield(L, 2, "color");
- if (!lua_isnil(L, -1))
- read_color(L, -1, &cloud_params.color_bright);
- lua_pop(L, 1);
- lua_getfield(L, 2, "ambient");
- if (!lua_isnil(L, -1))
- read_color(L, -1, &cloud_params.color_ambient);
- lua_pop(L, 1);
+ lua_getfield(L, 2, "color");
+ if (!lua_isnil(L, -1))
+ read_color(L, -1, &cloud_params.color_bright);
+ lua_pop(L, 1);
+ lua_getfield(L, 2, "ambient");
+ if (!lua_isnil(L, -1))
+ 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)) {
- v2f new_speed;
- new_speed.X = getfloatfield_default(L, -1, "x", 0);
- new_speed.Y = getfloatfield_default(L, -1, "z", 0);
- cloud_params.speed = new_speed;
+ lua_getfield(L, 2, "speed");
+ if (lua_istable(L, -1)) {
+ v2f new_speed;
+ new_speed.X = getfloatfield_default(L, -1, "x", 0);
+ new_speed.Y = getfloatfield_default(L, -1, "z", 0);
+ cloud_params.speed = new_speed;
+ }
+ lua_pop(L, 1);
}
- lua_pop(L, 1);
getServer(L)->setClouds(player, cloud_params);
- lua_pushboolean(L, true);
- return 1;
+ return 0;
}
int ObjectRef::l_get_clouds(lua_State *L)
}
getServer(L)->overrideDayNightRatio(player, do_override, ratio);
- lua_pushboolean(L, true);
- return 1;
+ return 0;
}
// get_day_night_ratio(self)
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) {
return 0;
}
+// set_lighting(self, lighting)
+int ObjectRef::l_set_lighting(lua_State *L)
+{
+ NO_MAP_LOCK_REQUIRED;
+ ObjectRef *ref = checkobject(L, 1);
+ RemotePlayer *player = getplayer(ref);
+ if (player == nullptr)
+ return 0;
+
+ luaL_checktype(L, 2, LUA_TTABLE);
+ Lighting lighting = player->getLighting();
+ lua_getfield(L, 2, "shadows");
+ if (lua_istable(L, -1)) {
+ lighting.shadow_intensity = getfloatfield_default(L, -1, "intensity", lighting.shadow_intensity);
+ }
+ lua_pop(L, -1);
+
+ getServer(L)->setLighting(player, lighting);
+ return 0;
+}
+
+// get_lighting(self)
+int ObjectRef::l_get_lighting(lua_State *L)
+{
+ NO_MAP_LOCK_REQUIRED;
+ ObjectRef *ref = checkobject(L, 1);
+ RemotePlayer *player = getplayer(ref);
+ if (player == nullptr)
+ return 0;
+
+ const Lighting &lighting = player->getLighting();
+
+ lua_newtable(L); // result
+ lua_newtable(L); // "shadows"
+ lua_pushnumber(L, lighting.shadow_intensity);
+ lua_setfield(L, -2, "intensity");
+ lua_setfield(L, -2, "shadows");
+ return 1;
+}
+
+// respawn(self)
+int ObjectRef::l_respawn(lua_State *L)
+{
+ NO_MAP_LOCK_REQUIRED;
+ ObjectRef *ref = checkobject(L, 1);
+ RemotePlayer *player = getplayer(ref);
+ if (player == nullptr)
+ return 0;
+
+ getServer(L)->RespawnPlayer(player->getPeerId());
+ lua_pushboolean(L, true);
+ return 1;
+}
+
+
ObjectRef::ObjectRef(ServerActiveObject *object):
m_object(object)
{}
lua_pop(L, 1); // drop metatable
- markAliasDeprecated(methods);
- luaL_openlib(L, 0, methods, 0); // fill methodtable
+ luaL_register(L, nullptr, methods); // fill methodtable
lua_pop(L, 1); // drop methodtable
}
luamethod(ObjectRef, get_nametag_attributes),
luamethod_aliased(ObjectRef, set_velocity, setvelocity),
- luamethod(ObjectRef, add_velocity),
- {"add_player_velocity", ObjectRef::l_add_velocity},
+ luamethod_aliased(ObjectRef, add_velocity, add_player_velocity),
luamethod_aliased(ObjectRef, get_velocity, getvelocity),
- {"get_player_velocity", ObjectRef::l_get_velocity},
+ luamethod_dep(ObjectRef, get_velocity, get_player_velocity),
// LuaEntitySAO-only
luamethod_aliased(ObjectRef, set_acceleration, setacceleration),
luamethod(ObjectRef, get_eye_offset),
luamethod(ObjectRef, send_mapblock),
luamethod(ObjectRef, set_minimap_modes),
+ luamethod(ObjectRef, set_lighting),
+ luamethod(ObjectRef, get_lighting),
+ luamethod(ObjectRef, respawn),
+
{0,0}
};