Jump to content

Mining rocks with ore [No IDs]


Explv

Recommended Posts

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
Link to comment
Share on other sites

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
Link to comment
Share on other sites

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
Link to comment
Share on other sites

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
Link to comment
Share on other sites

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
Link to comment
Share on other sites

  • 1 year later...

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

Link to comment
Share on other sites

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
Link to comment
Share on other sites

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.
Note: Your post will require moderator approval before it will be visible.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

  • Recently Browsing   0 members

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