@@ -637,56 +637,68 @@ private PanelItem createBlockButton(ItemTemplateRecord template, TemplatedPanel.
637637 return this .createMaterialButton (template , this .blockCountList .get (index ));
638638 }
639639
640- /**
641- * This method creates button for block.
642- *
643- * @param template the template of the button
644- * @param blockCount count
645- * @return PanelItem button
646- */
647640 private PanelItem createMaterialButton (ItemTemplateRecord template , BlockRec blockCount ) {
648641 PanelItemBuilder builder = new PanelItemBuilder ();
649- if (template .icon () != null )
642+
643+ // Set icon and amount based on the template and block count.
644+ if (template .icon () != null ) {
650645 builder .icon (template .icon ().clone ());
651- if (blockCount .value () < 64 )
646+ }
647+ if (blockCount .value () < 64 ) {
652648 builder .amount (blockCount .value ());
649+ }
650+
653651 final String ref = "level.gui.buttons.material." ;
654652 BlockDataRec d = getBlockData (blockCount .key ());
655- if (d .icon () != null )
653+
654+ // Override icon from block data if available.
655+ if (d .icon () != null ) {
656656 builder .icon (d .icon ());
657+ }
658+
659+ // Set name using the title translation if provided.
657660 if (template .title () != null ) {
658661 builder .name (this .user .getTranslation (this .world , template .title (), TextVariables .NUMBER ,
659662 String .valueOf (blockCount .value ()), "[material]" , d .displayMaterial ()));
660663 }
664+
665+ // Build and set description if provided.
661666 if (template .description () != null ) {
662- builder .description (this .user
663- .getTranslation (this .world , template .description (), "[description]" ,
664- Utils .prettifyDescription (blockCount .key (), this .user ) + d .extraDesc (), "[id]" ,
665- this .user .isOp () ? d .blockId () : "" , "[value]" ,
666- d .blockValue () > 0
667- ? this .user .getTranslationOrNothing (
668- ref + "value" , TextVariables .NUMBER , String .valueOf (d .blockValue ()))
669- : "" ,
670- "[calculated]" ,
671- ((long ) Math .min (d .blockLimit () > 0 ? d .blockLimit () : Integer .MAX_VALUE ,
672- blockCount .value ()) * d .blockValue ()) > 0
673- ? this .user .getTranslationOrNothing (ref + "calculated" ,
674- TextVariables .NUMBER ,
675- String .valueOf ((long ) Math .min (
676- d .blockLimit () > 0 ? d .blockLimit () : Integer .MAX_VALUE ,
677- blockCount .value ()) * d .blockValue ()))
678- : "" ,
679- "[limit]" ,
680- d .blockLimit () > 0 ? this .user .getTranslationOrNothing (
681- ref + "limit" , TextVariables .NUMBER , String .valueOf (d .blockLimit ())) : "" ,
682- "[count]" ,
683- this .user .getTranslationOrNothing (ref + "count" , TextVariables .NUMBER ,
684- String .valueOf (blockCount .value ())))
685- .replaceAll ("(?m)^[ \\ t]*\\ r?\\ n" , "" ).replaceAll ("(?<!\\ \\ )\\ |" , "\n " ).replace ("\\ \\ \\ |" , "|" ));
667+ String description = buildDescription (template .description (), blockCount , d , ref );
668+ builder .description (description );
686669 }
670+
687671 return builder .build ();
688672 }
689673
674+ private String buildDescription (String descriptionTemplate , BlockRec blockCount , BlockDataRec d , String ref ) {
675+ String desc = Utils .prettifyDescription (blockCount .key (), this .user ) + d .extraDesc ();
676+ String id = this .user .isOp () ? d .blockId () : "" ;
677+ String value = d .blockValue () > 0
678+ ? this .user .getTranslationOrNothing (ref + "value" , TextVariables .NUMBER , String .valueOf (d .blockValue ()))
679+ : "" ;
680+
681+ long calculatedRaw = (long ) Math .min (d .blockLimit () > 0 ? d .blockLimit () : Integer .MAX_VALUE ,
682+ blockCount .value ()) * d .blockValue ();
683+ String calculated = calculatedRaw > 0
684+ ? this .user .getTranslationOrNothing (ref + "calculated" , TextVariables .NUMBER ,
685+ String .valueOf (calculatedRaw ))
686+ : "" ;
687+
688+ String limit = d .blockLimit () > 0
689+ ? this .user .getTranslationOrNothing (ref + "limit" , TextVariables .NUMBER , String .valueOf (d .blockLimit ()))
690+ : "" ;
691+
692+ String count = this .user .getTranslationOrNothing (ref + "count" , TextVariables .NUMBER ,
693+ String .valueOf (blockCount .value ()));
694+
695+ String translated = this .user .getTranslation (this .world , descriptionTemplate , "[description]" , desc , "[id]" , id ,
696+ "[value]" , value , "[calculated]" , calculated , "[limit]" , limit , "[count]" , count );
697+
698+ return translated .replaceAll ("(?m)^[ \\ t]*\\ r?\\ n" , "" ).replaceAll ("(?<!\\ \\ )\\ |" , "\n " ).replace ("\\ \\ \\ |" ,
699+ "|" );
700+ }
701+
690702 private record BlockDataRec (ItemStack icon , String blockId , int blockValue , int blockLimit , String displayMaterial ,
691703 String extraDesc ) {
692704 }
0 commit comments