Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix method ChestInventory.selectItemAtWithShift #23

Open
opl- opened this issue May 4, 2014 · 1 comment
Open

Fix method ChestInventory.selectItemAtWithShift #23

opl- opened this issue May 4, 2014 · 1 comment
Labels

Comments

@opl-
Copy link

opl- commented May 4, 2014

Bug: Method ChestInventory.selectItemAtWithShift crashes every time you call it with slot >= 54.

Fix:

@Override
public synchronized void selectItemAtWithShift(int slot) {
    delay();
    ItemStack item = getItemAt(slot);
    int rangeStart, rangeEnd;
    if(item == null)
        return;
    if(slot < items.length) {
        rangeStart = items.length;
        rangeEnd = items.length + inventory.length;
    } else {
        rangeStart = 0;
        rangeEnd = items.length;
    }
    boolean slotFound = false;
    for(int i = rangeStart; i < rangeEnd; i++) {
        if((slot < items.length ? inventory[i - items.length] : items[i]) == null) {
            if(slot < items.length) {
                items[slot] = null;
                inventory[i - items.length] = item;
            } else {
                items[i] = item;
                inventory[slot - items.length] = null;
            }
            slotFound = true;
            break;
        }
    }
    if(!slotFound)
        return;
    bot.getEventBus().fire(new InventoryChangeEvent(this, slot, 0, (short) 0, item, true));
}

I tried making a PR but i failed. My GitHub skills are just terrible, so I'm posting this as an issue with proposed fix.

@DarkStorm652
Copy link
Owner

The inventory system is rather poorly implemented and now outdated.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

2 participants