diff options
Diffstat (limited to 'src/main/java/me')
-rw-r--r-- | src/main/java/me/xmrvizzy/skyblocker/skyblock/BackpackPreview.java | 32 | ||||
-rw-r--r-- | src/main/java/me/xmrvizzy/skyblocker/utils/Utils.java | 42 |
2 files changed, 35 insertions, 39 deletions
diff --git a/src/main/java/me/xmrvizzy/skyblocker/skyblock/BackpackPreview.java b/src/main/java/me/xmrvizzy/skyblocker/skyblock/BackpackPreview.java index 767d3dd1..f4615b52 100644 --- a/src/main/java/me/xmrvizzy/skyblocker/skyblock/BackpackPreview.java +++ b/src/main/java/me/xmrvizzy/skyblocker/skyblock/BackpackPreview.java @@ -10,26 +10,25 @@ import net.minecraft.client.font.TextRenderer; import net.minecraft.client.gui.DrawContext; import net.minecraft.client.gui.screen.Screen; import net.minecraft.client.gui.screen.ingame.HandledScreen; -import net.minecraft.client.network.PlayerListEntry; import net.minecraft.client.util.math.MatrixStack; import net.minecraft.entity.player.PlayerEntity; import net.minecraft.inventory.Inventory; import net.minecraft.item.ItemStack; import net.minecraft.nbt.*; import net.minecraft.util.Identifier; +import org.slf4j.Logger; +import org.slf4j.LoggerFactory; import java.io.File; import java.nio.file.Path; import java.util.ArrayList; -import java.util.Collection; import java.util.List; import java.util.regex.Matcher; import java.util.regex.Pattern; public class BackpackPreview { + private static final Logger LOGGER = LoggerFactory.getLogger(BackpackPreview.class); private static final Identifier TEXTURE = new Identifier(SkyblockerMod.NAMESPACE, "textures/gui/inventory_background.png"); - private static final BackpackPreview instance = new BackpackPreview(); - private static final Pattern PROFILE_PATTERN = Pattern.compile("Profile: ([a-zA-Z]+)"); private static final Pattern ECHEST_PATTERN = Pattern.compile("Ender Chest.*\\((\\d+)/\\d+\\)"); private static final Pattern BACKPACK_PATTERN = Pattern.compile("Backpack.*\\(Slot #(\\d+)\\)"); private static final int STORAGE_SIZE = 27; @@ -55,8 +54,8 @@ public class BackpackPreview { saveStorage(); // update save dir based on uuid and sb profile String uuid = MinecraftClient.getInstance().getSession().getUuid().replaceAll("-", ""); - String profile = getSkyblockProfile(); - if (profile != null) { + String profile = Utils.getProfile(); + if (profile != null && !profile.isEmpty()) { save_dir = FabricLoader.getInstance().getConfigDir().resolve("skyblocker/backpack-preview/" + uuid + "/" + profile); save_dir.toFile().mkdirs(); if (loaded.equals(uuid + "/" + profile)) { @@ -86,7 +85,7 @@ public class BackpackPreview { NbtCompound root = NbtIo.read(file); storage[index] = new DummyInventory(root); } catch (Exception e) { - e.printStackTrace(); + LOGGER.error("Failed to load backpack preview file: " + file.getName(), e); } } } @@ -118,7 +117,7 @@ public class BackpackPreview { NbtIo.write(root, save_dir.resolve(index + ".nbt").toFile()); dirty[index] = false; } catch (Exception e) { - e.printStackTrace(); + LOGGER.error("Failed to save backpack preview file: " + index + ".nbt", e); } } } @@ -143,14 +142,16 @@ public class BackpackPreview { int rows = (storage[index].size() - 9) / 9; Screen screen = MinecraftClient.getInstance().currentScreen; + if (screen == null) return false; int x = mouseX + 184 >= screen.width ? mouseX - 188 : mouseX + 8; int y = Math.max(0, mouseY - 16); RenderSystem.disableDepthTest(); RenderSystem.setShaderTexture(0, TEXTURE); context.drawTexture(TEXTURE, x, y, 0, 0, 176, 7); - for (int i = 0; i < rows; ++i) + for (int i = 0; i < rows; ++i) { context.drawTexture(TEXTURE, x, y + i * 18 + 7, 0, 7, 176, 18); + } context.drawTexture(TEXTURE, x, y + rows * 18 + 7, 0, 25, 176, 7); RenderSystem.enableDepthTest(); @@ -176,19 +177,6 @@ public class BackpackPreview { if (backpack.find()) return Integer.parseInt(backpack.group(1)) + 8; return -1; } - - private static String getSkyblockProfile() { - Collection<PlayerListEntry> list = MinecraftClient.getInstance().getNetworkHandler().getPlayerList(); - for (PlayerListEntry entry : list) { - if (entry.getDisplayName() != null) { - Matcher matcher = PROFILE_PATTERN.matcher(entry.getDisplayName().getString()); - if (matcher.find()) { - return matcher.group(1); - } - } - } - return null; - } } class DummyInventory implements Inventory { diff --git a/src/main/java/me/xmrvizzy/skyblocker/utils/Utils.java b/src/main/java/me/xmrvizzy/skyblocker/utils/Utils.java index 69279936..1e8e7ffa 100644 --- a/src/main/java/me/xmrvizzy/skyblocker/utils/Utils.java +++ b/src/main/java/me/xmrvizzy/skyblocker/utils/Utils.java @@ -9,6 +9,7 @@ import net.fabricmc.fabric.api.client.item.v1.ItemTooltipCallback; import net.fabricmc.fabric.api.client.message.v1.ClientReceiveMessageEvents; import net.fabricmc.fabric.api.client.networking.v1.ClientPlayConnectionEvents; import net.fabricmc.fabric.api.networking.v1.PacketSender; +import net.fabricmc.loader.api.FabricLoader; import net.minecraft.client.MinecraftClient; import net.minecraft.client.network.ClientPlayNetworkHandler; import net.minecraft.client.network.ClientPlayerEntity; @@ -19,6 +20,8 @@ import net.minecraft.scoreboard.ScoreboardPlayerScore; import net.minecraft.scoreboard.Team; import net.minecraft.text.Text; import net.minecraft.util.Formatting; +import org.slf4j.Logger; +import org.slf4j.LoggerFactory; import java.util.ArrayList; import java.util.Collections; @@ -28,6 +31,7 @@ import java.util.List; * Utility variables and methods for retrieving Skyblock related information. */ public class Utils { + private static final Logger LOGGER = LoggerFactory.getLogger(Utils.class); private static final String ALTERNATE_HYPIXEL_ADDRESS = System.getProperty("skyblocker.alternateHypixelAddress", ""); private static final String PROFILE_PREFIX = "Profile: "; private static boolean isOnHypixel = false; @@ -124,19 +128,25 @@ public class Utils { public static void updateFromScoreboard(MinecraftClient client) { List<String> sidebar; - if (client.world == null || client.isInSingleplayer() || (sidebar = getSidebar()) == null) { - isOnSkyblock = false; - isInDungeons = false; - return; + FabricLoader fabricLoader = FabricLoader.getInstance(); + if ((client.world == null || client.isInSingleplayer() || (sidebar = getSidebar()) == null)) { + if (fabricLoader.isDevelopmentEnvironment()) { + sidebar = Collections.emptyList(); + } else { + isOnSkyblock = false; + isInDungeons = false; + return; + } } + + if (sidebar.isEmpty() && !fabricLoader.isDevelopmentEnvironment()) return; String string = sidebar.toString(); - if (sidebar.isEmpty()) return; - if (isConnectedToHypixel(client)) { + if (fabricLoader.isDevelopmentEnvironment() || isConnectedToHypixel(client)) { if (!isOnHypixel) { isOnHypixel = true; } - if (sidebar.get(0).contains("SKYBLOCK") || sidebar.get(0).contains("SKIBLOCK")) { + if (fabricLoader.isDevelopmentEnvironment() || sidebar.get(0).contains("SKYBLOCK") || sidebar.get(0).contains("SKIBLOCK")) { if (!isOnSkyblock) { if (!isInjected) { isInjected = true; @@ -148,7 +158,7 @@ public class Utils { } else { leaveSkyblock(); } - isInDungeons = isOnSkyblock && string.contains("The Catacombs"); + isInDungeons = fabricLoader.isDevelopmentEnvironment() || isOnSkyblock && string.contains("The Catacombs"); } else if (isOnHypixel) { isOnHypixel = false; leaveSkyblock(); @@ -156,11 +166,10 @@ public class Utils { } private static boolean isConnectedToHypixel(MinecraftClient client) { - String serverAddress = (client.getCurrentServerEntry() != null) ? client.getCurrentServerEntry().address.toLowerCase() : ""; - String serverBrand = (client.player != null && client.player.getServerBrand() != null) ? client.player.getServerBrand() : ""; - boolean isOnHypixel = (serverAddress.equalsIgnoreCase(ALTERNATE_HYPIXEL_ADDRESS) || serverAddress.contains("hypixel.net") || serverAddress.contains("hypixel.io") || serverBrand.contains("Hypixel BungeeCord")); + String serverAddress = (client.getCurrentServerEntry() != null) ? client.getCurrentServerEntry().address.toLowerCase() : ""; + String serverBrand = (client.player != null && client.player.getServerBrand() != null) ? client.player.getServerBrand() : ""; - return isOnHypixel; + return serverAddress.equalsIgnoreCase(ALTERNATE_HYPIXEL_ADDRESS) || serverAddress.contains("hypixel.net") || serverAddress.contains("hypixel.io") || serverBrand.contains("Hypixel BungeeCord"); } private static void leaveSkyblock() { @@ -184,7 +193,7 @@ public class Utils { location = location.strip(); } } catch (IndexOutOfBoundsException e) { - e.printStackTrace(); + LOGGER.error("[Skyblocker] Failed to get location from sidebar", e); } return location; } @@ -206,7 +215,7 @@ public class Utils { else purse = 0; } catch (IndexOutOfBoundsException e) { - e.printStackTrace(); + LOGGER.error("[Skyblocker] Failed to get purse from sidebar", e); } return purse; } @@ -225,12 +234,11 @@ public class Utils { bits = Integer.parseInt(bitsString.replaceAll("[^0-9.]", "").strip()); } } catch (IndexOutOfBoundsException e) { - e.printStackTrace(); + LOGGER.error("[Skyblocker] Failed to get bits from sidebar", e); } return bits; } - public static List<String> getSidebar() { try { ClientPlayerEntity client = MinecraftClient.getInstance().player; @@ -242,7 +250,7 @@ public class Utils { Team team = scoreboard.getPlayerTeam(score.getPlayerName()); if (team != null) { String line = team.getPrefix().getString() + team.getSuffix().getString(); - if (line.trim().length() > 0) { + if (!line.trim().isEmpty()) { String formatted = Formatting.strip(line); lines.add(formatted); } |