2020import net .minecraft .client .gui .Font ;
2121import net .minecraft .client .gui .GuiGraphics ;
2222import net .minecraft .client .gui .components .toasts .Toast ;
23- import net .minecraft .client .gui .components .toasts .ToastComponent ;
23+ import net .minecraft .client .gui .components .toasts .ToastManager ;
24+ import net .minecraft .client .renderer .RenderType ;
2425import net .minecraft .network .chat .Component ;
2526import net .minecraft .resources .ResourceLocation ;
2627import net .minecraft .util .FormattedCharSequence ;
@@ -40,19 +41,30 @@ public class NotificationToast implements Toast {
4041
4142 private final int lineHeight ;
4243 private final List <FormattedCharSequence > messageLines ;
44+ private Toast .Visibility wantedVisibility ;
4345
4446 public NotificationToast (Component message ) {
4547 this .messageLines = Minecraft .getInstance ().font .split (message , WIDTH - X_MARGIN * 2 );
4648 this .lineHeight = Minecraft .getInstance ().font .lineHeight + LINE_SPACE ;
4749 }
4850
4951 @ Override
50- public @ NotNull Visibility render (@ NotNull GuiGraphics graphics ,
51- @ NotNull ToastComponent component , long elapsedTime ) {
52- Font font = component .getMinecraft ().font ;
52+ public @ NotNull Visibility getWantedVisibility () {
53+ return wantedVisibility ;
54+ }
55+
56+ @ Override
57+ public void update (@ NotNull ToastManager manager , long elapsedTime ) {
58+ this .wantedVisibility =
59+ elapsedTime < DISPLAY_TIME * manager .getNotificationDisplayTimeMultiplier ()
60+ ? Visibility .SHOW : Visibility .HIDE ;
61+ }
62+
63+ @ Override
64+ public void render (@ NotNull GuiGraphics graphics , @ NotNull Font font , long elapsedTime ) {
5365 if (messageLines .size () <= 1 ) {
5466 // Message fits in a single line, render a single sprite
55- graphics .blitSprite (BACKGROUND_SPRITE , 0 , 0 , WIDTH , height ());
67+ graphics .blitSprite (RenderType :: guiTextured , BACKGROUND_SPRITE , 0 , 0 , WIDTH , height ());
5668 } else {
5769 // Message requires multiple lines, stretch vertically by rendering
5870 // multiple sprites
@@ -88,9 +100,6 @@ public NotificationToast(Component message) {
88100 X_MARGIN , Y_MARGIN + lineHeight * j , -1 , false );
89101 }
90102 }
91-
92- return elapsedTime < DISPLAY_TIME * component .getNotificationDisplayTimeMultiplier ()
93- ? Visibility .SHOW : Visibility .HIDE ;
94103 }
95104
96105 private void renderBackgroundRow (GuiGraphics graphics , int width , int vOffset ,
@@ -99,18 +108,18 @@ private void renderBackgroundRow(GuiGraphics graphics, int width, int vOffset,
99108 int uRemainder = Math .min (60 , width - uWidth );
100109
101110 // Left border
102- graphics .blitSprite (BACKGROUND_SPRITE , WIDTH , HEIGHT , 0 , vOffset ,
103- 0 , y , uWidth , vHeight );
111+ graphics .blitSprite (RenderType :: guiTextured , BACKGROUND_SPRITE , WIDTH , HEIGHT ,
112+ 0 , vOffset , 0 , y , uWidth , vHeight );
104113
105114 // Middle background
106115 int offset = 64 ;
107116 for (int x = uWidth ; x < width - uRemainder ; x += offset ) {
108- graphics .blitSprite (BACKGROUND_SPRITE , WIDTH , HEIGHT , HEIGHT , vOffset ,
109- x , y , Math .min (offset , width - x - uRemainder ), vHeight );
117+ graphics .blitSprite (RenderType :: guiTextured , BACKGROUND_SPRITE , WIDTH , HEIGHT ,
118+ HEIGHT , vOffset , x , y , Math .min (offset , width - x - uRemainder ), vHeight );
110119 }
111120
112121 // Right border
113- graphics .blitSprite (BACKGROUND_SPRITE , WIDTH , HEIGHT , WIDTH - uRemainder , vOffset ,
114- width - uRemainder , y , uRemainder , vHeight );
122+ graphics .blitSprite (RenderType :: guiTextured , BACKGROUND_SPRITE , WIDTH , HEIGHT ,
123+ WIDTH - uRemainder , vOffset , width - uRemainder , y , uRemainder , vHeight );
115124 }
116125}
0 commit comments