5 #include "../Inventory.h"
6 #include "../Defines.h"
8 #include "../Items/ItemHandler.h"
10 #include "../StatisticsManager.h"
93 cPlayer(
const std::shared_ptr<cClientHandle> & a_Client);
167 virtual void TeleportToCoords(
double a_PosX,
double a_PosY,
double a_PosZ)
override;
187 void SendRotation(
double a_YawDegrees,
double a_PitchDegrees);
352 virtual void Heal(
int a_Health)
override;
368 bool Feed(
int a_Food,
double a_Saturation);
445 void UseItem(
int a_SlotNumber,
short a_Damage = 1);
572 bool PlaceBlocks(std::initializer_list<sSetBlock> a_Blocks);
612 std::variant<BodyStanceCrouching, BodyStanceSleeping, BodyStanceSprinting, BodyStanceStanding, BodyStanceGliding>
m_BodyStance;
808 virtual void Tick(std::chrono::milliseconds a_Dt,
cChunk & a_Chunk)
override;
unsigned char NIBBLETYPE
The datatype used by nibbledata (meta, light, skylight)
unsigned char BLOCKTYPE
The datatype used by blockdata.
eDamageType
Damage type, used in the TakeDamageInfo structure and related functions.
std::vector< int > cSlotNums
List of slot numbers, used for inventory-painting.
#define CLASS_PROTODEF(classname)
std::chrono::duration< signed long long int, cTickTime::period > cTickTimeLong
std::chrono::duration< signed int, std::ratio_multiply< std::chrono::milliseconds::period, std::ratio< 50 > >> cTickTime
std::vector< AString > AStringVector
Container for a single chat message composed of multiple functional parts.
bool m_IsFireproof
Whether the entity is capable of taking fire or lava damage.
static const UInt32 INVALID_ID
Special ID that is considered an "invalid value", signifying no entity.
cPawn(eEntityType a_EntityType, float a_Width, float a_Height)
cTeam * UpdateTeam(void)
Forces the player to query the scoreboard for his team.
void SendMessage(const AString &a_Message)
void SendMessageWarning(const AString &a_Message)
std::string m_CurrentWorldName
The name of the world which the player currently resides in.
cClientHandle * GetClientHandle(void) const
bool m_IsFlightCapable
If this is true the player can fly.
void SendAboveActionBarMessage(const AString &a_Message)
void SetFlying(bool a_ShouldFly)
Starts or stops flying, broadcasting the state change.
const AString & GetName(void) const
int m_SkinParts
Displayed skin part bit mask.
bool m_IsFrozen
If true, we are locking m_Position to m_FrozenPosition.
virtual cItem GetEquippedHelmet(void) const override
Returns the currently equipped helmet; empty item if none.
const cSlotNums & GetInventoryPaintSlots(void) const
Returns the list of slots currently stored for inventory painting.
Vector3i GetLastBedPos(void) const
Gets the player's potential respawn position (named LastBedPos for compatibility reasons).
bool IsStanding() const
Returns true if a player is standing normally, that is, in a neutral pose.
void HandleFood(void)
Called in each tick to handle food-related processing.
void ClearInventoryPaintSlots(void)
Clears the list of slots that are being inventory-painted.
void UpdateMovementStats(const Vector3d &a_DeltaPos, bool a_PreviousIsOnGround)
Update movement-related statistics.
void AwardAchievement(CustomStatistic a_Ach)
Awards the player an achievement.
void HandleFloater(void)
Called in each tick if the player is fishing to make sure the floater dissapears when the player does...
AString GetColor(void) const
Returns the full color code to use for this player, based on their rank.
unsigned int m_TicksUntilNextSave
How long till the player's inventory will be saved Default save interval is #defined in PLAYER_INVENT...
int GetSkinParts(void) const
std::string m_SpawnWorldName
The name of the world which the player respawns in upon death.
bool DoesPlacingBlocksIntersectEntity(std::initializer_list< sSetBlock > a_Blocks) const
Whether placing the given blocks would intersect any entitiy.
bool SetCurrentExperience(int a_XpTotal)
Sets the experience total Returns true on success "should" really only be called at init or player de...
std::variant< BodyStanceCrouching, BodyStanceSleeping, BodyStanceSprinting, BodyStanceStanding, BodyStanceGliding > m_BodyStance
The current body stance the player has adopted.
void LoadFromDisk()
Loads the player data from the save file.
void SendMessageInfo(const AString &a_Message)
bool IsFrozen()
Is the player frozen?
void AddInventoryPaintSlot(int a_SlotNum)
Adds a slot to the list for inventory painting.
double GetSprintingMaxSpeed(void) const
Gets the sprinting relative maximum speed.
StatisticsManager & GetStatistics()
Return the associated statistic and achievement manager.
double m_NormalMaxSpeed
Max speed, relative to the game default.
virtual cItem GetEquippedChestplate(void) const override
Returns the currently equipped chestplate; empty item if none.
void SetNormalMaxSpeed(double a_Speed)
Sets the normal relative maximum speed.
int GetCurrentXp(void)
Gets the current experience.
bool HasSkinPart(eSkinPart a_Part) const
cWorld * GetRespawnWorld()
double m_FlyingMaxSpeed
Max speed, relative to the game default flying max speed, when flying.
const cInventory & GetInventory(void) const
void CloseWindow(bool a_CanRefuse=true)
Closes the current window, resets current window to m_InventoryWindow.
void RefreshRank()
(Re)loads the rank and permissions from the cRankManager.
const cUUID & GetUUID(void) const
Returns the UUID that has been read from the client, or nil if not available.
bool IsRespawnPointForced(void) const
Returns if the respawn point is unconditionally used.
bool m_IsLeftHanded
Whether the player is left-handed, or right-handed.
virtual void Killed(const cEntity &a_Victim, eDamageType a_DamageType) override
Called when the entity kills another entity.
double m_SprintingMaxSpeed
Max speed, relative to the game default max speed, when sprinting.
void SendRotation(double a_YawDegrees, double a_PitchDegrees)
Sends the "look" packet to the player, forcing them to set their rotation to the specified values.
cItemGrid m_EnderChestContents
An item grid that stores the player specific enderchest contents.
bool PlaceBlocks(std::initializer_list< sSetBlock > a_Blocks)
Calls the block placement hooks and places the blocks in the world.
void TossItems(const cItems &a_Items)
Tosses a list of items.
const cItem & GetEquippedItem(void) const
void CancelChargingBow(void)
Cancels the current bow charging.
cPlayer(const std::shared_ptr< cClientHandle > &a_Client)
bool HasCustomName(void) const
Returns true if the player has a custom name.
bool Feed(int a_Food, double a_Saturation)
Adds to FoodLevel and FoodSaturationLevel, returns true if any food has been consumed,...
float GetXpPercentage(void) const
Gets the experience bar percentage - XpP.
void SpectateEntity(cEntity *a_Target)
Spectates the target entity.
void SendSystemMessage(const AString &a_Message)
void UpdateCapabilities()
Updates player's capabilities - flying, visibility, etc.
virtual void Tick(std::chrono::milliseconds a_Dt, cChunk &a_Chunk) override
void SendMessageFatal(const AString &a_Message)
void AbortEating(void)
Aborts the current eating operation.
static bool PermissionMatches(const AStringVector &a_Permission, const AStringVector &a_Template)
Returns true iff a_Permission matches the a_Template.
std::string m_DefaultWorldPath
The save path of the default world.
void SetIsFishing(bool a_IsFishing, UInt32 a_FloaterID=cEntity::INVALID_ID)
void SaveToDisk(void)
Saves all player data, such as inventory, to JSON.
virtual bool IsInvisible() const override
int FinishChargingBow(void)
Finishes charging the current bow.
void OpenWindow(cWindow &a_Window)
Opens the specified window; closes the current one first using CloseWindow()
void AddKnownItem(const cItem &a_Item)
Adds an Item to the list of known items.
double GetEyeHeight(void) const
float GetDigSpeed(BLOCKTYPE a_Block)
Returns the dig speed using the current tool on the block a_Block.
AStringVector m_Permissions
All the permissions that this player has, based on their rank.
bool IsGameModeSurvival(void) const
Returns true if the player is in Survival mode, either explicitly, or by inheriting from current worl...
virtual void ApplyArmorDamage(int DamageBlocked) override
Applies damage to the armor after the armor blocked the given amount.
void OpenHorseInventory()
Opens the inventory of any tame horse the player is riding.
std::set< cItem, cItem::sItemCompare > m_KnownItems
List of known items as Ids.
void TossPickup(const cItem &a_Item)
tosses a pickup newly created from a_Item
bool IsFishing(void) const
Returns true if the player has thrown out a floater.
virtual bool IsElytraFlying(void) const override
void SendMessageFailure(const AString &a_Message)
void LoadRank(void)
(Re)loads the rank and permissions from the cRankManager and sends a permission level update to the c...
double m_FoodSaturationLevel
"Overcharge" for the m_FoodLevel; is depleted before m_FoodLevel
bool m_IsManuallyFrozen
Was the player frozen manually by a plugin or automatically by the server?
int DeltaExperience(int a_Xp_delta)
virtual bool CanFly(void) const
Returns wheter the player can fly or not.
std::shared_ptr< cClientHandle > m_ClientHandle
double GetFlyingMaxSpeed(void) const
Gets the flying relative maximum speed.
void AddKnownRecipe(UInt32 RecipeId)
Add the recipe Id to the known recipes.
int m_FoodLevel
Represents the food bar, one point equals half a "drumstick".
void SetBedPos(Vector3i a_Position)
Sets the player's bed position to the specified position.
void SetFoodTickTimer(int a_FoodTickTimer)
AString GetSuffix(void) const
Returns the player name suffix, may contain @ format directives.
int GetXpLevel(void) const
Gets the current level - XpLevel.
void SetSprintingMaxSpeed(double a_Speed)
Sets the sprinting relative maximum speed.
virtual void Heal(int a_Health) override
Heals the player by the specified amount of HPs (positive only); sends health update.
void UseItem(int a_SlotNumber, short a_Damage=1)
Damage the item in a_SlotNumber by a_Damage, possibly less if the equipped item is enchanted.
virtual void HandlePhysics(std::chrono::milliseconds a_Dt, cChunk &) override
Handles the physics of the entity - updates position based on speed, updates speed based on environme...
void SetFlyingMaxSpeed(double a_Speed)
Sets the flying relative maximum speed.
const AString & GetLoadedWorldName() const
void NotifyNearbyWolves(cPawn *a_Opponent, bool a_IsPlayerInvolved)
Notify nearby wolves that the player or one of the player's wolves took damage or did damage to an en...
static const int MAX_HEALTH
AString GetIP(void) const
virtual bool IsCrouched(void) const override
bool IsLeftHanded() const
Returns true if the player's left hand is dominant.
bool m_IsTeleporting
Flag used by food handling system to determine whether a teleport has just happened.
int m_LifetimeTotalXp
Player Xp level.
const AString & GetCustomName(void) const
Returns the custom name of this player.
void TossEquippedItem(char a_Amount=1)
tosses the item in the selected hotbar slot
void StartChargingBow(void)
Starts charging the equipped bow.
static int CalcLevelFromXp(int a_CurrentXp)
Inverse of XpForLevel Ref: https://minecraft.wiki/w/XP values are as per this with pre-calculations.
cItem m_DraggingItem
The item being dragged by the cursor while in a UI window.
UInt32 GetFloaterID(void) const
AString GetUUIDFileName(const cUUID &a_UUID)
Returns the filename for the player data based on the UUID given.
void SetDraggingItem(const cItem &a_Item)
In UI windows, set the item that the player is dragging.
bool IsGameModeCreative(void) const
Returns true if the player is in Creative mode, either explicitly, or by inheriting from current worl...
unsigned int m_EnchantmentSeed
bool IsClimbing(void) const
Returns whether the player is climbing (ladders, vines etc.)
void SetRespawnPosition(Vector3i a_Position, const cWorld &a_World)
Sets the player's forced respawn position and world.
virtual ~cPlayer() override
cWindow * m_InventoryWindow
virtual cItem GetOffHandEquipedItem(void) const override
Returns the currently offhand equipped item; empty item if none.
cTickTimeLong m_EatingFinishTick
The world tick in which eating will be finished.
cInventory & GetInventory(void)
virtual void KilledBy(TakeDamageInfo &a_TDI) override
Called when the health drops below zero.
void TossHeldItem(char a_Amount=1)
tosses the item held in hand (when in UI windows)
eGameMode GetGameMode(void) const
Returns the current gamemode.
virtual void TeleportToCoords(double a_PosX, double a_PosY, double a_PosZ) override
Teleports to the coordinates specified.
void SetVisible(bool a_bVisible)
void FreezeInternal(const Vector3d &a_Location, bool a_ManuallyFrozen)
Pins the player to a_Location until Unfreeze() is called.
virtual void OnDetach() override
Called when this entity dismounts from m_AttachedTo.
cItem & GetDraggingItem(void)
In UI windows, get the item that the player is dragging.
virtual void BroadcastMovementUpdate(const cClientHandle *a_Exclude=nullptr) override
Updates clients of changes in the entity.
void AddFoodExhaustion(double a_Exhaustion)
Adds the specified exhaustion to m_FoodExhaustion.
bool CanMobsTarget(void) const
Returns true if the player can be targeted by Mobs.
void SetFoodLevel(int a_FoodLevel)
static const int MAX_FOOD_LEVEL
Vector3d GetThrowSpeed(double a_SpeedCoeff) const
Returns the initial speed vector of a throw, with a 3D length of a_SpeedCoeff.
void Freeze(const Vector3d &a_Location)
Prevent the player from moving and lock him into a_Location.
bool IsInBed(void) const
Returns true if a player is sleeping in a bed.
std::vector< std::vector< AString > > AStringVectorVector
AStringVector m_Restrictions
All the restrictions that this player has, based on their rank.
cEntity * m_Spectating
The entity that this player is spectating, nullptr if none.
void PermuteEnchantmentSeed()
Permute the seed for enchanting related PRNGs, don't use this for other purposes.
void SetSkinParts(int a_Parts)
double GetNormalMaxSpeed(void) const
Gets the normal relative maximum speed.
bool IsGameModeSpectator(void) const
Returns true if the player is in Spectator mode, either explicitly, or by inheriting from current wor...
void SetLeftHanded(bool a_IsLeftHanded)
Sets the dominant hand of the player.
cItemGrid & GetEnderChestContents(void)
Gets the contents of the player's associated enderchest.
int m_FoodTickTimer
Count-up to the healing or damaging action, based on m_FoodLevel.
bool CanInstantlyMine(BLOCKTYPE a_Block)
Given tool, enchantments, status effects, and world position returns whether a_Block would be instant...
bool HasPermission(const AString &a_Permission) const
bool IsFlying(void) const
Returns true if the player is currently flying.
double GetFoodExhaustionLevel(void) const
bool IsInsideWater()
Checks if the player is inside of water.
int GetXpLifetimeTotal(void)
Gets the experience total - XpTotal for score on death.
void SendMessageSuccess(const AString &a_Message)
bool IsEating(void) const
Returns true if the player is currently in the process of eating the currently equipped item.
const std::set< UInt32 > & GetKnownRecipes() const
Gets the set of IDs for recipes this player has discovered.
void SetFoodExhaustionLevel(double a_FoodExhaustionLevel)
int GetFoodLevel(void) const
void SetTeam(cTeam *a_Team)
Sets the player team, nullptr if none.
void SetElytraFlight(bool a_ShouldElytraFly)
Starts or stops elytra flight, if our current body stance permits, broadcasting the state change.
AString m_Rank
The name of the rank assigned to this player.
virtual void OnAddToWorld(cWorld &a_World) override
Called when the entity is added to a world.
virtual float GetEnchantmentBlastKnockbackReduction() override
Returns explosion knock back reduction percent from blast protection level.
void SendMessageRaw(const AString &a_MessageRaw, eChatType a_Type=eChatType::ctChatBox)
cWindow * GetWindow(void)
void StartEating(void)
Starts eating the currently equipped item.
void SetCrouch(bool a_ShouldCrouch)
Starts or stops crouching, if our current body stance permits, broadcasting the state change.
void SendBlocksAround(Vector3i a_BlockPos, int a_Range=1)
Sends the block in the specified range around the specified coord to the client as a block change pac...
const cWindow * GetWindow(void) const
cInventory m_Inventory
Stores the player's inventory, consisting of crafting grid, hotbar, and main slots.
Vector3i m_RespawnPosition
The player's potential respawn position, initialised to world spawn by default.
cWindow * m_CurrentWindow
void SendMessagePrivateMsg(const AString &a_Message, const AString &a_Sender)
const AStringVector & GetPermissions(void) const
Returns all the permissions that the player has assigned to them.
virtual cItem GetEquippedBoots(void) const override
Returns the currently equipped boots; empty item if none.
void ForceSetSpeed(const Vector3d &a_Speed)
Forces the player to move in the given direction.
void CloseWindowIfID(char a_WindowID, bool a_CanRefuse=true)
Closes the current window if it matches the specified ID, resets current window to m_InventoryWindow.
AStringVectorVector m_SplitRestrictions
All the restrictions that this player has, based on their rank, split into individual dot-delimited p...
virtual void SpawnOn(cClientHandle &a_Client) override
Descendants override this function to send a command to the specified client to spawn the entity on t...
void SetFoodSaturationLevel(double a_FoodSaturationLevel)
cTeam * GetTeam(void)
Returns the associated team, nullptr if none.
Vector3d GetEyePosition(void) const
virtual bool IsSprinting(void) const override
bool IsSatiated(void) const
Returns true if the player is satiated, i.
virtual bool IsFireproof() const override
Returns true if the player is fireproof Stops players burning in creative or spectator modes.
Vector3d GetThrowStartPos(void) const
Returns the position where projectiles thrown by this player should start, player eye position + adju...
void SetSprint(bool a_ShouldSprint)
Starts or stops sprinting, if our current body stance permits, broadcasting the state change.
float GetLiquidHeightPercent(NIBBLETYPE a_Meta)
Returns how high the liquid is in percent.
AStringVectorVector m_SplitPermissions
All the permissions that this player has, based on their rank, split into individual dot-delimited pa...
void Unfreeze()
Cancels Freeze(...) and allows the player to move naturally.
void SetCustomName(const AString &a_CustomName)
Sets the custom name of this player.
const cTeam * GetTeam(void) const
Returns the associated team, nullptr if none.
virtual cItem GetEquippedLeggings(void) const override
Returns the currently equipped leggings; empty item if none.
AString GetPrefix(void) const
Returns the player name prefix, may contain @ format directives.
void ReplaceOneEquippedItemTossRest(const cItem &)
Removes one item from the the current equipped item stack, and attempts to add the specified item sta...
bool IsGameModeAdventure(void) const
Returns true if the player is in Adventure mode, either explicitly, or by inheriting from current wor...
virtual cItem GetEquippedWeapon(void) const override
Returns the curently equipped weapon; empty item if none.
AString GetPlayerListName(void) const
Returns the name that is used in the playerlist.
void SetCanFly(bool a_CanFly)
If true the player can fly even when he's not in creative.
void SetTouchGround(bool a_bTouchGround)
virtual void OnRemoveFromWorld(cWorld &a_World) override
Called when the entity is removed from a world.
double m_FoodExhaustionLevel
A "buffer" which adds up hunger before it is substracted from m_FoodSaturationLevel or m_FoodLevel.
StatisticsManager m_Stats
MTRand GetEnchantmentRandomProvider()
Get a copy of the PRNG for enchanting related generation, don't use this for other purposes.
double GetMaxSpeed(void) const
Returns the current relative maximum speed (takes current sprinting / flying state into account)
virtual bool IsRclking(void) const override
void OnLoseSpectated()
Called when spectation stops, because the player crouched or when the entity we're spectating gets re...
virtual bool DoTakeDamage(TakeDamageInfo &TDI) override
Makes this entity take damage specified in the a_TDI.
static int XpForLevel(int a_Level)
Calculates the amount of XP needed for a given level Ref: https://minecraft.wiki/w/XP.
virtual bool IsOnGround(void) const override
Returns whether the entity is on ground or not.
void FinishEating(void)
Finishes eating the currently equipped item.
float GetMiningProgressPerTick(BLOCKTYPE a_Block)
Returns the progress mined per tick for the block a_Block as a fraction (1 would be completely mined)...
std::set< UInt32 > m_KnownRecipes
List on known recipes as Ids.
const AStringVector & GetRestrictions(void) const
Returns all the restrictions that the player has assigned to them.
eGameMode GetEffectiveGameMode(void) const
Returns the current effective gamemode (inherited gamemode is resolved before returning)
void UseEquippedItem(short a_Damage=1)
Damage the player's equipped item by a_Damage, possibly less if the equipped item is enchanted.
int GetFoodTickTimer(void) const
cSlotNums m_InventoryPaintSlots
double GetFoodSaturationLevel(void) const
void SetIsInBed(bool a_IsInBed)
Sets a player's in-bed state.
bool m_IsRespawnPointForced
Whether we unconditionally respawn to m_RespawnPosition, or check if a bed is unobstructed and availa...
bool PlaceBlock(Vector3i a_Position, BLOCKTYPE a_BlockType, NIBBLETYPE a_BlockMeta)
Attempts to place the block in the world with a call to PlaceBlocks.
AString m_MsgNameColorCode
void SetGameMode(eGameMode a_GameMode)
Sets the gamemode for the player.
bool IsChargingBow(void) const
Returns true if the player is currently charging the bow.
Tag representing a sneaking pose.
BodyStanceCrouching(cPlayer &a_Player)
Tag representing a sleeping pose.
BodyStanceSleeping(cPlayer &a_Player)
Tag representing a sprinting pose.
Tag representing the neutral stance.
BodyStanceStanding(cPlayer &a_Player)
Tag representing a swimming or elytra flying pose.
cTickTime TicksElytraFlying
BodyStanceGliding(cPlayer &a_Player)
Class to wrap any random engine to provide a more convenient interface.
This class represents the player's inventory The slots are divided into three areas:
const cItem & GetEquippedChestplate(void) const
const cItem & GetEquippedBoots(void) const
const cItem & GetEquippedHelmet(void) const
const cItem & GetEquippedItem(void) const
Returns current equiped item.
const cItem & GetShieldSlot() const
Returns current item in shield slot.
const cItem & GetEquippedLeggings(void) const
This class bridges a vector of cItem for safe access via Lua.
eDurabilityLostAction
Actions that may cause durability of an item may be lost, where the magnitude of the loss depends on ...
Class that manages the statistics and achievements of a single player.