Skip to content
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions doc/lua_api.md
Original file line number Diff line number Diff line change
Expand Up @@ -9028,6 +9028,7 @@ child will follow movement and rotation of that bone.
alpha channel is used to set overall star brightness.
(default: `#ebebff69`)
* `scale`: Float controlling the overall size of the stars (default: `1`)
* `star_seed`: Integer number which decides how to generate the sky stars. If set to zero, client picks a random number. (default: `0`)
* `get_stars()`: returns a table with the current stars parameters as in
`set_stars`.
* `set_clouds(cloud_parameters)`: set cloud parameters
Expand Down
4 changes: 3 additions & 1 deletion src/client/game.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -2850,7 +2850,7 @@ void Game::handleClientEvent_SetSky(ClientEvent *event, CameraOrientation *cam)
);
} else if (event->set_sky->type == "skybox" &&
event->set_sky->textures.size() == 6) {
// Disable the dyanmic mesh skybox:
// Disable the dynamic mesh skybox:
sky->setVisible(false);
// Set fog colors:
sky->setFallbackBgColor(event->set_sky->bgcolor);
Expand Down Expand Up @@ -2926,6 +2926,8 @@ void Game::handleClientEvent_SetStars(ClientEvent *event, CameraOrientation *cam
sky->setStarColor(event->star_params->starcolor);
sky->setStarScale(event->star_params->scale);
sky->setStarDayOpacity(event->star_params->day_opacity);
if (event->star_params->star_seed != 0)
sky->setStarSeed(event->star_params->star_seed);
delete event->star_params;
}

Expand Down
9 changes: 9 additions & 0 deletions src/client/sky.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -805,6 +805,15 @@ void Sky::setStarCount(u16 star_count)
}
}

void Sky::setStarSeed(u64 star_seed)
{
// Allow force updating star seed at game init.
if (m_star_params.star_seed != star_seed || m_first_update) {
Copy link
Contributor

@appgurueu appgurueu Nov 19, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Nitpick: I don't think the || m_first_update is necessary. setStarCount already calls updateStars() on the first update; if the star_seed is unchanged, there's nothing to do?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

alright! If you say so :) I copied || m_first_update from setStarCount thinking that it's a typical setter, but turns out setStarCount is a special case which I do not completely understand yet. o.0 Does setStarCount check m_first_update because it is called in Sky constructor?

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Does setStarCount check m_first_update because it is called in Sky constructor?

Basically. Something needs to call updateStars the first time, and setStarCount does that.

This could probably be refactored, but we can do that later.

In either case it's not a problem.

m_star_params.star_seed = star_seed;
updateStars();
}
}

void Sky::updateStars()
{
m_stars.reset(new scene::SMeshBuffer());
Expand Down
1 change: 1 addition & 0 deletions src/client/sky.h
Original file line number Diff line number Diff line change
Expand Up @@ -77,6 +77,7 @@ class Sky : public scene::ISceneNode
void setStarColor(video::SColor star_color) { m_star_params.starcolor = star_color; }
void setStarScale(f32 star_scale) { m_star_params.scale = star_scale; updateStars(); }
void setStarDayOpacity(f32 day_opacity) { m_star_params.day_opacity = day_opacity; }
void setStarSeed(u64 star_seed);

bool getCloudsVisible() const { return m_clouds_visible && m_clouds_enabled; }
const video::SColorf &getCloudColor() const { return m_cloudcolor_f; }
Expand Down
1 change: 1 addition & 0 deletions src/network/clientpackethandler.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1444,6 +1444,7 @@ void Client::handleCommand_HudSetStars(NetworkPacket *pkt)
>> stars.starcolor >> stars.scale;
try {
*pkt >> stars.day_opacity;
*pkt >> stars.star_seed;
} catch (PacketError &e) {};

ClientEvent *event = new ClientEvent();
Expand Down
3 changes: 3 additions & 0 deletions src/script/lua_api/l_object.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -2452,6 +2452,7 @@ int ObjectRef::l_set_stars(lua_State *L)
"scale", star_params.scale);
star_params.day_opacity = getfloatfield_default(L, 2,
"day_opacity", star_params.day_opacity);
star_params.star_seed = getintfield_default(L, 2, "star_seed", star_params.star_seed);
}

getServer(L)->setStars(player, star_params);
Expand Down Expand Up @@ -2480,6 +2481,8 @@ int ObjectRef::l_get_stars(lua_State *L)
lua_setfield(L, -2, "scale");
lua_pushnumber(L, star_params.day_opacity);
lua_setfield(L, -2, "day_opacity");
lua_pushnumber(L, star_params.star_seed);
lua_setfield(L, -2, "star_seed");
return 1;
}

Expand Down
2 changes: 1 addition & 1 deletion src/server.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1953,7 +1953,7 @@ void Server::SendSetStars(session_t peer_id, const StarParams &params)

pkt << params.visible << params.count
<< params.starcolor << params.scale
<< params.day_opacity;
<< params.day_opacity << params.star_seed;

Send(&pkt);
}
Expand Down
2 changes: 2 additions & 0 deletions src/skyparams.h
Original file line number Diff line number Diff line change
Expand Up @@ -64,6 +64,7 @@ struct StarParams
video::SColor starcolor;
f32 scale;
f32 day_opacity;
u64 star_seed;
};

struct CloudParams
Expand Down Expand Up @@ -142,6 +143,7 @@ class SkyboxDefaults
stars.starcolor = video::SColor(105, 235, 235, 255);
stars.scale = 1;
stars.day_opacity = 0;
stars.star_seed = 0;
return stars;
}

Expand Down
Loading