1
1
package dynamic_fps .impl .feature .battery ;
2
2
3
+ import com .mojang .blaze3d .systems .RenderSystem ;
4
+ import com .mojang .blaze3d .vertex .PoseStack ;
3
5
import dynamic_fps .impl .util .ResourceLocations ;
4
6
import net .minecraft .client .Minecraft ;
5
- import net .minecraft .client .gui .Font ;
6
- import net .minecraft .client .gui .GuiGraphics ;
7
+ import net .minecraft .client .gui .GuiComponent ;
7
8
import net .minecraft .client .gui .components .toasts .Toast ;
8
- import net .minecraft .client .gui .components .toasts .ToastManager ;
9
+ import net .minecraft .client .gui .components .toasts .ToastComponent ;
9
10
import net .minecraft .client .renderer .RenderType ;
10
11
import net .minecraft .network .chat .Component ;
11
12
import net .minecraft .resources .ResourceLocation ;
14
15
15
16
public class BaseToast implements Toast {
16
17
private long firstRender ;
17
- private Visibility visibility ;
18
18
19
19
protected Component title ;
20
20
protected Component description ;
@@ -28,47 +28,33 @@ protected BaseToast(Component title, Component description, @Nullable ResourceLo
28
28
this .description = description ;
29
29
30
30
this .icon = icon ;
31
-
32
- this .visibility = Visibility .SHOW ;
33
- }
34
-
35
- @ Override
36
- public @ NotNull Visibility getWantedVisibility () {
37
- return this .visibility ;
38
- }
39
-
40
- @ Override
41
- public void update (ToastManager toastManager , long currentTime ) {
42
- if (this .firstRender == 0 ) {
43
- return ;
44
- }
45
-
46
- if (currentTime - this .firstRender >= 5000.0 * toastManager .getNotificationDisplayTimeMultiplier ()) {
47
- this .visibility = Visibility .HIDE ;
48
- }
49
31
}
50
32
51
33
@ Override
52
- public void render (GuiGraphics graphics , Font font , long currentTime ) {
34
+ public @ NotNull Visibility render (PoseStack poseStack , ToastComponent toastComponent , long currentTime ) {
53
35
if (this .firstRender == 0 ) {
54
36
this .onFirstRender ();
55
37
this .firstRender = currentTime ;
56
38
}
57
39
58
- // type, resource, x, y, ?, ?, width, height, width, height
59
- graphics .blit (RenderType :: guiTextured , BACKGROUND_IMAGE , 0 , 0 , 0.0f , 0 , this . width (), this . height (), this . width (), this . height () );
40
+ RenderSystem . setShaderTexture ( 0 , BACKGROUND_IMAGE );
41
+ GuiComponent .blit (poseStack , 0 , 0 , 0.0f , 0.0f , 160 , 32 , 160 , 32 );
60
42
61
43
int x = 8 ;
62
44
63
45
if (this .icon != null ) {
64
46
x += 22 ;
65
47
66
- graphics .blit (RenderType ::guiTextured , MOD_ICON , 2 , 2 , 0.0f , 0 , 8 , 8 , 8 , 8 );
67
- graphics .blit (RenderType ::guiTextured , this .icon , 8 , 8 , 0.0f , 0 , 16 , 16 , 16 , 16 );
48
+ RenderSystem .setShaderTexture (0 , MOD_ICON );
49
+ GuiComponent .blit (poseStack , 2 , 2 , 0.0f , 0.0f , 8 , 8 , 8 , 8 );
50
+ RenderSystem .setShaderTexture (0 , this .icon );
51
+ GuiComponent .blit (poseStack , 8 , 8 , 0.0f , 0.0f , 16 , 16 , 16 , 16 );
68
52
}
69
53
70
- graphics .drawString (Minecraft .getInstance ().font , this .title , x , 7 , 0x5f3315 , false );
71
- graphics .drawString (Minecraft .getInstance ().font , this .description , x , 18 , -16777216 , false );
54
+ Minecraft .getInstance ().font .draw (poseStack , this .title , x , 7 , 0x5f3315 );
55
+ Minecraft .getInstance ().font .draw (poseStack , this .description , x , 18 , -16777216 );
56
+
57
+ return currentTime - this .firstRender >= 5000.0 ? Toast .Visibility .HIDE : Toast .Visibility .SHOW ;
72
58
}
73
59
74
60
public void onFirstRender () {}
0 commit comments