Skip to content

Commit

Permalink
Fix NPE for HUD text presets
Browse files Browse the repository at this point in the history
If the search bar didn't match any preset, pressing enter would crash due to a null preset trying to be instantiated.
  • Loading branch information
Big-Iron-Cheems authored and Wide-Cat committed Jan 30, 2025
1 parent d2a9f4e commit 191e4ed
Show file tree
Hide file tree
Showing 2 changed files with 5 additions and 2 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -161,13 +161,13 @@ public void add(HudElementInfo<?> info, int x, int y) {
}

@SuppressWarnings({"unchecked", "rawtypes"})
public void add(HudElementInfo.Preset preset, int x, int y, XAnchor xAnchor, YAnchor yAnchor) {
public void add(@NotNull HudElementInfo.Preset preset, int x, int y, XAnchor xAnchor, YAnchor yAnchor) {
HudElement element = preset.info.create();
preset.callback.accept(element);
add(element, x, y, xAnchor, yAnchor);
}

public void add(HudElementInfo<?>.Preset preset, int x, int y) {
public void add(@NotNull HudElementInfo<?>.Preset preset, int x, int y) {
add(preset, x, y, null, null);
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,12 +14,14 @@
import meteordevelopment.meteorclient.systems.hud.HudElementInfo;
import meteordevelopment.meteorclient.utils.Utils;
import net.minecraft.client.gui.DrawContext;
import org.jetbrains.annotations.Nullable;

public class HudElementPresetsScreen extends WindowScreen {
private final HudElementInfo<?> info;
private final int x, y;

private final WTextBox searchBar;
@Nullable
private HudElementInfo<?>.Preset firstPreset;

public HudElementPresetsScreen(GuiTheme theme, HudElementInfo<?> info, int x, int y) {
Expand All @@ -36,6 +38,7 @@ public HudElementPresetsScreen(GuiTheme theme, HudElementInfo<?> info, int x, in
};

enterAction = () -> {
if (firstPreset == null) return;
Hud.get().add(firstPreset, x, y);
close();
};
Expand Down

0 comments on commit 191e4ed

Please sign in to comment.