Added method to find objects of particular type in a world

This commit is contained in:
simon 2018-05-12 19:09:00 -04:00
parent 80f45f1eb0
commit be8dd14d36
2 changed files with 14 additions and 3 deletions

View File

@ -45,9 +45,7 @@ public class HarvestTask extends NPCTask {
if (pause == 0) { if (pause == 0) {
//Get biomass //Get biomass
/* todo replace by some sort of .collect call with object ArrayList<GameObject> biomass = npc.getWorld().findGameObjects("net.simon987.biomassplugin.BiomassBlob");
id (See https://github.com/simon987/Much-Assembly-Required/pull/66)*/
ArrayList<GameObject> biomass = npc.getWorld().findObjects(0x4000);
//Get closest one //Get closest one
int minDist = Integer.MAX_VALUE; int minDist = Integer.MAX_VALUE;

View File

@ -131,6 +131,19 @@ public class World implements MongoSerializable {
return matchingObjects; return matchingObjects;
} }
public ArrayList<GameObject> findGameObjects(String type) {
ArrayList<GameObject> matchingObjects = new ArrayList<>(2);
for (GameObject obj : gameObjects.values()) {
if ((obj.getClass().getName().equals(type))) {
matchingObjects.add(obj);
}
}
return matchingObjects;
}
public void addObject(GameObject object) { public void addObject(GameObject object) {
gameObjects.put(object.getObjectId(), object); gameObjects.put(object.getObjectId(), object);
} }