1
1
package dynamic_fps .impl .feature .battery ;
2
2
3
+ import com .mojang .blaze3d .vertex .PoseStack ;
3
4
import dynamic_fps .impl .util .ResourceLocations ;
4
5
import net .minecraft .client .Minecraft ;
5
6
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 ;
21
21
protected @ Nullable ResourceLocation icon ;
22
22
23
+ private static final Minecraft MINECRAFT = Minecraft .getInstance ();
24
+
23
25
private static final ResourceLocation MOD_ICON = ResourceLocations .of ("dynamic_fps" , "textures/battery/toast/background_icon.png" );
24
26
private static final ResourceLocation BACKGROUND_IMAGE = ResourceLocations .of ("dynamic_fps" , "textures/battery/toast/background.png" );
25
27
@@ -28,47 +30,34 @@ protected BaseToast(Component title, Component description, @Nullable ResourceLo
28
30
this .description = description ;
29
31
30
32
this .icon = icon ;
31
-
32
- this .visibility = Visibility .SHOW ;
33
33
}
34
34
35
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
- }
50
-
51
- @ Override
52
- public void render (GuiGraphics graphics , Font font , long currentTime ) {
36
+ public @ NotNull Visibility render (PoseStack poseStack , ToastComponent toastComponent , long currentTime ) {
53
37
if (this .firstRender == 0 ) {
54
38
this .onFirstRender ();
55
39
this .firstRender = currentTime ;
56
40
}
57
41
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 ());
42
+ MINECRAFT .getTextureManager ().bind (BACKGROUND_IMAGE );
43
+ // resource, x, y, z, ?, ?, width, height, width, height
44
+ GuiComponent .blit (poseStack , 0 , 0 , 0.0f , 0.0f , this .width (), this .height (), this .width (), this .height ());
60
45
61
46
int x = 8 ;
62
47
63
48
if (this .icon != null ) {
64
49
x += 22 ;
65
50
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 );
51
+ MINECRAFT .getTextureManager ().bind (MOD_ICON );
52
+ GuiComponent .blit (poseStack , 2 , 2 , 0.0f , 0.0f , 8 , 8 , 8 , 8 );
53
+ MINECRAFT .getTextureManager ().bind (this .icon );
54
+ GuiComponent .blit (poseStack , 8 , 8 , 0.0f , 0.0f , 16 , 16 , 16 , 16 );
68
55
}
69
56
70
- graphics .drawString (Minecraft .getInstance ().font , this .title , x , 7 , 0x5f3315 , false );
71
- graphics .drawString (Minecraft .getInstance ().font , this .description , x , 18 , -16777216 , false );
57
+ MINECRAFT .font .draw (poseStack , this .title , x , 7 , 0x5f3315 );
58
+ MINECRAFT .font .draw (poseStack , this .description , x , 18 , -16777216 );
59
+
60
+ return currentTime - this .firstRender >= 5000.0 ? Toast .Visibility .HIDE : Toast .Visibility .SHOW ;
72
61
}
73
62
74
63
public void onFirstRender () {}
0 commit comments