Botcraft 1.21.4
Loading...
Searching...
No Matches
Botcraft::PhysicsManager Class Reference

#include <PhysicsManager.hpp>

Inheritance diagram for Botcraft::PhysicsManager:
ProtocolCraft::Handler ProtocolCraft::GenericHandler< Message, AllMessages >

Public Member Functions

 PhysicsManager ()=delete
 
 PhysicsManager (const std::shared_ptr< Renderer::RenderingManager > &rendering_manager_, const std::shared_ptr< InventoryManager > &inventory_manager_, const std::shared_ptr< EntityManager > &entity_manager_, const std::shared_ptr< NetworkManager > &network_manager_, const std::shared_ptr< World > &world_)
 
 ~PhysicsManager ()
 
void StartPhysics ()
 
void StopPhysics ()
 
void SetDoubleTapCauseSprint (const bool b)
 Enable/disable auto triggering of sprint when press/unpress/press forward key in less than 7 ticks (enabled by default)
 
double GetMsPerTick () const
 

Protected Member Functions

virtual void Handle (ProtocolCraft::ClientboundLoginPacket &msg) override
 
virtual void Handle (ProtocolCraft::ClientboundPlayerPositionPacket &msg) override
 
virtual void Handle (ProtocolCraft::ClientboundTickingStatePacket &msg) override
 
virtual void Handle (ProtocolCraft::ClientboundPlayerRotationPacket &msg) override
 

Private Member Functions

void Physics ()
 
void PhysicsTick ()
 Follow minecraft physics related flow in LocalPlayer tick function.
 
void UpdateSwimming () const
 
void FluidPhysics (const bool water)
 Perform fluid physics on the player, and set in_water/lava boolean accordingly.
 
void InputsToCrouch () const
 
void InputsToSprint () const
 
void SetSprinting (const bool b) const
 
void InputsToFly () const
 
void InputsToJump () const
 
void ApplyInputs (const float strength) const
 
void SendPosition ()
 Send position/rotation/on_ground to server.
 
Vector3< double > CollideBoundingBox (const AABB &aabb, const Vector3< double > &movement) const
 Check collisions of an AABB with a given movement.
 
void CollideOneAxis (AABB &aabb, Vector3< double > &movement, const unsigned int axis, const std::vector< AABB > &colliders) const
 
bool IsSwimmingAndNotFlying () const
 
bool IsInClimbable () const
 
void MovePlayer () const
 
void ApplyMovement () const
 
void OnUpdateAbilities () const
 
void CheckInsideBlocks () const
 
Position GetBlockBelowAffectingMovement () const
 

Private Attributes

std::shared_ptr< Renderer::RenderingManagerrendering_manager
 
std::shared_ptr< EntityManagerentity_manager
 
std::shared_ptr< InventoryManagerinventory_manager
 
std::shared_ptr< LocalPlayerplayer
 
std::shared_ptr< NetworkManagernetwork_manager
 
std::shared_ptr< Worldworld
 
std::atomic< bool > should_run
 
std::optional< int > teleport_id
 
int ticks_since_last_position_sent
 
std::thread thread_physics
 
const Itemelytra_item
 
std::atomic< double > ms_per_tick = 50.0
 
std::atomic< bool > double_tap_cause_sprint
 

Detailed Description

Definition at line 30 of file PhysicsManager.hpp.

Constructor & Destructor Documentation

◆ PhysicsManager() [1/2]

Botcraft::PhysicsManager::PhysicsManager ( )
delete

◆ PhysicsManager() [2/2]

Botcraft::PhysicsManager::PhysicsManager ( const std::shared_ptr< Renderer::RenderingManager > &  rendering_manager_,
const std::shared_ptr< InventoryManager > &  inventory_manager_,
const std::shared_ptr< EntityManager > &  entity_manager_,
const std::shared_ptr< NetworkManager > &  network_manager_,
const std::shared_ptr< World > &  world_ 
)

◆ ~PhysicsManager()

Botcraft::PhysicsManager::~PhysicsManager ( )

Definition at line 52 of file PhysicsManager.cpp.

References StopPhysics().

Member Function Documentation

◆ ApplyInputs()

void Botcraft::PhysicsManager::ApplyInputs ( const float  strength) const
private

◆ ApplyMovement()

◆ CheckInsideBlocks()

◆ CollideBoundingBox()

Vector3< double > Botcraft::PhysicsManager::CollideBoundingBox ( const AABB aabb,
const Vector3< double > &  movement 
) const
private

Check collisions of an AABB with a given movement.

Parameters
aabbAABB to move
movementMovement vector to apply to AABB
Returns
New movement vector after collisions

Definition at line 1078 of file PhysicsManager.cpp.

References CollideOneAxis(), world, Botcraft::Vector3< T >::x, and Botcraft::Vector3< T >::z.

Referenced by ApplyMovement().

◆ CollideOneAxis()

void Botcraft::PhysicsManager::CollideOneAxis ( AABB aabb,
Vector3< double > &  movement,
const unsigned int  axis,
const std::vector< AABB > &  colliders 
) const
private

◆ FluidPhysics()

void Botcraft::PhysicsManager::FluidPhysics ( const bool  water)
private

◆ GetBlockBelowAffectingMovement()

Position Botcraft::PhysicsManager::GetBlockBelowAffectingMovement ( ) const
private

Definition at line 1665 of file PhysicsManager.cpp.

References player, and Botcraft::Vector3< T >::y.

Referenced by ApplyMovement(), InputsToJump(), and MovePlayer().

◆ GetMsPerTick()

double Botcraft::PhysicsManager::GetMsPerTick ( ) const

Definition at line 85 of file PhysicsManager.cpp.

References ms_per_tick.

◆ Handle() [1/4]

void Botcraft::PhysicsManager::Handle ( ProtocolCraft::ClientboundLoginPacket msg)
overrideprotectedvirtual

Definition at line 91 of file PhysicsManager.cpp.

References entity_manager, and player.

◆ Handle() [2/4]

void Botcraft::PhysicsManager::Handle ( ProtocolCraft::ClientboundPlayerPositionPacket msg)
overrideprotectedvirtual

◆ Handle() [3/4]

void Botcraft::PhysicsManager::Handle ( ProtocolCraft::ClientboundPlayerRotationPacket msg)
overrideprotectedvirtual

Definition at line 215 of file PhysicsManager.cpp.

References LOG_WARNING, and player.

◆ Handle() [4/4]

void Botcraft::PhysicsManager::Handle ( ProtocolCraft::ClientboundTickingStatePacket msg)
overrideprotectedvirtual

Definition at line 199 of file PhysicsManager.cpp.

References ms_per_tick.

◆ InputsToCrouch()

◆ InputsToFly()

◆ InputsToJump()

void Botcraft::PhysicsManager::InputsToJump ( ) const
private

◆ InputsToSprint()

void Botcraft::PhysicsManager::InputsToSprint ( ) const
private

◆ IsInClimbable()

bool Botcraft::PhysicsManager::IsInClimbable ( ) const
private

Definition at line 1151 of file PhysicsManager.cpp.

References Botcraft::Blockstate::IsClimbable(), player, Botcraft::Spectator, and world.

Referenced by PhysicsTick().

◆ IsSwimmingAndNotFlying()

bool Botcraft::PhysicsManager::IsSwimmingAndNotFlying ( ) const
private

◆ MovePlayer()

◆ OnUpdateAbilities()

void Botcraft::PhysicsManager::OnUpdateAbilities ( ) const
private

Definition at line 1573 of file PhysicsManager.cpp.

References network_manager, and player.

Referenced by InputsToFly(), and PhysicsTick().

◆ Physics()

◆ PhysicsTick()

◆ SendPosition()

void Botcraft::PhysicsManager::SendPosition ( )
private

◆ SetDoubleTapCauseSprint()

void Botcraft::PhysicsManager::SetDoubleTapCauseSprint ( const bool  b)

Enable/disable auto triggering of sprint when press/unpress/press forward key in less than 7 ticks (enabled by default)

Parameters
bDouble tap will start sprinting if b is true

Definition at line 74 of file PhysicsManager.cpp.

References double_tap_cause_sprint, and player.

◆ SetSprinting()

void Botcraft::PhysicsManager::SetSprinting ( const bool  b) const
private

◆ StartPhysics()

void Botcraft::PhysicsManager::StartPhysics ( )

Definition at line 57 of file PhysicsManager.cpp.

References Physics(), should_run, and thread_physics.

◆ StopPhysics()

void Botcraft::PhysicsManager::StopPhysics ( )

Definition at line 65 of file PhysicsManager.cpp.

References should_run, and thread_physics.

Referenced by ~PhysicsManager().

◆ UpdateSwimming()

void Botcraft::PhysicsManager::UpdateSwimming ( ) const
private

Member Data Documentation

◆ double_tap_cause_sprint

std::atomic<bool> Botcraft::PhysicsManager::double_tap_cause_sprint
private

Definition at line 125 of file PhysicsManager.hpp.

Referenced by InputsToSprint(), PhysicsManager(), and SetDoubleTapCauseSprint().

◆ elytra_item

const Item* Botcraft::PhysicsManager::elytra_item
private

Definition at line 117 of file PhysicsManager.hpp.

Referenced by InputsToFly(), and PhysicsManager().

◆ entity_manager

std::shared_ptr<EntityManager> Botcraft::PhysicsManager::entity_manager
private

Definition at line 104 of file PhysicsManager.hpp.

Referenced by Handle(), PhysicsManager(), and PhysicsTick().

◆ inventory_manager

std::shared_ptr<InventoryManager> Botcraft::PhysicsManager::inventory_manager
private

◆ ms_per_tick

std::atomic<double> Botcraft::PhysicsManager::ms_per_tick = 50.0
private

Definition at line 120 of file PhysicsManager.hpp.

Referenced by GetMsPerTick(), Handle(), and Physics().

◆ network_manager

std::shared_ptr<NetworkManager> Botcraft::PhysicsManager::network_manager
private

◆ player

◆ rendering_manager

std::shared_ptr<Renderer::RenderingManager> Botcraft::PhysicsManager::rendering_manager
private

Definition at line 102 of file PhysicsManager.hpp.

Referenced by PhysicsManager(), and SendPosition().

◆ should_run

std::atomic<bool> Botcraft::PhysicsManager::should_run
private

Definition at line 110 of file PhysicsManager.hpp.

Referenced by Physics(), PhysicsManager(), StartPhysics(), and StopPhysics().

◆ teleport_id

std::optional<int> Botcraft::PhysicsManager::teleport_id
private

Definition at line 111 of file PhysicsManager.hpp.

Referenced by Handle(), Physics(), and PhysicsManager().

◆ thread_physics

std::thread Botcraft::PhysicsManager::thread_physics
private

Definition at line 115 of file PhysicsManager.hpp.

Referenced by StartPhysics(), and StopPhysics().

◆ ticks_since_last_position_sent

int Botcraft::PhysicsManager::ticks_since_last_position_sent
private

Definition at line 113 of file PhysicsManager.hpp.

Referenced by PhysicsManager(), and SendPosition().

◆ world


The documentation for this class was generated from the following files: