Jump to content

Basic Inventory Painting (For Begginers)


TheScrub

Recommended Posts

Every wondered how to get this effect it's simple in a few easy steps!

2sbpvyu.jpg

 

 

this doesn't show the item id but it shows a string or an int for example this shows how many tabs I've made just to be creative!

 

first we will need to get the inventory slot of the item we will be painting

int i = client.getInventory().getSlotForId(ITEM);

next we will return the rectangle around it

Rectangle r = client.getInventory().getDestinationForSlot(i);

next seeming we can't just draw r we need to get the values also keeping in mind they return as doubles and we need to Round them if you round a double you return a long so we need to cast it as an int

we will do this for X,Y,Width and Height

        int recX = (int) Math.round(r.getX());
        int recY = (int) Math.round(r.getY());
        int recWidth = (int) Math.round(r.getWidth());
        int recHeight = (int) Math.round(r.getHeight());

once we have this we can draw your rectangle!!!

 

arg0 for me is set to g

g.drawRect(recX, recY, recWidth, recHeight);

if we want to take this a step further and draw an int or something next to the item inside the box we need to get the middle of the rectangle

 

so we need to get the height and add the Y and then get the x and add the Width but we need to div the height and width by 2 to get the middle

        int recMidX = Math.round(recX + recWidth / 2);
        int recMidY = Math.round(recY + recHeight / 2);

and there we go we can now draw it!

g.drawString("123", recMidX, recMidY);

now all together

        int i = client.getInventory().getSlotForId(ITEM);
        Rectangle r = client.getInventory().getDestinationForSlot(i);
        int recX = (int) Math.round(r.getX());
        int recY = (int) Math.round(r.getY());
        int recWidth = (int) Math.round(r.getWidth());
        int recHeight = (int) Math.round(r.getHeight());
        int recMidX = Math.round(recX + recWidth / 2);
        int recMidY = Math.round(recY + recHeight / 2);
        g.drawRect(recX, recY, recWidth, recHeight);
        g.drawString("123", recMidX, recMidY);

Hope this helps people!

 

if we want to do this same effect but show item ids we can do this simply by taking the code we have and just making some adjustments!!

 

 

first we will need to get all the Inventory Items

Item[] items = client.getInventory().getItems();

next this is an array of items so to use this in the next section we will just need to put it in an for loop like so

for (Item singluarItem:items){

now we need to use the singluarItem to grab the id's of items

int jj= singluarItem.getId();

and the rest is the same as before but just adding what we just did

 

so all together it will look like this  we need to remember we didn't take into en-count the items that are not there so u will need to keep the items in the inventory lumped at the beginning for this to work

i would not suggest using this for anything other than debugging as it is a very a simple and crude method

                Item[] items = client.getInventory().getItems();
                for (Item singluarItem:items){
                int jj= singluarItem.getId();
                int i = client.getInventory().getSlotForId(jj);
                Rectangle r = client.getInventory().getDestinationForSlot(i);
                int recX = (int) Math.round(r.getX());
                int recY = (int) Math.round(r.getY());
                int recWidth = (int) Math.round(r.getWidth());
                int recHeight = (int) Math.round(r.getHeight());
                int recMidX = Math.round(recX + recWidth / 2);
                int recMidY = Math.round(recY + recHeight / 2);
                g.drawRect(recX, recY, recWidth, recHeight);
                g.drawString(""+jj, recMidX, recMidY);
                }

Expanded this for item id debugging hope this helps!!

Edited by TheScrub
Link to comment
Share on other sites

Guest
This topic is now closed to further replies.
  • Recently Browsing   0 members

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