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 ;
@@ -41,22 +42,30 @@ public class NotificationToast implements Toast {
4142
4243 private final int lineHeight ;
4344 private final List <FormattedCharSequence > messageLines ;
45+ private Toast .Visibility wantedVisibility ;
4446
4547 public NotificationToast (Component message ) {
4648 this .messageLines = Minecraft .getInstance ().font .split (message , WIDTH - X_MARGIN * 2 );
4749 this .lineHeight = Minecraft .getInstance ().font .lineHeight + LINE_SPACE ;
4850 }
4951
5052 @ Override
51- public @ NotNull Visibility render (
52- @ NotNull GuiGraphics graphics ,
53- @ NotNull ToastComponent component ,
54- long elapsedTime
55- ) {
56- Font font = component .getMinecraft ().font ;
53+ public @ NotNull Visibility getWantedVisibility () {
54+ return wantedVisibility ;
55+ }
56+
57+ @ Override
58+ public void update (@ NotNull ToastManager manager , long elapsedTime ) {
59+ this .wantedVisibility =
60+ elapsedTime < DISPLAY_TIME * manager .getNotificationDisplayTimeMultiplier ()
61+ ? Visibility .SHOW : Visibility .HIDE ;
62+ }
63+
64+ @ Override
65+ public void render (@ NotNull GuiGraphics graphics , @ NotNull Font font , long elapsedTime ) {
5766 if (messageLines .size () <= 1 ) {
5867 // Message fits in a single line, render a single sprite
59- graphics .blitSprite (BACKGROUND_SPRITE , 0 , 0 , WIDTH , height ());
68+ graphics .blitSprite (RenderType :: guiTextured , BACKGROUND_SPRITE , 0 , 0 , WIDTH , height ());
6069 } else {
6170 // Message requires multiple lines, stretch vertically by rendering
6271 // multiple sprites
@@ -109,10 +118,6 @@ public NotificationToast(Component message) {
109118 );
110119 }
111120 }
112-
113- return elapsedTime < DISPLAY_TIME * component .getNotificationDisplayTimeMultiplier ()
114- ? Visibility .SHOW
115- : Visibility .HIDE ;
116121 }
117122
118123 private void renderBackgroundRow (
@@ -126,12 +131,24 @@ private void renderBackgroundRow(
126131 int uRemainder = Math .min (60 , width - uWidth );
127132
128133 // Left border
129- graphics .blitSprite (BACKGROUND_SPRITE , WIDTH , HEIGHT , 0 , vOffset , 0 , y , uWidth , vHeight );
134+ graphics .blitSprite (
135+ RenderType ::guiTextured ,
136+ BACKGROUND_SPRITE ,
137+ WIDTH ,
138+ HEIGHT ,
139+ 0 ,
140+ vOffset ,
141+ 0 ,
142+ y ,
143+ uWidth ,
144+ vHeight
145+ );
130146
131147 // Middle background
132148 int offset = 64 ;
133149 for (int x = uWidth ; x < width - uRemainder ; x += offset ) {
134150 graphics .blitSprite (
151+ RenderType ::guiTextured ,
135152 BACKGROUND_SPRITE ,
136153 WIDTH ,
137154 HEIGHT ,
@@ -146,6 +163,7 @@ private void renderBackgroundRow(
146163
147164 // Right border
148165 graphics .blitSprite (
166+ RenderType ::guiTextured ,
149167 BACKGROUND_SPRITE ,
150168 WIDTH ,
151169 HEIGHT ,
0 commit comments