@@ -42,11 +42,14 @@ public final class EditItemListScreen extends Screen
4242
4343 private ListGui listGui ;
4444 private TextFieldWidget itemNameField ;
45+ private ButtonWidget addKeywordButton ;
4546 private ButtonWidget addButton ;
4647 private ButtonWidget removeButton ;
4748 private ButtonWidget doneButton ;
4849
4950 private Item itemToAdd ;
51+ private java .util .List <net .minecraft .item .Item > fuzzyMatches =
52+ java .util .Collections .emptyList ();
5053
5154 public EditItemListScreen (Screen prevScreen , ItemListSetting itemList )
5255 {
@@ -61,23 +64,61 @@ public void init()
6164 listGui = new ListGui (client , this , itemList .getItemNames ());
6265 addSelectableChild (listGui );
6366
64- itemNameField = new TextFieldWidget (client .textRenderer ,
65- width / 2 - 152 , height - 56 , 150 , 20 , Text .literal ("" ));
67+ int rowY = height - 56 ;
68+ int gap = 8 ;
69+ int fieldWidth = 160 ;
70+ int keywordWidth = 110 ;
71+ int addWidth = 80 ;
72+ int removeWidth = 120 ;
73+ int totalWidth =
74+ fieldWidth + keywordWidth + addWidth + removeWidth + gap * 3 ;
75+ int rowStart = width / 2 - totalWidth / 2 ;
76+
77+ itemNameField = new TextFieldWidget (client .textRenderer , rowStart , rowY ,
78+ fieldWidth , 20 , Text .literal ("" ));
6679 addSelectableChild (itemNameField );
6780 itemNameField .setMaxLength (256 );
6881
82+ int keywordX = rowStart + fieldWidth + gap ;
83+ int addX = keywordX + keywordWidth + gap ;
84+ int removeX = addX + addWidth + gap ;
85+
86+ addDrawableChild (addKeywordButton =
87+ ButtonWidget .builder (Text .literal ("Add Keyword" ), b -> {
88+ String raw = itemNameField .getText ();
89+ if (raw != null )
90+ raw = raw .trim ();
91+ if (raw != null && !raw .isEmpty ())
92+ itemList .addRawName (raw );
93+ client .setScreen (EditItemListScreen .this );
94+ }).dimensions (keywordX , rowY , keywordWidth , 20 ).build ());
95+
6996 addDrawableChild (
7097 addButton = ButtonWidget .builder (Text .literal ("Add" ), b -> {
71- itemList .add (itemToAdd );
98+ if (itemToAdd != null )
99+ {
100+ itemList .add (itemToAdd );
101+ }else if (fuzzyMatches != null && !fuzzyMatches .isEmpty ())
102+ {
103+ for (net .minecraft .item .Item it : fuzzyMatches )
104+ itemList .add (it );
105+ }else
106+ {
107+ String raw = itemNameField .getText ();
108+ if (raw != null )
109+ raw = raw .trim ();
110+ if (raw != null && !raw .isEmpty ())
111+ itemList .addRawName (raw );
112+ }
72113 client .setScreen (EditItemListScreen .this );
73- }).dimensions (width / 2 - 2 , height - 56 , 30 , 20 ).build ());
114+ }).dimensions (addX , rowY , addWidth , 20 ).build ());
74115
75116 addDrawableChild (removeButton =
76117 ButtonWidget .builder (Text .literal ("Remove Selected" ), b -> {
77118 itemList .remove (itemList .getItemNames ()
78119 .indexOf (listGui .getSelectedBlockName ()));
79120 client .setScreen (EditItemListScreen .this );
80- }).dimensions (width / 2 + 52 , height - 56 , 100 , 20 ).build ());
121+ }).dimensions (removeX , rowY , removeWidth , 20 ).build ());
81122
82123 addDrawableChild (ButtonWidget .builder (Text .literal ("Reset to Defaults" ),
83124 b -> client .setScreen (new ConfirmScreen (b2 -> {
@@ -86,7 +127,12 @@ public void init()
86127 client .setScreen (EditItemListScreen .this );
87128 }, Text .literal ("Reset to Defaults" ),
88129 Text .literal ("Are you sure?" ))))
89- .dimensions (width - 108 , 8 , 100 , 20 ).build ());
130+ .dimensions (width - 328 , 8 , 150 , 20 ).build ());
131+
132+ addDrawableChild (ButtonWidget .builder (Text .literal ("Clear List" ), b -> {
133+ itemList .clear ();
134+ client .setScreen (EditItemListScreen .this );
135+ }).dimensions (width - 168 , 8 , 150 , 20 ).build ());
90136
91137 addDrawableChild (doneButton = ButtonWidget
92138 .builder (Text .literal ("Done" ), b -> client .setScreen (prevScreen ))
@@ -129,10 +175,51 @@ public boolean keyPressed(KeyInput context)
129175 @ Override
130176 public void tick ()
131177 {
132- String nameOrId = itemNameField .getText ().toLowerCase ();
178+ String nameOrId = itemNameField .getText ();
179+ String trimmed = nameOrId == null ? "" : nameOrId .trim ();
180+ boolean hasInput = !trimmed .isEmpty ();
133181 itemToAdd = ItemUtils .getItemFromNameOrID (nameOrId );
134- addButton .active = itemToAdd != null ;
182+ // Build fuzzy matches if no exact item found
183+ if (itemToAdd == null )
184+ {
185+ String q = trimmed .toLowerCase (java .util .Locale .ROOT );
186+ if (q .isEmpty ())
187+ {
188+ fuzzyMatches = java .util .Collections .emptyList ();
189+ }else
190+ {
191+ java .util .ArrayList <net .minecraft .item .Item > list =
192+ new java .util .ArrayList <>();
193+ for (net .minecraft .util .Identifier id : net .minecraft .registry .Registries .ITEM
194+ .getIds ())
195+ {
196+ String s = id .toString ().toLowerCase (java .util .Locale .ROOT );
197+ if (s .contains (q ))
198+ list .add (
199+ net .minecraft .registry .Registries .ITEM .get (id ));
200+ }
201+ // Deduplicate and sort by identifier
202+ java .util .LinkedHashMap <String , net .minecraft .item .Item > map =
203+ new java .util .LinkedHashMap <>();
204+ for (net .minecraft .item .Item it : list )
205+ map .put (net .minecraft .registry .Registries .ITEM .getId (it )
206+ .toString (), it );
207+ fuzzyMatches = new java .util .ArrayList <>(map .values ());
208+ fuzzyMatches .sort (java .util .Comparator
209+ .comparing (it -> net .minecraft .registry .Registries .ITEM
210+ .getId (it ).toString ()));
211+ }
212+ addButton .active = !fuzzyMatches .isEmpty () || hasInput ;
213+ addButton .setMessage (Text .literal (fuzzyMatches .isEmpty () ? "Add"
214+ : ("Add Matches (" + fuzzyMatches .size () + ")" )));
215+ }else
216+ {
217+ fuzzyMatches = java .util .Collections .emptyList ();
218+ addButton .active = true ;
219+ addButton .setMessage (Text .literal ("Add" ));
220+ }
135221
222+ addKeywordButton .active = hasInput ;
136223 removeButton .active = listGui .getSelectedOrNull () != null ;
137224 }
138225
@@ -155,33 +242,28 @@ public void render(DrawContext context, int mouseX, int mouseY,
155242 for (Drawable drawable : drawables )
156243 drawable .render (context , mouseX , mouseY , partialTicks );
157244
245+ // Draw placeholder + decorative left icon frame anchored to the field
158246 context .state .goUpLayer ();
159- matrixStack .pushMatrix ();
160- matrixStack .translate (-64 + width / 2 - 152 , 0 );
247+
248+ int x0 = itemNameField .getX ();
249+ int y0 = itemNameField .getY ();
250+ int y1 = y0 + itemNameField .getHeight ();
161251
162252 if (itemNameField .getText ().isEmpty () && !itemNameField .isFocused ())
163253 context .drawTextWithShadow (client .textRenderer , "item name or ID" ,
164- 68 , height - 50 , Colors .GRAY );
254+ x0 + 6 , y0 + 6 , Colors .GRAY );
165255
166256 int border =
167257 itemNameField .isFocused () ? Colors .WHITE : Colors .LIGHT_GRAY ;
168258 int black = Colors .BLACK ;
259+ int iconBoxLeft = x0 - 20 ;
169260
170- context .fill (48 , height - 56 , 64 , height - 36 , border );
171- context .fill (49 , height - 55 , 65 , height - 37 , black );
172- context .fill (214 , height - 56 , 244 , height - 55 , border );
173- context .fill (214 , height - 37 , 244 , height - 36 , border );
174- context .fill (244 , height - 56 , 246 , height - 36 , border );
175- context .fill (213 , height - 55 , 243 , height - 52 , black );
176- context .fill (213 , height - 40 , 243 , height - 37 , black );
177- context .fill (213 , height - 55 , 216 , height - 37 , black );
178- context .fill (242 , height - 55 , 245 , height - 37 , black );
179-
180- matrixStack .popMatrix ();
261+ context .fill (iconBoxLeft , y0 , x0 , y1 , border );
262+ context .fill (iconBoxLeft + 1 , y0 + 1 , x0 - 1 , y1 - 1 , black );
181263
182264 RenderUtils .drawItem (context ,
183265 itemToAdd == null ? ItemStack .EMPTY : new ItemStack (itemToAdd ),
184- width / 2 - 164 , height - 52 , false );
266+ iconBoxLeft + 2 , y0 + 2 , false );
185267
186268 matrixStack .popMatrix ();
187269 }
0 commit comments