player
Player entity management and physics controller.
This module defines the Player class, which extends the base Camera to add AABB (Axis-Aligned Bounding Box) collision detection, gravity, fluid dynamics, inventory state, and survival statistics (health, hunger, oxygen). It acts as the primary interface between user input and the 3D voxel world.
- class player.Player(app, position=None, yaw=-90.0, pitch=0.0)[source]
Bases:
CameraRepresents the player entity in the world.
Handles movement physics, collision detection, block interaction, inventory management, and survival statistics like health and hunger.
- Parameters:
- find_spawn_position()[source]
Locates a valid surface spawn position near the center of the world by scanning outward iteratively until a solid block above water is found.
- Return type:
- update()[source]
Called every frame. Updates player inputs, physics logic, view bobbing, dynamic FOV for sprinting, fluid dynamics, and core survival metric drains.
- Return type:
None
- handle_event(event)[source]
Processes discrete user inputs such as key presses (mode toggling, hotbar selection) and mouse clicks (block mining and placing).
- Parameters:
event (Any)
- Return type:
None
- mouse_control()[source]
Retrieves relative mouse movement and adjusts the camera’s yaw and pitch based on the configured sensitivity.
- Return type:
None
- handle_interaction()[source]
Processes continuous block interactions (mining and placing). Factoring in tool requirements, block hardness, and interaction delays.
- Return type:
None
- keyboard_control()[source]
Calculates movement vectors based on keyboard input. Adapts movement physics depending on whether the player is in Creative or Survival mode.
- Return type:
None
- apply_gravity()[source]
Applies downward gravitational acceleration to the player’s vertical velocity, accounting for drag if the player is swimming in water.
- Return type:
None
- move_and_collide()[source]
Moves the player incrementally along the X, Y, and Z axes, resolving collision clipping individually for each axis.
- Return type:
None
- resolve_axis(axis)[source]
Checks for intersection between the player’s AABB and the surrounding solid voxels. Stops the player’s velocity along the tested axis if a collision is detected to prevent clipping.
- Parameters:
axis (str)
- Return type:
None
- get_aabb()[source]
Calculates and returns the minimum and maximum boundaries of the Axis-Aligned Bounding Box representing the player’s physical volume.
- static aabb_intersect(a_min, a_max, b_min, b_max)[source]
Static helper that determines if two given 3D Axis-Aligned Bounding Boxes overlap with each other.
- add_item(voxel_id)[source]
Attempts to add an item to the player’s inventory by stacking onto existing slots or finding an empty one. Returns True if successful.