37
37
import net .minecraft .client .Minecraft ;
38
38
import net .minecraft .client .gui .screens .inventory .AbstractContainerScreen ;
39
39
import net .minecraft .client .resources .language .I18n ;
40
- import net .minecraft .network .chat .Component ;
41
40
import net .minecraft .network .chat .MutableComponent ;
42
41
import net .minecraft .network .chat .TextComponent ;
43
42
import net .minecraft .network .chat .TranslatableComponent ;
@@ -64,34 +63,34 @@ public static class AutoCraftingResult {
64
63
public static AutoCraftingResult evaluateAutoCrafting (boolean actuallyCrafting , boolean stackedCrafting , Display display , Supplier <Collection <ResourceLocation >> idsSupplier ) {
65
64
AbstractContainerScreen <?> containerScreen = REIRuntime .getInstance ().getPreviousContainerScreen ();
66
65
AutoCraftingResult result = new AutoCraftingResult ();
67
- final List <Component > errorTooltip = new ArrayList <>();
66
+ final List <Tooltip . Entry > errorTooltip = new ArrayList <>();
68
67
result .tooltipRenderer = (pos , sink ) -> {
69
- List <Component > str = new ArrayList <>(errorTooltip );
68
+ List <Tooltip . Entry > str = new ArrayList <>(errorTooltip );
70
69
71
70
if (ConfigObject .getInstance ().isFavoritesEnabled ()) {
72
- str .add (new TextComponent (" " ));
73
- str .add (new TranslatableComponent ("text.rei.save.recipes" , new TextComponent (ConfigObject .getInstance ().getFavoriteKeyCode ().getLocalizedName ().getString ().toUpperCase (Locale .ROOT )).withStyle (ChatFormatting .BOLD )).withStyle (ChatFormatting .GRAY ));
71
+ str .add (Tooltip . entry ( new TextComponent (" " ) ));
72
+ str .add (Tooltip . entry ( new TranslatableComponent ("text.rei.save.recipes" , new TextComponent (ConfigObject .getInstance ().getFavoriteKeyCode ().getLocalizedName ().getString ().toUpperCase (Locale .ROOT )).withStyle (ChatFormatting .BOLD )).withStyle (ChatFormatting .GRAY ) ));
74
73
}
75
74
76
75
if (Minecraft .getInstance ().options .advancedItemTooltips && idsSupplier != null ) {
77
76
Collection <ResourceLocation > locations = idsSupplier .get ();
78
77
if (!locations .isEmpty ()) {
79
- str .add (new TextComponent (" " ));
78
+ str .add (Tooltip . entry ( new TextComponent (" " ) ));
80
79
for (ResourceLocation location : locations ) {
81
80
String t = I18n .get ("text.rei.recipe_id" , "" , location .toString ());
82
81
if (t .startsWith ("\n " )) {
83
82
t = t .substring ("\n " .length ());
84
83
}
85
- str .add (new TextComponent (t ).withStyle (ChatFormatting .GRAY ));
84
+ str .add (Tooltip . entry ( new TextComponent (t ).withStyle (ChatFormatting .GRAY ) ));
86
85
}
87
86
}
88
87
}
89
88
90
- sink .accept (Tooltip .create (pos , str ));
89
+ sink .accept (Tooltip .from (pos , str ));
91
90
};
92
91
93
92
if (containerScreen == null ) {
94
- errorTooltip .add (new TranslatableComponent ("error.rei.not.supported.move.items" ).withStyle (ChatFormatting .RED ));
93
+ errorTooltip .add (Tooltip . entry ( new TranslatableComponent ("error.rei.not.supported.move.items" ).withStyle (ChatFormatting .RED ) ));
95
94
return result ;
96
95
}
97
96
@@ -147,38 +146,46 @@ public static AutoCraftingResult evaluateAutoCrafting(boolean actuallyCrafting,
147
146
148
147
if (!result .hasApplicable ) {
149
148
errorTooltip .clear ();
150
- errorTooltip .add (new TranslatableComponent ("error.rei.not.supported.move.items" ).withStyle (ChatFormatting .RED ));
149
+ errorTooltip .add (Tooltip . entry ( new TranslatableComponent ("error.rei.not.supported.move.items" ).withStyle (ChatFormatting .RED ) ));
151
150
return result ;
152
151
}
153
152
154
153
if (errors .isEmpty ()) {
155
154
errorTooltip .clear ();
156
- errorTooltip .add (new TranslatableComponent ("text.auto_craft.move_items" ));
155
+ errorTooltip .add (Tooltip . entry ( new TranslatableComponent ("text.auto_craft.move_items" ) ));
157
156
158
157
if (successfulResult != null ) {
159
158
successfulResult .fillTooltip (errorTooltip );
160
159
}
161
160
} else {
162
161
errorTooltip .clear ();
163
- List <Component > tooltipsFilled = new ArrayList <>();
162
+ List <Tooltip . Entry > tooltipsFilled = new ArrayList <>();
164
163
for (TransferHandler .Result error : errors ) {
165
164
error .fillTooltip (tooltipsFilled );
166
165
}
167
166
168
167
if (errors .size () == 1 ) {
169
- for (Component tooltipFilled : tooltipsFilled ) {
170
- MutableComponent colored = tooltipFilled .copy ().withStyle (ChatFormatting .RED );
171
- if (!CollectionUtils .anyMatch (errorTooltip , ss -> ss .getString ().equalsIgnoreCase (tooltipFilled .getString ()))) {
172
- errorTooltip .add (colored );
168
+ for (Tooltip .Entry tooltipFilled : tooltipsFilled ) {
169
+ if (tooltipFilled .isText ()) {
170
+ MutableComponent colored = tooltipFilled .getAsText ().copy ().withStyle (ChatFormatting .RED );
171
+ if (!CollectionUtils .anyMatch (errorTooltip , ss -> ss .isText () && ss .getAsText ().getString ().equalsIgnoreCase (colored .getString ()))) {
172
+ errorTooltip .add (Tooltip .entry (colored ));
173
+ }
174
+ } else {
175
+ errorTooltip .add (tooltipFilled );
173
176
}
174
177
}
175
178
} else {
176
- errorTooltip .add (new TranslatableComponent ("error.rei.multi.errors" ).withStyle (ChatFormatting .RED ));
177
- for (Component tooltipFilled : tooltipsFilled ) {
178
- MutableComponent colored = new TextComponent ("- " ).withStyle (ChatFormatting .RED )
179
- .append (tooltipFilled .copy ().withStyle (ChatFormatting .RED ));
180
- if (!CollectionUtils .anyMatch (errorTooltip , ss -> ss .getString ().equalsIgnoreCase (colored .getString ()))) {
181
- errorTooltip .add (colored );
179
+ errorTooltip .add (Tooltip .entry (new TranslatableComponent ("error.rei.multi.errors" ).withStyle (ChatFormatting .RED )));
180
+ for (Tooltip .Entry tooltipFilled : tooltipsFilled ) {
181
+ if (tooltipFilled .isText ()) {
182
+ MutableComponent colored = new TextComponent ("- " ).withStyle (ChatFormatting .RED )
183
+ .append (tooltipFilled .getAsText ().copy ().withStyle (ChatFormatting .RED ));
184
+ if (!CollectionUtils .anyMatch (errorTooltip , ss -> ss .isText () && ss .getAsText ().getString ().equalsIgnoreCase (colored .getString ()))) {
185
+ errorTooltip .add (Tooltip .entry (colored ));
186
+ }
187
+ } else {
188
+ errorTooltip .add (tooltipFilled );
182
189
}
183
190
}
184
191
}
0 commit comments