[refactor] BaseNPC now uses Entity XYZ fields for handling positions

- fixed many references to Entity.appearanceData.i[XYZ] to use the base Entity XYZ values
- BaseNPC::enterIntoViewOf grabs the position from the base Entity XYZ values
- NPCManager::updateNPCPosition updates the base Entity XYZ values
- MobAI.c/deadStep() also sends it's packet based on the Entity XYZ values
This commit is contained in:
2021-04-13 19:57:24 -05:00
parent 48fb510b53
commit 9b84d9dc4d
11 changed files with 80 additions and 74 deletions

View File

@@ -69,9 +69,9 @@ void NPCManager::updateNPCPosition(int32_t id, int X, int Y, int Z, uint64_t I,
npc->appearanceData.iAngle = angle;
ChunkPos oldChunk = npc->chunkPos;
ChunkPos newChunk = Chunking::chunkPosAt(X, Y, I);
npc->appearanceData.iX = X;
npc->appearanceData.iY = Y;
npc->appearanceData.iZ = Z;
npc->x = X;
npc->y = Y;
npc->z = Z;
npc->instanceID = I;
if (oldChunk == newChunk)
return; // didn't change chunks
@@ -280,8 +280,8 @@ BaseNPC* NPCManager::getNearestNPC(std::set<Chunk*>* chunks, int X, int Y, int Z
continue;
BaseNPC* npcTemp = (BaseNPC*)ent->getEntity();
int distXY = std::hypot(X - npcTemp->appearanceData.iX, Y - npcTemp->appearanceData.iY);
int dist = std::hypot(distXY, Z - npcTemp->appearanceData.iZ);
int distXY = std::hypot(X - npcTemp->x, Y - npcTemp->y);
int dist = std::hypot(distXY, Z - npcTemp->z);
if (dist < lastDist) {
npc = npcTemp;
lastDist = dist;