bigMack420 0 Posted November 25, 2021 I want to make a power miner but the bot keeps running off because it finish's mining the iron too quickly. I want something like below so that it only mines objects within 1 tile I have no idea how to do it can anyone give some insight GameObject rock = GameObjects.closest(Rock,Rock2 .distance(Players.localPlayer() < 1);
420x69x420 72 Posted November 25, 2021 Very close buddy 🙂 There is a filtering function that the API supports for getting most things like this (includings NPCs, GameObjects, and others). Try this code: GameObject rock = GameObjects.closest(p -> p.getName().equals("Rock") && p.distance() <= 1); Some relevant info about this code line: -p is a name, and doesn't matter what its called, could've been named "literallyUselessVariableName" or "Rock" -everything after the -> has to return true in order for the GameObject to be considered valid and returned, otherwise will skip those GameObjects for which these conditions are false -When this line runs it finds all rendered GameObjects and filters these to match both the name and the distance. Each GameObject takes a turn at being "p" and gets evaluated, then the closest is determined and that one GameObject is returned -the method .distance() will automatically assume distance is being calculated from the local player's tile -distance is calculated via pythagorian theorem to get real circle radius distances, rather than "square" distances. For example: something 15 tiles east and 15 tiles north will result in 21.2132 as distance, whereas "square" distance would simply be 15. So therefore any rocks that are adjacent to your player will be 1.0 distance away, and if you only say "distance < 1" then it wouldn't ever pick up any rocks because you can never stand on any rocks, so it must be "distance <= 1" or "distance < 2"
Recommended Posts
Archived
This topic is now archived and is closed to further replies.