Explv Posted December 12, 2015 Share Posted December 12, 2015 (edited) import org.osbot.rs07.api.model.Entity; public enum Rock { CLAY(new short[]{6705}), COPPER(new short[]{4645, 4510}), TIN(new short[]{53}), IRON(new short[]{2576}), SILVER(new short[]{74}), COAL(new short[]{10508}), GOLD(new short[]{8885}), MITHRIL(new short[]{-22239}), ADAMANTITE(new short[]{21662}), RUNITE(new short[]{-31437}); private short[] colours; Rock(final short[] colours) { this.colours = colours; } public boolean hasOre(final Entity rockEntity) { if (rockEntity.getDefinition() == null) { return false; } short[] colours = rockEntity.getDefinition().getModifiedModelColors(); if (colours == null) { return false; } for (short rockColour : this.colours) { for (short entityColour : colours) { if (rockColour == entityColour) { return true; } } } return false; } } Usage: RS2Object tinRock = getObjects().closest(obj -> Rock.TIN.hasOre(obj)); Edited July 10, 2018 by Explv 6 Quote Link to comment Share on other sites More sharing options...
Chris Posted December 12, 2015 Share Posted December 12, 2015 Nice Quote Link to comment Share on other sites More sharing options...
Soldtodie Posted December 12, 2015 Share Posted December 12, 2015 This takes long. If you don't need the names you can make a method without predefined id's. Quote Link to comment Share on other sites More sharing options...
Explv Posted December 12, 2015 Author Share Posted December 12, 2015 This takes long. If you don't need the names you can make a method without predefined id's. This takes long? Care to elaborate? Quote Link to comment Share on other sites More sharing options...
Soldtodie Posted December 12, 2015 Share Posted December 12, 2015 (edited) This takes long? Care to elaborate? It takes long from the first use of this method in april 2014 to the first snippet . Anyone interested? Edited December 12, 2015 by Soldtodie Quote Link to comment Share on other sites More sharing options...
Explv Posted December 12, 2015 Author Share Posted December 12, 2015 It takes long from the first use of this method in april 2014 to the first snippet . Anyone interested? I don't really understand what you are saying... But if you think there is a better method that is as concise as this one, I would be interested to see it. Quote Link to comment Share on other sites More sharing options...
Soldtodie Posted December 12, 2015 Share Posted December 12, 2015 A method for checking if the rock is mined. public boolean isMined(RS2Object rock) { if(rock != null) { /* Doesn't exist anymore. if(rock.getName().equals("Pile of Rock")) { return rock.getHeight() <= 24; } */ short[] col = rock.getDefinition().getModifiedModelColors(); if(col == null) { return true; } else if(col.length == 1) { return col[0] == 6040; // Ok, you need one predefined color id because of the three different rock styles. } else { return col[0] == col[1]; } } return true; } I prefer to select and save the rock positions. It's faster because you don't have to check every rock in your neighborhood. 1 Quote Link to comment Share on other sites More sharing options...
Explv Posted December 12, 2015 Author Share Posted December 12, 2015 A method for checking if the rock is mined. public boolean isMined(RS2Object rock) { if(rock != null) { /* Doesn't exist anymore. if(rock.getName().equals("Pile of Rock")) { return rock.getHeight() <= 24; } */ short[] col = rock.getDefinition().getModifiedModelColors(); if(col == null) { return true; } else if(col.length == 1) { return col[0] == 6040; // Ok, you need one predefined color id because of the three different rock styles. } else { return col[0] == col[1]; } } return true; } I prefer to select and save the rock positions. It's faster because you don't have to check every rock in your neighborhood. Have you not considered the case of an AIO miner where the location is not fixed? It takes far longer to record the positions of every rock in the game than it does to record 1 colour per rock. Checking "every rock in your neighborhood" takes such a short amount of time that optimising it is pointless. If you are finding a rock based on its position, you are still checking "every rock in your neighborhood" to find the object at that position. The solution I posted is a global solution, it doesn't require recording rock positions, and it doesn't require recording IDs. Just sayin' 1 Quote Link to comment Share on other sites More sharing options...
Soldtodie Posted December 12, 2015 Share Posted December 12, 2015 (edited) Have you not considered the case of an AIO miner where the location is not fixed? It takes far longer to record the positions of every rock in the game than it does to record 1 colour per rock. Checking "every rock in your neighborhood" takes such a short amount of time that optimising it is pointless. If you are finding a rock based on its position, you are still checking "every rock in your neighborhood" to find the object at that position. The solution I posted is a global solution, it doesn't require recording rock positions, and it doesn't require recording IDs. Just sayin' That the user select the rocks. If you are finding a rock based on its position, you are still checking "every rock in your neighborhood" to find the object at that position. No you haven't. Edited December 12, 2015 by Soldtodie Quote Link to comment Share on other sites More sharing options...
Explv Posted December 12, 2015 Author Share Posted December 12, 2015 That the user select the rocks. No you haven't. Ok I get you now. The user selects the rock and you store it. Still... 18ms.... meh Quote Link to comment Share on other sites More sharing options...
Soldtodie Posted December 12, 2015 Share Posted December 12, 2015 Ok I get you now. The user selects the rock and you store it. Still... 18ms.... meh 0-1ms is better Quote Link to comment Share on other sites More sharing options...
Explv Posted December 12, 2015 Author Share Posted December 12, 2015 0-1ms is better Its unnoticeable :P And it is less convenient for the user to manually select the rocks they want to mine. Either way... both viable solutions Quote Link to comment Share on other sites More sharing options...
Soldtodie Posted December 12, 2015 Share Posted December 12, 2015 (edited) Its unnoticeable And it is less convenient for the user to manually select the rocks they want to mine. Either way... both viable solutions I am not saying that your solution is bad, but with saving position you can add next spawning rock and then you must update all rocks every few seconds/ms and then the time could be noticeable. Edited December 12, 2015 by Soldtodie Quote Link to comment Share on other sites More sharing options...
jogna Posted December 17, 2016 Share Posted December 17, 2016 method: public RS2Object getRockWithOre(Rock rock){ return getObjects().closest(obj -> { short[] colours = obj.getDefinition().getModifiedModelColors(); if(colours != null){ for(short c : colours){ if(c == rock.COLOUR) return true; } } return false; }); } This method's throwing up some errors for me. What is obj? Doesn't look like it's defined anywhere. It also doesn't like the syntax you've written with the code you written after the ->. Quote Link to comment Share on other sites More sharing options...
Xerifos Posted December 17, 2016 Share Posted December 17, 2016 (edited) These -> {} are lambda expressions you can use them if you import java.util.functions if I can recall correctly. These expressions can be used in various ways to save more lines of code. I am not 100℅ sure if you have to import something. Edit: check here for more info http://www.oracle.com/webfolder/technetwork/tutorials/obe/java/Lambda-QuickStart/index.html Edited December 17, 2016 by Xerifos Quote Link to comment Share on other sites More sharing options...