Solved Inventory Pages

Discussion in 'Plugin Development' started by mehboss, Aug 18, 2022.

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

    mehboss

    Hello, I have set up a GUI that has infinite pages; however, I can not think of a way to do what I need to do. Any help would be appreciated.
    Code:
            int[] slots = {19,20,21,22,23,24,25,28,29,30,31,32,33,34}; // the 14 slots I will be setting each item to
      
            for (int setr : slots) {
          
                ItemStack recipe = Main.getInstance().menui.get(????); // menui is my arraylist
                inv.setItem(setr, recipe);
            }
         
            // depending on page get only these from the arraylist
            // page 1 get 1-14
            // page 2 get 15 - 29
            // page 3 get 30 - 44
            // etc etc automated checks
            
    I have all of my items saved into an arraylist. I am trying to get certain ranges depending on the pages.
    // page 1 get 1-14 from arraylist
    // page 2 get 15 - 29 from arraylist
    // page 3 get 30 - 44 from arraylist
    // page 4 get 45 - 59 from arraylist
    // etc etc
    ^ compact into one check, not multiple for each page. defeats the purpose of having infinite pages. Also, I have a way to get the page number already, just not a way to get the ranges depending on the page.
    I hope you understand what I mean.
     
  2. Offline

    timtower Administrator Administrator Moderator

    @mehboss start = page * 14, end = page * 14 + 14
     
  3. Offline

    mehboss

    I've already got this solved using
    Code:
            int[] slots = { 19, 20, 21, 22, 23, 24, 25, 28, 29, 30, 31, 32, 33, 34 };
            for (int slot = page * slots.length; slot < (page + 1) * slots.length; slot++) {
                if (slot >= Main.getInstance().menui.size()) {
                    break;
                }
                inv.setItem(slots[slot - page * slots.length], Main.getInstance().menui.get(slot));
            }
    
    =)
     
Thread Status:
Not open for further replies.

Share This Page