Skip to content

Commit 12ba40e

Browse files
committed
work around the fact we can't render items anymore
1 parent 2961c0e commit 12ba40e

3 files changed

Lines changed: 39 additions & 8 deletions

File tree

src/main/java/dev/isxander/yacl3/gui/controllers/dropdown/ItemControllerElement.java

Lines changed: 37 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -32,7 +32,12 @@ protected void drawValueText(GuiGraphicsExtractor graphics, int mouseX, int mous
3232
super.drawValueText(graphics, mouseX, mouseY, delta);
3333
setDimension(oldDimension);
3434
if (currentItem != null) {
35-
graphics.fakeItem(new ItemStack(currentItem), getDimension().xLimit() - getXPadding() - getDecorationPadding() + 2, getDimension().y() + 2);
35+
renderFakeItem(
36+
graphics,
37+
currentItem,
38+
getDimension().xLimit() - getXPadding() - getDecorationPadding() + 2,
39+
getDimension().y() + 2
40+
);
3641
}
3742
}
3843

@@ -49,13 +54,27 @@ public List<Identifier> computeMatchingValues() {
4954
@Override
5055
protected void renderDropdownEntry(GuiGraphicsExtractor graphics, Dimension<Integer> entryDimension, Identifier identifier) {
5156
super.renderDropdownEntry(graphics, entryDimension, identifier);
52-
graphics.fakeItem(
53-
new ItemStack(matchingItems.get(identifier)),
54-
entryDimension.xLimit() - 2,
55-
entryDimension.y() + 1
56-
);
57+
renderFakeItem(
58+
graphics,
59+
matchingItems.get(identifier),
60+
entryDimension.xLimit() - 2,
61+
entryDimension.y() + 1
62+
);
5763
}
5864

65+
private void renderFakeItem(GuiGraphicsExtractor graphics, Item item, int x, int y) {
66+
ItemStack stack = null;
67+
try {
68+
stack = new ItemStack(item);
69+
} catch (NullPointerException ignored) {
70+
// ItemStacks no longer exist until dynamic registries have been loaded,
71+
// which is either loading into a level or opening the create world screen.
72+
// This means we cannot do anything that involves ItemStacks until then.
73+
}
74+
if (stack == null) return;
75+
graphics.fakeItem(stack, x, y);
76+
}
77+
5978
@Override
6079
public String getString(Identifier identifier) {
6180
return identifier.toString();
@@ -85,6 +104,17 @@ protected Component getValueText() {
85104
return Component.literal(inputField);
86105

87106
Item item = itemController.option().pendingValue();
88-
return item.getName(item.getDefaultInstance());
107+
ItemStack stack = null;
108+
try {
109+
stack = item.getDefaultInstance();
110+
} catch (NullPointerException ignored) {
111+
// fapi has a bug (i think) that doesn't bind item components early enough anymore,
112+
// causing an NPE on <init> of ItemStack.
113+
}
114+
if (stack != null) {
115+
return item.getName(stack);
116+
} else {
117+
return Component.literal(item.toString());
118+
}
89119
}
90120
}

stonecutter.gradle.kts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@ plugins {
55

66
val modstitchVersion = "0.8.4"
77
id("dev.isxander.modstitch.base") version modstitchVersion apply false
8+
id("net.fabricmc.fabric-loom") version "1.15-SNAPSHOT" apply false
89

910
id("me.modmuss50.mod-publish-plugin") version "0.8.4" apply false
1011
id("org.ajoberstar.grgit") version "5.0.+" apply false

versions/26.1-fabric/gradle.properties

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@ modstitch.platform=fabric-loom
22

33
mcVersion=26.1-pre-1
44

5-
deps.fabricApi=0.143.11+26.1
5+
deps.fabricApi=0.143.12+26.1
66

77
meta.mcDep=^26.1-
88

0 commit comments

Comments
 (0)