Updated Version - This is now the correct version and loops through objects only in your region.
If you release this anywhere else, please give me credits.
In your Region class, add this:
Code:
private ArrayList<Objects> realObjects = new ArrayList<Objects>();
public static Region getRegion(int x, int y) {
int regionX = x >> 3;
int regionY = y >> 3;
int regionId = (regionX / 8 << 8) + regionY / 8;
for (Region region : regions) {
if (region.id() == regionId) {
return region;
}
}
return null;
}
public static boolean objectExists(int id, int x, int y, int z) {
RegionClipping r = getRegion(x, y);
if (r == null)
return false;
for (Objects o : r.realObjects) {
if (o.objectId == id) {
if (o.objectX == x && o.objectY == y && o.objectHeight == z) {
return true;
}
}
}
return false;
}
At the bottom of your addObject method, add this:
Code:
Region r = getRegion(x, y);
if (r != null) {
if (startUp)
r.realObjects.add(new Objects(objectId, x, y, height, direction, type));
else if (!objectExists(objectId, x, y, height))
r.realObjects.add(new Objects(objectId, x, y, height, direction, type));
}
In ActionHandler.java (or whatever you use for handling object clicking)
Below: (or whatever you use)
Code:
public void firstClickObject(int objectType, int obX, int obY) {
c.clickObjectType = 0;
And (or whatever you use)
Code:
public void secondClickObject(int objectType, int obX, int obY) {
c.clickObjectType = 0;
And (or whatever you use)
Code:
public void thirdClickObject(int objectType, int obX, int obY) {
c.clickObjectType = 0;
Add:
Code:
if (!Region.objectExists(objectType, obX, obY, c.heightLevel))
return;
Don't forget to import.
Credits:
DotEXE for the getRegion method.
Anyone who contributed in making region clipping.
Me.
Please thank and rep if you use this or found it helpful in any way.