Soldtodie 76 Share Posted December 16, 2014 (edited) 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! Edited December 16, 2014 by Soldtodie Link to comment Share on other sites More sharing options...
Chris 154 Share 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. Link to comment Share on other sites More sharing options...
Soldtodie 76 Author Share 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 Link to comment Share on other sites More sharing options...
Chris 154 Share 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? } } } Link to comment Share on other sites More sharing options...
hakerman72 0 Share 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 Link to comment Share on other sites More sharing options...
Recommended Posts
Create an account or sign in to comment
You need to be a member in order to leave a comment
Create an account
Sign up for a new account in our community. It's easy!
Register a new accountSign in
Already have an account? Sign in here.
Sign In Now