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

DropdownBoxEntry not working inside a AbstractListListEntry #105

Open
ChocolateLoverRaj opened this issue Jul 8, 2021 · 0 comments
Open

Comments

@ChocolateLoverRaj
Copy link

I made a custom GUI for an Item, and now I'm trying to make one for List<Item>. There isn't an easy way to do this, so I made a ItemListListEntry class which extends AbstractListListEntry.

The list appears on the config screen, but when I click on the add button or expand the list, the game crashes.

The error:

java.lang.NullPointerException: Cannot invoke "me.shedaniel.clothconfig2.gui.widget.DynamicEntryListWidget.isMouseOver(double, double)" because the return value of "me.shedaniel.clothconfig2.api.AbstractConfigListEntry.getParent()" is null
	at me.shedaniel.clothconfig2.api.AbstractConfigListEntry.isMouseInside(AbstractConfigListEntry.java:67)
	at me.shedaniel.clothconfig2.api.AbstractConfigListEntry.render(AbstractConfigListEntry.java:72)
	at me.shedaniel.clothconfig2.gui.entries.TooltipListEntry.render(TooltipListEntry.java:57)
	at me.shedaniel.clothconfig2.gui.entries.DropdownBoxEntry.render(DropdownBoxEntry.java:84)
	at net.fabricmc.magic_bowl.ItemListListEntry$ItemListCell.render(ItemListListEntry.java:74)
	at me.shedaniel.clothconfig2.gui.entries.BaseListEntry.render(BaseListEntry.java:287)
	at net.fabricmc.magic_bowl.ItemListListEntry.render(ItemListListEntry.java:94)
	at me.shedaniel.clothconfig2.gui.widget.DynamicEntryListWidget.renderItem(DynamicEntryListWidget.java:494)
	at me.shedaniel.clothconfig2.gui.ClothConfigScreen$ListWidget.renderItem(ClothConfigScreen.java:357)
	at me.shedaniel.clothconfig2.gui.ClothConfigScreen$ListWidget.renderItem(ClothConfigScreen.java:324)
	at me.shedaniel.clothconfig2.gui.widget.DynamicEntryListWidget.renderList(DynamicEntryListWidget.java:489)
	at me.shedaniel.clothconfig2.gui.ClothConfigScreen$ListWidget.renderList(ClothConfigScreen.java:369)
	at me.shedaniel.clothconfig2.gui.widget.DynamicEntryListWidget.render(DynamicEntryListWidget.java:258)
	at me.shedaniel.clothconfig2.gui.widget.DynamicNewSmoothScrollingEntryListWidget.render(DynamicNewSmoothScrollingEntryListWidget.java:131)
	at me.shedaniel.clothconfig2.gui.ClothConfigScreen.render(ClothConfigScreen.java:230)
	at net.minecraft.client.render.GameRenderer.render(GameRenderer.java:885)
	at net.minecraft.client.MinecraftClient.render(MinecraftClient.java:1149)
	at net.minecraft.client.MinecraftClient.run(MinecraftClient.java:746)
	at net.minecraft.client.main.Main.main(Main.java:191)
	at java.base/jdk.internal.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
	at java.base/jdk.internal.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:78)
	at java.base/jdk.internal.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
	at java.base/java.lang.reflect.Method.invoke(Method.java:567)
	at net.fabricmc.loader.game.MinecraftGameProvider.launch(MinecraftGameProvider.java:234)
	at net.fabricmc.loader.launch.knot.Knot.launch(Knot.java:153)
	at net.fabricmc.loader.launch.knot.KnotClient.main(KnotClient.java:28)
	at net.fabricmc.devlaunchinjector.Main.main(Main.java:86)

My ItemListListEntry class:

package net.fabricmc.magic_bowl;

import java.util.List;
import java.util.Optional;
import java.util.function.Consumer;
import java.util.function.Supplier;

import org.jetbrains.annotations.Nullable;

import me.shedaniel.clothconfig2.gui.entries.AbstractListListEntry;
import me.shedaniel.clothconfig2.gui.entries.DropdownBoxEntry;
import me.shedaniel.clothconfig2.impl.builders.DropdownMenuBuilder;
import net.minecraft.client.gui.Element;
import net.minecraft.client.gui.screen.narration.NarrationMessageBuilder;
import net.minecraft.client.util.math.MatrixStack;
import net.minecraft.item.Item;
import net.minecraft.item.Items;
import net.minecraft.text.Text;

public class ItemListListEntry extends AbstractListListEntry<Item, ItemListListEntry.ItemListCell, ItemListListEntry> {
  public ItemListListEntry(Text fieldName, List<Item> value, boolean defaultExpanded,
      Supplier<Optional<Text[]>> tooltipSupplier, Consumer<List<Item>> saveConsumer, Supplier<List<Item>> defaultValue,
      Text resetButtonKey, boolean requiresRestart, boolean deleteButtonEnabled, boolean insertInFront) {
    super(fieldName, value, defaultExpanded, tooltipSupplier, saveConsumer, defaultValue, resetButtonKey,
        requiresRestart, deleteButtonEnabled, insertInFront, ItemListCell::new);
  }

  public static class ItemListCell
      extends AbstractListListEntry.AbstractListCell<Item, ItemListCell, ItemListListEntry> {

    private DropdownBoxEntry<Item> widget;

    public ItemListCell(@Nullable Item value, ItemListListEntry listListEntry) {
      super(value, listListEntry);
      widget = new DropdownMenuBuilder<Item>(listListEntry.resetWidget.getMessage(), listListEntry.getFieldName(),
          DropdownMenuBuilder.TopCellElementBuilder.ofItemObject(substituteDefault(value)),
          DropdownMenuBuilder.CellCreatorBuilder.ofItemObject()).build();
    }

    @Override
    public SelectionType getType() {
      return null;
    }

    @Override
    public void appendNarrations(NarrationMessageBuilder builder) {
      // TODO Auto-generated method stub

    }

    @Override
    public List<? extends Element> children() {
      return widget.children();
    }

    @Override
    public Item getValue() {
      return widget.getValue();
    }

    @Override
    public int getCellHeight() {
      return widget.getItemHeight();
    }

    @Override
    public Optional<Text> getError() {
      return widget.getError();
    }

    @Override
    public void render(MatrixStack matrices, int index, int y, int x, int entryWidth, int entryHeight, int mouseX,
        int mouseY, boolean isHovered, float delta) {
      widget.render(matrices, index, x, y, entryWidth, entryHeight, mouseX, mouseY, isHovered, delta);
    }

    private Item substituteDefault(@Nullable Item value) {
      if (value == null)
        return Items.AIR;
      else
        return value;
    }
  }

  @Override
  public ItemListListEntry self() {
    return this;
  }

  @Override
  public void render(MatrixStack arg0, int arg1, int arg2, int arg3, int arg4, int arg5, int arg6, int arg7,
      boolean arg8, float arg9) {
    // TODO Auto-generated method stub
    super.render(arg0, arg1, arg2, arg3, arg4, arg5, arg6, arg7, arg8, arg9);
  }
}
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

1 participant