Skip to content
This repository was archived by the owner on Nov 28, 2025. It is now read-only.

Commit 692c3f4

Browse files
committed
add QR codes in the device code screen
1 parent 7ecae1d commit 692c3f4

File tree

31 files changed

+278
-182
lines changed

31 files changed

+278
-182
lines changed

1.16_combat-6/src/main/java/io/github/axolotlclient/api/StatusUpdateProviderImpl.java

Lines changed: 10 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -83,7 +83,7 @@ public Request getStatus() {
8383
}
8484
}
8585
}
86-
86+
} else if (MinecraftClient.getInstance().player != null) {
8787
String gamemode = getGameMode(MinecraftClient.getInstance().player);
8888
return StatusUpdate.inGameUnknown(entry.address, "", entry.name, gamemode);
8989

@@ -98,17 +98,15 @@ private String getOrEmpty(JsonObject object, String name) {
9898

9999
private String getGameMode(PlayerEntity entity) {
100100
PlayerListEntry entry = MinecraftClient.getInstance().getNetworkHandler().getPlayerListEntry(entity.getUuid());
101-
switch (entry.getGameMode()) {
102-
case CREATIVE:
103-
return "Creative Mode";
104-
case SURVIVAL:
105-
return "Survival Mode";
106-
case SPECTATOR:
107-
return "Spectator Mode";
108-
case ADVENTURE:
109-
return "Adventure Mode";
110-
default:
111-
return "";
101+
if (entry == null) {
102+
return "";
112103
}
104+
return switch (entry.getGameMode()) {
105+
case CREATIVE -> "Creative Mode";
106+
case SURVIVAL -> "Survival Mode";
107+
case SPECTATOR -> "Spectator Mode";
108+
case ADVENTURE -> "Adventure Mode";
109+
default -> "";
110+
};
113111
}
114112
}

1.16_combat-6/src/main/java/io/github/axolotlclient/modules/auth/Auth.java

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -109,9 +109,9 @@ protected void login(Account account) {
109109
if (account.isExpired()) {
110110
Notifications.getInstance().addStatus(new TranslatableText("auth.notif.title"), new TranslatableText("auth.notif.refreshing", account.getName()));
111111
}
112-
account.refresh(auth, runnable);
112+
account.refresh(auth, () -> {});
113113
} else {
114-
new Thread(runnable).start();
114+
runnable.run();
115115
}
116116
}
117117

1.16_combat-6/src/main/java/io/github/axolotlclient/modules/auth/DeviceCodeDisplayScreen.java

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -25,14 +25,17 @@
2525
import java.net.URI;
2626
import java.util.List;
2727

28+
import io.github.axolotlclient.AxolotlClientConfig.api.util.Graphics;
2829
import io.github.axolotlclient.util.OSUtil;
30+
import io.github.axolotlclient.util.Util;
2931
import net.minecraft.client.MinecraftClient;
3032
import net.minecraft.client.gui.screen.Screen;
3133
import net.minecraft.client.gui.widget.ButtonWidget;
3234
import net.minecraft.client.util.math.MatrixStack;
3335
import net.minecraft.text.OrderedText;
3436
import net.minecraft.text.Text;
3537
import net.minecraft.text.TranslatableText;
38+
import net.minecraft.util.Identifier;
3639

3740
public class DeviceCodeDisplayScreen extends Screen {
3841
private final Screen parent;
@@ -41,6 +44,7 @@ public class DeviceCodeDisplayScreen extends Screen {
4144
private int ticksLeft;
4245
private Text status;
4346
private boolean working;
47+
private final Identifier qrCode;
4448

4549
public DeviceCodeDisplayScreen(Screen parent, DeviceFlowData data) {
4650
super(new TranslatableText("auth.add"));
@@ -49,6 +53,7 @@ public DeviceCodeDisplayScreen(Screen parent, DeviceFlowData data) {
4953
this.verificationUri = data.getVerificationUri();
5054
this.userCode = data.getUserCode();
5155
this.ticksLeft = data.getExpiresIn() * 20;
56+
this.qrCode = Util.getTexture(data.getQrCode(), "device_auth_"+ data.getUserCode());
5257
this.status = new TranslatableText("auth.time_left",
5358
((ticksLeft / 20) / 60) + "m" + ((ticksLeft / 20) % 60) + "s");
5459
data.setStatusConsumer(s -> {
@@ -86,6 +91,13 @@ public void render(MatrixStack graphics, int mouseX, int mouseY, float delta) {
8691
drawCenteredText(graphics, client.textRenderer, working ? status : new TranslatableText("auth.time_left",
8792
((ticksLeft / 20) / 60) + "m" + ((ticksLeft / 20) % 60) + "s"),
8893
width / 2, y + 10, -1);
94+
95+
y = height/2+30;
96+
if (height-y > 40) {
97+
int qrImageSize = height - y - 20;
98+
client.getTextureManager().bindTexture(qrCode);
99+
drawTexture(graphics, width/2 - qrImageSize/2, y, 0, 0, qrImageSize, qrImageSize, qrImageSize, qrImageSize);
100+
}
89101
}
90102

91103
@Override

1.16_combat-6/src/main/java/io/github/axolotlclient/util/Util.java

Lines changed: 22 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -31,11 +31,11 @@
3131
import com.google.common.collect.Iterables;
3232
import com.google.common.collect.Lists;
3333
import io.github.axolotlclient.AxolotlClient;
34+
import io.github.axolotlclient.AxolotlClientConfig.api.util.Graphics;
3435
import io.github.axolotlclient.AxolotlClientConfig.impl.options.GraphicsOption;
3536
import net.minecraft.client.MinecraftClient;
3637
import net.minecraft.client.texture.NativeImage;
3738
import net.minecraft.client.texture.NativeImageBackedTexture;
38-
import net.minecraft.client.util.Window;
3939
import net.minecraft.scoreboard.Scoreboard;
4040
import net.minecraft.scoreboard.ScoreboardObjective;
4141
import net.minecraft.scoreboard.ScoreboardPlayerScore;
@@ -46,7 +46,6 @@
4646
import net.minecraft.util.Formatting;
4747
import net.minecraft.util.Identifier;
4848
import net.minecraft.util.math.Vec3d;
49-
import org.lwjgl.opengl.GL11;
5049

5150
public class Util {
5251
public static Color GlColor = new Color();
@@ -72,10 +71,10 @@ public static String getGame() {
7271
if (sidebar.isEmpty())
7372
game = "";
7473
else if (MinecraftClient.getInstance().getCurrentServerEntry() != null
75-
&& MinecraftClient.getInstance().getCurrentServerEntry().address.toLowerCase()
76-
.contains(sidebar.get(0).toLowerCase())) {
74+
&& MinecraftClient.getInstance().getCurrentServerEntry().address.toLowerCase()
75+
.contains(sidebar.get(0).toLowerCase())) {
7776
if (sidebar.get(sidebar.size() - 1).toLowerCase(Locale.ROOT)
78-
.contains(MinecraftClient.getInstance().getCurrentServerEntry().address.toLowerCase(Locale.ROOT))
77+
.contains(MinecraftClient.getInstance().getCurrentServerEntry().address.toLowerCase(Locale.ROOT))
7978
|| sidebar.get(sidebar.size() - 1).contains("Playtime")) {
8079
game = "In Lobby";
8180
} else {
@@ -130,7 +129,7 @@ public static List<String> getSidebar() {
130129
if (team == null)
131130
return lines;
132131
String text = team.getPrefix().getString() + team.getSuffix().getString();
133-
if (text.trim().length() > 0)
132+
if (!text.trim().isEmpty())
134133
lines.add(text);
135134
}
136135

@@ -146,11 +145,11 @@ public static Text formatFromCodes(String formattedString) {
146145

147146
List<Formatting> modifiers = new ArrayList<>();
148147
for (String s : arr) {
149-
Formatting formatting = Formatting.byCode(s.length() > 0 ? s.charAt(0) : 0);
148+
Formatting formatting = Formatting.byCode(!s.isEmpty() ? s.charAt(0) : 0);
150149
if (formatting != null && formatting.isModifier()) {
151150
modifiers.add(formatting);
152151
}
153-
MutableText part = new LiteralText(s.length() > 0 ? s.substring(1) : "");
152+
MutableText part = new LiteralText(!s.isEmpty() ? s.substring(1) : "");
154153
if (formatting != null) {
155154
part.formatted(formatting);
156155

@@ -182,35 +181,36 @@ public static void sendChatMessage(Text msg) {
182181
MinecraftClient.getInstance().inGameHud.getChatHud().addMessage(msg);
183182
}
184183

185-
public static void applyScissor(int x, int y, int width, int height) {
186-
GL11.glEnable(GL11.GL_SCISSOR_TEST);
187-
Window window = MinecraftClient.getInstance().getWindow();
188-
double scale = window.getScaleFactor();
189-
GL11.glScissor((int) (x * scale), (int) ((window.getScaledHeight() - height - y) * scale),
190-
(int) (width * scale), (int) (height * scale));
184+
public static Identifier getTexture(GraphicsOption option) {
185+
return getTexture(option.get(), option.getName());
191186
}
192187

193-
public static void bindTexture(GraphicsOption option) {
194-
Identifier id = new Identifier("graphicsoption", option.getName().toLowerCase(Locale.ROOT));
188+
public static Identifier getTexture(Graphics graphics, String name) {
189+
Identifier id = new Identifier("axolotlclient", "graphics_" + name.toLowerCase(Locale.ROOT));
195190
try {
196191
NativeImageBackedTexture texture;
197192
if (MinecraftClient.getInstance().getTextureManager().getTexture(id) == null) {
198-
texture = new NativeImageBackedTexture(NativeImage.read(new ByteArrayInputStream(option.get().getPixelData())));
193+
texture = new NativeImageBackedTexture(NativeImage.read(new ByteArrayInputStream(graphics.getPixelData())));
199194
MinecraftClient.getInstance().getTextureManager().registerTexture(id, texture);
200195
} else {
201196
texture = (NativeImageBackedTexture) MinecraftClient.getInstance().getTextureManager().getTexture(id);
202-
for (int x = 0; x < option.get().getWidth(); x++) {
203-
for (int y = 0; y < option.get().getHeight(); y++) {
204-
texture.getImage().setPixelColor(x, y, option.get().getPixelColor(x, y));
197+
for (int x = 0; x < graphics.getWidth(); x++) {
198+
for (int y = 0; y < graphics.getHeight(); y++) {
199+
texture.getImage().setPixelColor(x, y, graphics.getPixelColor(x, y));
205200
}
206201
}
207202
}
208203

209204
texture.upload();
210-
MinecraftClient.getInstance().getTextureManager().bindTexture(id);
211205
} catch (IOException e) {
212-
AxolotlClient.LOGGER.error("Failed to bind texture of " + option.getName() + ": ", e);
206+
AxolotlClient.LOGGER.error("Failed to bind texture for " + name + ": ", e);
213207
}
208+
return id;
209+
}
210+
211+
public static void bindTexture(GraphicsOption option) {
212+
Identifier id = getTexture(option);
213+
MinecraftClient.getInstance().getTextureManager().bindTexture(id);
214214
}
215215

216216
public static double lerp(double start, double end, double percent) {

1.20/src/main/java/io/github/axolotlclient/api/StatusUpdateProviderImpl.java

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -83,7 +83,7 @@ public Request getStatus() {
8383
}
8484
}
8585
}
86-
86+
} else if (MinecraftClient.getInstance().player != null) {
8787
String gamemode = getGameMode(MinecraftClient.getInstance().player);
8888
return StatusUpdate.inGameUnknown(entry.address, "", entry.name, gamemode);
8989

@@ -98,6 +98,9 @@ private String getOrEmpty(JsonObject object, String name) {
9898

9999
private String getGameMode(PlayerEntity entity) {
100100
PlayerListEntry entry = MinecraftClient.getInstance().getNetworkHandler().getPlayerListEntry(entity.getUuid());
101+
if (entry == null) {
102+
return "";
103+
}
101104
return switch (entry.getGameMode()) {
102105
case CREATIVE -> "Creative Mode";
103106
case SURVIVAL -> "Survival Mode";

1.20/src/main/java/io/github/axolotlclient/modules/auth/Auth.java

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -123,9 +123,9 @@ protected void login(Account account) {
123123
if (account.isExpired()) {
124124
Notifications.getInstance().addStatus(Text.translatable("auth.notif.title"), Text.translatable("auth.notif.refreshing", account.getName()));
125125
}
126-
account.refresh(auth, runnable);
126+
account.refresh(auth, () -> {});
127127
} else {
128-
new Thread(runnable).start();
128+
runnable.run();
129129
}
130130
}
131131

1.20/src/main/java/io/github/axolotlclient/modules/auth/DeviceCodeDisplayScreen.java

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -25,13 +25,16 @@
2525
import java.net.URI;
2626
import java.util.List;
2727

28+
import io.github.axolotlclient.AxolotlClientConfig.api.util.Graphics;
2829
import io.github.axolotlclient.util.OSUtil;
30+
import io.github.axolotlclient.util.Util;
2931
import net.minecraft.client.MinecraftClient;
3032
import net.minecraft.client.gui.GuiGraphics;
3133
import net.minecraft.client.gui.screen.Screen;
3234
import net.minecraft.client.gui.widget.ButtonWidget;
3335
import net.minecraft.text.OrderedText;
3436
import net.minecraft.text.Text;
37+
import net.minecraft.util.Identifier;
3538

3639
public class DeviceCodeDisplayScreen extends Screen {
3740
private final Screen parent;
@@ -40,6 +43,7 @@ public class DeviceCodeDisplayScreen extends Screen {
4043
private int ticksLeft;
4144
private Text status;
4245
private boolean working;
46+
private final Identifier qrCode;
4347

4448
public DeviceCodeDisplayScreen(Screen parent, DeviceFlowData data) {
4549
super(Text.translatable("auth.add"));
@@ -48,6 +52,7 @@ public DeviceCodeDisplayScreen(Screen parent, DeviceFlowData data) {
4852
this.verificationUri = data.getVerificationUri();
4953
this.userCode = data.getUserCode();
5054
this.ticksLeft = data.getExpiresIn() * 20;
55+
this.qrCode = Util.getTexture(data.getQrCode(), "device_auth_"+ data.getUserCode());
5156
this.status = Text.translatable("auth.time_left",
5257
((ticksLeft / 20) / 60) + "m" + ((ticksLeft / 20) % 60) + "s");
5358
data.setStatusConsumer(s -> {
@@ -71,6 +76,7 @@ protected void init() {
7176

7277
@Override
7378
public void render(GuiGraphics graphics, int mouseX, int mouseY, float delta) {
79+
renderBackground(graphics);
7480
super.render(graphics, mouseX, mouseY, delta);
7581

7682
graphics.drawCenteredShadowedText(client.textRenderer, title, width / 2, 25, -1);
@@ -83,6 +89,12 @@ public void render(GuiGraphics graphics, int mouseX, int mouseY, float delta) {
8389
graphics.drawCenteredShadowedText(client.textRenderer, working ? status : Text.translatable("auth.time_left",
8490
((ticksLeft / 20) / 60) + "m" + ((ticksLeft / 20) % 60) + "s"),
8591
width / 2, y + 10, -1);
92+
93+
y = height/2+30;
94+
if (height-y > 40) {
95+
int qrImageSize = height - y - 20;
96+
graphics.drawTexture(qrCode, width/2 - qrImageSize/2, y, 0, 0, qrImageSize, qrImageSize, qrImageSize, qrImageSize);
97+
}
8698
}
8799

88100
@Override

1.20/src/main/java/io/github/axolotlclient/util/Util.java

Lines changed: 16 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -22,16 +22,15 @@
2222

2323
package io.github.axolotlclient.util;
2424

25-
import java.io.ByteArrayInputStream;
2625
import java.io.IOException;
2726
import java.util.*;
2827
import java.util.stream.Collectors;
2928

3029
import com.google.common.collect.Iterables;
3130
import com.google.common.collect.Lists;
32-
import com.mojang.blaze3d.systems.RenderSystem;
3331
import com.mojang.blaze3d.texture.NativeImage;
3432
import io.github.axolotlclient.AxolotlClient;
33+
import io.github.axolotlclient.AxolotlClientConfig.api.util.Graphics;
3534
import io.github.axolotlclient.AxolotlClientConfig.impl.options.GraphicsOption;
3635
import net.minecraft.client.MinecraftClient;
3736
import net.minecraft.client.texture.NativeImageBackedTexture;
@@ -70,10 +69,10 @@ public static String getGame() {
7069
if (sidebar.isEmpty())
7170
game = "";
7271
else if (MinecraftClient.getInstance().getCurrentServerEntry() != null
73-
&& MinecraftClient.getInstance().getCurrentServerEntry().address.toLowerCase()
74-
.contains(sidebar.get(0).toLowerCase())) {
72+
&& MinecraftClient.getInstance().getCurrentServerEntry().address.toLowerCase()
73+
.contains(sidebar.get(0).toLowerCase())) {
7574
if (sidebar.get(sidebar.size() - 1).toLowerCase(Locale.ROOT)
76-
.contains(MinecraftClient.getInstance().getCurrentServerEntry().address.toLowerCase(Locale.ROOT))
75+
.contains(MinecraftClient.getInstance().getCurrentServerEntry().address.toLowerCase(Locale.ROOT))
7776
|| sidebar.get(sidebar.size() - 1).contains("Playtime")) {
7877
game = "In Lobby";
7978
} else {
@@ -144,11 +143,11 @@ public static Text formatFromCodes(String formattedString) {
144143

145144
List<Formatting> modifiers = new ArrayList<>();
146145
for (String s : arr) {
147-
Formatting formatting = Formatting.byCode(s.length() > 0 ? s.charAt(0) : 0);
146+
Formatting formatting = Formatting.byCode(!s.isEmpty() ? s.charAt(0) : 0);
148147
if (formatting != null && formatting.isModifier()) {
149148
modifiers.add(formatting);
150149
}
151-
MutableText part = Text.literal(s.length() > 0 ? s.substring(1) : "");
150+
MutableText part = Text.literal(!s.isEmpty() ? s.substring(1) : "");
152151
if (formatting != null) {
153152
part.formatted(formatting);
154153

@@ -187,25 +186,28 @@ public static void sendChatMessage(Text msg) {
187186
}
188187

189188
public static Identifier getTexture(GraphicsOption option) {
190-
Identifier id = new Identifier("graphicsoption", option.getName().toLowerCase(Locale.ROOT));
189+
return getTexture(option.get(), option.getName());
190+
}
191+
192+
public static Identifier getTexture(Graphics graphics, String name) {
193+
Identifier id = new Identifier("axolotlclient", "graphics_" + name.toLowerCase(Locale.ROOT));
191194
try {
192195
NativeImageBackedTexture texture;
193196
if (MinecraftClient.getInstance().getTextureManager().getOrDefault(id, null) == null) {
194-
texture = new NativeImageBackedTexture(NativeImage.read(new ByteArrayInputStream(option.get().getPixelData())));
197+
texture = new NativeImageBackedTexture(NativeImage.read(graphics.getPixelData()));
195198
MinecraftClient.getInstance().getTextureManager().registerTexture(id, texture);
196199
} else {
197200
texture = (NativeImageBackedTexture) MinecraftClient.getInstance().getTextureManager().getTexture(id);
198-
for (int x = 0; x < option.get().getWidth(); x++) {
199-
for (int y = 0; y < option.get().getHeight(); y++) {
200-
texture.getImage().setPixelColor(x, y, option.get().getPixelColor(x, y));
201+
for (int x = 0; x < graphics.getWidth(); x++) {
202+
for (int y = 0; y < graphics.getHeight(); y++) {
203+
texture.getImage().setPixelColor(x, y, graphics.getPixelColor(x, y));
201204
}
202205
}
203206
}
204207

205208
texture.upload();
206-
RenderSystem.setShaderTexture(0, id);
207209
} catch (IOException e) {
208-
AxolotlClient.LOGGER.error("Failed to bind texture of " + option.getName() + ": ", e);
210+
AxolotlClient.LOGGER.error("Failed to bind texture for " + name + ": ", e);
209211
}
210212
return id;
211213
}

1.21.3/src/main/java/io/github/axolotlclient/api/FriendsSidebar.java

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -83,7 +83,7 @@ public void render(GuiGraphics graphics, int mouseX, int mouseY, float delta) {
8383
graphics.drawString(font, channel.getName(), sidebarAnimX + 75, 20, -1);
8484
if (channel.isDM()) {
8585
graphics.drawString(font, ChatFormatting.ITALIC + ((Channel.DM) channel).getReceiver().getStatus().getTitle() + ":" + ((Channel.DM) channel).getReceiver().getStatus().getDescription(),
86-
sidebarAnimX + 80, 30, 8421504);
86+
sidebarAnimX + 80, 30, 0x808080);
8787
}
8888
}
8989

@@ -92,6 +92,11 @@ public void render(GuiGraphics graphics, int mouseX, int mouseY, float delta) {
9292
animate();
9393
}
9494

95+
@Override
96+
public void renderBackground(GuiGraphics guiGraphics, int mouseX, int mouseY, float partialTick) {
97+
98+
}
99+
95100
@Override
96101
protected void init() {
97102
removeChat();

0 commit comments

Comments
 (0)