Soldtodie 76 Posted December 16, 2014 public int getSelectedItemSlot() { if(getInventory().isItemSelected()) { for(int slot = 0; slot < 28; slot++) { Item it = getInventory().getItemInSlot(slot); if(it != null && getInventory().getSelectedItemName().contains(it.getName())) { Rectangle is = getInventory().getSlotBounds(slot); for(int x = is.x; x < is.x + is.width; x++) { for(int y = is.y; y < is.y + is.height; y++) { if(getColorPicker().isColor(x, y, new Color(255, 255, 255))) { return slot; } } } } } } return -1; } The inventory must be open!
Chris 154 Posted December 16, 2014 A bit of feedback -> Some items have color 255,255,255 inside them. White partyhat for instance. You should check if there are > 1 items (of the name selected) in the inventory. If there are, run your computation. An alternative to this would be to store item slot when selecting an item. Once the menu is no longer use, reset the selected item slot number.
Soldtodie 76 Author Posted December 16, 2014 A bit of feedback -> Some items have color 255,255,255 inside them. White partyhat for instance. You should check if there are > 1 items (of the name selected) in the inventory. If there are, run your computation. An alternative to this would be to store item slot when selecting an item. Once the menu is no longer use, reset the selected item slot number. No you can't find a item with a completely white pixel. The whitest pixel in a white partyhat is 0xFBFBFB
Chris 154 Posted December 16, 2014 No you can't find a item with a completely white pixel. The whitest pixel in a white partyhat is 0xFBFBFB Oh ok, good find. To speed up your color searching, you could iterate diagonally (2x1) through the item instead of searching the entire bitmap. for (int i = 0; i < height; i++) { for (int j = 0; j < 2; j++) { if (i + j < width) { //is it white? } } }
hakerman72 0 Posted December 16, 2014 Oh ok, good find. To speed up your color searching, you could iterate diagonally (2x1) through the item instead of searching the entire bitmap. for (int i = 0; i < height; i++) { for (int j = 0; j < 2; j++) { if (i + j < width) { //is it white? } } } u guy have selected item index hooked but it not in api why that? it would make this whole method not needed
Recommended Posts
Archived
This topic is now archived and is closed to further replies.