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

Adding items using addItems method on SimpleGUI does not seem to work when creating a Tab GUI #14

Closed
tank-o opened this issue Dec 21, 2022 · 1 comment

Comments

@tank-o
Copy link

tank-o commented Dec 21, 2022

Version 0.10

I was creating a tab GUI and the example worked great, I then tried just adding specific items using the addItems method instead of using the fill method and it would not add any items.

I stepped into the method below and the emptyIndex was constantly coming back as -1, why it was doing that I am not sure, since the GUI had not had any items added to it yet.

    @Override
    public void addItems(@NotNull Item... items) {
        for (Item item : items) {
            int emptyIndex = ArrayUtils.findFirstEmptyIndex(items);
            if (emptyIndex == -1) break;
            setItem(emptyIndex, item);
        }
    }

This is the code to reproduce the GUI that isnt working, this exact code works perfectly fine with using fill or setItem

  GUI pickaxeTab = new SimpleGUI(9, 3);
  GUI axeTab = new SimpleGUI(9, 3);
  for (int i =0; i < 9; i++){
      pickaxeTab.addItems(new SimpleItem(new ItemBuilder(Material.IRON_PICKAXE)));
      axeTab.addItems(new SimpleItem(new ItemBuilder(Material.IRON_AXE)));
  }
  menu = new GUIBuilder<>(GUIType.TAB)
          .setStructure(
                  "# # # 0 # 1 # # #",
                  "x x x x x x x x x",
                  "x x x x x x x x x",
                  "x x x x x x x x x")
          .addIngredient('x', Markers.ITEM_LIST_SLOT_HORIZONTAL)
          .addIngredient('#', Border::new)
          .addIngredient('0', new PickTab(0))
          .addIngredient('1', new AxeTab(1))
          .setGUIs(Arrays.asList(pickaxeTab, axeTab))
          .build();
}
@D0gmaDev
Copy link
Contributor

I believe that should fix it: #15

NichtStudioCode added a commit that referenced this issue Dec 22, 2022
fixes wrong array check (fixes #14)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants