#include "network/networkprotocol.h"
#include "unit_sao.h"
#include "util/numeric.h"
+#include "util/pointedthing.h"
/*
PlayerSAO needs some internals exposed.
PlayerSAO(ServerEnvironment *env_, RemotePlayer *player_, session_t peer_id_,
bool is_singleplayer);
- ActiveObjectType getType() const { return ACTIVEOBJECT_TYPE_PLAYER; }
- ActiveObjectType getSendType() const { return ACTIVEOBJECT_TYPE_GENERIC; }
- std::string getDescription();
+ ActiveObjectType getType() const override { return ACTIVEOBJECT_TYPE_PLAYER; }
+ ActiveObjectType getSendType() const override { return ACTIVEOBJECT_TYPE_GENERIC; }
+ std::string getDescription() override;
/*
Active object <-> environment interface
*/
- void addedToEnvironment(u32 dtime_s);
- void removingFromEnvironment();
- bool isStaticAllowed() const { return false; }
- bool shouldUnload() const { return false; }
- std::string getClientInitializationData(u16 protocol_version);
- void getStaticData(std::string *result) const;
- void step(float dtime, bool send_recommended);
- void setBasePosition(const v3f &position);
- void setPos(const v3f &pos);
- void moveTo(v3f pos, bool continuous);
+ void addedToEnvironment(u32 dtime_s) override;
+ void removingFromEnvironment() override;
+ bool isStaticAllowed() const override { return false; }
+ bool shouldUnload() const override { return false; }
+ std::string getClientInitializationData(u16 protocol_version) override;
+ void getStaticData(std::string *result) const override;
+ void step(float dtime, bool send_recommended) override;
+ void setBasePosition(v3f position);
+ void setPos(const v3f &pos) override;
+ void moveTo(v3f pos, bool continuous) override;
void setPlayerYaw(const float yaw);
// Data should not be sent at player initialization
void setPlayerYawAndSend(const float yaw);
Interaction interface
*/
- u16 punch(v3f dir, const ToolCapabilities *toolcap, ServerActiveObject *puncher,
- float time_from_last_punch);
- void rightClick(ServerActiveObject *clicker);
- void setHP(s32 hp, const PlayerHPChangeReason &reason);
+ u32 punch(v3f dir, const ToolCapabilities *toolcap, ServerActiveObject *puncher,
+ float time_from_last_punch, u16 initial_wear = 0) override;
+ void rightClick(ServerActiveObject *clicker) override;
+ void setHP(s32 hp, const PlayerHPChangeReason &reason) override
+ {
+ return setHP(hp, reason, false);
+ }
+ void setHP(s32 hp, const PlayerHPChangeReason &reason, bool from_client);
void setHPRaw(u16 hp) { m_hp = hp; }
- s16 readDamage();
u16 getBreath() const { return m_breath; }
void setBreath(const u16 breath, bool send = true);
/*
Inventory interface
*/
- Inventory *getInventory() const;
- InventoryLocation getInventoryLocation() const;
- void setInventoryModified() {}
- std::string getWieldList() const { return "main"; }
- u16 getWieldIndex() const;
- ItemStack getWieldedItem(ItemStack *selected, ItemStack *hand = nullptr) const;
- bool setWieldedItem(const ItemStack &item);
+ Inventory *getInventory() const override;
+ InventoryLocation getInventoryLocation() const override;
+ void setInventoryModified() override {}
+ std::string getWieldList() const override { return "main"; }
+ u16 getWieldIndex() const override;
+ ItemStack getWieldedItem(ItemStack *selected, ItemStack *hand = nullptr) const override;
+ bool getOffhandWieldedItem(ItemStack *offhand, ItemStack *place, IItemDefManager *itemdef_manager, PointedThing pointed) const;
+ bool setWieldedItem(const ItemStack &item) override;
+ bool setOffhandWieldedItem(const ItemStack &item);
/*
PlayerSAO-specific
m_is_singleplayer = is_singleplayer;
}
- bool getCollisionBox(aabb3f *toset) const;
- bool getSelectionBox(aabb3f *toset) const;
- bool collideWithObjects() const { return true; }
+ bool getCollisionBox(aabb3f *toset) const override;
+ bool getSelectionBox(aabb3f *toset) const override;
+ bool collideWithObjects() const override { return true; }
void finalize(RemotePlayer *player, const std::set<std::string> &privs);
v3f getEyeOffset() const;
float getZoomFOV() const;
- inline Metadata &getMeta() { return m_meta; }
+ inline SimpleMetadata &getMeta() { return m_meta; }
private:
std::string getPropertyPacket();
f32 m_fov = 0.0f;
s16 m_wanted_range = 0.0f;
- Metadata m_meta;
+ SimpleMetadata m_meta;
public:
- float m_physics_override_speed = 1.0f;
- float m_physics_override_jump = 1.0f;
- float m_physics_override_gravity = 1.0f;
- bool m_physics_override_sneak = true;
- bool m_physics_override_sneak_glitch = false;
- bool m_physics_override_new_move = true;
bool m_physics_override_sent = false;
};
enum Type : u8
{
SET_HP,
+ SET_HP_MAX, // internal type to allow distinguishing hp reset and damage (for effects)
PLAYER_PUNCH,
FALL,
NODE_DAMAGE,
{
switch (type) {
case PlayerHPChangeReason::SET_HP:
+ case PlayerHPChangeReason::SET_HP_MAX:
return "set_hp";
case PlayerHPChangeReason::PLAYER_PUNCH:
return "punch";