I call the handleClipping(i) in three different areas within npcHandler.
This is the method:
Code:
public void handleClipping(final int i) {
final NPC npc = NPCHandler.npcs[i];
if(npc.moveX == 1 && npc.moveY == 1) {
if((Region.getClipping(npc.absX + 1, npc.absY + 1, npc.heightLevel) & 0x12801e0) != 0) {
npc.moveX = 0; npc.moveY = 0;
if((Region.getClipping(npc.absX, npc.absY + 1, npc.heightLevel) & 0x1280120) == 0) {
npc.moveY = 1;
} else {
npc.moveX = 1;
}
}
} else if(npc.moveX == -1 && npc.moveY == -1) {
if((Region.getClipping(npc.absX - 1, npc.absY - 1, npc.heightLevel) & 0x128010e) != 0) {
npc.moveX = 0; npc.moveY = 0;
if((Region.getClipping(npc.absX, npc.absY - 1, npc.heightLevel) & 0x1280102) == 0) {
npc.moveY = -1;
} else {
npc.moveX = -1;
}
}
} else if(npc.moveX == 1 && npc.moveY == -1) {
if((Region.getClipping(npc.absX + 1, npc.absY - 1, npc.heightLevel) & 0x1280183) != 0) {
npc.moveX = 0; npc.moveY = 0;
if((Region.getClipping(npc.absX, npc.absY - 1, npc.heightLevel) & 0x1280102) == 0) {
npc.moveY = -1;
} else {
npc.moveX = 1;
}
}
} else if(npc.moveX == -1 && npc.moveY == 1) {
if((Region.getClipping(npc.absX - 1, npc.absY + 1, npc.heightLevel) & 0x128013) != 0) {
npc.moveX = 0; npc.moveY = 0;
if((Region.getClipping(npc.absX, npc.absY + 1, npc.heightLevel) & 0x1280120) == 0) {
npc.moveY = 1;
} else {
npc.moveX = -1;
}
}
} //Checking Diagonal movement.
if (npc.moveY == -1) {
if ((Region.getClipping(npc.absX, npc.absY - 1, npc.heightLevel) & 0x1280102) == 0) {
npc.moveY = 0;
}
} else if( npc.moveY == 1) {
if((Region.getClipping(npc.absX, npc.absY + 1, npc.heightLevel) & 0x1280120) == 0) {
npc.moveY = 0;
}
} //Checking Y movement.
if(npc.moveX == 1) {
if((Region.getClipping(npc.absX + 1, npc.absY, npc.heightLevel) & 0x1280180) == 0) {
npc.moveX = 0;
}
} else if(npc.moveX == -1) {
if((Region.getClipping(npc.absX - 1, npc.absY, npc.heightLevel) & 0x1280108) == 0) {
npc.moveX = 0;
}
} //Checking X movement.
}
Where it's being called is under process method:
Code:
if (npcs[i].walkingHome && npcs[i].absX == npcs[i].makeX
&& npcs[i].absY == npcs[i].makeY) {
npcs[i].walkingHome = false;
} else if (npcs[i].walkingHome) {
npcs[i].getNextNPCMovement(i);
npcs[i].getNextWalkingDirection();
handleClipping(i); // <------------------HERE
npcs[i].updateRequired = true;
}
if (npcs[i].walkingType >= 2) {
switch(npcs[i].walkingType) {
case 5:
npcs[i].turnNpc(npcs[i].absX -1, npcs[i].absY);
break;
case 4:
npcs[i].turnNpc(npcs[i].absX +1, npcs[i].absY);
break;
case 3:
npcs[i].turnNpc(npcs[i].absX, npcs[i].absY -1);
break;
case 2:
npcs[i].turnNpc(npcs[i].absX, npcs[i].absY +1);
break;
default:
if (npcs[i].walkingType >= 0) {
npcs[i].turnNpc(npcs[i].absX, npcs[i].absY);
}
break;
}
}
if (npcs[i].walkingType == 1) {
if (Misc.random(3) == 1 && !npcs[i].walkingHome) {
int MoveX = 0;
int MoveY = 0;
int Rnd = Misc.random(9);
if (Rnd == 1) {
MoveX = 1;
MoveY = 1;
} else if (Rnd == 2) {
MoveX = -1;
} else if (Rnd == 3) {
MoveY = -1;
} else if (Rnd == 4) {
MoveX = 1;
} else if (Rnd == 5) {
MoveY = 1;
} else if (Rnd == 6) {
MoveX = -1;
MoveY = -1;
} else if (Rnd == 7) {
MoveX = -1;
MoveY = 1;
} else if (Rnd == 8) {
MoveX = 1;
MoveY = -1;
}
if (MoveX == 1) {
if (npcs[i].absX + MoveX < npcs[i].makeX + 1) {
npcs[i].moveX = MoveX;
} else {
npcs[i].moveX = 0;
}
}
if (MoveX == -1) {
if (npcs[i].absX - MoveX > npcs[i].makeX - 1) {
npcs[i].moveX = MoveX;
} else {
npcs[i].moveX = 0;
}
}
if (MoveY == 1) {
if (npcs[i].absY + MoveY < npcs[i].makeY + 1) {
npcs[i].moveY = MoveY;
} else {
npcs[i].moveY = 0;
}
}
if (MoveY == -1) {
if (npcs[i].absY - MoveY > npcs[i].makeY - 1) {
npcs[i].moveY = MoveY;
} else {
npcs[i].moveY = 0;
}
}
npcs[i].getNextNPCMovement(i);
npcs[i].getNextWalkingDirection();
handleClipping(i); // <------------------HERE
npcs[i].updateRequired = true;
}
}
}
Under followPlayer method:
Code:
public void followPlayer(int i, int playerId) {
if (PlayerHandler.players[playerId] == null) {
return;
}
if (PlayerHandler.players[playerId].respawnTimer > 0) {
npcs[i].facePlayer(0);
npcs[i].randomWalk = true;
npcs[i].underAttack = false;
return;
}
if (!followPlayer(i)) {
npcs[i].facePlayer(playerId);
return;
}
int playerX = PlayerHandler.players[playerId].absX;
int playerY = PlayerHandler.players[playerId].absY;
npcs[i].randomWalk = false;
if (goodDistance(npcs[i].getX(), npcs[i].getY(), playerX, playerY,
distanceRequired(i)))
return;
if ((npcs[i].spawnedBy > 0)
|| ((npcs[i].absX < npcs[i].makeX + Config.NPC_FOLLOW_DISTANCE)
&& (npcs[i].absX > npcs[i].makeX
- Config.NPC_FOLLOW_DISTANCE)
&& (npcs[i].absY < npcs[i].makeY
+ Config.NPC_FOLLOW_DISTANCE) && (npcs[i].absY > npcs[i].makeY
- Config.NPC_FOLLOW_DISTANCE))) {
if (npcs[i].heightLevel == PlayerHandler.players[playerId].heightLevel) {
if (PlayerHandler.players[playerId] != null && npcs[i] != null) {
if (playerY < npcs[i].absY) {
npcs[i].moveX = GetMove(npcs[i].absX, playerX);
npcs[i].moveY = GetMove(npcs[i].absY, playerY);
} else if (playerY > npcs[i].absY) {
npcs[i].moveX = GetMove(npcs[i].absX, playerX);
npcs[i].moveY = GetMove(npcs[i].absY, playerY);
} else if (playerX < npcs[i].absX) {
npcs[i].moveX = GetMove(npcs[i].absX, playerX);
npcs[i].moveY = GetMove(npcs[i].absY, playerY);
} else if (playerX > npcs[i].absX) {
npcs[i].moveX = GetMove(npcs[i].absX, playerX);
npcs[i].moveY = GetMove(npcs[i].absY, playerY);
} else if (playerX == npcs[i].absX
|| playerY == npcs[i].absY) {
int o = Misc.random(3);
switch (o) {
case 0:
npcs[i].moveX = GetMove(npcs[i].absX, playerX);
npcs[i].moveY = GetMove(npcs[i].absY, playerY + 1);
break;
case 1:
npcs[i].moveX = GetMove(npcs[i].absX, playerX);
npcs[i].moveY = GetMove(npcs[i].absY, playerY - 1);
break;
case 2:
npcs[i].moveX = GetMove(npcs[i].absX, playerX + 1);
npcs[i].moveY = GetMove(npcs[i].absY, playerY);
break;
case 3:
npcs[i].moveX = GetMove(npcs[i].absX, playerX - 1);
npcs[i].moveY = GetMove(npcs[i].absY, playerY);
break;
}
}
npcs[i].getNextNPCMovement(i);
npcs[i].getNextWalkingDirection();
handleClipping(i); // <------------------HERE
npcs[i].facePlayer(playerId);
npcs[i].updateRequired = true;
}
}
} else {
npcs[i].facePlayer(0);
npcs[i].randomWalk = true;
npcs[i].underAttack = false;
}
}