Jump to content

Mining rocks with ore [No IDs]


Recommended Posts

Posted (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 by Explv
  • Like 6
Posted

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.

  • Like 1
Posted

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' :doge:

  • Like 1
Posted (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' doge.png

 

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.

 

2050e3c18069a21f65a3334748e3635e.png

Edited by Soldtodie
Posted (edited)

Its unnoticeable tongue.png

And it is less convenient for the user to manually select the rocks they want to mine.

Either way... both viable solutions smile.png

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 by Soldtodie
  • 1 year later...
Posted

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 ->.

Posted (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 by Xerifos

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...