Pegasus Posted July 22, 2018 Share Posted July 22, 2018 (edited) package org; import org.osbot.rs07.api.map.Position; import org.osbot.rs07.api.model.RS2Object; import org.osbot.rs07.script.Plugin; import java.util.Comparator; import java.util.List; import java.util.function.Predicate; import java.util.stream.Collectors; public class Test extends Plugin { public String treeToCut = "Tree"; private Predicate<RS2Object> suitableObj = n -> n.getName().equals(treeToCut) && getMap().canReach(n) && getMap().distance(n) < 4; private java.util.List<RS2Object> treeObjs; @Override public int onLoop() throws InterruptedException { log("onLoop: "); List<RS2Object> allObjs = getObjects().getAll(); log("getObjects().getAll().size(): " + allObjs.size()); int count = 0; for(RS2Object obj : allObjs){ if (obj.getName().equals(treeToCut) && getMap().distance(obj) < 4) { log("AAA " + obj.getX() + " " + obj.getY()); count++; } } log("count: " + count); treeObjs = getObjects().getAll().stream().filter(suitableObj).collect(Collectors.toList()); if (!treeObjs.isEmpty()) { log("treeObjs.size(): " + treeObjs.size()); treeObjs.sort(Comparator.<RS2Object>comparingInt(a -> getMap().distance(a)).thenComparingInt(b -> getMap().distance(b))); log("sort treeObjs.size(): " + treeObjs.size()); treeObjs.forEach(obj -> log(obj.getX() + " " + obj.getY())); } else { log("treeObjs.isEmpty()"); } return 2000; } } onLoop: getObjects().getAll().size(): 8618 AAA 3163 3454 AAA 3163 3454 AAA 3163 3454 AAA 3163 3454 count: 4 treeObjs.size(): 4 sort treeObjs.size(): 4 3163 3454 3163 3454 3163 3454 3163 3454 Why? What is the meaning and different of these "duplicate" objects? Thanks Edited July 22, 2018 by Pegasus Quote Link to comment Share on other sites More sharing options...
FrostBug Posted July 23, 2018 Share Posted July 23, 2018 (edited) Just a guess, but it may be that Objects#getAll iterates the coordinates of the region graph, adding all InteractableObjects found. If this is the case, the result might be that an object of 2x2 size (large object that spans 4 tiles) would be added multiple times, as it can be found on multiple coordinates, even though the objects 'anchor position' is the same. Depending on whether or not they're the same object instance, using Collectors.toSet might function as a workaround Edited July 23, 2018 by FrostBug 1 Quote Link to comment Share on other sites More sharing options...