25 return it ==
entities.end() ? nullptr : it->second;
30 if (entity ==
nullptr)
36 entities[entity->GetEntityID()] = entity;
49#if PROTOCOL_VERSION < 764
58#if PROTOCOL_VERSION < 755
62 auto it =
entities.find(msg.GetEntityId());
65 std::shared_ptr<Entity> entity = std::make_shared<UnknownEntity>();
66 entity->SetEntityID(msg.GetEntityId());
67 entities[msg.GetEntityId()] = entity;
74 std::shared_ptr<Entity> entity =
nullptr;
78 auto it =
entities.find(msg.GetEntityId());
85 if (entity !=
nullptr)
89 (msg.GetXA() / 128.0f + entity_position.
x * 32.0f) / 32.0f,
90 (msg.GetYA() / 128.0f + entity_position.
y * 32.0f) / 32.0f,
91 (msg.GetZA() / 128.0f + entity_position.
z * 32.0f) / 32.0f
93 entity->SetOnGround(msg.GetOnGround());
99 std::shared_ptr<Entity> entity =
nullptr;
103 auto it =
entities.find(msg.GetEntityId());
110 if (entity !=
nullptr)
114 (msg.GetXA() / 128.0f + entity_position.
x * 32.0f) / 32.0f,
115 (msg.GetYA() / 128.0f + entity_position.
y * 32.0f) / 32.0f,
116 (msg.GetZA() / 128.0f + entity_position.
z * 32.0f) / 32.0f
118 entity->SetYaw(360.0f * msg.GetYRot() / 256.0f);
119 entity->SetPitch(360.0f * msg.GetXRot() / 256.0f);
120 entity->SetOnGround(msg.GetOnGround());
126 std::shared_ptr<Entity> entity =
nullptr;
130 auto it =
entities.find(msg.GetEntityId());
137 if (entity !=
nullptr)
139 entity->SetYaw(360.0f * msg.GetYRot() / 256.0f);
140 entity->SetPitch(360.0f * msg.GetXRot() / 256.0f);
141 entity->SetOnGround(msg.GetOnGround());
147#if PROTOCOL_VERSION < 458
148 std::shared_ptr<Entity> entity = Entity::CreateObjectEntity(
static_cast<ObjectEntityType
>(msg.GetType()));
153 entity->SetEntityID(msg.GetEntityId());
154 entity->SetX(msg.GetX());
155 entity->SetY(msg.GetY());
156 entity->SetZ(msg.GetZ());
157 entity->SetYaw(360.0f * msg.GetYRot() / 256.0f);
158 entity->SetPitch(360.0f * msg.GetXRot() / 256.0f);
159 entity->SetUUID(msg.GetUuid());
162 entities[msg.GetEntityId()] = entity;
165#if PROTOCOL_VERSION < 759
170 entity->SetEntityID(msg.GetEntityId());
171 entity->SetX(msg.GetX());
172 entity->SetY(msg.GetY());
173 entity->SetZ(msg.GetZ());
174 entity->SetYaw(360.0f * msg.GetYRot() / 256.0f);
175 entity->SetPitch(360.0f * msg.GetXRot() / 256.0f);
176 entity->SetUUID(msg.GetUuid());
179 entities[msg.GetEntityId()] = entity;
187 entity->SetEntityID(msg.GetEntityId());
188 entity->SetX(msg.GetX());
189 entity->SetY(msg.GetY());
190 entity->SetZ(msg.GetZ());
193 entities[msg.GetEntityId()] = entity;
196#if PROTOCOL_VERSION < 721
201 entity->SetEntityID(msg.GetEntityId());
202 entity->SetX(msg.GetX());
203 entity->SetY(msg.GetY());
204 entity->SetZ(msg.GetZ());
207 entities[msg.GetEntityId()] = entity;
211#if PROTOCOL_VERSION < 764
214 std::shared_ptr<Entity> entity =
nullptr;
218 auto it =
entities.find(msg.GetEntityId());
222 entities[msg.GetEntityId()] = entity;
230 entity->SetEntityID(msg.GetEntityId());
231 entity->SetPosition(Vector3<double>(
236 entity->SetYaw(360.0f * msg.GetYRot() / 256.0f);
237 entity->SetPitch(360.0f * msg.GetXRot() / 256.0f);
238 entity->SetUUID(msg.GetPlayerId());
246 local_player->SetFoodSaturation(msg.GetFoodSaturation());
251 std::shared_ptr<Entity> entity =
nullptr;
255 auto it =
entities.find(msg.GetEntityId());
262 if (entity !=
nullptr)
264#if PROTOCOL_VERSION < 768
270 entity->SetYaw(360.0f * msg.GetYRot() / 256.0f);
271 entity->SetPitch(360.0f * msg.GetXRot() / 256.0f);
274 msg.GetRelatives() & (1 << 0) ? entity->GetX() + msg.GetChange().GetPosition()[0] : msg.GetChange().GetPosition()[0],
275 msg.GetRelatives() & (1 << 1) ? entity->GetY() + msg.GetChange().GetPosition()[1] : msg.GetChange().GetPosition()[1],
276 msg.GetRelatives() & (1 << 2) ? entity->GetZ() + msg.GetChange().GetPosition()[2] : msg.GetChange().GetPosition()[2]
278 entity->SetYaw(msg.GetRelatives() & (1 << 3) ? entity->GetYaw() + msg.GetChange().GetYRot() : msg.GetChange().GetYRot());
279 entity->SetPitch(msg.GetRelatives() & (1 << 4) ? entity->GetPitch() + msg.GetChange().GetXRot() : msg.GetChange().GetXRot());
281 entity->SetOnGround(msg.GetOnGround());
292#if PROTOCOL_VERSION == 755
302 for (
int i = 0; i < msg.GetEntityIds().size(); ++i)
304 entities.erase(msg.GetEntityIds()[i]);
311#if PROTOCOL_VERSION < 764
320 switch (msg.GetType())
332 std::shared_ptr<Entity> entity =
nullptr;
336 auto it =
entities.find(msg.GetEntityId());
343 if (entity ==
nullptr)
345 LOG_WARNING(
"Trying to load metadata in unexisting entity");
349 entity->LoadMetadataFromRawArray(msg.GetPackedItems());
355 std::shared_ptr<Entity> entity =
nullptr;
359 auto it =
entities.find(msg.GetEntityId());
366 if (entity ==
nullptr)
368 LOG_WARNING(
"Trying to set speed of an unexisting entity");
373 entity->SetSpeed(
Vector3<double>(msg.GetXA(), msg.GetYA(), msg.GetZA()) / 8000.0);
379 std::shared_ptr<Entity> entity =
nullptr;
383 auto it =
entities.find(msg.GetEntityId());
390 if (entity ==
nullptr)
392 LOG_WARNING(
"Trying to set equipment of an unexisting entity");
396#if PROTOCOL_VERSION > 730
397 for (
auto& p : msg.GetSlots())
399 entity->SetEquipment(
static_cast<EquipmentSlot>(p.first), p.second);
402 entity->SetEquipment(
static_cast<EquipmentSlot>(msg.GetSlot().first), msg.GetSlot().second);
409 std::shared_ptr<Entity> entity =
nullptr;
413 auto it =
entities.find(msg.GetEntityId());
420 if (entity ==
nullptr)
422 LOG_WARNING(
"Trying to set attributes of an unexisting entity");
424 else if (!entity->IsLivingEntity())
426 LOG_WARNING(
"Trying to set attributes of a non LivingEntity");
430 std::shared_ptr<LivingEntity> living_entity = std::dynamic_pointer_cast<LivingEntity>(entity);
431 for (
const auto& a : msg.GetAttributes())
433#if PROTOCOL_VERSION > 765
435#elif PROTOCOL_VERSION > 709
441 for (
const auto& m : a.GetModifiers())
444#
if PROTOCOL_VERSION < 767
452 living_entity->AddAttribute(attribute);
459 std::shared_ptr<Entity> entity =
nullptr;
463 auto it =
entities.find(msg.GetEntityId());
470 if (entity ==
nullptr)
472 LOG_WARNING(
"Trying to set effect of an unexisting entity");
478 static_cast<unsigned char>(msg.GetEffectAmplifier()),
479 std::chrono::steady_clock::now() + std::chrono::milliseconds(50 * msg.GetEffectDurationTicks())
487 std::shared_ptr<Entity> entity =
nullptr;
491 auto it =
entities.find(msg.GetEntityId());
498 if (entity ==
nullptr)
500 LOG_WARNING(
"Trying to remove effect of an unexisting entity");
508#if PROTOCOL_VERSION > 767
511 std::shared_ptr<Entity> entity =
nullptr;
515 auto it =
entities.find(msg.GetEntityId());
522 if (entity !=
nullptr)
524 entity->SetPosition(msg.GetValues().GetPosition());
529 entity->SetYaw(msg.GetValues().GetYRot());
530 entity->SetPitch(msg.GetValues().GetXRot());
531 entity->SetOnGround(msg.GetOnGround());
537 std::shared_ptr<Entity> entity =
nullptr;
541 auto it =
entities.find(msg.GetEntityId());
548 if (entity ==
nullptr || !entity->IsAbstractMinecart())
556 entity->SetPosition(step.GetPosition());
557 entity->SetYaw(360.0f * step.GetYRot() / 256.0f);
558 entity->SetPitch(360.0f * step.GetXRot() / 256.0f);
#define LOG_WARNING(osstream)
void SetModifier(const ModifierKey &key, const Modifier &modifier)
std::shared_ptr< LocalPlayer > GetLocalPlayer()
std::shared_ptr< LocalPlayer > local_player
std::shared_mutex entity_manager_mutex
Utilities::ScopeLockedWrapper< const std::unordered_map< int, std::shared_ptr< Entity > >, std::shared_mutex, std::shared_lock > GetEntities() const
Get a read-only locked version of all the loaded entities (including local player)
std::unordered_map< int, std::shared_ptr< Entity > > entities
void AddEntity(const std::shared_ptr< Entity > &entity)
virtual void Handle(ProtocolCraft::ClientboundLoginPacket &msg) override
EntityManager(const std::shared_ptr< NetworkManager > &network_manager)
std::shared_ptr< Entity > GetEntity(const int id) const
static std::shared_ptr< Entity > CreateEntity(const EntityType type)
Mutex protected reference, will be locked until destroyed.