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 ;
@@ -19,17 +19,17 @@ public class BatteryToast implements Toast {
19
19
private Component title ;
20
20
private Component description ;
21
21
private ResourceLocation icon ;
22
- private Visibility visibility ;
23
22
24
23
private static BatteryToast queuedToast ;
25
24
25
+ private static final Minecraft MINECRAFT = Minecraft .getInstance ();
26
+
26
27
private static final ResourceLocation MOD_ICON = ResourceLocations .of ("dynamic_fps" , "textures/battery/toast/background_icon.png" );
27
28
private static final ResourceLocation BACKGROUND_IMAGE = ResourceLocations .of ("dynamic_fps" , "textures/battery/toast/background.png" );
28
29
29
30
private BatteryToast (Component title , ResourceLocation icon ) {
30
31
this .title = title ;
31
32
this .icon = icon ;
32
- this .visibility = Visibility .SHOW ;
33
33
}
34
34
35
35
/**
@@ -42,28 +42,12 @@ public static void queueToast(Component title, ResourceLocation icon) {
42
42
queuedToast .icon = icon ;
43
43
} else {
44
44
queuedToast = new BatteryToast (title , icon );
45
- Minecraft .getInstance ().getToastManager ().addToast (queuedToast );
46
- }
47
- }
48
-
49
- @ Override
50
- public @ NotNull Visibility getWantedVisibility () {
51
- return this .visibility ;
52
- }
53
-
54
- @ Override
55
- public void update (ToastManager toastManager , long currentTime ) {
56
- if (this .firstRender == 0 ) {
57
- return ;
58
- }
59
-
60
- if (currentTime - this .firstRender >= 5000.0 * toastManager .getNotificationDisplayTimeMultiplier ()) {
61
- this .visibility = Visibility .HIDE ;
45
+ Minecraft .getInstance ().getToasts ().addToast (queuedToast );
62
46
}
63
47
}
64
48
65
49
@ Override
66
- public void render (GuiGraphics graphics , Font font , long currentTime ) {
50
+ public @ NotNull Visibility render (PoseStack poseStack , ToastComponent toastComponent , long currentTime ) {
67
51
if (this .firstRender == 0 ) {
68
52
if (this == queuedToast ) {
69
53
queuedToast = null ;
@@ -74,13 +58,18 @@ public void render(GuiGraphics graphics, Font font, long currentTime) {
74
58
this .description = localized ("toast" , "battery_charge" , BatteryTracker .charge ());
75
59
}
76
60
61
+ MINECRAFT .getTextureManager ().bind (BACKGROUND_IMAGE );
77
62
// resource, x, y, z, ?, ?, width, height, width, height
78
- graphics .blit (RenderType ::guiTextured , BACKGROUND_IMAGE , 0 , 0 , 0 , 0.0f , 0 , this .width (), this .height (), this .width (), this .height ());
63
+ GuiComponent .blit (poseStack , 0 , 0 , 0 , 0.0f , 0.0f , this .width (), this .height (), this .width (), this .height ());
64
+
65
+ MINECRAFT .getTextureManager ().bind (MOD_ICON );
66
+ GuiComponent .blit (poseStack , 2 , 2 , 0 , 0.0f , 0.0f , 8 , 8 , 8 , 8 );
67
+ MINECRAFT .getTextureManager ().bind (this .icon );
68
+ GuiComponent .blit (poseStack , 8 , 8 , 0 , 0.0f , 0.0f , 16 , 16 , 16 , 16 );
79
69
80
- graphics . blit ( RenderType :: guiTextured , MOD_ICON , 2 , 2 , 0 , 0.0f , 0 , 8 , 8 , 8 , 8 );
81
- graphics . blit ( RenderType :: guiTextured , this . icon , 8 , 8 , 0 , 0.0f , 0 , 16 , 16 , 16 , 16 );
70
+ GuiComponent . drawString ( poseStack , toastComponent . getMinecraft (). font , this . title , 30 , 7 , 0x5f3315 );
71
+ GuiComponent . drawString ( poseStack , toastComponent . getMinecraft (). font , this . description , 30 , 18 , - 16777216 );
82
72
83
- graphics .drawString (Minecraft .getInstance ().font , this .title , 30 , 7 , 0x5f3315 , false );
84
- graphics .drawString (Minecraft .getInstance ().font , this .description , 30 , 18 , -16777216 , false );
73
+ return currentTime - this .firstRender >= 5000.0 ? Toast .Visibility .HIDE : Toast .Visibility .SHOW ;
85
74
}
86
75
}
0 commit comments