Fix set_camera() not being resettable

This commit is contained in:
sfan5
2026-04-11 15:38:29 +02:00
parent a12ac21066
commit ea929b4368
7 changed files with 28 additions and 12 deletions
+1
View File
@@ -54,6 +54,7 @@ core.features = {
chunksize_vector = true,
item_inventory_image_animation = true,
get_modnames_load_order = true,
set_camera_resettable = true,
}
function core.has_feature(arg)
+11 -6
View File
@@ -6123,7 +6123,7 @@ Utilities
remove_item_match_meta = true,
-- The HTTP API supports the HEAD and PATCH methods (5.12.0)
httpfetch_additional_methods = true,
-- objects have get_guid method (5.13.0)
-- `ObjectRef:get_guid()` method exists (5.13.0)
object_guids = true,
-- The NodeTimer `on_timer` callback is passed additional `node` and `timeout` args (5.14.0)
on_timer_four_args = true,
@@ -6136,8 +6136,10 @@ Utilities
-- Item definition fields `inventory_image`, `inventory_overlay`, `wield_image`
-- and `wield_overlay` accept a table containing animation definitions. (5.15.0)
item_image_animation = true,
-- `core.get_modnames`' parameter `load_order` (5.16.0)
-- `core.get_modnames` has parameter `load_order` (5.16.0)
get_modnames_load_order = true,
-- `ObjectRef:set_camera()` accepts `nil` to indicate reset (5.16.0)
set_camera_resettable = true,
}
```
@@ -9395,21 +9397,24 @@ child will follow movement and rotation of that bone.
Defaults to `thirdperson_back` if unspecified.
* `get_eye_offset()`: Returns camera offset vectors as set via `set_eye_offset`.
* `set_camera(params)`: Sets camera parameters.
* `params` must be a table to update the parameters or `nil` (requires >= 5.16.0)
to reset all parameters to defaults.
* `mode`: Defines the camera mode used
- `any`: free choice between all modes (default)
- `first`: first-person camera
- `third`: third-person camera
- `third_front`: third-person camera, looking opposite of movement direction
* Supported by client since 5.12.0.
* Supported by clients since 5.12.0.
* `get_camera()`: Returns the camera parameters as a table as above.
* `send_mapblock(blockpos)`:
* Sends an already loaded mapblock to the player.
* Returns `false` if nothing was sent (note that this can also mean that
the client already has the block)
* Resource intensive - use sparsely
* `set_lighting(light_definition)`: sets lighting for the player
* Passing no arguments resets lighting to its default values.
* `light_definition` is a table with the following optional fields:
* `set_lighting(light_def)`: Sets lighting for the player
* `light_def` must be a table to update the parameters or `nil` to reset all
light parameters to defaults.
* Table fields:
* `saturation` sets the saturation (vividness; default: `1.0`).
* It is applied according to the function `result = b*(1-s) + c*s`, where:
* `c` is the original color
+1
View File
@@ -356,6 +356,7 @@ void Camera::update(LocalPlayer* player, f32 frametime, f32 tool_reload_ratio)
v3f eye_offset = player->getEyeOffset();
switch(m_camera_mode) {
case CAMERA_MODE_ANY:
case CameraMode_END:
assert(false);
break;
case CAMERA_MODE_FIRST:
+1
View File
@@ -2683,6 +2683,7 @@ void Game::processPlayerInteraction(f32 dtime, bool show_hud)
switch (camera->getCameraMode()) {
case CAMERA_MODE_ANY:
case CameraMode_END:
assert(false);
break;
case CAMERA_MODE_FIRST:
+2
View File
@@ -1597,6 +1597,8 @@ void Client::handleCommand_Camera(NetworkPacket* pkt)
u8 tmp;
*pkt >> tmp;
player->allowed_camera_mode = static_cast<CameraMode>(tmp);
if (player->allowed_camera_mode >= CameraMode_END)
player->allowed_camera_mode = CAMERA_MODE_ANY;
m_client_event_queue.push(new ClientEvent(CE_UPDATE_CAMERA));
}
+3 -1
View File
@@ -129,7 +129,9 @@ enum CameraMode : int {
CAMERA_MODE_ANY = 0,
CAMERA_MODE_FIRST,
CAMERA_MODE_THIRD,
CAMERA_MODE_THIRD_FRONT
CAMERA_MODE_THIRD_FRONT,
CameraMode_END // Dummy for validity check
};
extern const struct EnumString es_CameraMode[];
+9 -5
View File
@@ -533,12 +533,16 @@ int ObjectRef::l_set_camera(lua_State *L)
if (player == nullptr)
return 0;
luaL_checktype(L, 2, LUA_TTABLE);
if (lua_isnoneornil(L, 2)) {
player->allowed_camera_mode = CAMERA_MODE_ANY;
} else {
luaL_checktype(L, 2, LUA_TTABLE);
lua_getfield(L, -1, "mode");
if (lua_isstring(L, -1))
string_to_enum(es_CameraMode, player->allowed_camera_mode, lua_tostring(L, -1));
lua_pop(L, 1);
lua_getfield(L, -1, "mode");
if (lua_isstring(L, -1))
string_to_enum(es_CameraMode, player->allowed_camera_mode, lua_tostring(L, -1));
lua_pop(L, 1);
}
getServer(L)->SendCamera(player->getPeerId(), player);
return 0;