Skip to content

Commit e8a2eea

Browse files
committed
Update to mc1.21.3
1 parent 02d9bd8 commit e8a2eea

File tree

11 files changed

+94
-56
lines changed

11 files changed

+94
-56
lines changed

common/src/main/java/dev/terminalmc/chatnotify/ChatNotify.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -92,7 +92,7 @@ public static void afterClientTick(Minecraft mc) {
9292
// Config reset warning toast
9393
if (hasResetConfig && mc.screen instanceof TitleScreen) {
9494
hasResetConfig = false;
95-
mc.getToasts().addToast(new SystemToast(
95+
mc.getToastManager().addToast(new SystemToast(
9696
new SystemToast.SystemToastId(15000L),
9797
localized("toast", "reset.title"),
9898
localized(

common/src/main/java/dev/terminalmc/chatnotify/command/Commands.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -37,7 +37,7 @@ public static <S> void register(CommandDispatcher<S> dispatcher, CommandBuildCon
3737
//noinspection unchecked
3838
dispatcher.register((LiteralArgumentBuilder<S>) literal(ChatNotify.MOD_ID)
3939
.executes((ctx) -> {
40-
mc.tell(() -> mc.setScreen(new RootScreen(mc.screen)));
40+
mc.schedule(() -> mc.setScreen(new RootScreen(mc.screen)));
4141
return Command.SINGLE_SUCCESS;
4242
})
4343
);

common/src/main/java/dev/terminalmc/chatnotify/gui/toast/NotificationToast.java

Lines changed: 31 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,8 @@
2020
import net.minecraft.client.gui.Font;
2121
import net.minecraft.client.gui.GuiGraphics;
2222
import net.minecraft.client.gui.components.toasts.Toast;
23-
import net.minecraft.client.gui.components.toasts.ToastComponent;
23+
import net.minecraft.client.gui.components.toasts.ToastManager;
24+
import net.minecraft.client.renderer.RenderType;
2425
import net.minecraft.network.chat.Component;
2526
import net.minecraft.resources.ResourceLocation;
2627
import net.minecraft.util.FormattedCharSequence;
@@ -40,6 +41,7 @@ public class NotificationToast implements Toast {
4041

4142
private final int lineHeight;
4243
private final List<FormattedCharSequence> messageLines;
44+
private Toast.Visibility wantedVisibility;
4345
private final int displayTime;
4446

4547
public NotificationToast(Component message, int displayTime) {
@@ -49,15 +51,22 @@ public NotificationToast(Component message, int displayTime) {
4951
}
5052

5153
@Override
52-
public @NotNull Visibility render(
53-
@NotNull GuiGraphics graphics,
54-
@NotNull ToastComponent component,
55-
long elapsedTime
56-
) {
57-
Font font = component.getMinecraft().font;
54+
public @NotNull Visibility getWantedVisibility() {
55+
return wantedVisibility;
56+
}
57+
58+
@Override
59+
public void update(@NotNull ToastManager manager, long elapsedTime) {
60+
this.wantedVisibility =
61+
elapsedTime < displayTime * manager.getNotificationDisplayTimeMultiplier()
62+
? Visibility.SHOW : Visibility.HIDE;
63+
}
64+
65+
@Override
66+
public void render(@NotNull GuiGraphics graphics, @NotNull Font font, long elapsedTime) {
5867
if (messageLines.size() <= 1) {
5968
// Message fits in a single line, render a single sprite
60-
graphics.blitSprite(BACKGROUND_SPRITE, 0, 0, WIDTH, height());
69+
graphics.blitSprite(RenderType::guiTextured, BACKGROUND_SPRITE, 0, 0, WIDTH, height());
6170
} else {
6271
// Message requires multiple lines, stretch vertically by rendering
6372
// multiple sprites
@@ -110,10 +119,6 @@ public NotificationToast(Component message, int displayTime) {
110119
);
111120
}
112121
}
113-
114-
return elapsedTime < displayTime * component.getNotificationDisplayTimeMultiplier()
115-
? Visibility.SHOW
116-
: Visibility.HIDE;
117122
}
118123

119124
private void renderBackgroundRow(
@@ -127,12 +132,24 @@ private void renderBackgroundRow(
127132
int uRemainder = Math.min(60, width - uWidth);
128133

129134
// Left border
130-
graphics.blitSprite(BACKGROUND_SPRITE, WIDTH, HEIGHT, 0, vOffset, 0, y, uWidth, vHeight);
135+
graphics.blitSprite(
136+
RenderType::guiTextured,
137+
BACKGROUND_SPRITE,
138+
WIDTH,
139+
HEIGHT,
140+
0,
141+
vOffset,
142+
0,
143+
y,
144+
uWidth,
145+
vHeight
146+
);
131147

132148
// Middle background
133149
int offset = 64;
134150
for (int x = uWidth; x < width - uRemainder; x += offset) {
135151
graphics.blitSprite(
152+
RenderType::guiTextured,
136153
BACKGROUND_SPRITE,
137154
WIDTH,
138155
HEIGHT,
@@ -147,6 +164,7 @@ private void renderBackgroundRow(
147164

148165
// Right border
149166
graphics.blitSprite(
167+
RenderType::guiTextured,
150168
BACKGROUND_SPRITE,
151169
WIDTH,
152170
HEIGHT,

common/src/main/java/dev/terminalmc/chatnotify/gui/widget/HorizontalList.java

Lines changed: 26 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,7 @@
2727
import net.minecraft.client.gui.narration.NarratedElementType;
2828
import net.minecraft.client.gui.narration.NarrationElementOutput;
2929
import net.minecraft.client.gui.screens.Screen;
30+
import net.minecraft.client.renderer.RenderType;
3031
import net.minecraft.network.chat.Component;
3132
import net.minecraft.resources.ResourceLocation;
3233
import net.minecraft.util.Mth;
@@ -246,7 +247,18 @@ protected void renderWidget(
246247
*/
247248
protected void renderListBackground(GuiGraphics graphics) {
248249
RenderSystem.enableBlend();
249-
graphics.blit(MENU_LIST_BACKGROUND, getX(), getY(), 0, 0, getWidth(), getHeight(), 32, 32);
250+
graphics.blit(
251+
RenderType::guiTextured,
252+
MENU_LIST_BACKGROUND,
253+
getX(),
254+
getY(),
255+
0,
256+
0,
257+
getWidth(),
258+
getHeight(),
259+
32,
260+
32
261+
);
250262
RenderSystem.disableBlend();
251263
}
252264

@@ -297,13 +309,21 @@ protected void renderScrollbar(GuiGraphics graphics) {
297309

298310
RenderSystem.enableBlend();
299311
graphics.blitSprite(
312+
RenderType::guiTextured,
300313
SCROLLER_BACKGROUND_SPRITE,
301314
getX(),
302315
y,
303316
getWidth(),
304317
SCROLLBAR_HEIGHT
305318
);
306-
graphics.blitSprite(SCROLLER_SPRITE, scrollerPos, y, scrollerWidth, SCROLLBAR_HEIGHT);
319+
graphics.blitSprite(
320+
RenderType::guiTextured,
321+
SCROLLER_SPRITE,
322+
scrollerPos,
323+
y,
324+
scrollerWidth,
325+
SCROLLBAR_HEIGHT
326+
);
307327
RenderSystem.disableBlend();
308328
}
309329
}
@@ -321,6 +341,7 @@ protected boolean scrollbarVisible() {
321341
protected void renderSeparators(GuiGraphics guiGraphics) {
322342
RenderSystem.enableBlend();
323343
guiGraphics.blit(
344+
RenderType::guiTextured,
324345
LEFT_SEPARATOR,
325346
getX() - 2,
326347
getY() - 1,
@@ -332,6 +353,7 @@ protected void renderSeparators(GuiGraphics guiGraphics) {
332353
32
333354
);
334355
guiGraphics.blit(
356+
RenderType::guiTextured,
335357
RIGHT_SEPARATOR,
336358
getRight(),
337359
getY() - 1,
@@ -343,6 +365,7 @@ protected void renderSeparators(GuiGraphics guiGraphics) {
343365
32
344366
);
345367
guiGraphics.blit(
368+
RenderType::guiTextured,
346369
Screen.HEADER_SEPARATOR,
347370
getX() - 1,
348371
getY() - 2,
@@ -354,6 +377,7 @@ protected void renderSeparators(GuiGraphics guiGraphics) {
354377
2
355378
);
356379
guiGraphics.blit(
380+
RenderType::guiTextured,
357381
Screen.FOOTER_SEPARATOR,
358382
getX() - 1,
359383
getBottom(),

common/src/main/java/dev/terminalmc/chatnotify/gui/widget/HsvColorPicker.java

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,7 @@
2929
import net.minecraft.network.chat.CommonComponents;
3030
import net.minecraft.network.chat.Component;
3131
import net.minecraft.network.chat.TextColor;
32-
import net.minecraft.util.FastColor;
32+
import net.minecraft.util.ARGB;
3333
import net.minecraft.util.Mth;
3434
import org.jetbrains.annotations.NotNull;
3535

@@ -258,9 +258,9 @@ public int getMaxHeight() {
258258
public void updateColorFromSource() {
259259
int color = source.get();
260260
Color.RGBtoHSB(
261-
FastColor.ARGB32.red(color),
262-
FastColor.ARGB32.green(color),
263-
FastColor.ARGB32.blue(color),
261+
ARGB.red(color),
262+
ARGB.green(color),
263+
ARGB.blue(color),
264264
hsv
265265
);
266266
oldColor = color;
@@ -282,9 +282,9 @@ private void updateColorFromHexField(String s) {
282282
int color = textColor.getValue();
283283
if (!updateFromCursor) {
284284
Color.RGBtoHSB(
285-
FastColor.ARGB32.red(color),
286-
FastColor.ARGB32.green(color),
287-
FastColor.ARGB32.blue(color),
285+
ARGB.red(color),
286+
ARGB.green(color),
287+
ARGB.blue(color),
288288
hsv
289289
);
290290
updateHCursor();

common/src/main/java/dev/terminalmc/chatnotify/gui/widget/list/FilterList.java

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -41,7 +41,7 @@
4141
import net.minecraft.network.chat.Component;
4242
import net.minecraft.network.chat.MutableComponent;
4343
import net.minecraft.network.chat.TextColor;
44-
import net.minecraft.util.FastColor;
44+
import net.minecraft.util.ARGB;
4545
import net.minecraft.util.StringUtil;
4646
import org.jetbrains.annotations.Nullable;
4747

@@ -980,9 +980,9 @@ public NotifOptions(
980980
notif.textStyle.color = color;
981981
float[] hsv = new float[3];
982982
Color.RGBtoHSB(
983-
FastColor.ARGB32.red(color),
984-
FastColor.ARGB32.green(color),
985-
FastColor.ARGB32.blue(color),
983+
ARGB.red(color),
984+
ARGB.green(color),
985+
ARGB.blue(color),
986986
hsv
987987
);
988988
if (hsv[2] < 0.1)

common/src/main/java/dev/terminalmc/chatnotify/gui/widget/list/root/DefaultList.java

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -35,7 +35,7 @@
3535
import net.minecraft.network.chat.Style;
3636
import net.minecraft.network.chat.TextColor;
3737
import net.minecraft.resources.ResourceLocation;
38-
import net.minecraft.util.FastColor;
38+
import net.minecraft.util.ARGB;
3939

4040
import java.awt.*;
4141

@@ -149,9 +149,9 @@ private static class DefaultColor extends Entry {
149149
).setStyle(Style.EMPTY.withColor(textColor)));
150150
float[] hsv = new float[3];
151151
Color.RGBtoHSB(
152-
FastColor.ARGB32.red(color),
153-
FastColor.ARGB32.green(color),
154-
FastColor.ARGB32.blue(color),
152+
ARGB.red(color),
153+
ARGB.green(color),
154+
ARGB.blue(color),
155155
hsv
156156
);
157157
if (hsv[2] < 0.1)

common/src/main/java/dev/terminalmc/chatnotify/gui/widget/list/root/notif/FormatList.java

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -34,7 +34,7 @@
3434
import net.minecraft.network.chat.Component;
3535
import net.minecraft.network.chat.MutableComponent;
3636
import net.minecraft.network.chat.TextColor;
37-
import net.minecraft.util.FastColor;
37+
import net.minecraft.util.ARGB;
3838

3939
import java.awt.*;
4040
import java.time.Duration;
@@ -152,9 +152,9 @@ private static class ColorOptions extends Entry {
152152
mainButton.setMessage(mainButton.getMessage().copy().withColor(color));
153153
float[] hsv = new float[3];
154154
Color.RGBtoHSB(
155-
FastColor.ARGB32.red(color),
156-
FastColor.ARGB32.green(color),
157-
FastColor.ARGB32.blue(color),
155+
ARGB.red(color),
156+
ARGB.green(color),
157+
ARGB.blue(color),
158158
hsv
159159
);
160160
if (hsv[2] < 0.1)

common/src/main/java/dev/terminalmc/chatnotify/mixin/GuiGraphicsMixin.java

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -38,9 +38,6 @@ public abstract class GuiGraphicsMixin implements IGuiGraphics {
3838
@Final
3939
private PoseStack pose;
4040

41-
@Shadow
42-
protected abstract void flushIfUnmanaged();
43-
4441
@Override
4542
public void chatnotify$fillGradientHorizontal(
4643
int x0,
@@ -56,6 +53,5 @@ public abstract class GuiGraphicsMixin implements IGuiGraphics {
5653
consumer.addVertex(matrix4f, (float) x0, (float) y1, 0F).setColor(colorFrom);
5754
consumer.addVertex(matrix4f, (float) x1, (float) y1, 0F).setColor(colorTo);
5855
consumer.addVertex(matrix4f, (float) x1, (float) y0, 0F).setColor(colorTo);
59-
flushIfUnmanaged();
6056
}
6157
}

common/src/main/java/dev/terminalmc/chatnotify/util/text/MessageUtil.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -588,7 +588,7 @@ private static void showToastMsg(Notification notif, Component msg, Matcher matc
588588
: convertMsg(notif.toastMsg, matcher, msg);
589589
// Convert from ticks to milliseconds
590590
Minecraft.getInstance()
591-
.getToasts()
591+
.getToastManager()
592592
.addToast(new NotificationToast(displayMsg, notif.toastStay * 50));
593593
}
594594
}

0 commit comments

Comments
 (0)