December 12, 201510 yr 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, 20187 yr by Explv
December 12, 201510 yr This takes long. If you don't need the names you can make a method without predefined id's.
December 12, 201510 yr Author 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?
December 12, 201510 yr 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, 201510 yr by Soldtodie
December 12, 201510 yr Author 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.
December 12, 201510 yr 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.
December 12, 201510 yr Author 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'
December 12, 201510 yr 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, 201510 yr by Soldtodie
December 12, 201510 yr Author 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
December 12, 201510 yr Ok I get you now. The user selects the rock and you store it. Still... 18ms.... meh 0-1ms is better
December 12, 201510 yr Author 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
December 12, 201510 yr 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, 201510 yr by Soldtodie
December 17, 20169 yr 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 ->.
December 17, 20169 yr 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, 20169 yr by Xerifos
Create an account or sign in to comment