Bug in InventoryView convertSlot() ?

Discussion in 'Plugin Development' started by desht, Jan 14, 2013.

Thread Status:
Not open for further replies.
  1. Offline

    desht

    Planning to raise this as a bug on atlassian, but would like a second opinion first to make sure I'm not being dumb...

    The Javadocs for convertSlot(int rawSlot) in InventoryView state:
    I tried this from an InventoryClickEvent handler on the crafting/inventory view you get when you press 'E' - player inventory at the bottom (InventoryType.PLAYER), 2x2 crafting inventory at the top (InventoryType.CRAFTING).

    But clicking a slot in the player inventory (other than a hotbar slot, which seems to work correctly) and running convertSlot() on the raw slot from the event gives me the same slot as a result, implying the click was in the top inventory (crafting inventory), when in fact it was in the main player inventory... and that doesn't seem right.

    This code:

    PHP:
    int rawSlot event.getRawSlot();
    int slot event.getView().convertSlot(rawSlot);
    System.out.println("rawSlot = " rawSlot ", slot = " slot);
    gives me this output if I click the top left slot in the main player inventory:
    Code:
    rawSlot = 9, slot = 9
    
    So the slot is right (slot 9 is the top-left slot in the player's inventory, the hotbar being 0-8), but the raw event slot and the local (converted) slot should be different, it would seem...
     
  2. I think the inventory of the player is the first inventory
     
  3. Offline

    fireblast709

    desht might be a copy-paste mistake, but you are printing the rawSlot twice

    System.out.println("rawSlot = " + rawSlot + ", slot = " + rawSlot);
     
  4. Offline

    desht

    Yep, was a typo in the debug statement!

    It isn't. event.getView().getTopInventory().getType() returns InventoryType.CRAFTING.

    EDIT by Moderator: merged posts, please use the edit button instead of double posting.
     
    Last edited by a moderator: May 30, 2016
  5. Offline

    fireblast709

    desht Might it be that it also counts the 4 armor slots, the 4 crafting grid slots and the result slot? In which case the first slot of the 3*9 inventory would be 4+4+1 (the slots) + 1 = 10 - 1 (as the index is n - 1) = 9
     
  6. Offline

    desht

    Possibly, but the problem is that convertSlot() is returning the same slot number, which as the docs state, mean the top inventory has been clicked. But the top inventory here has a type of InventoryType.CRAFTING, and the top left slot of the player inventory is definitely not part of the crafting inventory.

    I've worked around it for now by checking if the inventory type is CRAFTING and the slot is >= 9, in which case I use the bottom inventory (the PLAYER inventory), and that works. But something isn't right here.
     
    Netizen likes this.
Thread Status:
Not open for further replies.

Share This Page