]> git.localhorst.tv Git - blank.git/blobdiff - src/world/World.cpp
fix block placement
[blank.git] / src / world / World.cpp
index 8b43657d3b58b1520e40c25019762883e6f7e5fb..505cbbb70f3838c0b89e0a27d5d18a2d41b752df 100644 (file)
@@ -114,6 +114,26 @@ Entity *World::AddEntity(std::uint32_t id) {
        return &*entity;
 }
 
+Entity &World::ForceAddEntity(std::uint32_t id) {
+       if (entities.empty() || entities.back().ID() < id) {
+               entities.emplace_back();
+               entities.back().ID(id);
+               return entities.back();
+       }
+
+       auto position = entities.begin();
+       auto end = entities.end();
+       while (position != end && position->ID() < id) {
+               ++position;
+       }
+       if (position != end && position->ID() == id) {
+               return *position;
+       }
+       auto entity = entities.emplace(position);
+       entity->ID(id);
+       return *entity;
+}
+
 
 namespace {
 
@@ -279,6 +299,7 @@ World::EntityHandle World::RemoveEntity(EntityHandle &eh) {
                if (player->entity == &*eh) {
                        chunks.UnregisterIndex(*player->chunks);
                        player = players.erase(player);
+                       end = players.end();
                } else {
                        ++player;
                }