October 14, 201510 yr How would you get the x and y coordinates on the screen of the inventory item? It's probably super simple I just can't figure it out.
October 14, 201510 yr 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 October 14, 201510 yr by Bobrocket
October 14, 201510 yr Author 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......
October 14, 201510 yr 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
October 14, 201510 yr Author 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-> 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); }
October 14, 201510 yr 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
October 14, 201510 yr Author 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.
October 14, 201510 yr 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. The bank API might not have been updated recently then, no clue lmao
October 14, 201510 yr Author The bank API might not have been updated recently then, no clue lmao Just to be sure i'm not crazy, proper usage could be if (getBank().isOpen()) { g.draw(getRectForItem(getBank().getItem(toMake2)); } assuming toMake2 returns an int or a string.
October 14, 201510 yr Just to be sure i'm not crazy, proper usage could be if (getBank().isOpen()) { g.draw(getRectForItem(getBank().getItem(toMake2)); } assuming toMake2 returns an int or a string. g.draw(new BankSlotDestination(bot, bank.getSlot(ITEM_ID_OR_SOMETHING)).getBoundingBox());
October 14, 201510 yr Author g.draw(new BankSlotDestination(bot, bank.getSlot(ITEM_ID_OR_SOMETHING)).getBoundingBox()); Hngh dat coding. You're a smart cookie. Thanks dude.
Create an account or sign in to comment