aboutsummaryrefslogtreecommitdiff
path: root/src/main/java/me/xmrvizzy/skyblocker/skyblock
diff options
context:
space:
mode:
Diffstat (limited to 'src/main/java/me/xmrvizzy/skyblocker/skyblock')
-rw-r--r--src/main/java/me/xmrvizzy/skyblocker/skyblock/BackpackPreview.java2
-rw-r--r--src/main/java/me/xmrvizzy/skyblocker/skyblock/FairySouls.java175
-rw-r--r--src/main/java/me/xmrvizzy/skyblocker/skyblock/api/RepositoryUpdate.java62
-rw-r--r--src/main/java/me/xmrvizzy/skyblocker/skyblock/dungeon/LividColor.java3
-rw-r--r--src/main/java/me/xmrvizzy/skyblocker/skyblock/itemlist/ItemRegistry.java79
-rw-r--r--src/main/java/me/xmrvizzy/skyblocker/skyblock/itemlist/ItemStackBuilder.java5
6 files changed, 193 insertions, 133 deletions
diff --git a/src/main/java/me/xmrvizzy/skyblocker/skyblock/BackpackPreview.java b/src/main/java/me/xmrvizzy/skyblocker/skyblock/BackpackPreview.java
index e35ef605..d89a18e0 100644
--- a/src/main/java/me/xmrvizzy/skyblocker/skyblock/BackpackPreview.java
+++ b/src/main/java/me/xmrvizzy/skyblocker/skyblock/BackpackPreview.java
@@ -50,7 +50,7 @@ public class BackpackPreview {
}
public static void tick() {
- Utils.sbChecker(); // force update isOnSkyblock to prevent crash on disconnect
+ Utils.update(); // force update isOnSkyblock to prevent crash on disconnect
if (Utils.isOnSkyblock()) {
// save all dirty storages
saveStorage();
diff --git a/src/main/java/me/xmrvizzy/skyblocker/skyblock/FairySouls.java b/src/main/java/me/xmrvizzy/skyblocker/skyblock/FairySouls.java
new file mode 100644
index 00000000..ccffdcca
--- /dev/null
+++ b/src/main/java/me/xmrvizzy/skyblocker/skyblock/FairySouls.java
@@ -0,0 +1,175 @@
+package me.xmrvizzy.skyblocker.skyblock;
+
+import com.google.common.collect.ImmutableSet;
+import com.google.gson.JsonArray;
+import com.google.gson.JsonElement;
+import com.google.gson.JsonObject;
+import com.google.gson.JsonParser;
+import me.xmrvizzy.skyblocker.SkyblockerMod;
+import me.xmrvizzy.skyblocker.config.SkyblockerConfig;
+import me.xmrvizzy.skyblocker.utils.NEURepo;
+import me.xmrvizzy.skyblocker.utils.RenderHelper;
+import me.xmrvizzy.skyblocker.utils.Utils;
+import net.fabricmc.fabric.api.client.command.v2.ClientCommandRegistrationCallback;
+import net.fabricmc.fabric.api.client.event.lifecycle.v1.ClientLifecycleEvents;
+import net.fabricmc.fabric.api.client.message.v1.ClientReceiveMessageEvents;
+import net.fabricmc.fabric.api.client.rendering.v1.WorldRenderContext;
+import net.fabricmc.fabric.api.client.rendering.v1.WorldRenderEvents;
+import net.minecraft.client.MinecraftClient;
+import net.minecraft.entity.player.PlayerEntity;
+import net.minecraft.text.Text;
+import net.minecraft.util.DyeColor;
+import net.minecraft.util.math.BlockPos;
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
+
+import java.io.*;
+import java.util.*;
+import java.util.concurrent.CompletableFuture;
+
+import static net.fabricmc.fabric.api.client.command.v2.ClientCommandManager.literal;
+
+public class FairySouls {
+ private static final Logger LOGGER = LoggerFactory.getLogger(FairySouls.class);
+ private static CompletableFuture<Void> fairySoulsLoaded;
+ private static final Map<String, Set<BlockPos>> fairySouls = new HashMap<>();
+ private static final Map<String, Map<String, Set<BlockPos>>> foundFairies = new HashMap<>();
+
+ public static void init() {
+ fairySoulsLoaded = NEURepo.runAsyncAfterLoad(() -> {
+ try {
+ BufferedReader reader = new BufferedReader(new FileReader(NEURepo.LOCAL_REPO_DIR.resolve("constants").resolve("fairy_souls.json").toFile()));
+ for (Map.Entry<String, JsonElement> fairySoulJson : JsonParser.parseReader(reader).getAsJsonObject().asMap().entrySet()) {
+ if (fairySoulJson.getKey().equals("//") || fairySoulJson.getKey().equals("Max Souls")) {
+ continue;
+ }
+ ImmutableSet.Builder<BlockPos> fairySoulsForLocation = ImmutableSet.builder();
+ for (JsonElement fairySoul : fairySoulJson.getValue().getAsJsonArray().asList()) {
+ fairySoulsForLocation.add(parseBlockPos(fairySoul));
+ }
+ fairySouls.put(fairySoulJson.getKey(), fairySoulsForLocation.build());
+ }
+ reader = new BufferedReader(new FileReader(SkyblockerMod.CONFIG_DIR.resolve("found_fairy_souls.json").toFile()));
+ for (Map.Entry<String, JsonElement> foundFairiesForProfileJson : JsonParser.parseReader(reader).getAsJsonObject().asMap().entrySet()) {
+ Map<String, Set<BlockPos>> foundFairiesForProfile = new HashMap<>();
+ for (Map.Entry<String, JsonElement> foundFairiesForLocationJson : foundFairiesForProfileJson.getValue().getAsJsonObject().asMap().entrySet()) {
+ Set<BlockPos> foundFairiesForLocation = new HashSet<>();
+ for (JsonElement foundFairy : foundFairiesForLocationJson.getValue().getAsJsonArray().asList()) {
+ foundFairiesForLocation.add(parseBlockPos(foundFairy));
+ }
+ foundFairiesForProfile.put(foundFairiesForLocationJson.getKey(), foundFairiesForLocation);
+ }
+ foundFairies.put(foundFairiesForProfileJson.getKey(), foundFairiesForProfile);
+ }
+ reader.close();
+ } catch (IOException e) {
+ LOGGER.error("Failed to load found fairy souls", e);
+ } catch (Exception e) {
+ LOGGER.error("Encountered unknown exception loading fairy souls", e);
+ }
+ });
+ ClientLifecycleEvents.CLIENT_STOPPING.register(FairySouls::saveFoundFairySouls);
+ WorldRenderEvents.AFTER_TRANSLUCENT.register(FairySouls::render);
+ ClientReceiveMessageEvents.GAME.register(FairySouls::onChatMessage);
+ ClientCommandRegistrationCallback.EVENT.register((dispatcher, registryAccess) -> dispatcher.register(literal(SkyblockerMod.NAMESPACE)
+ .then(literal("fairySouls")
+ .then(literal("markAllInCurrentIslandFound").executes(context -> {
+ FairySouls.markAllFairiesFound();
+ context.getSource().sendFeedback(Text.translatable("skyblocker.fairySouls.markAllFound"));
+ return 1;
+ }))
+ .then(literal("markAllInCurrentIslandMissing").executes(context -> {
+ FairySouls.markAllFairiesNotFound();
+ context.getSource().sendFeedback(Text.translatable("skyblocker.fairySouls.markAllMissing"));
+ return 1;
+ })))));
+ }
+
+ private static BlockPos parseBlockPos(JsonElement posJson) {
+ String[] posArray = posJson.getAsString().split(",");
+ return new BlockPos(Integer.parseInt(posArray[0]), Integer.parseInt(posArray[1]), Integer.parseInt(posArray[2]));
+ }
+
+ public static void saveFoundFairySouls(MinecraftClient client) {
+ try {
+ BufferedWriter writer = new BufferedWriter(new FileWriter(SkyblockerMod.CONFIG_DIR.resolve("found_fairy_souls.json").toFile()));
+ JsonObject foundFairiesJson = new JsonObject();
+ for (Map.Entry<String, Map<String, Set<BlockPos>>> foundFairiesForProfile : foundFairies.entrySet()) {
+ JsonObject foundFairiesForProfileJson = new JsonObject();
+ for (Map.Entry<String, Set<BlockPos>> foundFairiesForLocation : foundFairiesForProfile.getValue().entrySet()) {
+ JsonArray foundFairiesForLocationJson = new JsonArray();
+ for (BlockPos foundFairy : foundFairiesForLocation.getValue()) {
+ foundFairiesForLocationJson.add(foundFairy.getX() + "," + foundFairy.getY() + "," + foundFairy.getZ());
+ }
+ foundFairiesForProfileJson.add(foundFairiesForLocation.getKey(), foundFairiesForLocationJson);
+ }
+ foundFairiesJson.add(foundFairiesForProfile.getKey(), foundFairiesForProfileJson);
+ }
+ SkyblockerMod.GSON.toJson(foundFairiesJson, writer);
+ writer.close();
+ } catch (IOException e) {
+ LOGGER.error("Failed to write found fairy souls to file.");
+ }
+ }
+
+ public static void render(WorldRenderContext context) {
+ if (SkyblockerConfig.get().general.fairySouls.enableFairySoulsHelper && fairySoulsLoaded.isDone() && fairySouls.containsKey(Utils.getLocationRaw())) {
+ for (BlockPos fairySoul : fairySouls.get(Utils.getLocationRaw())) {
+ float[] colorComponents = isFairySoulNotFound(fairySoul) ? DyeColor.GREEN.getColorComponents() : DyeColor.RED.getColorComponents();
+ RenderHelper.renderFilledThroughWallsWithBeaconBeam(context, fairySoul, colorComponents, 0.5F);
+ }
+ }
+ }
+
+ private static boolean isFairySoulNotFound(BlockPos fairySoul) {
+ Map<String, Set<BlockPos>> foundFairiesForProfile = foundFairies.get(Utils.getProfile());
+ if (foundFairiesForProfile == null) {
+ return true;
+ }
+ Set<BlockPos> foundFairiesForProfileAndLocation = foundFairiesForProfile.get(Utils.getLocationRaw());
+ if (foundFairiesForProfileAndLocation == null) {
+ return true;
+ }
+ return !foundFairiesForProfileAndLocation.contains(fairySoul);
+ }
+
+ public static void onChatMessage(Text text, boolean overlay) {
+ String message = text.getString();
+ if (message.equals("You have already found that Fairy Soul!") || message.equals("SOUL! You found a Fairy Soul!")) {
+ markClosestFairyFound();
+ }
+ }
+
+ private static void markClosestFairyFound() {
+ PlayerEntity player = MinecraftClient.getInstance().player;
+ if (player == null) {
+ LOGGER.warn("Failed to mark closest fairy soul as found because player is null.");
+ return;
+ }
+ fairySouls.get(Utils.getLocationRaw()).stream().filter(FairySouls::isFairySoulNotFound).min(Comparator.comparingDouble(fairySoul -> fairySoul.getSquaredDistance(player.getPos()))).ifPresent(fairySoul -> {
+ initializeFoundFairiesForCurrentProfileAndLocation();
+ foundFairies.get(Utils.getProfile()).get(Utils.getLocationRaw()).add(fairySoul);
+ });
+ }
+
+ public static void markAllFairiesFound() {
+ initializeFoundFairiesForCurrentProfileAndLocation();
+ foundFairies.get(Utils.getProfile()).get(Utils.getLocationRaw()).addAll(fairySouls.get(Utils.getLocationRaw()));
+ }
+
+ public static void markAllFairiesNotFound() {
+ Map<String, Set<BlockPos>> foundFairiesForProfile = foundFairies.get(Utils.getProfile());
+ if (foundFairiesForProfile != null) {
+ foundFairiesForProfile.remove(Utils.getLocationRaw());
+ }
+ }
+
+ private static void initializeFoundFairiesForCurrentProfileAndLocation() {
+ initializeFoundFairiesForProfileAndLocation(Utils.getProfile(), Utils.getLocationRaw());
+ }
+
+ private static void initializeFoundFairiesForProfileAndLocation(String profile, String location) {
+ foundFairies.computeIfAbsent(profile, profileKey -> new HashMap<>());
+ foundFairies.get(profile).computeIfAbsent(location, locationKey -> new HashSet<>());
+ }
+}
diff --git a/src/main/java/me/xmrvizzy/skyblocker/skyblock/api/RepositoryUpdate.java b/src/main/java/me/xmrvizzy/skyblocker/skyblock/api/RepositoryUpdate.java
deleted file mode 100644
index e08cb1c0..00000000
--- a/src/main/java/me/xmrvizzy/skyblocker/skyblock/api/RepositoryUpdate.java
+++ /dev/null
@@ -1,62 +0,0 @@
-package me.xmrvizzy.skyblocker.skyblock.api;
-
-import me.xmrvizzy.skyblocker.skyblock.itemlist.ItemRegistry;
-import net.fabricmc.fabric.api.client.command.v2.ClientCommandManager;
-import net.fabricmc.fabric.api.client.command.v2.ClientCommandRegistrationCallback;
-import net.minecraft.client.MinecraftClient;
-import net.minecraft.text.Text;
-
-import java.io.File;
-import java.nio.file.Files;
-import java.util.concurrent.CompletableFuture;
-
-public class RepositoryUpdate {
- public static final MinecraftClient client = MinecraftClient.getInstance();
-
- /**
- * Adds command to update repository manually from ingame.
- * <p></p>
- * TODO A button could be added to the settings menu that will trigger this command.
- */
- public static void init(){
- ClientCommandRegistrationCallback.EVENT.register((dispatcher, registryAccess) -> dispatcher.register(
- ClientCommandManager.literal("skyblocker")
- .then(ClientCommandManager.literal("updaterepository")
- .executes(context -> {
- updateRepository();
- return 1;
- })
- )
- )
- );
-
- }
-
- public static void updateRepository() {
- CompletableFuture.runAsync(() -> {
- try {
- ItemRegistry.filesImported = false;
- File dir = ItemRegistry.LOCAL_ITEM_REPO_DIR.toFile();
- recursiveDelete(dir);
- } catch (Exception ex) {
- if (client.player != null)
- client.player.sendMessage(
- Text.translatable("skyblocker.updaterepository.failed")
- , false
- );
- return;
- }
-
- ItemRegistry.init();
- });
- }
-
- private static void recursiveDelete(File dir) {
- if (dir.isDirectory() && !Files.isSymbolicLink(dir.toPath())) {
- for (File child : dir.listFiles()) {
- recursiveDelete(child);
- }
- }
- dir.delete();
- }
-}
diff --git a/src/main/java/me/xmrvizzy/skyblocker/skyblock/dungeon/LividColor.java b/src/main/java/me/xmrvizzy/skyblocker/skyblock/dungeon/LividColor.java
index 276a41b6..4701c485 100644
--- a/src/main/java/me/xmrvizzy/skyblocker/skyblock/dungeon/LividColor.java
+++ b/src/main/java/me/xmrvizzy/skyblocker/skyblock/dungeon/LividColor.java
@@ -11,11 +11,10 @@ public class LividColor {
private static int tenTicks = 0;
public static void init() {
- ClientReceiveMessageEvents.ALLOW_GAME.register((message, overlay) -> {
+ ClientReceiveMessageEvents.GAME.register((message, overlay) -> {
if (SkyblockerConfig.get().locations.dungeons.lividColor.enableLividColor && message.getString().equals("[BOSS] Livid: I respect you for making it to here, but I'll be your undoing.")) {
tenTicks = 8;
}
- return true;
});
}
diff --git a/src/main/java/me/xmrvizzy/skyblocker/skyblock/itemlist/ItemRegistry.java b/src/main/java/me/xmrvizzy/skyblocker/skyblock/itemlist/ItemRegistry.java
index d9f3b473..dc63e351 100644
--- a/src/main/java/me/xmrvizzy/skyblocker/skyblock/itemlist/ItemRegistry.java
+++ b/src/main/java/me/xmrvizzy/skyblocker/skyblock/itemlist/ItemRegistry.java
@@ -2,32 +2,23 @@ package me.xmrvizzy.skyblocker.skyblock.itemlist;
import com.google.gson.JsonObject;
import com.google.gson.JsonParser;
-
-import me.xmrvizzy.skyblocker.skyblock.api.RepositoryUpdate;
-import net.fabricmc.loader.api.FabricLoader;
+import me.xmrvizzy.skyblocker.utils.NEURepo;
import net.minecraft.client.MinecraftClient;
import net.minecraft.item.ItemStack;
import net.minecraft.item.Items;
import net.minecraft.text.Text;
-import org.eclipse.jgit.api.Git;
-import org.eclipse.jgit.api.PullResult;
-import org.eclipse.jgit.errors.RepositoryNotFoundException;
-import org.slf4j.Logger;
-import org.slf4j.LoggerFactory;
import java.io.File;
import java.io.IOException;
import java.nio.file.Files;
import java.nio.file.Path;
-import java.util.*;
-import java.util.concurrent.CompletableFuture;
+import java.util.ArrayList;
+import java.util.HashMap;
+import java.util.List;
+import java.util.Map;
public class ItemRegistry {
- private static final Logger LOGGER = LoggerFactory.getLogger(ItemRegistry.class);
- protected static final String REMOTE_ITEM_REPO = "https://github.com/NotEnoughUpdates/NotEnoughUpdates-REPO";
- public static final Path LOCAL_ITEM_REPO_DIR = FabricLoader.getInstance().getConfigDir().resolve("skyblocker/item-repo");
-
- protected static final Path ITEM_LIST_DIR = LOCAL_ITEM_REPO_DIR.resolve("items");
+ protected static final Path ITEM_LIST_DIR = NEURepo.LOCAL_REPO_DIR.resolve("items");
protected static final List<ItemStack> items = new ArrayList<>();
protected static final Map<String, ItemStack> itemsMap = new HashMap<>();
@@ -36,52 +27,8 @@ public class ItemRegistry {
public static boolean filesImported = false;
public static void init() {
- CompletableFuture.runAsync(ItemRegistry::updateItemRepo)
- .whenComplete((result, ex) -> {
- if (ex == null) {
- ItemStackBuilder.init();
- importItemFiles();
- }
- else {
- LOGGER.error("[Skyblocker-ItemRegistry] " + ex);
- }
- });
- }
-
- private static void updateItemRepo() {
- Git git;
- if (!Files.isDirectory(LOCAL_ITEM_REPO_DIR)) {
- try {
- git = Git.cloneRepository()
- .setURI(REMOTE_ITEM_REPO)
- .setDirectory(LOCAL_ITEM_REPO_DIR.toFile())
- .setBranchesToClone(List.of("refs/heads/master"))
- .setBranch("refs/heads/master")
- .call();
- git.close();
- LOGGER.info("[Skyblocker Repository Update] Repository updated.");
- } catch (Exception e) {
- e.printStackTrace();
- }
- } else {
- try {
- git = Git.open(LOCAL_ITEM_REPO_DIR.toFile());
- PullResult pull = git.pull().setRebase(true).call();
- git.close();
-
- if (pull.getRebaseResult() == null) {
- LOGGER.info("[Skyblocker Repository Update] No update result");
- } else if (pull.getRebaseResult().getStatus().isSuccessful()) {
- LOGGER.info("[Skyblocker Repository Update] Status: " + pull.getRebaseResult().getStatus().name());
- } else if (!pull.getRebaseResult().getStatus().isSuccessful()) {
- LOGGER.warn("[Skyblocker Repository Update] Status: " + pull.getRebaseResult().getStatus().name());
- }
- } catch (RepositoryNotFoundException e) {
- RepositoryUpdate.updateRepository();
- } catch (Exception e) {
- e.printStackTrace();
- }
- }
+ NEURepo.runAsyncAfterLoad(ItemStackBuilder::loadPetNums);
+ NEURepo.runAsyncAfterLoad(ItemRegistry::importItemFiles);
}
private static void importItemFiles() {
@@ -89,7 +36,9 @@ public class ItemRegistry {
File dir = ITEM_LIST_DIR.toFile();
File[] files = dir.listFiles();
- assert files != null;
+ if (files == null) {
+ return;
+ }
for (File file : files) {
Path path = ITEM_LIST_DIR.resolve(file.getName());
try {
@@ -119,8 +68,7 @@ public class ItemRegistry {
if (lhsFamilyName.equals(rhsFamilyName)) {
if (lhsInternalName.length() != rhsInternalName.length())
return lhsInternalName.length() - rhsInternalName.length();
- else
- return lhsInternalName.compareTo(rhsInternalName);
+ else return lhsInternalName.compareTo(rhsInternalName);
}
return lhsFamilyName.compareTo(rhsFamilyName);
});
@@ -147,8 +95,7 @@ public class ItemRegistry {
public static List<SkyblockCraftingRecipe> getRecipes(String internalName) {
List<SkyblockCraftingRecipe> result = new ArrayList<>();
for (SkyblockCraftingRecipe recipe : recipes)
- if (getInternalName(recipe.result).equals(internalName))
- result.add(recipe);
+ if (getInternalName(recipe.result).equals(internalName)) result.add(recipe);
for (SkyblockCraftingRecipe recipe : recipes)
for (ItemStack ingredient : recipe.grid)
if (!ingredient.getItem().equals(Items.AIR) && getInternalName(ingredient).equals(internalName)) {
diff --git a/src/main/java/me/xmrvizzy/skyblocker/skyblock/itemlist/ItemStackBuilder.java b/src/main/java/me/xmrvizzy/skyblocker/skyblock/itemlist/ItemStackBuilder.java
index b2d909a8..d420d54f 100644
--- a/src/main/java/me/xmrvizzy/skyblocker/skyblock/itemlist/ItemStackBuilder.java
+++ b/src/main/java/me/xmrvizzy/skyblocker/skyblock/itemlist/ItemStackBuilder.java
@@ -4,6 +4,7 @@ import com.google.gson.JsonArray;
import com.google.gson.JsonElement;
import com.google.gson.JsonObject;
import com.google.gson.JsonParser;
+import me.xmrvizzy.skyblocker.utils.NEURepo;
import net.minecraft.item.ItemStack;
import net.minecraft.nbt.*;
import net.minecraft.text.Text;
@@ -16,10 +17,10 @@ import java.util.regex.Matcher;
import java.util.regex.Pattern;
public class ItemStackBuilder {
- private final static Path PETNUMS_PATH = ItemRegistry.LOCAL_ITEM_REPO_DIR.resolve("constants/petnums.json");
+ private final static Path PETNUMS_PATH = NEURepo.LOCAL_REPO_DIR.resolve("constants/petnums.json");
private static JsonObject petNums;
- public static void init() {
+ public static void loadPetNums() {
try {
petNums = JsonParser.parseString(Files.readString(PETNUMS_PATH)).getAsJsonObject();
} catch (Exception e) {