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