Skip to content

Commit

Permalink
refactor: move getAttribute from Player to Actor
Browse files Browse the repository at this point in the history
  • Loading branch information
wu-vincent committed Jun 18, 2024
1 parent c1e33ac commit ed5fbc8
Show file tree
Hide file tree
Showing 5 changed files with 9 additions and 9 deletions.
1 change: 1 addition & 0 deletions include/bedrock/world/actor/actor.h
Original file line number Diff line number Diff line change
Expand Up @@ -269,6 +269,7 @@ class Actor {
[[nodiscard]] bool isRiding() const;
[[nodiscard]] bool hasCategory(ActorCategory) const;
[[nodiscard]] bool isJumping() const;
[[nodiscard]] const AttributeInstance &getAttribute(const Attribute &) const;

static Actor *tryGetFromEntity(EntityContext const &, bool include_removed);

Expand Down
1 change: 0 additions & 1 deletion include/bedrock/world/actor/player/player.h
Original file line number Diff line number Diff line change
Expand Up @@ -128,7 +128,6 @@ class Player : public Mob {
[[nodiscard]] bool isEmoting() const;
[[nodiscard]] bool isFlying() const;
// Attributes
[[nodiscard]] const AttributeInstance &getAttribute(const Attribute &) const;
[[nodiscard]] int getPlayerLevel() const;
[[nodiscard]] float getLevelProgress() const;

Expand Down
4 changes: 2 additions & 2 deletions include/bedrock/world/attribute/base_attribute_map.h
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,6 @@ class BaseAttributeMap {

private:
std::unordered_map<std::uint32_t, AttributeInstance> instance_map_; // +0
std::vector<void *> dirty_attributes_; //+64 (+56) std::vector<AttributeInstanceHandle>
std::vector<void *> dirty_attributes_; //+64 (+40) std::vector<AttributeInstanceHandle>
};
BEDROCK_STATIC_ASSERT_SIZE(BaseAttributeMap, 88, 80);
BEDROCK_STATIC_ASSERT_SIZE(BaseAttributeMap, 88, 64);
6 changes: 6 additions & 0 deletions src/endstone_runtime/bedrock/world/actor/actor.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -178,3 +178,9 @@ bool Actor::isJumping() const
{
return MobJump::isJumping(entity_context_);
}

const AttributeInstance &Actor::getAttribute(const Attribute &attribute) const
{
auto component = getPersistentComponent<AttributesComponent>();
return component->attributes.getInstance(attribute);
}
6 changes: 0 additions & 6 deletions src/endstone_runtime/bedrock/world/actor/player/player.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -81,12 +81,6 @@ bool Player::isFlying() const
return getAbilities().getBool(AbilitiesIndex::Flying);
}

const AttributeInstance &Player::getAttribute(const Attribute &attribute) const
{
auto component = getPersistentComponent<AttributesComponent>();
return component->attributes.getInstance(attribute);
}

int Player::getPlayerLevel() const
{
static Attribute *level = AttributeCollection::getAttribute("minecraft:player.level");
Expand Down

0 comments on commit ed5fbc8

Please sign in to comment.