11package fi .dy .masa .litematica .gui .widgets ;
22
33import java .util .ArrayList ;
4+ import java .util .Collection ;
45import java .util .Collections ;
56import java .util .List ;
7+
8+ import fi .dy .masa .litematica .gui .Icons ;
9+ import fi .dy .masa .malilib .gui .LeftRight ;
10+ import fi .dy .masa .malilib .gui .widgets .WidgetSearchBar ;
611import it .unimi .dsi .fastutil .objects .Object2IntOpenHashMap ;
712import it .unimi .dsi .fastutil .objects .Object2ObjectOpenHashMap ;
813
14+ import net .minecraft .block .Block ;
915import net .minecraft .block .BlockState ;
1016import net .minecraft .client .gui .DrawContext ;
1117import net .minecraft .item .ItemStack ;
2026import fi .dy .masa .malilib .gui .widgets .WidgetListBase ;
2127import fi .dy .masa .malilib .util .ItemType ;
2228import fi .dy .masa .malilib .util .StringUtils ;
29+ import net .minecraft .registry .Registries ;
30+ import net .minecraft .util .Identifier ;
2331
2432public class WidgetListSchematicVerificationResults extends WidgetListBase <BlockMismatchEntry , WidgetSchematicVerificationResult >
2533{
@@ -36,6 +44,8 @@ public WidgetListSchematicVerificationResults(int x, int y, int width, int heigh
3644 this .browserEntryHeight = 22 ;
3745 this .guiSchematicVerifier = parent ;
3846 this .allowMultiSelection = true ;
47+ this .widgetSearchBar = new WidgetSearchBar (x + 2 , y + 8 , width - 16 , 14 , 0 , Icons .FILE_ICON_SEARCH , LeftRight .RIGHT );
48+ this .widgetSearchBar .setZLevel (1 );
3949 this .sorter = new VerifierResultSorter (parent .getPlacement ().getSchematicVerifier ());
4050 }
4151
@@ -53,6 +63,57 @@ protected void offsetSelectionOrScrollbar(int amount, boolean changeSelection)
5363 lastScrollbarPosition = this .scrollBar .getValue ();
5464 }
5565
66+ @ Override
67+ protected Collection <BlockMismatchEntry > getAllEntries ()
68+ {
69+ List <BlockMismatchEntry > listContents = new ArrayList <>();
70+
71+ MismatchType type = this .guiSchematicVerifier .getResultMode ();
72+
73+ if (type == MismatchType .ALL )
74+ {
75+ this .addEntriesForType (listContents , MismatchType .WRONG_BLOCK );
76+ if (Configs .Generic .ENABLE_DIFFERENT_BLOCKS .getBooleanValue ())
77+ {
78+ this .addEntriesForType (listContents , MismatchType .DIFF_BLOCK );
79+ }
80+ this .addEntriesForType (listContents , MismatchType .WRONG_STATE );
81+ this .addEntriesForType (listContents , MismatchType .EXTRA );
82+ this .addEntriesForType (listContents , MismatchType .MISSING );
83+ }
84+ else
85+ {
86+ this .addEntriesForType (listContents , type );
87+ }
88+
89+ return listContents ;
90+ }
91+
92+ @ Override
93+ protected List <String > getEntryStringsForFilter (BlockMismatchEntry entry )
94+ {
95+ if (entry .blockMismatch == null )
96+ return Collections .emptyList ();
97+
98+ List <String > list = new ArrayList <>();
99+
100+ Block block = entry .blockMismatch .stateExpected .getBlock ();
101+ Identifier rl = Registries .ITEM .getId (block .asItem ());
102+
103+ list .add (block .getName ().getString ().toLowerCase ());
104+ if (rl != null )
105+ list .add (rl .toString ().toLowerCase ());
106+
107+ block = entry .blockMismatch .stateFound .getBlock ();
108+ rl = Registries .ITEM .getId (block .asItem ());
109+
110+ list .add (block .getName ().getString ().toLowerCase ());
111+ if (rl != null )
112+ list .add (rl .toString ().toLowerCase ());
113+
114+ return list ;
115+ }
116+
56117 @ Override
57118 protected WidgetSchematicVerificationResult createHeaderWidget (int x , int y , int listIndexStart , int usableHeight , int usedHeight )
58119 {
@@ -83,27 +144,7 @@ protected WidgetSchematicVerificationResult createHeaderWidget(int x, int y, int
83144 @ Override
84145 protected void refreshBrowserEntries ()
85146 {
86- this .listContents .clear ();
87-
88- MismatchType type = this .guiSchematicVerifier .getResultMode ();
89-
90- if (type == MismatchType .ALL )
91- {
92- this .addEntriesForType (MismatchType .WRONG_BLOCK );
93- if (Configs .Generic .ENABLE_DIFFERENT_BLOCKS .getBooleanValue ())
94- {
95- this .addEntriesForType (MismatchType .DIFF_BLOCK );
96- }
97- this .addEntriesForType (MismatchType .WRONG_STATE );
98- this .addEntriesForType (MismatchType .EXTRA );
99- this .addEntriesForType (MismatchType .MISSING );
100- }
101- else
102- {
103- this .addEntriesForType (type );
104- }
105-
106- this .reCreateListEntryWidgets ();
147+ super .refreshBrowserEntries ();
107148
108149 if (this .scrollbarRestored == false && lastScrollbarPosition <= this .scrollBar .getMaxValue ())
109150 {
@@ -114,10 +155,10 @@ protected void refreshBrowserEntries()
114155 }
115156 }
116157
117- private void addEntriesForType (MismatchType type )
158+ private void addEntriesForType (Collection < BlockMismatchEntry > listContents , MismatchType type )
118159 {
119160 String title = type .getFormattingCode () + type .getDisplayname () + TXT_RST ;
120- this . listContents .add (new BlockMismatchEntry (type , title ));
161+ listContents .add (new BlockMismatchEntry (type , title ));
121162 List <BlockMismatch > list ;
122163
123164 if (type == MismatchType .CORRECT_STATE )
@@ -162,7 +203,7 @@ private void addEntriesForType(MismatchType type)
162203
163204 for (BlockMismatch mismatch : list )
164205 {
165- this . listContents .add (new BlockMismatchEntry (type , mismatch ));
206+ listContents .add (new BlockMismatchEntry (type , mismatch ));
166207 }
167208 }
168209
0 commit comments