2323 */
2424package aztech .modern_industrialization .items .client ;
2525
26+ import aztech .modern_industrialization .MI ;
2627import aztech .modern_industrialization .MIText ;
2728import aztech .modern_industrialization .MITooltips ;
2829import aztech .modern_industrialization .blocks .structure .member .StructureMemberMode ;
3637import aztech .modern_industrialization .util .RenderHelper ;
3738import java .util .ArrayList ;
3839import java .util .List ;
39- import java .util .Locale ;
4040import net .minecraft .client .Minecraft ;
4141import net .minecraft .client .gui .Font ;
4242import net .minecraft .client .gui .GuiGraphics ;
4343import net .minecraft .client .gui .screens .inventory .tooltip .ClientTooltipComponent ;
4444import net .minecraft .client .renderer .MultiBufferSource ;
4545import net .minecraft .core .registries .BuiltInRegistries ;
4646import net .minecraft .network .chat .Component ;
47+ import net .minecraft .resources .ResourceLocation ;
4748import net .minecraft .tags .TagKey ;
4849import net .minecraft .util .FormattedCharSequence ;
4950import net .minecraft .world .item .ItemStack ;
5455import org .joml .Matrix4f ;
5556
5657public final class ClientStructureMemberBlockTooltip implements ClientTooltipComponent {
58+ private static final ResourceLocation HATCH_ICON_ATLAS = MI .id ("textures/gui/tooltip/hatch_icons.png" );
59+
5760 private final StructureMultiblockMemberBlockItem .TooltipData data ;
5861
5962 private final List <Line > lines = new ArrayList <>();
@@ -76,22 +79,22 @@ public ClientStructureMemberBlockTooltip(StructureMultiblockMemberBlockItem.Tool
7679 BlockState preview = data .preview ();
7780 if (preview != null && !preview .isAir ()) {
7881 ItemStack previewStack = preview .getBlock ().asItem ().getDefaultInstance ();
79- lines .add (new ItemStacksLine (MIText .StructureMultiblockMemberTooltipPreview .text ().append (" " ),
80- List .of (new ItemStacksLine .StackEntry (previewStack ))));
82+ lines .add (new IconsLine (MIText .StructureMultiblockMemberTooltipPreview .text ().append (" " ),
83+ List .of (new IconsLine .StackEntry (previewStack )), 6 ));
8184 }
8285
83- List <ItemStacksLine .Entry > members = new ArrayList <>();
86+ List <IconsLine .Entry > members = new ArrayList <>();
8487 if (data .members () != null ) {
8588 for (StructureMemberTest member : data .members ()) {
8689 if (member instanceof StateStructureMemberTest stateTest ) {
87- members .add (new ItemStacksLine .StackEntry (stateTest .blockState ().getBlock ().asItem ().getDefaultInstance ()));
90+ members .add (new IconsLine .StackEntry (stateTest .blockState ().getBlock ().asItem ().getDefaultInstance ()));
8891 } else if (member instanceof TagStructureMemberTest tagTest ) {
89- members .add (new ItemStacksLine .TagEntry (tagTest .blockTag ()));
92+ members .add (new IconsLine .TagEntry (tagTest .blockTag ()));
9093 }
9194 }
9295 }
9396 if (!members .isEmpty ()) {
94- lines .add (new ItemStacksLine (MIText .StructureMultiblockMemberTooltipMembers .text ().append (" " ), members ));
97+ lines .add (new IconsLine (MIText .StructureMultiblockMemberTooltipMembers .text ().append (" " ), members , 6 ));
9598 }
9699 }
97100
@@ -103,17 +106,13 @@ public ClientStructureMemberBlockTooltip(StructureMultiblockMemberBlockItem.Tool
103106
104107 HatchFlags hatchFlags = data .hatchFlags ();
105108 if (hatchFlags != null && hatchFlags .flags != 0 ) {
106- StringBuilder hatchText = new StringBuilder ();
109+ List < IconsLine . Entry > hatches = new ArrayList <> ();
107110 for (HatchType hatchType : HatchType .values ()) {
108111 if (hatchFlags .allows (hatchType )) {
109- if (!hatchText .isEmpty ()) {
110- hatchText .append (", " );
111- }
112- hatchText .append (hatchType .name ().toLowerCase (Locale .ROOT ));
112+ hatches .add (new IconsLine .HatchEntry (hatchType ));
113113 }
114114 }
115- lines .add (new ComponentLine (MIText .StructureMultiblockMemberTooltipHatches .text ().append (" " ),
116- Component .literal (hatchText .toString ())));
115+ lines .add (new IconsLine (MIText .StructureMultiblockMemberTooltipHatches .text ().append (" " ), hatches , 9 ));
117116 }
118117 }
119118 }
@@ -211,7 +210,7 @@ public void renderText(Font font, int x, int y, Matrix4f matrix, MultiBufferSour
211210 }
212211 }
213212
214- private record ItemStacksLine (Component label , List <Entry > entries ) implements Line {
213+ private record IconsLine (Component label , List <Entry > entries , int maxToDisplay ) implements Line {
215214
216215 @ Override
217216 public int height (Font font ) {
@@ -220,17 +219,17 @@ public int height(Font font) {
220219
221220 @ Override
222221 public int width (Font font ) {
223- return font .width (label ) + (18 * Math .min (6 , entries .size ())) + (entries .size () >= 6 ? font .width (Component .literal ("+ ..." )) : 0 );
222+ return font .width (label ) + (18 * Math .min (maxToDisplay , entries .size ()))
223+ + (entries .size () > maxToDisplay ? font .width (Component .literal ("+ ..." )) : 0 );
224224 }
225225
226226 @ Override
227227 public void renderImage (Font font , int x , int y , GuiGraphics graphics ) {
228228 int i = 0 ;
229229 for (var entry : entries ) {
230- if (entry .renderImage (font , x + (i * 18 ) + font .width (label ), y + 1 , graphics )) {
231- if (++i >= 5 ) {
232- break ;
233- }
230+ entry .renderImage (font , x + (i * 18 ) + font .width (label ), y + 1 , graphics );
231+ if (++i >= maxToDisplay ) {
232+ break ;
234233 }
235234 }
236235 }
@@ -239,28 +238,28 @@ public void renderImage(Font font, int x, int y, GuiGraphics graphics) {
239238 public void renderText (Font font , int x , int y , Matrix4f matrix , MultiBufferSource .BufferSource buffer ) {
240239 font .drawInBatch (label , x , y + 5 , -1 , true , matrix , buffer , Font .DisplayMode .NORMAL , 0 , 0xF000F0 );
241240
242- if (entries .size () >= 6 ) {
243- font .drawInBatch (Component .literal ("+ ..." ).withStyle (MITooltips .DEFAULT_STYLE ), x + (18 * 5 ) + 2 + font .width (label ), y + 5 , -1 ,
241+ if (entries .size () > maxToDisplay ) {
242+ font .drawInBatch (Component .literal ("+ ..." ).withStyle (MITooltips .DEFAULT_STYLE ), x + (18 * maxToDisplay ) + 2 + font .width (label ),
243+ y + 5 , -1 ,
244244 true , matrix , buffer ,
245245 Font .DisplayMode .NORMAL , 0 , 0xF000F0 );
246246 }
247247 }
248248
249249 private interface Entry {
250- boolean renderImage (Font font , int x , int y , GuiGraphics graphics );
250+ void renderImage (Font font , int x , int y , GuiGraphics graphics );
251251 }
252252
253253 private record StackEntry (ItemStack stack ) implements Entry {
254254 @ Override
255- public boolean renderImage (Font font , int x , int y , GuiGraphics graphics ) {
255+ public void renderImage (Font font , int x , int y , GuiGraphics graphics ) {
256256 RenderHelper .renderAndDecorateItem (graphics , font , stack , x , y );
257- return true ;
258257 }
259258 }
260259
261260 private record TagEntry (TagKey <Block > tag ) implements Entry {
262261 @ Override
263- public boolean renderImage (Font font , int x , int y , GuiGraphics graphics ) {
262+ public void renderImage (Font font , int x , int y , GuiGraphics graphics ) {
264263 var maybeTag = BuiltInRegistries .BLOCK .getTag (tag );
265264 ItemStack stack ;
266265 if (maybeTag .isPresent ()) {
@@ -275,8 +274,14 @@ public boolean renderImage(Font font, int x, int y, GuiGraphics graphics) {
275274 graphics .pose ().translate (0 , 0 , 200 );
276275 graphics .drawString (font , Component .literal ("#" ).withStyle (MITooltips .DEFAULT_STYLE ), x , y , 0xFFFFFF , true );
277276 graphics .pose ().popPose ();
277+ }
278+ }
278279
279- return true ;
280+ private record HatchEntry (HatchType type ) implements Entry {
281+ @ Override
282+ public void renderImage (Font font , int x , int y , GuiGraphics graphics ) {
283+ int u = type .getId () * 16 ;
284+ graphics .blit (HATCH_ICON_ATLAS , x , y , u , 0 , 16 , 16 );
280285 }
281286 }
282287 }
0 commit comments