tehcrab 0 Posted June 16, 2017 public int onLoop() { List<GameObject> trees = getGameObjects().all(GameObjects -> GameObjects != null && GameObjects.getName().equals("Tree")); // Gets all the trees nearby List<Double> distance = new ArrayList(); // A new list to hold the distance of every tree for (int i = 0; i < trees.size(); i++) { distance.add(trees.get(i).distance()); // Here we add all the distances to the distance list } Collections.sort(distance); // We sort it int d = 0; // d is the number we use to look through our tree list int index = 0; // index is the numer we use to decide where we insert stuff while (true) { if (distance.get(index) == trees.get(d).distance()) { // if the distance in the distance list matches the distance in the tree list trees.add(index, trees.get(d)); // We resort our tree list, we add the shortest tree to the first place in the tree list trees.remove(d + 1); // We remove that tree index++; // We add one to the index so we wont mess up our sorted tree list d = 0; // We reset the counter which goes through the tree array if (d <= trees.size()) // If our counter reaches the end of the tree list we break out of the loop break; } else { // If it doesn't match we add +1 to our counter and we try again; d++; } } This probably looks messy as hell but i tried to explain the most of it, so the thing I'm basically trying to do is have my wc bot not go to the closest tree all the time to make it more human like if that makes sense. I hope that there's an easy way to do this I just wanted to see if I would be able to code it myself and to some extent it works. My idea was to sort the tree list full of trees to the closest ones and then have a random number generator choose one of the three closest trees. For some reason it only manages to sort the first closest tree in the tree list, so obviously there's something wrong with my code the screenshot shows how far i am from the first 11 trees in the tree list. I started trying to code yesterday so don't bully me too much, but if anyone knows a simple way to not target the first tree 24/7, or see whats wrong with my code it'd be great EDIT - screenshot of log - http://i.imgur.com/PFnnqZT.png also tried to make it more clean
tehcrab 0 Author Posted June 16, 2017 to much aids to read that like that lol hahahah i have no idea how to sort it, tell me how and i will
Nex 2546 Posted June 16, 2017 also its more human like to go to the first tree, like cmon if ur legit woodcutting clearly u gonna click on the nearest thing
tehcrab 0 Author Posted June 16, 2017 Upload it to pastebin lol looks just as aids there also its more human like to go to the first tree, like cmon if ur legit woodcutting clearly u gonna click on the nearest thing not with 100% accuracy over 6h
Noidlox 11 Posted June 16, 2017 looks just as aids there not with 100% accuracy over 6h Make sure you select 'java' to highlight syntax
tehcrab 0 Author Posted June 16, 2017 Make sure you select 'java' to highlight syntax There isn't an option for java, I took the next best thing javascript idk if it helps
Eclipseop 194 Posted June 16, 2017 https://gist.github.com/anonymous/45ff1d7e37608d834282ad094962383d since it's 2 hard apparently.
Recommended Posts
Archived
This topic is now archived and is closed to further replies.