diff --git a/src/bedrock/world/actor/actor.cpp b/src/bedrock/world/actor/actor.cpp index c398f7a68..32616d05e 100644 --- a/src/bedrock/world/actor/actor.cpp +++ b/src/bedrock/world/actor/actor.cpp @@ -44,14 +44,15 @@ void Actor::setStatusFlag(ActorFlags flag, bool value) bool Actor::isType(ActorType type) const { - auto component = getPersistentComponent(); - return component->type == type; + return type == getEntityTypeId(); } -bool Actor::hasType(ActorType type) const +bool Actor::hasType(ActorType types) const { - auto component = getPersistentComponent(); - return !!(component->type & type); + if (static_cast>(types)) { + return types == getEntityTypeId(); + } + return (types & getEntityTypeId()) == types; } ActorType Actor::getEntityTypeId() const @@ -183,9 +184,9 @@ bool Actor::isRiding() const return getVehicle() != nullptr; } -bool Actor::hasCategory(ActorCategory category) const +bool Actor::hasCategory(ActorCategory categories) const { - return !!(categories_ & category); + return (categories & categories_) == categories; } Actor *Actor::tryGetFromEntity(EntityContext const &entity, bool include_removed) diff --git a/src/bedrock/world/actor/actor.h b/src/bedrock/world/actor/actor.h index cf6c8051d..9c48681c1 100644 --- a/src/bedrock/world/actor/actor.h +++ b/src/bedrock/world/actor/actor.h @@ -251,7 +251,7 @@ class Actor { [[nodiscard]] bool getStatusFlag(ActorFlags) const; void setStatusFlag(ActorFlags, bool); [[nodiscard]] bool isType(ActorType type) const; - [[nodiscard]] bool hasType(ActorType type) const; + [[nodiscard]] bool hasType(ActorType types) const; [[nodiscard]] ActorType getEntityTypeId() const; [[nodiscard]] const ActorDefinitionIdentifier &getActorIdentifier() const; [[nodiscard]] bool isSneaking() const; @@ -275,7 +275,7 @@ class Actor { [[nodiscard]] ActorUniqueID getOrCreateUniqueID() const; [[nodiscard]] Actor *getVehicle() const; [[nodiscard]] bool isRiding() const; - [[nodiscard]] bool hasCategory(ActorCategory) const; + [[nodiscard]] bool hasCategory(ActorCategory categories) const; [[nodiscard]] bool isJumping() const; [[nodiscard]] std::vector getTags() const; bool addTag(const std::string &tag); diff --git a/src/bedrock/world/actor/actor_category.h b/src/bedrock/world/actor/actor_category.h index 789f3d0b3..a81e70d1f 100644 --- a/src/bedrock/world/actor/actor_category.h +++ b/src/bedrock/world/actor/actor_category.h @@ -14,12 +14,7 @@ #pragma once -#include - -/** - * From entityCategoryFromString - */ -enum class ActorCategory { +enum class ActorCategory : std::uint32_t { None = 0, Player = 1 << 0, Mob = 1 << 1, @@ -38,15 +33,20 @@ enum class ActorCategory { Zombie = 1 << 15, Minecart = 1 << 16, Boat = 1 << 17, - + NonTargetable = 1 << 18, + Predictable = 1 << 19, BoatRideable = Boat | Ridable, MinecartRidable = Minecart | Ridable, HumanoidMonster = Humanoid | Monster, WaterAnimal = Water | Animal, TamableAnimal = Tamable | Animal, UndeadMob = Undead | Monster, // wtf mojang - ZombieMonster = Zombie | Monster + ZombieMonster = Zombie | Monster, + EvocationIllagerMonster = Villager | HumanoidMonster, }; -template <> -struct entt::enum_as_bitmask : std::true_type {}; +constexpr ActorCategory operator&(const ActorCategory lhs, const ActorCategory rhs) +{ + return static_cast(static_cast>(lhs) & + static_cast>(rhs)); +} diff --git a/src/bedrock/world/actor/actor_types.h b/src/bedrock/world/actor/actor_types.h index 521debc76..1182c5d68 100644 --- a/src/bedrock/world/actor/actor_types.h +++ b/src/bedrock/world/actor/actor_types.h @@ -167,5 +167,10 @@ enum class ActorType : int { Bogged = 144 | SkeletonMonster, OminousItemSpawner = 145, Creaking = 146 | Monster, - _entt_enum_as_bitmask }; + +constexpr ActorType operator&(const ActorType lhs, const ActorType rhs) +{ + return static_cast(static_cast>(lhs) & + static_cast>(rhs)); +} diff --git a/src/bedrock/world/actor/mob.cpp b/src/bedrock/world/actor/mob.cpp index dcd1f6369..a04b6222d 100644 --- a/src/bedrock/world/actor/mob.cpp +++ b/src/bedrock/world/actor/mob.cpp @@ -23,7 +23,7 @@ Mob *Mob::tryGetFromEntity(EntityContext &entity, bool include_removed) if (!actor) { return nullptr; } - if (!actor->isType(ActorType::Mob) || !actor->hasCategory(ActorCategory::Mob)) { + if (!actor->isType(ActorType::Mob) && !actor->hasCategory(ActorCategory::Mob)) { return nullptr; } return static_cast(actor); diff --git a/src/endstone/core/actor/actor.cpp b/src/endstone/core/actor/actor.cpp index db943d0c9..c84ed2818 100644 --- a/src/endstone/core/actor/actor.cpp +++ b/src/endstone/core/actor/actor.cpp @@ -314,7 +314,7 @@ endstone::core::EndstoneActor &Actor::getEndstoneActor0() const auto *player = static_cast(self); component.actor = endstone::core::EndstonePlayer::create(server, *player); } - else if (self->hasType(ActorType::Mob) || self->hasCategory(ActorCategory::Mob)) { + else if (self->isType(ActorType::Mob) || self->hasCategory(ActorCategory::Mob)) { auto *mob = static_cast(self); component.actor = endstone::core::EndstoneMob::create(server, *mob); }