Jump to content

Draw Rectangle surrounding item in inventory.


Paradox68

Recommended Posts

There is no native support in the Item class, or even ItemContainer for that matter. You (sadly) need to make an inventory destination and get the rectangle through there.

 

EDIT: For bank, you can get it like so:

public Rectangle getRectForItem(Item i) {
    int slot = getBank().getSlot(i);
    int tab = getBank().getTabForAbsoluteSlot(slot);
    return getBank().getAbsoluteSlotPosition(tab, slot);
}
Edited by Bobrocket
Link to comment
Share on other sites

InventorySlotDestination.getSlot(inventory.getSlot(item))

returns a rectangle

 

 

That makes it super simple. Thanks dude!

 

There is no native support in the Item class, or even ItemContainer for that matter. You (sadly) need to make an inventory destination and get the rectangle through there.

 

Thank you for the information......

Link to comment
Share on other sites

Unfortunately from the current api it seems you can only draw the first slot as mousedestination returns the first item in the inventory (L->R,T->B)

 

But in order not to overlap the number, you can do something like:

g.drawRect(
								(int) this.inventory
										.getMouseDestination(
												this.inventory.getSlot(item))
										.getBoundingBox().getX() - 1,
								(int) this.inventory
										.getMouseDestination(
												this.inventory.getSlot(item))
										.getBoundingBox().getY() - 1,
								(int) this.inventory
										.getMouseDestination(
												this.inventory.getSlot(item))
										.getBoundingBox().getWidth() + 2,
								(int) this.inventory
										.getMouseDestination(
												this.inventory.getSlot(item))
										.getBoundingBox().getHeight() + 2);

where the additions correct the rectangle dimensions

 

apa

Link to comment
Share on other sites

Unfortunately from the current api it seems you can only draw the first slot as mousedestination returns the first item in the inventory (L->R,T->cool.png

 

But in order not to overlap the number, you can do something like:

g.drawRect(
								(int) this.inventory
										.getMouseDestination(
												this.inventory.getSlot(item))
										.getBoundingBox().getX() - 1,
								(int) this.inventory
										.getMouseDestination(
												this.inventory.getSlot(item))
										.getBoundingBox().getY() - 1,
								(int) this.inventory
										.getMouseDestination(
												this.inventory.getSlot(item))
										.getBoundingBox().getWidth() + 2,
								(int) this.inventory
										.getMouseDestination(
												this.inventory.getSlot(item))
										.getBoundingBox().getHeight() + 2);

where the additions correct the rectangle dimensions

 

apa

 

 

Actually this is the method i went with:

if (getInventory().contains(other)) {
	Rectangle rec = new Rectangle(InventorySlotDestination.getSlot(inventory.getSlot(other)));
	g.setColor(Color.ORANGE);
	g.draw(rec);
}
Link to comment
Share on other sites

 

Actually this is the method i went with:

if (getInventory().contains(other)) {
	Rectangle rec = new Rectangle(InventorySlotDestination.getSlot(inventory.getSlot(other)));
	g.setColor(Color.ORANGE);
	g.draw(rec);
}

 

That will work just fine too however the rect may overlap with the stack size should the item be stackable

 

apa

Link to comment
Share on other sites

 

There is no native support in the Item class, or even ItemContainer for that matter. You (sadly) need to make an inventory destination and get the rectangle through there.

 

EDIT: For bank, you can get it like so:

public Rectangle getRectForItem(Item i) {
    int slot = getBank().getSlot(i);
    int tab = getBank().getTabForAbsoluteSlot(slot);
    return getBank().getAbsoluteSlotPosition(tab, slot);
}

 

 

This method isn't working for drawing in bank. Not sure why, it seems logical but it just wont draw the rect in the right spot. It's drawing it on a completely different item.

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