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