Jump to content
Frequently Asked Questions
  • Are you not able to open the client? Try following our getting started guide
  • Still not working? Try downloading and running JarFix
  • Help! My bot doesn't do anything! Enable fresh start in client settings and restart the client
  • How to purchase with PayPal/OSRS/Crypto gold? You can purchase vouchers from other users
  • [SNIPPET] Rune Pouch Handler


    TheCloakdOne

    Recommended Posts

    Seen a few people ask about rune pouches and how to view whats inside them etc. See below for snippet to view whats inside the runepouch. Its been built as a static class to best match DB3

     

    Info

    * a translation map is used between pouch numbering (1 -> 20) && actual rune ID's

    * Wrath rune currently isnt supported

     

    Usage

    RunePouch.count(Runes.MIND_RUNE)
    RunePouch.contains(Runes.MIND_RUNE)
    RunePouch.containsAll(Arrays.asList(Runes.MIND_RUNE, Runes.LAW_RUNE, Runes.AIR_RUNE))

    Snippet

    package org.cloakd.runecrafting;
    
    import org.cloakd.common.Constants;
    import org.dreambot.api.methods.container.impl.Inventory;
    import org.dreambot.api.methods.settings.PlayerSettings;
    
    import java.util.HashMap;
    import java.util.List;
    
    public class RunePouch {
    
        private static final HashMap<Integer, Integer> idMap = new HashMap<Integer, Integer>() {{
            put(1, Runes.AIR_RUNE);
            put(2, Runes.WATER_RUNE);
            put(3, Runes.EARTH_RUNE);
            put(4, Runes.FIRE_RUNE);
            put(5, Runes.MIND_RUNE);
            put(6, Runes.CHAOS_RUNE);
            put(7, Runes.DEATH_RUNE);
            put(8, Runes.BLOOD_RUNE);
            put(9, Runes.COSMIC_RUNE);
            put(10, Runes.NATURE_RUNE);
            put(11, Runes.LAW_RUNE);
            put(12, Runes.BODY_RUNE);
            put(13, Runes.SOUL_RUNE);
            put(14, Runes.ASTRAL_RUNE);
            put(15, Runes.MIST_RUNE);
            put(16, Runes.MUD_RUNE);
            put(17, Runes.DUST_RUNE);
            put(18, Runes.LAVA_RUNE);
            put(19, Runes.STEAM_RUNE);
            put(20, Runes.SMOKE_RUNE);
        }};
    
        private static final HashMap<Integer, Integer> runeMap = new HashMap<Integer, Integer>() {{
            put(Runes.AIR_RUNE, 1);
            put(Runes.WATER_RUNE, 2);
            put(Runes.EARTH_RUNE, 3);
            put(Runes.FIRE_RUNE, 4);
            put(Runes.MIND_RUNE, 5);
            put(Runes.CHAOS_RUNE, 6);
            put(Runes.DEATH_RUNE, 7);
            put(Runes.BLOOD_RUNE, 8);
            put(Runes.COSMIC_RUNE, 9);
            put(Runes.NATURE_RUNE, 10);
            put(Runes.LAW_RUNE, 11);
            put(Runes.BODY_RUNE, 12);
            put(Runes.SOUL_RUNE, 13);
            put(Runes.ASTRAL_RUNE, 14);
            put(Runes.MIST_RUNE, 15);
            put(Runes.MUD_RUNE, 16);
            put(Runes.DUST_RUNE, 17);
            put(Runes.LAVA_RUNE, 18);
            put(Runes.STEAM_RUNE, 19);
            put(Runes.SMOKE_RUNE, 20);
        }};
    
        public static boolean inInventory() {
            return Inventory.contains(Constants.RUNE_POUCH);
        }
    
        public static boolean contains(int rune) {
            return contains(rune, 0);
        }
    
        public static boolean contains(int rune, int amount) {
            int r = runeMap.get(rune);
    
            if (getRuneId(Slot.FIRST) == r)
                return getAmount(Slot.FIRST) >= amount;
    
            if (getRuneId(Slot.SECOND) == r)
                return getAmount(Slot.SECOND) >= amount;
    
            if (getRuneId(Slot.THIRD) == r)
                return getAmount(Slot.THIRD) >= amount;
    
            return false;
        }
    
        public static boolean containsAll(List<Integer> runes) {
            for (Integer rune : runes) {
                if (!contains(runeMap.get(rune)))
                    return false;
            }
            return true;
        }
    
        public static int count(int rune) {
            int r = runeMap.get(rune);
    
            if (getRuneId(Slot.FIRST) == r)
                return getAmount(Slot.FIRST);
    
            if (getRuneId(Slot.SECOND) == r)
                return getAmount(Slot.SECOND);
    
            if (getRuneId(Slot.THIRD) == r)
                return getAmount(Slot.THIRD);
    
            return 0;
        }
    
        public static int getRuneId(final Slot slot) {
            final int c = PlayerSettings.getConfig(slot.configRuneName);
            switch (slot) {
                case FIRST:
                    return c & 0x3F;
                case SECOND:
                    return c >>> 6 & 0x3F;
                case THIRD:
                    return c >>> 12 & 0x3F;
                default:
                    return 0;
            }
        }
    
        /**
         * Returns the actual rune ID
         *
         * @param slot
         * @return
         */
        public static int getRuneIdAsRune(final Slot slot) {
            int r = getRuneId(slot);
            return idMap.get(r);
        }
    
        public static int getAmount(final Slot slot) {
            final int c = PlayerSettings.getConfig(slot.configRuneAmount);
            switch (slot) {
                case FIRST:
                    return c >>> 18;
                case SECOND:
                    return c & 0x3FFF;
                case THIRD:
                    return c >>> 14;
                default:
                    return 0;
            }
        }
    
        public static String toString(final Slot slot) {
            return getName(slot) + "x" + getAmount(slot);
        }
    
        public static String getName(final Slot slot) {
            switch (getRuneId(slot)) {
                case 1:
                    return "Air rune";
                case 2:
                    return "Water rune";
                case 3:
                    return "Earth rune";
                case 4:
                    return "Fire rune";
                case 5:
                    return "Mind rune";
                case 6:
                    return "Chaos rune";
                case 7:
                    return "Death rune";
                case 8:
                    return "Blood rune";
                case 9:
                    return "Cosmic rune";
                case 10:
                    return "Nature rune";
                case 11:
                    return "Law rune";
                case 12:
                    return "Body rune";
                case 13:
                    return "Soul rune";
                case 14:
                    return "Astral rune";
                case 15:
                    return "Mist rune";
                case 16:
                    return "Mud rune";
                case 17:
                    return "Dust rune";
                case 18:
                    return "Lava rune";
                case 19:
                    return "Steam rune";
                case 20:
                    return "Smoke rune";
                default:
                    return "None";
            }
        }
    
        public enum Slot {
    
            FIRST(1139, 1139),
            SECOND(1139, 1140),
            THIRD(1139, 1140);
    
            private final int configRuneName;
            private final int configRuneAmount;
    
            Slot(final int configRuneName, final int configRuneAmount) {
                this.configRuneName = configRuneName;
                this.configRuneAmount = configRuneAmount;
            }
        }
    
        public static class Runes {
    
            public static final int MIND_RUNE = 558;
            public static final int FIRE_RUNE = 554;
            public static final int AIR_RUNE = 556;
            public static final int WATER_RUNE = 555;
            public static final int EARTH_RUNE = 557;
            public static final int NATURE_RUNE = 561;
            public static final int COSMIC_RUNE = 564;
            public static final int BLOOD_RUNE = 565;
            public static final int DEATH_RUNE = 560;
            public static final int CHAOS_RUNE = 562;
            public static final int LAW_RUNE = 563;
            public static final int BODY_RUNE = 559;
            public static final int SOUL_RUNE = 566;
            public static final int WRATH_RUNE = 21880;
            public static final int ASTRAL_RUNE = 9075;
    
            public static final int MIST_RUNE = 4695;
            public static final int MUD_RUNE = 4698;
            public static final int DUST_RUNE = 4696;
            public static final int LAVA_RUNE = 4699;
            public static final int STEAM_RUNE = 4694;
            public static final int SMOKE_RUNE = 4697;
    
        }
    }

     

     

    Credits:

    https://osbot.org/forum/topic/130485-rune-pouch-snippet/

    https://github.com/runelite/runelite/blob/d936a23894da46ad89513664d891970ea721165d/runelite-client/src/main/java/net/runelite/client/plugins/runepouch/RunepouchOverlay.java

    Link to comment
    Share on other sites

    Agreed with Nex, if you replaced Runes with an enum, you could probably remove both the maps, as well as the get rune name switch/case, since you could just get the name from enum, as well as changing enum name to "Rune" instead of "Runes" because semantics :P
    contains(rune) should probably forward with an amount of 1 instead of 0

    Then you could replace contains(rune,count) with just return count(rune) >= amount, as the methods are duplicate code.
    I'd also personally say count should return -1 instead of 0 if the slots don't match the given id. Same with getRuneId, and pretty much any method you have defaulting to return 0, -1 is generally the "this isn't a valid response" return code for integer methods (at least, I usually treat it that way)

    You could also change containsAll to a Integer...runes (or if you swap to enum, Rune...runes) then you don't have to worry about converting things to lists when passing the numbers to check for.
     

    Link to comment
    Share on other sites

    14 hours ago, Nuclear Nezz said:

    Agreed with Nex, if you replaced Runes with an enum, you could probably remove both the maps, as well as the get rune name switch/case, since you could just get the name from enum, as well as changing enum name to "Rune" instead of "Runes" because semantics :P
    contains(rune) should probably forward with an amount of 1 instead of 0

    Then you could replace contains(rune,count) with just return count(rune) >= amount, as the methods are duplicate code.
    I'd also personally say count should return -1 instead of 0 if the slots don't match the given id. Same with getRuneId, and pretty much any method you have defaulting to return 0, -1 is generally the "this isn't a valid response" return code for integer methods (at least, I usually treat it that way)

    You could also change containsAll to a Integer...runes (or if you swap to enum, Rune...runes) then you don't have to worry about converting things to lists when passing the numbers to check for.
     

     

    100% agree, tried to ensure readability for newer scripters so just dumped into maps etc as pulled from other places in my codebase hence the odd naming to fit into this snippet. If i have time ill adjust to reflect better enum usage but was really just to show how to deal with runepouch varbits more than anything :)

    For anyone looking for a good way to implement Runes in an enum'd format i would suggest snooping around Runelites data directories: 

    https://github.com/runelite/runelite/blob/d936a23894da46ad89513664d891970ea721165d/runelite-client/src/main/java/net/runelite/client/plugins/runepouch/Runes.java

     

    :)

    Link to comment
    Share on other sites

    Archived

    This topic is now archived and is closed to further replies.

    ×
    ×
    • Create New...

    Important Information

    We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.