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