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

Commit 6ed63c2

Browse files
committed
fix API-related buttons not appearing correctly on the TitleScreen
1 parent be22595 commit 6ed63c2

File tree

7 files changed

+77
-36
lines changed

7 files changed

+77
-36
lines changed

1.16_combat-6/src/main/java/io/github/axolotlclient/mixin/TitleScreenMixin.java

Lines changed: 13 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -78,12 +78,19 @@ protected TitleScreenMixin() {
7878
buttons.add(addButton(new AuthWidget(10, leftButtonY)));
7979
leftButtonY += 25;
8080
}
81-
if (APIOptions.getInstance().addShortcutButtons.get() && API.getInstance().isAuthenticated()) {
82-
buttons.add(addButton(new ButtonWidget(10, leftButtonY, 50, 20, new TranslatableText("api.friends"),
83-
w -> client.openScreen(new FriendsScreen(this)))));
84-
leftButtonY += 25;
85-
buttons.add(addButton(new ButtonWidget(10, leftButtonY, 50, 20, new TranslatableText("api.chats"),
86-
w -> client.openScreen(new ChatListScreen(this)))));
81+
if (APIOptions.getInstance().addShortcutButtons.get()) {
82+
int shortcutButtonY = leftButtonY;
83+
Runnable addApiButtons = () -> {
84+
buttons.add(addButton(new ButtonWidget(10, shortcutButtonY, 50, 20, new TranslatableText("api.friends"),
85+
w -> client.openScreen(new FriendsScreen(this)))));
86+
buttons.add(addButton(new ButtonWidget(10, shortcutButtonY+25, 50, 20, new TranslatableText("api.chats"),
87+
w -> client.openScreen(new ChatListScreen(this)))));
88+
};
89+
if (API.getInstance().isAuthenticated()) {
90+
addApiButtons.run();
91+
} else {
92+
API.addStartupListener(addApiButtons, API.ListenerType.ONCE);
93+
}
8794
}
8895
GlobalDataRequest.get().thenAccept(data -> {
8996
int buttonY = 10;

1.20/src/main/java/io/github/axolotlclient/mixin/TitleScreenMixin.java

Lines changed: 13 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -87,12 +87,19 @@ protected TitleScreenMixin() {
8787
buttons.add(addDrawableChild(new AuthWidget(10, leftButtonY)));
8888
leftButtonY += 25;
8989
}
90-
if (APIOptions.getInstance().addShortcutButtons.get() && API.getInstance().isAuthenticated()) {
91-
buttons.add(addDrawableChild(ButtonWidget.builder(Text.translatable("api.friends"),
92-
w -> client.setScreen(new FriendsScreen(this))).positionAndSize(10, leftButtonY, 50, 20).build()));
93-
leftButtonY += 25;
94-
buttons.add(addDrawableChild(ButtonWidget.builder(Text.translatable("api.chats"),
95-
w -> client.setScreen(new ChatListScreen(this))).positionAndSize(10, leftButtonY, 50, 20).build()));
90+
if (APIOptions.getInstance().addShortcutButtons.get()) {
91+
int shortcutButtonY = leftButtonY;
92+
Runnable addApiButtons = () -> {
93+
buttons.add(addDrawableChild(ButtonWidget.builder(Text.translatable("api.friends"),
94+
w -> client.setScreen(new FriendsScreen(this))).positionAndSize(10, shortcutButtonY, 50, 20).build()));
95+
buttons.add(addDrawableChild(ButtonWidget.builder(Text.translatable("api.chats"),
96+
w -> client.setScreen(new ChatListScreen(this))).positionAndSize(10, shortcutButtonY+25, 50, 20).build()));
97+
};
98+
if (API.getInstance().isAuthenticated()) {
99+
addApiButtons.run();
100+
} else {
101+
API.addStartupListener(addApiButtons, API.ListenerType.ONCE);
102+
}
96103
}
97104
GlobalDataRequest.get().thenAccept(data -> {
98105
int buttonY = 10;

1.21.4/src/main/java/io/github/axolotlclient/mixin/TitleScreenMixin.java

Lines changed: 13 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -90,12 +90,19 @@ protected TitleScreenMixin() {
9090
buttons.add(button);
9191
leftButtonY += button.getHeight() + 5;
9292
}
93-
if (APIOptions.getInstance().addShortcutButtons.get() && API.getInstance().isAuthenticated()) {
94-
buttons.add(addRenderableWidget(Button.builder(Component.translatable("api.friends"),
95-
w -> minecraft.setScreen(new FriendsScreen(this))).bounds(10, leftButtonY, 50, 20).build()));
96-
leftButtonY += 25;
97-
buttons.add(addRenderableWidget(Button.builder(Component.translatable("api.chats"),
98-
w -> minecraft.setScreen(new ChatListScreen(this))).bounds(10, leftButtonY, 50, 20).build()));
93+
if (APIOptions.getInstance().addShortcutButtons.get()) {
94+
int shortcutButtonY = leftButtonY;
95+
Runnable addApiButtons = () -> {
96+
buttons.add(addRenderableWidget(Button.builder(Component.translatable("api.friends"),
97+
w -> minecraft.setScreen(new FriendsScreen(this))).bounds(10, shortcutButtonY, 50, 20).build()));
98+
buttons.add(addRenderableWidget(Button.builder(Component.translatable("api.chats"),
99+
w -> minecraft.setScreen(new ChatListScreen(this))).bounds(10, shortcutButtonY+25, 50, 20).build()));
100+
};
101+
if (API.getInstance().isAuthenticated()) {
102+
addApiButtons.run();
103+
} else {
104+
API.addStartupListener(addApiButtons, API.ListenerType.ONCE);
105+
}
99106
}
100107
GlobalDataRequest.get().thenAccept(data -> {
101108
int buttonY = 10;

1.21/src/main/java/io/github/axolotlclient/mixin/TitleScreenMixin.java

Lines changed: 13 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -87,12 +87,19 @@ protected TitleScreenMixin() {
8787
buttons.add(addDrawableSelectableElement(new AuthWidget(10, leftButtonY)));
8888
leftButtonY += 25;
8989
}
90-
if (APIOptions.getInstance().addShortcutButtons.get() && API.getInstance().isAuthenticated()) {
91-
buttons.add(addDrawableSelectableElement(ButtonWidget.builder(Text.translatable("api.friends"),
92-
w -> client.setScreen(new FriendsScreen(this))).positionAndSize(10, leftButtonY, 50, 20).build()));
93-
leftButtonY += 25;
94-
buttons.add(addDrawableSelectableElement(ButtonWidget.builder(Text.translatable("api.chats"),
95-
w -> client.setScreen(new ChatListScreen(this))).positionAndSize(10, leftButtonY, 50, 20).build()));
90+
if (APIOptions.getInstance().addShortcutButtons.get()) {
91+
int shortcutButtonY = leftButtonY;
92+
Runnable addApiButtons = () -> {
93+
buttons.add(addDrawableSelectableElement(ButtonWidget.builder(Text.translatable("api.friends"),
94+
w -> client.setScreen(new FriendsScreen(this))).positionAndSize(10, shortcutButtonY, 50, 20).build()));
95+
buttons.add(addDrawableSelectableElement(ButtonWidget.builder(Text.translatable("api.chats"),
96+
w -> client.setScreen(new ChatListScreen(this))).positionAndSize(10, shortcutButtonY+25, 50, 20).build()));
97+
};
98+
if (API.getInstance().isAuthenticated()) {
99+
addApiButtons.run();
100+
} else {
101+
API.addStartupListener(addApiButtons, API.ListenerType.ONCE);
102+
}
96103
}
97104
GlobalDataRequest.get().thenAccept(data -> {
98105
int buttonY = 10;

1.8.9/src/main/java/io/github/axolotlclient/mixin/TitleScreenMixin.java

Lines changed: 11 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -76,10 +76,17 @@ public abstract class TitleScreenMixin extends Screen {
7676
buttons.add(new AuthWidget(10, leftButtonY));
7777
leftButtonY += 25;
7878
}
79-
if (APIOptions.getInstance().addShortcutButtons.get() && API.getInstance().isAuthenticated()) {
80-
buttons.add(new ButtonWidget(142, 10, leftButtonY, 50, 20, I18n.translate("api.friends")));
81-
leftButtonY += 25;
82-
buttons.add(new ButtonWidget(42, 10, leftButtonY, 50, 20, I18n.translate("api.chats")));
79+
if (APIOptions.getInstance().addShortcutButtons.get()) {
80+
int y = leftButtonY;
81+
Runnable addApiButtons = () -> {
82+
buttons.add(new ButtonWidget(142, 10, y, 50, 20, I18n.translate("api.friends")));
83+
buttons.add(new ButtonWidget(42, 10, y + 25, 50, 20, I18n.translate("api.chats")));
84+
};
85+
if (API.getInstance().isAuthenticated()) {
86+
addApiButtons.run();
87+
} else {
88+
API.addStartupListener(addApiButtons, API.ListenerType.ONCE);
89+
}
8390
}
8491
GlobalDataRequest.get().thenAccept(data -> {
8592
int buttonY = 10;

1.8.9/src/main/java/io/github/axolotlclient/modules/hud/gui/hud/ChatHud.java

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -124,7 +124,8 @@ public void render(float delta) {
124124
}
125125

126126
++j;
127-
int opacity = (int) (Math.max(bgColor.get().getAlpha(), textColor.get().getAlpha()) * d);
127+
int alpha = Math.max(bgColor.get().getAlpha(), textColor.get().getAlpha());
128+
int opacity = isChatFocused() ? alpha : (int) (alpha * d);
128129
if (opacity > 3) {
129130
int y = pos.y + getHeight() - (m * (9 + lineSpacing.get()));
130131
if (background.get()) {

common/src/main/java/io/github/axolotlclient/api/API.java

Lines changed: 12 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -37,10 +37,7 @@
3737
import io.github.axolotlclient.api.requests.AccountSettingsRequest;
3838
import io.github.axolotlclient.api.requests.GlobalDataRequest;
3939
import io.github.axolotlclient.api.types.*;
40-
import io.github.axolotlclient.api.util.MojangAuth;
41-
import io.github.axolotlclient.api.util.SocketMessageHandler;
42-
import io.github.axolotlclient.api.util.StatusUpdateProvider;
43-
import io.github.axolotlclient.api.util.TimestampParser;
40+
import io.github.axolotlclient.api.util.*;
4441
import io.github.axolotlclient.modules.auth.Account;
4542
import io.github.axolotlclient.util.GsonHelper;
4643
import io.github.axolotlclient.util.Logger;
@@ -75,7 +72,7 @@ public class API {
7572
private AccountSettings settings;
7673
private HttpClient client;
7774
private CompletableFuture<?> restartingFuture;
78-
private static final List<Runnable> afterStartupListeners = new ArrayList<>();
75+
private static final List<BiContainer<Runnable, ListenerType>> afterStartupListeners = new ArrayList<>();
7976

8077
public API(Logger logger, TranslationProvider translationProvider,
8178
StatusUpdateProvider statusUpdateProvider, Options apiOptions) {
@@ -98,14 +95,22 @@ public API(Logger logger, TranslationProvider translationProvider,
9895
}
9996

10097
public static void addStartupListener(Runnable listener) {
101-
afterStartupListeners.add(listener);
98+
afterStartupListeners.add(BiContainer.of(listener, ListenerType.REPEATING));
10299
}
103100

101+
public static void addStartupListener(Runnable listener, ListenerType type) {
102+
afterStartupListeners.add(BiContainer.of(listener, type));
103+
}
104+
105+
public enum ListenerType {
106+
ONCE, REPEATING
107+
}
104108

105109
public void onOpen(WebSocket channel) {
106110
this.socket = channel;
107111
logger.debug("API connected!");
108-
afterStartupListeners.forEach(Runnable::run);
112+
afterStartupListeners.forEach(p -> p.getLeft().run());
113+
afterStartupListeners.removeIf(p -> p.getRight() == ListenerType.ONCE);
109114
}
110115

111116
private void authenticate() {

0 commit comments

Comments
 (0)