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,7 +19,6 @@ 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
@@ -29,7 +28,6 @@ public class BatteryToast implements Toast {
29
28
private BatteryToast (Component title , ResourceLocation icon ) {
30
29
this .title = title ;
31
30
this .icon = icon ;
32
- this .visibility = Visibility .SHOW ;
33
31
}
34
32
35
33
/**
@@ -42,28 +40,12 @@ public static void queueToast(Component title, ResourceLocation icon) {
42
40
queuedToast .icon = icon ;
43
41
} else {
44
42
queuedToast = new BatteryToast (title , icon );
45
- Minecraft .getInstance ().getToastManager ().addToast (queuedToast );
43
+ Minecraft .getInstance ().getToasts ().addToast (queuedToast );
46
44
}
47
45
}
48
46
49
47
@ 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 ;
62
- }
63
- }
64
-
65
- @ Override
66
- public void render (GuiGraphics graphics , Font font , long currentTime ) {
48
+ public @ NotNull Visibility render (PoseStack poseStack , ToastComponent toastComponent , long currentTime ) {
67
49
if (this .firstRender == 0 ) {
68
50
if (this == queuedToast ) {
69
51
queuedToast = null ;
@@ -74,13 +56,18 @@ public void render(GuiGraphics graphics, Font font, long currentTime) {
74
56
this .description = localized ("toast" , "battery_charge" , BatteryTracker .charge ());
75
57
}
76
58
59
+ RenderSystem .setShaderTexture (0 , BACKGROUND_IMAGE );
77
60
// 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 ());
61
+ GuiComponent .blit (poseStack , 0 , 0 , 0 , 0.0f , 0.0f , this .width (), this .height (), this .width (), this .height ());
62
+
63
+ RenderSystem .setShaderTexture (0 , MOD_ICON );
64
+ GuiComponent .blit (poseStack , 2 , 2 , 0 , 0.0f , 0.0f , 8 , 8 , 8 , 8 );
65
+ RenderSystem .setShaderTexture (0 , this .icon );
66
+ GuiComponent .blit (poseStack , 8 , 8 , 0 , 0.0f , 0.0f , 16 , 16 , 16 , 16 );
79
67
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 );
68
+ GuiComponent . drawString ( poseStack , toastComponent . getMinecraft (). font , this . title , 30 , 7 , 0x5f3315 );
69
+ GuiComponent . drawString ( poseStack , toastComponent . getMinecraft (). font , this . description , 30 , 18 , - 16777216 );
82
70
83
- graphics .drawString (Minecraft .getInstance ().font , this .title , 30 , 7 , 0x5f3315 , false );
84
- graphics .drawString (Minecraft .getInstance ().font , this .description , 30 , 18 , -16777216 , false );
71
+ return currentTime - this .firstRender >= 5000.0 ? Toast .Visibility .HIDE : Toast .Visibility .SHOW ;
85
72
}
86
73
}
0 commit comments