Skip to content

Interacting With Game Objects

  1. You'll need the object name or ID
  2. You're going to need to find that object, make sure it exists, interact with that object.

If you'd like to find the object with a name.

GameObject normalTree = GameObjects.closest("tree"); //This will find the closest GameObject that has the name "Tree"

if(normalTree != null) {                             //Make sure the cow isn't null
    normalTree.interact("Chop down");                //Interact in this example we want to chop the tree
}

If you'd like to find the object with an ID

GameObject normalTree = GameObjects.closest(1276);  //This will find the closest GameObject that has the ID "1276"

if(normalTree != null) {                            //Make sure the cow isn't null
    normalTree.interact("Chop down");               //Interact in this example we want to chop the tree
}

You are able to put the above checks directly into a Lambda expression.

GameObject normalTree = GameObjects.closest(t -> "Tree".equalsIgnoreCase(t.getName()));

GameObject normalTree = GameObjects.closest(t -> t.getID() == 1276);