Fix Config Option NPE (#951)

This commit is contained in:
slprime authored and GitHub committed 2026-06-14 21:14:44 +03:00
1 parent 4562ecf087
commit 937c1858a4
6 files changed
+68 -28

No files matched your search

@@ -92,7 +92,7 @@ public abstract class DataDumper extends Option {
}
public Rectangle4i dumpButtonSize() {
int width = 80;
int width = 50;
return new Rectangle4i(getSlot().slotWidth() - width, 0, width, 20);
}
@@ -18,6 +18,7 @@ import org.lwjgl.input.Keyboard;
import codechicken.core.gui.GuiCCButton;
import codechicken.core.gui.GuiScreenWidget;
import codechicken.lib.config.ConfigTag;
import codechicken.lib.math.MathHelper;
import codechicken.lib.vec.Rectangle4i;
import codechicken.nei.HUDRenderer;
@@ -27,12 +28,16 @@ public class GuiHighlightTips extends GuiScreenWidget {
private final String name;
private GuiCCButton toggleButton;
private final Option opt;
private final GuiOptionList parentGui;
private final boolean world;
private Point dragDown;
public GuiHighlightTips(Option opt) {
super(80, 20);
this.opt = opt;
name = opt.name;
this.parentGui = (GuiOptionList) Minecraft.getMinecraft().currentScreen;
this.world = parentGui.worldConfig();
}
@Override
@@ -48,7 +53,7 @@ public class GuiHighlightTips extends GuiScreenWidget {
@Override
public void actionPerformed(String ident, Object... params) {
if (ident.equals("show")) {
opt.getTag(name).setBooleanValue(!show());
getTag(name).setBooleanValue(!show());
updateNames();
}
}
@@ -58,13 +63,21 @@ public class GuiHighlightTips extends GuiScreenWidget {
}
private boolean show() {
return opt.renderTag(name).getBooleanValue();
return renderTag(name).getBooleanValue();
}
private ConfigTag getTag(String s) {
return (world ? opt.worldConfigSet() : opt.globalConfigSet()).config.getTag(s);
}
private ConfigTag renderTag(String s) {
return (world && opt.worldSpecific(s) ? opt.worldConfigSet() : opt.globalConfigSet()).config.getTag(s);
}
@Override
public void keyTyped(char c, int keycode) {
if (keycode == Keyboard.KEY_ESCAPE || keycode == Keyboard.KEY_BACK) {
Minecraft.getMinecraft().displayGuiScreen(opt.getSlot().getGui());
Minecraft.getMinecraft().displayGuiScreen(parentGui);
return;
}
super.keyTyped(c, keycode);
@@ -82,7 +95,7 @@ public class GuiHighlightTips extends GuiScreenWidget {
}
public Point getPos() {
return new Point(opt.renderTag(name + ".x").getIntValue(), opt.renderTag(name + ".y").getIntValue());
return new Point(renderTag(name + ".x").getIntValue(), renderTag(name + ".y").getIntValue());
}
public Dimension sampleSize() // copied from HUDManager when running with the sample for this gui
@@ -148,8 +161,8 @@ public class GuiHighlightTips extends GuiScreenWidget {
}
private void setPos(Point p) {
opt.getTag(name).setBooleanValue(show()); // duplicates global tag for the option gui if in world mode
opt.getTag(name + ".x").setIntValue(p.x);
opt.getTag(name + ".y").setIntValue(p.y);
getTag(name).setBooleanValue(show()); // duplicates global tag for the option gui if in world mode
getTag(name + ".x").setIntValue(p.x);
getTag(name + ".y").setIntValue(p.y);
}
}
@@ -43,6 +43,7 @@ public class GuiItemIconDumper extends GuiScreen {
}
private Option opt;
private final GuiOptionList parentGui;
private int drawIndex;
private int parseIndex;
private final File dir = new File(CommonUtils.getMinecraftDir(), "dumps/itempanel_icons");
@@ -52,6 +53,7 @@ public class GuiItemIconDumper extends GuiScreen {
public GuiItemIconDumper(Option opt, int iconSize) {
this.opt = opt;
this.parentGui = (GuiOptionList) Minecraft.getMinecraft().currentScreen;
this.iconSize = iconSize;
borderSize = iconSize / 16;
boxSize = iconSize + borderSize * 2;
@@ -62,7 +64,7 @@ public class GuiItemIconDumper extends GuiScreen {
}
private void returnScreen(IChatComponent msg) {
Minecraft.getMinecraft().displayGuiScreen(opt.getSlot().getGui());
Minecraft.getMinecraft().displayGuiScreen(parentGui);
NEIClientUtils.printChatMessage(msg);
}
@@ -7,10 +7,12 @@ import java.awt.Rectangle;
import java.util.ArrayList;
import java.util.List;
import net.minecraft.client.Minecraft;
import net.minecraft.client.gui.GuiScreen;
import org.lwjgl.opengl.GL11;
import codechicken.lib.config.ConfigTag;
import codechicken.lib.math.MathHelper;
import codechicken.nei.ItemSorter;
import codechicken.nei.ItemSorter.SortEntry;
@@ -48,6 +50,8 @@ public class GuiItemSorter extends GuiOptionPane {
public final Option opt;
public final List<SortItem> slots = new ArrayList<>();
public final List<SortEntry> list;
private final GuiOptionList parentGui;
private final boolean world;
boolean dragging;
public SortItem dragged;
@@ -56,7 +60,9 @@ public class GuiItemSorter extends GuiOptionPane {
public GuiItemSorter(Option opt) {
this.opt = opt;
list = ItemSorter.fromSaveString(opt.renderTag().getValue());
this.parentGui = (GuiOptionList) Minecraft.getMinecraft().currentScreen;
this.world = parentGui.worldConfig();
list = ItemSorter.fromSaveString(renderTag(opt.configName()).getValue());
for (SortEntry e : list) slots.add(new SortItem(e));
}
@@ -98,7 +104,7 @@ public class GuiItemSorter extends GuiOptionPane {
@Override
public GuiScreen getParentScreen() {
return opt.getSlot().getGui();
return parentGui;
}
@Override
@@ -114,16 +120,24 @@ public class GuiItemSorter extends GuiOptionPane {
list.remove(dragged.e);
list.add(nslot, dragged.e);
opt.getTag().setValue(ItemSorter.getSaveString(list));
getTag(opt.configName()).setValue(ItemSorter.getSaveString(list));
LayoutManager.markItemsDirty();
if (opt.activeTag() == opt.getTag()) {
if (opt.activeTag() == getTag(opt.configName())) {
ItemSorter.list = new ArrayList<>(list);
}
}
}
}
private ConfigTag getTag(String s) {
return (world ? opt.worldConfigSet() : opt.globalConfigSet()).config.getTag(s);
}
private ConfigTag renderTag(String s) {
return (world && opt.worldSpecific(s) ? opt.worldConfigSet() : opt.globalConfigSet()).config.getTag(s);
}
public SortItem itemAt(int mx, int my) {
if (!pane.windowBounds().contains(mx, my)) return null;
@@ -12,6 +12,7 @@ import org.lwjgl.opengl.GL11;
import org.lwjgl.opengl.GL12;
import codechicken.core.gui.GuiScreenWidget;
import codechicken.lib.config.ConfigTag;
import codechicken.lib.gui.GuiDraw;
import codechicken.lib.render.CCRenderState;
import codechicken.lib.vec.Rectangle4i;
@@ -21,7 +22,7 @@ import codechicken.nei.guihook.GuiContainerManager;
public class GuiPanelSettings extends GuiScreenWidget {
private final Option opt;
private final GuiOptionList parentGui;
private PanelPlaceholder bookmarksPanel;
private PanelPlaceholder itemsPanel;
@@ -54,6 +55,7 @@ public class GuiPanelSettings extends GuiScreenWidget {
private final Option opt;
private final String name;
private final boolean world;
private Rectangle4i margin;
private Point dragDown;
private String dragDir;
@@ -67,9 +69,10 @@ public class GuiPanelSettings extends GuiScreenWidget {
private PanelResizeButton rightButton = new PanelResizeButton(PANEL_SIZE, PANEL_SIZE * 2);
private PanelResizeButton bottomButton = new PanelResizeButton(PANEL_SIZE * 2, PANEL_SIZE);
public PanelPlaceholder(Option opt, String name) {
public PanelPlaceholder(Option opt, String name, boolean world) {
this.opt = opt;
this.name = name;
this.world = world;
}
public void resize(Rectangle4i margin) {
@@ -116,10 +119,10 @@ public class GuiPanelSettings extends GuiScreenWidget {
final int minWidth = ItemsGrid.SLOT_SIZE;
final int minHeight = ItemsGrid.SLOT_SIZE;
int paddingLeft = (int) Math.ceil(margin.w * opt.renderTag(name + ".left").getIntValue() / 100000.0);
int paddingTop = (int) Math.ceil(margin.h * opt.renderTag(name + ".top").getIntValue() / 100000.0);
int paddingRight = (int) Math.ceil(margin.w * opt.renderTag(name + ".right").getIntValue() / 100000.0);
int paddingBottom = (int) Math.ceil(margin.h * opt.renderTag(name + ".bottom").getIntValue() / 100000.0);
int paddingLeft = (int) Math.ceil(margin.w * getTag(name + ".left").getIntValue() / 100000.0);
int paddingTop = (int) Math.ceil(margin.h * getTag(name + ".top").getIntValue() / 100000.0);
int paddingRight = (int) Math.ceil(margin.w * getTag(name + ".right").getIntValue() / 100000.0);
int paddingBottom = (int) Math.ceil(margin.h * getTag(name + ".bottom").getIntValue() / 100000.0);
if (dragDir != null) {
final Point mouse = GuiDraw.getMousePosition();
@@ -159,6 +162,10 @@ public class GuiPanelSettings extends GuiScreenWidget {
return new int[] { paddingLeft, paddingTop, paddingRight, paddingBottom };
}
private ConfigTag getTag(String s) {
return (world ? opt.worldConfigSet() : opt.globalConfigSet()).config.getTag(s);
}
protected void drawItems() {
final int columns = (w - 2) / ItemsGrid.SLOT_SIZE;
final int rows = (h - (PANEL_SIZE + 2) * 2 - 2) / ItemsGrid.SLOT_SIZE;
@@ -219,10 +226,10 @@ public class GuiPanelSettings extends GuiScreenWidget {
if (button == 0 && dragDown != null) {
int[] padding = getPaddings();
opt.renderTag(name + ".left").setIntValue(padding[0] * 100000 / margin.w);
opt.renderTag(name + ".top").setIntValue(padding[1] * 100000 / margin.h);
opt.renderTag(name + ".right").setIntValue(padding[2] * 100000 / margin.w);
opt.renderTag(name + ".bottom").setIntValue(padding[3] * 100000 / margin.h);
getTag(name + ".left").setIntValue(padding[0] * 100000 / margin.w);
getTag(name + ".top").setIntValue(padding[1] * 100000 / margin.h);
getTag(name + ".right").setIntValue(padding[2] * 100000 / margin.w);
getTag(name + ".bottom").setIntValue(padding[3] * 100000 / margin.h);
dragDir = null;
dragDown = null;
@@ -232,10 +239,11 @@ public class GuiPanelSettings extends GuiScreenWidget {
public GuiPanelSettings(Option opt) {
super(176, 198);
this.opt = opt;
this.parentGui = (GuiOptionList) Minecraft.getMinecraft().currentScreen;
bookmarksPanel = new PanelPlaceholder(opt, opt.name + ".bookmarks");
itemsPanel = new PanelPlaceholder(opt, opt.name + ".items");
boolean world = parentGui.worldConfig();
bookmarksPanel = new PanelPlaceholder(opt, opt.name + ".bookmarks", world);
itemsPanel = new PanelPlaceholder(opt, opt.name + ".items", world);
}
@Override
@@ -247,7 +255,7 @@ public class GuiPanelSettings extends GuiScreenWidget {
public void keyTyped(char c, int keycode) {
if (keycode == Keyboard.KEY_ESCAPE || keycode == Keyboard.KEY_BACK) {
Minecraft.getMinecraft().displayGuiScreen(opt.getSlot().getGui());
Minecraft.getMinecraft().displayGuiScreen(parentGui);
return;
}
@@ -17,12 +17,14 @@ import codechicken.nei.LayoutManager;
import codechicken.nei.NEIClientUtils;
import codechicken.nei.PresetsList;
import codechicken.nei.PresetsList.Preset;
import codechicken.nei.config.GuiOptionList;
import codechicken.nei.config.GuiOptionPane;
import codechicken.nei.config.Option;
public class GuiPresetList extends GuiOptionPane {
private final Option opt;
private final GuiOptionList parentGui;
protected static final int SLOT_HEIGHT = 24;
protected static final int BUTTON_HEIGHT = 20;
protected GuiCCButton createButton;
@@ -31,6 +33,7 @@ public class GuiPresetList extends GuiOptionPane {
public GuiPresetList(Option opt) {
this.opt = opt;
this.parentGui = (GuiOptionList) Minecraft.getMinecraft().currentScreen;
this.createButton = new GuiCCButton(0, 2, 0, 16, NEIClientUtils.translate("presets.new"))
.setActionCommand("create");
this.toggleButton = new GuiCCButton(0, 2, 0, 16, NEIClientUtils.translate("presets.toggle"))
@@ -253,7 +256,7 @@ public class GuiPresetList extends GuiOptionPane {
@Override
public GuiScreen getParentScreen() {
return opt.getSlot().getGui();
return parentGui;
}
@Override