Skip to content

Commit 584f4de

Browse files
committed
fix: brushed the cobwebs off some long-forgotten TODO and FIXME commented codes
Fixes ButtonBanner, copyOpenGl command, Slayer Boss Approach Alert, Zealots killed DiscordStatus, version text location on `/sba` (again) also updates Fancy Warp island coords
1 parent f3890be commit 584f4de

File tree

14 files changed

+170
-141
lines changed

14 files changed

+170
-141
lines changed

src/main/java/com/fix3dll/skyblockaddons/SkyblockAddons.java

Lines changed: 8 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -5,20 +5,21 @@
55
import com.fix3dll.skyblockaddons.config.ConfigValuesManager.ConfigValues;
66
import com.fix3dll.skyblockaddons.config.PersistentValuesManager;
77
import com.fix3dll.skyblockaddons.config.PetCacheManager;
8-
import com.fix3dll.skyblockaddons.core.feature.Feature;
98
import com.fix3dll.skyblockaddons.core.SkyblockKeyBinding;
109
import com.fix3dll.skyblockaddons.core.SkyblockRarity;
10+
import com.fix3dll.skyblockaddons.core.feature.Feature;
1111
import com.fix3dll.skyblockaddons.core.feature.FeatureData;
12+
import com.fix3dll.skyblockaddons.core.scheduler.Scheduler;
13+
import com.fix3dll.skyblockaddons.core.updater.Updater;
1214
import com.fix3dll.skyblockaddons.events.ClientEvents;
1315
import com.fix3dll.skyblockaddons.features.SkillXpManager;
1416
import com.fix3dll.skyblockaddons.features.discordrpc.DiscordRPCManager;
1517
import com.fix3dll.skyblockaddons.features.dungeons.DungeonManager;
18+
import com.fix3dll.skyblockaddons.gui.buttons.ButtonBanner;
1619
import com.fix3dll.skyblockaddons.gui.screens.IslandWarpGui;
1720
import com.fix3dll.skyblockaddons.listeners.NetworkListener;
1821
import com.fix3dll.skyblockaddons.listeners.PlayerListener;
1922
import com.fix3dll.skyblockaddons.listeners.RenderListener;
20-
import com.fix3dll.skyblockaddons.core.updater.Updater;
21-
import com.fix3dll.skyblockaddons.core.scheduler.Scheduler;
2223
import com.fix3dll.skyblockaddons.listeners.ScreenListener;
2324
import com.fix3dll.skyblockaddons.utils.DevUtils;
2425
import com.fix3dll.skyblockaddons.utils.InventoryUtils;
@@ -44,7 +45,6 @@
4445
import lombok.Getter;
4546
import lombok.Setter;
4647
import net.fabricmc.api.ClientModInitializer;
47-
4848
import net.fabricmc.loader.api.FabricLoader;
4949
import net.fabricmc.loader.api.SemanticVersion;
5050
import net.fabricmc.loader.api.metadata.ModMetadata;
@@ -186,6 +186,8 @@ public void onInitializeClient() {
186186
SkyblockAddonsCommand.initialize();
187187

188188
ClientEvents.AFTER_INITIALIZATION.register(client -> {
189+
runAsync(ButtonBanner.REGISTER_BANNER); // Load banner image
190+
189191
if (Feature.DEVELOPER_MODE.isDisabled()) {
190192
SkyblockKeyBinding.DEVELOPER_COPY_NBT.deRegister();
191193
}
@@ -200,8 +202,8 @@ public void onInitializeClient() {
200202
DevUtils.resetEntityNamesToDefault(); // initialize class
201203
NetworkListener.setupModAPI();
202204

203-
immediatelyFastLoaded = FabricLoader.getInstance().isModLoaded("immediatelyfast");
204-
entityCullingLoaded = FabricLoader.getInstance().isModLoaded("entityculling");
205+
immediatelyFastLoaded = utils.isModLoaded("immediatelyfast");
206+
entityCullingLoaded = utils.isModLoaded("entityculling");
205207
fullyInitialized = true;
206208
TextUtils.setInstanceLoaded(true);
207209
});

src/main/java/com/fix3dll/skyblockaddons/commands/SkyblockAddonsCommand.java

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -335,6 +335,12 @@ public static LiteralArgumentBuilder<FabricClientCommandSource> buildCommands()
335335
return 1;
336336
}));
337337

338+
// COPY_OPEN_GL
339+
builder.then(literal("copyOpenGl").requires(rq -> Feature.DEVELOPER_MODE.isEnabled()).executes(ctx -> {
340+
DevUtils.copyOpenGLLogs();
341+
return 1;
342+
}));
343+
338344
// PD
339345
builder.then(literal("pd").requires(rq -> Feature.DEVELOPER_MODE.isEnabled()).executes(ctx -> {
340346
Utils.sendMessage(ColorCode.BOLD + "Death Counts: ");

src/main/java/com/fix3dll/skyblockaddons/features/discordrpc/DiscordStatus.java

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -92,9 +92,9 @@ public enum DiscordStatus implements ButtonCycling.SelectItem, RegistrableEnum {
9292

9393
ZEALOTS("discordStatus.titleZealots", "discordStatus.descriptionZealots",
9494
() -> String.format(
95-
"%d Zealots killed",
96-
0)//SkyblockAddons.getInstance().getPersistentValuesManager().getPersistentValues().getKills()) TODO
97-
),
95+
"%d Zealots killed"
96+
, SkyblockAddons.getInstance().getPersistentValuesManager().getPersistentValues().getKills())
97+
),
9898

9999
ITEM("discordStatus.titleItem", "discordStatus.descriptionItem",
100100
() -> {

src/main/java/com/fix3dll/skyblockaddons/gui/buttons/ButtonBanner.java

Lines changed: 71 additions & 46 deletions
Original file line numberDiff line numberDiff line change
@@ -4,9 +4,11 @@
44
import com.fix3dll.skyblockaddons.utils.Utils;
55
import com.mojang.blaze3d.platform.NativeImage;
66
import net.minecraft.Util;
7+
import net.minecraft.client.Minecraft;
78
import net.minecraft.client.gui.GuiGraphics;
89
import net.minecraft.client.input.MouseButtonEvent;
910
import net.minecraft.client.renderer.RenderPipelines;
11+
import net.minecraft.client.renderer.texture.DynamicTexture;
1012
import net.minecraft.network.chat.Component;
1113
import net.minecraft.resources.ResourceLocation;
1214
import net.minecraft.util.ARGB;
@@ -18,91 +20,114 @@
1820
import java.net.URI;
1921
import java.net.URISyntaxException;
2022
import java.net.URL;
23+
import java.util.UUID;
2124

2225
public class ButtonBanner extends SkyblockAddonsButton {
2326

2427
private static final Logger LOGGER = SkyblockAddons.getLogger();
25-
private static final int WIDTH = 130;
28+
29+
public static final int WIDTH = 130;
30+
public static final int HEIGHT = 95;
2631

2732
private static ResourceLocation banner;
2833
private static NativeImage bannerImage;
2934

30-
private static boolean grabbedBanner;
35+
public static boolean bannerRegistered;
36+
37+
public static Runnable REGISTER_BANNER = () -> {
38+
String bannerImageUrl = main.getOnlineData().getBannerImageURL();
39+
if (bannerImageUrl == null) {
40+
bannerRegistered = false;
41+
return;
42+
}
43+
44+
HttpURLConnection connection = null;
45+
try {
46+
URL url = new URI(bannerImageUrl).toURL();
47+
connection = (HttpURLConnection)url.openConnection();
48+
connection.setConnectTimeout(5000);
49+
connection.setReadTimeout(5000);
50+
connection.addRequestProperty("User-Agent", Utils.USER_AGENT);
51+
52+
banner = SkyblockAddons.resourceLocation("dynamic/" + UUID.randomUUID());
53+
bannerImage = NativeImage.read(connection.getInputStream());
54+
55+
connection.disconnect();
56+
57+
MC.execute(() -> {
58+
DynamicTexture dynamicTexture = new DynamicTexture(() -> banner.toString(), bannerImage);
59+
Minecraft.getInstance().getTextureManager().register(banner, dynamicTexture);
60+
bannerRegistered = true;
61+
});
62+
} catch (IOException ex) {
63+
LOGGER.warn("Couldn't grab main menu banner image from URL, falling back to local banner.", ex);
64+
} catch (URISyntaxException e) {
65+
LOGGER.error("Wrong banner image URL!", e);
66+
} finally {
67+
if (connection != null) connection.disconnect();
68+
}
69+
};
3170

3271
/**
3372
* Create a button for toggling a feature on or off. This includes all the Features that have a proper ID.
3473
*/
3574
public ButtonBanner(double x, double y) {
36-
super((int) x, (int) y, Component.empty());
75+
super((int) x, (int) y, WIDTH, HEIGHT, Component.empty());
3776

38-
if (!grabbedBanner) {
39-
grabbedBanner = true;
77+
if (!bannerRegistered) {
4078
bannerImage = null;
4179
banner = null;
4280

43-
SkyblockAddons.runAsync(() -> {
44-
try {
45-
URL url = new URI(main.getOnlineData().getBannerImageURL()).toURL();
46-
HttpURLConnection connection = (HttpURLConnection)url.openConnection();
47-
connection.setReadTimeout(5000);
48-
connection.addRequestProperty("User-Agent", Utils.USER_AGENT);
49-
50-
bannerImage = NativeImage.read(connection.getInputStream());
51-
52-
connection.disconnect();
53-
54-
this.width = bannerImage.getWidth();
55-
this.height = bannerImage.getHeight();
56-
} catch (IOException ex) {
57-
LOGGER.warn("Couldn't grab main menu banner image from URL, falling back to local banner.", ex);
58-
} catch (URISyntaxException e) {
59-
LOGGER.error("Wrong banner image URL!", e);
60-
}
61-
});
81+
SkyblockAddons.runAsync(REGISTER_BANNER);
6282
}
6383

64-
setX(getX() - WIDTH / 2);
65-
6684
if (bannerImage != null) {
67-
this.width = bannerImage.getWidth();
68-
this.height = bannerImage.getHeight();
85+
int imageWidth = bannerImage.getWidth();
86+
int imageHeight = bannerImage.getHeight();
87+
this.scale = (float) WIDTH / imageWidth; // max width
88+
float scaledImageHeight = imageHeight * scale;
89+
90+
if (scaledImageHeight < HEIGHT) {
91+
setY(getY() + (HEIGHT / 2 - (int) (scaledImageHeight / 2.0F)));
92+
}
6993
}
7094
}
7195

7296
@Override
7397
public void renderWidget(GuiGraphics graphics, int mouseX, int mouseY, float partialTick) {
74-
// This means it was just loaded from the URL above.
75-
if (bannerImage != null && banner == null) {
76-
// banner = MC.getTextureManager().registerDynamicTexture("banner", new NativeImageBackedTexture(bannerImage)); FIXME
77-
}
98+
if (bannerRegistered) { // Could have not been loaded yet.
99+
int imageWidth = bannerImage.getWidth();
100+
int imageHeight = bannerImage.getHeight();
78101

79-
if (banner != null) { // Could have not been loaded yet.
80102
float alphaMultiplier = calculateAlphaMultiplier();
103+
this.scale = (float) WIDTH / imageWidth; // max width
104+
this.isHovered = isMouseOver(mouseX, mouseY);
81105
int color = ARGB.white(alphaMultiplier * (this.isHovered ? 1F : 0.8F));
82-
this.scale = (float) WIDTH / bannerImage.getWidth(); // max width
83-
this.isHovered = mouseX >= getX() && mouseX < getX() + WIDTH
84-
&& mouseY >= getY() && mouseY < getY() + bannerImage.getHeight() * scale;
85106

86107
Matrix3x2fStack poseStack = graphics.pose();
87108
poseStack.pushMatrix();
88-
poseStack.scale(scale, scale);
109+
poseStack.scale(scale);
89110
int x = Math.round(getX() / scale);
90111
int y = Math.round(getY() / scale);
91-
graphics.blit(RenderPipelines.GUI_TEXTURED, banner, x, y, 0, 0, width, height, width, height, color);
92-
// drawModalRectWithCustomSizedTexture(Math.round(xPosition / scale), Math.round(xPosition / scale), 0, 0, width, height, width, height);
112+
graphics.blit(RenderPipelines.GUI_TEXTURED, banner, x, y, 0, 0, imageWidth, imageHeight, imageWidth, imageHeight, color);
93113
poseStack.popMatrix();
94114
}
95115
}
96116

117+
@Override
118+
public boolean isMouseOver(double mouseX, double mouseY) {
119+
return mouseX >= getX() && mouseX < getX() + WIDTH &&
120+
mouseY >= getY() && mouseY < getY() + bannerImage.getHeight() * scale;
121+
}
122+
97123
@Override
98124
public void onClick(MouseButtonEvent event, boolean isDoubleClick) {
99-
if (this.isHovered) {
100-
String link = main.getOnlineData().getBannerLink();
101-
if (link != null && !link.isEmpty()) {
102-
try {
103-
Util.getPlatform().openUri(link);
104-
} catch (Exception ignored) {}
105-
}
125+
String link = main.getOnlineData().getBannerLink();
126+
if (link != null && !link.isBlank()) {
127+
try {
128+
Util.getPlatform().openUri(link);
129+
} catch (Exception ignored) {}
106130
}
107131
}
132+
108133
}

src/main/java/com/fix3dll/skyblockaddons/gui/screens/ColorSelectionGui.java

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -142,6 +142,8 @@ public ColorSelectionGui(FeatureSetting setting, EnumUtils.GUIType lastGUI, Enum
142142

143143
@Override
144144
public void init() {
145+
super.init();
146+
145147
if (COLOR_PICKER_IMAGE == null) {
146148
COLOR_PICKER_IMAGE = loadColorPicker();
147149
}
@@ -201,7 +203,7 @@ public void init() {
201203
public void render(GuiGraphics graphics, int mouseX, int mouseY, float partialTick) {
202204
// Draw background and default text.
203205
drawGradientBackground(graphics, 128, 192);
204-
drawDefaultTitleText(graphics, this, 255);
206+
drawDefaultTitleText(graphics, mouseX, mouseY, partialTick, this, 255);
205207

206208
int defaultBlue = ColorUtils.getDefaultBlue(1);
207209

@@ -285,6 +287,7 @@ public boolean mouseClicked(MouseButtonEvent event, boolean isDoubleClick) {
285287
}
286288

287289
if (chromaCheckbox != null) chromaCheckbox.onMouseClick(event, isDoubleClick);
290+
if (buttonBanner != null) buttonBanner.mouseClicked(event, isDoubleClick);
288291

289292
Optional<GuiEventListener> optional = this.getChildAt(event.x(), event.y());
290293
if (optional.isEmpty()) {

src/main/java/com/fix3dll/skyblockaddons/gui/screens/IslandWarpGui.java

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -50,6 +50,8 @@ public IslandWarpGui() {
5050

5151
@Override
5252
public void init() {
53+
super.init();
54+
5355
for (Island island : Island.values()) {
5456
if (island == Island.JERRYS_WORKSHOP
5557
&& main.getUtils().getCurrentDate().getMonth() != SkyblockDate.SkyblockMonth.LATE_WINTER
@@ -236,21 +238,21 @@ public static Pair<Integer, Integer> getScaledMouseLocation(int mouseX, int mous
236238
@Getter
237239
public enum Island {
238240
THE_END("The End", 240, 30),
239-
CRIMSON_ISLE("Crimson Isle", 835, 25),
241+
CRIMSON_ISLE("Crimson Isle", 835, 45),
240242
THE_PARK("The Park", 80, 440),
241243
SPIDERS_DEN("Spider's Den", 500, 470),
242244
DEEP_CAVERNS("Deep Caverns", 1400, 250),
243245
GOLD_MINE("Gold Mine", 1130, 525),
244246
MUSHROOM_DESERT("Mushroom Desert", 1470, 525),
245-
THE_BARN("The Barn", 1125, 850),
247+
THE_BARN("The Barn", 1100, 860),
246248
HUB("Hub", 300, 820),
247249
PRIVATE_ISLAND("Private Island", 275, 1172),
248250
THE_GARDEN("The Garden", 50, 1050),
249251
DUNGEON_HUB("Dungeon Hub", 1500, 1100),
250252
JERRYS_WORKSHOP("Jerry's Workshop", 1280, 1150),
251253
THE_RIFT("The Rift", 1720, 1050),
252254
BACKWATER_BAYOU("Backwater Bayou", 960, 1275),
253-
GALATEA("Galatea", -250, 220);
255+
GALATEA("Galatea", -200, 240);
254256

255257
private final String label;
256258
private final int x;
@@ -266,8 +268,7 @@ public enum Island {
266268
this.label = label;
267269
this.x = x;
268270
this.y = y;
269-
this.resourceLocation = ResourceLocation.fromNamespaceAndPath(
270-
"skyblockaddons",
271+
this.resourceLocation = SkyblockAddons.resourceLocation(
271272
"islands/" + this.name().toLowerCase(Locale.US).replace("_", "") + ".png"
272273
);
273274

src/main/java/com/fix3dll/skyblockaddons/gui/screens/LocationEditGui.java

Lines changed: 10 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -74,6 +74,8 @@ public LocationEditGui(int lastPage, EnumUtils.GuiTab lastTab) {
7474

7575
@Override
7676
public void init() {
77+
super.init();
78+
7779
// Add all gui elements that can be edited to the gui.
7880
for (Feature feature : Feature.getGuiFeatures()) {
7981
// Don't display features that have been disabled
@@ -489,7 +491,6 @@ public float getCoordinate(ButtonLocation button) {
489491
TOP.getCoordinate(button) + (BOTTOM.getCoordinate(button) - TOP.getCoordinate(button)) / 2F;
490492
case VERTICAL_MIDDLE ->
491493
LEFT.getCoordinate(button) + (RIGHT.getCoordinate(button) - LEFT.getCoordinate(button)) / 2F;
492-
default -> 0;
493494
};
494495
}
495496
}
@@ -762,13 +763,13 @@ private void drawFeatureCoords(GuiGraphics graphics, ButtonLocation lastHoveredB
762763
* If button is pressed, update the currently dragged button.
763764
* Otherwise, they clicked the reset button, so reset the coordinates.
764765
*/
765-
private void actionPerformed(GuiEventListener eventListener, double mouseX, double mouseY, int button) {
766+
private void actionPerformed(GuiEventListener eventListener, MouseButtonEvent event) {
766767
switch (eventListener) {
767768
case ButtonLocation buttonLocation -> {
768769
draggedFeature = buttonLocation.getFeature();
769770
if (draggedFeature != null) {
770-
xOffset = (float) mouseX - draggedFeature.getActualX();
771-
yOffset = (float) mouseY - draggedFeature.getActualY();
771+
xOffset = (float) event.x() - draggedFeature.getActualX();
772+
yOffset = (float) event.y() - draggedFeature.getActualY();
772773
}
773774
}
774775
case ButtonSolid buttonSolid -> {
@@ -794,11 +795,11 @@ private void actionPerformed(GuiEventListener eventListener, double mouseX, doub
794795

795796
if (editMode == EditMode.RESCALE_FEATURES) {
796797
float scale = draggedFeature.getGuiScale();
797-
xOffset = ((float) mouseX - buttonResize.resizeX * scale) / scale;
798-
yOffset = ((float) mouseY - buttonResize.resizeY * scale) / scale;
798+
xOffset = ((float) event.x() - buttonResize.resizeX * scale) / scale;
799+
yOffset = ((float) event.y() - buttonResize.resizeY * scale) / scale;
799800
} else {
800-
xOffset = (float) mouseX;
801-
yOffset = (float) mouseY;
801+
xOffset = (float) event.x();
802+
yOffset = (float) event.y();
802803
}
803804

804805
resizingCorner = buttonResize.getCorner();
@@ -842,7 +843,7 @@ public boolean mouseClicked(MouseButtonEvent event, boolean isDoubleClick) {
842843
if (event.button() == 0) {
843844
this.setDragging(true);
844845
}
845-
actionPerformed(guiEventListener, event.x(), event.y(), event.button());
846+
actionPerformed(guiEventListener, event);
846847
}
847848

848849
return true;

src/main/java/com/fix3dll/skyblockaddons/gui/screens/SettingsGui.java

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -66,6 +66,8 @@ public SettingsGui(Feature feature, int page, int lastPage, EnumUtils.GuiTab las
6666
@SuppressWarnings("IntegerDivisionInFloatingPointContext")
6767
@Override
6868
public void init() {
69+
super.init();
70+
6971
scrollValue = 0;
7072
maxScrollValue = MC.getWindow().getScreenHeight() / 2;
7173
row = 1;
@@ -141,7 +143,7 @@ public void render(GuiGraphics graphics, int mouseX, int mouseY, float partialTi
141143

142144
if (alpha < 4) alpha = 4; // Text under 4 alpha appear 100% transparent for some reason o.O
143145
int defaultBlue = ColorUtils.getDefaultBlue(alpha * 2);
144-
drawDefaultTitleText(graphics, this, alpha * 2);
146+
drawDefaultTitleText(graphics, mouseX, mouseY, partialTick, this, alpha * 2);
145147

146148
boolean scissorEnabled = false;
147149
if (feature != Feature.LANGUAGE) {

0 commit comments

Comments
 (0)