Okay so I recently added NPC + player clipping and havent really found any issues yet, until now.
If I go into barrows and click the Sarcophagus the barrows brother spawns, but in the mean time an error comes up in the server cmd (none clientsided).
Code:
[24-8-13 21:58]: java.lang.ArrayIndexOutOfBound***ception: -1
[24-8-13 21:58]: A fatal exception has been thrown!
[24-8-13 21:58]: at server.clip.region.Region.getClip(Region.java:21)
[24-8-13 21:58]: at server.clip.region.Region.getClipping(Region.java:226)
[24-8-13 21:58]: at server.model.npcs.NPCHandler.handleClipping(NPCHandler.java:50)
[24-8-13 21:58]: at server.model.npcs.NPCHandler.followPlayer(NPCHandler.java:2279)
[24-8-13 21:58]: at server.model.npcs.NPCHandler.process(NPCHandler.java:1582)
[24-8-13 21:58]: at server.Server.main(Server.java:144)
Region.java method on line 21 (line 21 in red)
Code:
private int getClip(int x, int y, int height) {
int regionAbsX = (id >> 8) * 64;
int regionAbsY = (id & 0xff) * 64;
if (clips[height] == null) {
return 0;
}
return clips[height][x - regionAbsX][y - regionAbsY];
}
Region.java method on line 226 (line 226 in red)
Code:
public static int getClipping(int x, int y, int height) {
if(height > 3)
height = 0;
int regionX = x >> 3;
int regionY = y >> 3;
int regionId = ((regionX / 8) << 8) + (regionY / 8);
for (Region r : regions) {
if (r.id() == regionId) {
return r.getClip(x, y, height);
}
}
return 0;
}
And the handleClipping in NPCHandler.. (line 50 in red)
Code:
public void handleClipping(int i) {
NPC npc = 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.
}
The code activated when clicking sarcophagus: (This is dharok only, but it happens on all the brothers)
Code:
case 6771:
if(server.model.minigames.Barrows.selectCoffin(c, 4)) {
return;
}
if(c.barrowsNpcs[4][1] == 0) {
Server.npcHandler.spawnNpc(c, 2026, 3551, 9713, -1, 0, 120, 28, 80, 80, true, true);
c.barrowsNpcs[4][1] = 1;
} else {
c.sendMessage("You have already searched in this sarcophagus.");
}
break;
Extra: Im guessing it has something to do with the player standing on the stairs that lead to the coffin, and the brothers spawning on the ground and there is a problem with the player height? Like this: http://puu.sh/49VY9.jpg