aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--build.gradle14
-rw-r--r--gradle.properties2
-rw-r--r--src/main/java/de/hysky/skyblocker/utils/Utils.java120
-rw-r--r--src/main/resources/assets/skyblocker/lang/en_us.json2
-rw-r--r--src/main/resources/fabric.mod.json1
5 files changed, 82 insertions, 57 deletions
diff --git a/build.gradle b/build.gradle
index ea70c4ef..b3c46376 100644
--- a/build.gradle
+++ b/build.gradle
@@ -30,6 +30,17 @@ repositories {
}
maven { url "https://repo.codemc.io/repository/maven-public/" } // For Occlusion Culling library
maven { url "https://repo.nea.moe/releases" } // For neu repoparser
+
+ exclusiveContent {
+ forRepository {
+ maven { url "https://maven.azureaaron.net/releases" }
+ maven { url "https://maven.azureaaron.net/snapshots" }
+ }
+
+ filter {
+ includeGroup "net.azureaaron"
+ }
+ }
}
dependencies {
@@ -50,6 +61,9 @@ dependencies {
// YACL
include modImplementation("dev.isxander:yet-another-config-lib:${project.yacl_version}-fabric")
+ // HM API
+ include modImplementation("net.azureaaron:hm-api:${project.hm_api_version}")
+
// Mod Menu
modImplementation "com.terraformersmc:modmenu:${project.mod_menu_version}"
diff --git a/gradle.properties b/gradle.properties
index 614c7a1d..3135716a 100644
--- a/gradle.properties
+++ b/gradle.properties
@@ -14,6 +14,8 @@ fabric_api_version=0.100.1+1.21
# Minecraft Mods
## YACL (https://github.com/isXander/YetAnotherConfigLib)
yacl_version=3.5.0+1.21
+## HM API
+hm_api_version=1.0.0-alpha.10+1.21
## Mod Menu (https://modrinth.com/mod/modmenu/versions)
mod_menu_version = 11.0.0-beta.1
## REI (https://modrinth.com/mod/rei/versions?l=fabric)
diff --git a/src/main/java/de/hysky/skyblocker/utils/Utils.java b/src/main/java/de/hysky/skyblocker/utils/Utils.java
index 051110b2..d0508096 100644
--- a/src/main/java/de/hysky/skyblocker/utils/Utils.java
+++ b/src/main/java/de/hysky/skyblocker/utils/Utils.java
@@ -6,21 +6,27 @@ import com.mojang.util.UndashedUuid;
import de.hysky.skyblocker.events.SkyblockEvents;
import de.hysky.skyblocker.mixins.accessors.MessageHandlerAccessor;
import de.hysky.skyblocker.skyblock.item.MuseumItemCache;
-import de.hysky.skyblocker.utils.scheduler.MessageScheduler;
import de.hysky.skyblocker.utils.scheduler.Scheduler;
+import it.unimi.dsi.fastutil.objects.Object2IntOpenHashMap;
import it.unimi.dsi.fastutil.objects.ObjectArrayList;
+import net.azureaaron.hmapi.data.server.Environment;
+import net.azureaaron.hmapi.events.HypixelPacketEvents;
+import net.azureaaron.hmapi.network.HypixelNetworking;
+import net.azureaaron.hmapi.network.packet.s2c.ErrorS2CPacket;
+import net.azureaaron.hmapi.network.packet.s2c.HelloS2CPacket;
+import net.azureaaron.hmapi.network.packet.s2c.HypixelS2CPacket;
+import net.azureaaron.hmapi.network.packet.v1.s2c.LocationUpdateS2CPacket;
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;
import net.minecraft.client.network.PlayerListEntry;
import net.minecraft.scoreboard.*;
import net.minecraft.text.MutableText;
import net.minecraft.text.Text;
import net.minecraft.util.Formatting;
+import net.minecraft.util.Util;
+
import org.apache.http.client.HttpResponseException;
import org.jetbrains.annotations.NotNull;
import org.slf4j.Logger;
@@ -45,7 +51,7 @@ public class Utils {
private static boolean isOnSkyblock = false;
private static boolean isInjected = false;
/**
- * Current Skyblock location (from /locraw)
+ * Current Skyblock location (from the Mod API)
*/
@NotNull
private static Location location = Location.UNKNOWN;
@@ -60,10 +66,12 @@ public class Utils {
@NotNull
private static String profileId = "";
/**
- * The following fields store data returned from /locraw: {@link #server}, {@link #gameType}, {@link #locationRaw}, and {@link #map}.
+ * The following fields store data returned from the Mod API: {@link #environment}, {@link #server}, {@link #gameType}, {@link #locationRaw}, and {@link #map}.
*/
@SuppressWarnings("JavadocDeclaration")
@NotNull
+ private static Environment environment = Environment.PRODUCTION;
+ @NotNull
private static String server = "";
@NotNull
private static String gameType = "";
@@ -71,11 +79,6 @@ public class Utils {
private static String locationRaw = "";
@NotNull
private static String map = "";
- private static long clientWorldJoinTime = 0;
- private static boolean sentLocRaw = false;
- private static boolean canSendLocRaw = false;
- //This is required to prevent the location change event from being fired twice.
- private static boolean locationChanged = true;
private static boolean mayorTickScheduled = false;
private static int mayorTickRetryAttempts = 0;
private static String mayor = "";
@@ -146,7 +149,7 @@ public class Utils {
}
/**
- * @return the location parsed from /locraw.
+ * @return the location parsed from the Mod API.
*/
@NotNull
public static Location getLocation() {
@@ -154,7 +157,17 @@ public class Utils {
}
/**
- * @return the server parsed from /locraw.
+ * Can be used to restrict features to being active only on the Alpha network.
+ *
+ * @return the current environment parsed from the Mod API.
+ */
+ @NotNull
+ public static Environment getEnvironment() {
+ return environment;
+ }
+
+ /**
+ * @return the server parsed from the Mod API.
*/
@NotNull
public static String getServer() {
@@ -162,7 +175,7 @@ public class Utils {
}
/**
- * @return the game type parsed from /locraw.
+ * @return the game type parsed from the Mod API.
*/
@NotNull
public static String getGameType() {
@@ -170,7 +183,7 @@ public class Utils {
}
/**
- * @return the location raw parsed from /locraw.
+ * @return the location raw parsed from the the Mod API.
*/
@NotNull
public static String getLocationRaw() {
@@ -178,7 +191,7 @@ public class Utils {
}
/**
- * @return the map parsed from /locraw.
+ * @return the map parsed from the Mod API.
*/
@NotNull
public static String getMap() {
@@ -201,20 +214,23 @@ public class Utils {
mayorTickScheduled = true;
}
});
- ClientPlayConnectionEvents.JOIN.register(Utils::onClientWorldJoin);
ClientReceiveMessageEvents.ALLOW_GAME.register(Utils::onChatMessage);
ClientReceiveMessageEvents.GAME_CANCELED.register(Utils::onChatMessage); // Somehow this works even though onChatMessage returns a boolean
+
+ //Register Mod API stuff
+ HypixelNetworking.registerToEvents(Util.make(new Object2IntOpenHashMap<>(), map -> map.put(LocationUpdateS2CPacket.ID, 1)));
+ HypixelPacketEvents.HELLO.register(Utils::onPacket);
+ HypixelPacketEvents.LOCATION_UPDATE.register(Utils::onPacket);
}
/**
- * Updates all the fields stored in this class from the sidebar, player list, and /locraw.
+ * Updates all the fields stored in this class from the sidebar, and player list.
*/
public static void update() {
MinecraftClient client = MinecraftClient.getInstance();
updateScoreboard(client);
updatePlayerPresenceFromScoreboard(client);
updateFromPlayerList(client);
- updateLocRaw();
}
/**
@@ -244,7 +260,7 @@ public class Utils {
if (!isInjected) {
isInjected = true;
}
- isOnSkyblock = true;
+ isOnSkyblock = true; //TODO in the future we can probably replace these skyblock checks entirely with the Mod API
SkyblockEvents.JOIN.invoker().onSkyblockJoin();
}
} else {
@@ -260,7 +276,7 @@ public class Utils {
String serverAddress = (client.getCurrentServerEntry() != null) ? client.getCurrentServerEntry().address.toLowerCase() : "";
String serverBrand = (client.player != null && client.player.networkHandler != null && client.player.networkHandler.getBrand() != null) ? client.player.networkHandler.getBrand() : "";
- return serverAddress.equalsIgnoreCase(ALTERNATE_HYPIXEL_ADDRESS) || serverAddress.contains("hypixel.net") || serverAddress.contains("hypixel.io") || serverBrand.contains("Hypixel BungeeCord");
+ return (!serverAddress.isEmpty() && serverAddress.equalsIgnoreCase(ALTERNATE_HYPIXEL_ADDRESS)) || serverAddress.contains("hypixel.net") || serverAddress.contains("hypixel.io") || serverBrand.contains("Hypixel BungeeCord");
}
private static void onLeaveSkyblock() {
@@ -395,25 +411,33 @@ public class Utils {
}
}
- public static void onClientWorldJoin(ClientPlayNetworkHandler handler, PacketSender sender, MinecraftClient client) {
- clientWorldJoinTime = System.currentTimeMillis();
- resetLocRawInfo();
- }
+ private static void onPacket(HypixelS2CPacket packet) {
+ switch (packet) {
+ case HelloS2CPacket(var environment) -> {
+ Utils.environment = environment;
+ }
- /**
- * Sends /locraw to the server if the player is on skyblock and on a new island.
- */
- private static void updateLocRaw() {
- if (isOnSkyblock) {
- long currentTime = System.currentTimeMillis();
- if (!sentLocRaw && canSendLocRaw && currentTime > clientWorldJoinTime + 1000) {
- MessageScheduler.INSTANCE.sendMessageAfterCooldown("/locraw");
- sentLocRaw = true;
- canSendLocRaw = false;
- locationChanged = true;
+ case LocationUpdateS2CPacket(var serverName, var serverType, var _lobbyName, var mode, var map) -> {
+ Utils.server = serverName;
+ Utils.gameType = serverType.orElse("");
+ Utils.locationRaw = mode.orElse("");
+ Utils.location = Location.from(locationRaw);
+ Utils.map = map.orElse("");
+
+ SkyblockEvents.LOCATION_CHANGE.invoker().onSkyblockLocationChange(location);
}
- } else {
- resetLocRawInfo();
+
+ case ErrorS2CPacket(var id, var error) when id == LocationUpdateS2CPacket.ID -> {
+ ClientPlayerEntity player = MinecraftClient.getInstance().player;
+
+ if (player != null) {
+ player.sendMessage(Constants.PREFIX.get().append(Text.translatable("skyblocker.utils.locationUpdateError").formatted(Formatting.RED)));
+ }
+
+ LOGGER.error("[Skyblocker] Failed to update your current location! Some features of the mod may not work correctly :( - Error: {}", error);
+ }
+
+ default -> {} //Do Nothing
}
}
@@ -423,6 +447,7 @@ public class Utils {
*
* @param message json message from chat
*/
+ @Deprecated
private static void parseLocRaw(String message) {
JsonObject locRaw = JsonParser.parseString(message).getAsJsonObject();
@@ -441,11 +466,6 @@ public class Utils {
if (locRaw.has("map")) {
map = locRaw.get("map").getAsString();
}
-
- if (locationChanged) {
- SkyblockEvents.LOCATION_CHANGE.invoker().onSkyblockLocationChange(location);
- locationChanged = false;
- }
}
/**
@@ -458,10 +478,6 @@ public class Utils {
if (message.startsWith("{\"server\":") && message.endsWith("}")) {
parseLocRaw(message);
- boolean shouldFilter = !sentLocRaw;
- sentLocRaw = false;
-
- return shouldFilter;
}
if (isOnSkyblock) {
@@ -481,16 +497,6 @@ public class Utils {
return true;
}
- private static void resetLocRawInfo() {
- sentLocRaw = false;
- canSendLocRaw = true;
- server = "";
- gameType = "";
- locationRaw = "";
- map = "";
- location = Location.UNKNOWN;
- }
-
private static void scheduleMayorTick() {
long currentYearMillis = SkyblockTime.getSkyblockMillis() % 446400000L; //446400000ms is 1 year, 105600000ms is the amount of time from early spring 1st to late spring 27th
// If current time is past late spring 27th, the next mayor change is at next year's spring 27th, otherwise it's at this year's spring 27th
diff --git a/src/main/resources/assets/skyblocker/lang/en_us.json b/src/main/resources/assets/skyblocker/lang/en_us.json
index bf154048..ce7b7d46 100644
--- a/src/main/resources/assets/skyblocker/lang/en_us.json
+++ b/src/main/resources/assets/skyblocker/lang/en_us.json
@@ -654,6 +654,8 @@
"skyblocker.config.uiAndVisuals.waypoints.waypointType.@Tooltip": "Waypoint: Displays a highlight and a beacon beam.\n\nOutlined Waypoint: Displays both a waypoint and an outline.\n\nHighlight: Only displays a highlight.\n\nOutlined Highlight: Displays both a highlight and an outline.\n\nOutline: Only displays an outline.",
"skyblocker.config.uiAndVisuals.waypoints.waypointType.generalNote": "\n\n\nThis option does not apply to all waypoints. Some waypoints such as secret waypoints have their own waypoint type option.",
+ "skyblocker.utils.locationUpdateError": "Failed to update your location! Some features of the mod may not work properly :(",
+
"skyblocker.itemTooltip.noData": "\u00a7cNo Data",
"skyblocker.itemTooltip.nullMessage": "\u00a7cItem price information on tooltip will renew in max 60 seconds. If not, check latest.log",
diff --git a/src/main/resources/fabric.mod.json b/src/main/resources/fabric.mod.json
index e46085de..93e2bd6a 100644
--- a/src/main/resources/fabric.mod.json
+++ b/src/main/resources/fabric.mod.json
@@ -36,6 +36,7 @@
"fabricloader": ">=0.15.11",
"fabric-api": ">=0.100.1+1.21",
"yet_another_config_lib_v3": ">=3.5.0+1.21",
+ "hm-api": ">=1.0.0-alpha.10+1.21",
"minecraft": "~1.21",
"java": ">=21"
},