@@ -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}
0 commit comments