Skip to content

Commit

Permalink
Merge pull request #806 from SkyblockerMod/networth
Browse files Browse the repository at this point in the history
Networth
  • Loading branch information
AzureAaron authored Aug 12, 2024
2 parents 50d735b + 61c1316 commit 9b95005
Show file tree
Hide file tree
Showing 18 changed files with 355 additions and 51 deletions.
109 changes: 98 additions & 11 deletions build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -16,23 +16,107 @@ repositories {
flatDir {
dirs 'libs'
}
maven { url "https://maven.terraformersmc.com/releases" }
maven { url "https://maven.shedaniel.me/" }
maven { url "https://maven.isxander.dev/releases" }
maven { url "https://maven.isxander.dev/snapshots" } //For minecraft snapshots

maven {
url 'https://repo.maven.apache.org/maven2'
name 'Maven Central'
url 'https://repo.maven.apache.org/maven2'
}

// For ModMenu and EMI
exclusiveContent {
forRepository {
maven { url "https://maven.terraformersmc.com/releases" }
}

filter {
includeGroup "com.terraformersmc"
includeGroup "dev.emi"
}
}

// For REI
exclusiveContent {
forRepository {
maven { url "https://maven.shedaniel.me/" }
}

filter {
includeGroup "me.shedaniel"
includeGroup "me.shedaniel.cloth"
includeGroup "dev.architectury"
}
}

// YACL
maven {
url "https://maven.isxander.dev/releases"

content {
includeGroup "dev.isxander"
includeGroup "org.quiltmc.parsers"
}
}

// For Minecraft snapshots
maven {
name = "meteor-maven"
url = "https://maven.meteordev.org/releases"
url "https://maven.isxander.dev/snapshots"

content {
includeGroup "dev.isxander"
}
}
maven { url "https://repo.codemc.io/repository/maven-public/" } // For Occlusion Culling library
maven { url "https://repo.nea.moe/releases" } // For neu repoparser

maven { url "https://maven.azureaaron.net/releases" }
maven { url "https://maven.azureaaron.net/snapshots" }
// For Discord RPC
exclusiveContent {
forRepository {
maven {
name = "meteor-maven"
url = "https://maven.meteordev.org/releases"
}
}

filter {
includeGroup "meteordevelopment"
}
}

// For Occlusion Culling library
exclusiveContent {
forRepository {
maven { url "https://repo.codemc.io/repository/maven-public/" }
}

filter {
includeGroup "com.logisticscraft"
}
}

// For NEU repo parser
exclusiveContent {
forRepository {
maven { url "https://repo.nea.moe/releases" }
}

filter {
includeGroup "moe.nea"
}
}

maven {
url "https://maven.azureaaron.net/releases"

content {
includeGroup "net.azureaaron"
}
}

maven {
url "https://maven.azureaaron.net/snapshots"

content {
includeGroup "net.azureaaron"
}
}
}

dependencies {
Expand Down Expand Up @@ -77,6 +161,9 @@ dependencies {
// NEU RepoParser
include implementation("moe.nea:neurepoparser:${project.repoparser_version}")

// Networth Calculator (https://github.com/AzureAaron/networth-calculator)
include implementation("net.azureaaron:networth-calculator:${project.networth_calculator_version}")

// JGit used pull data from the NEU item repo
include implementation("org.eclipse.jgit:org.eclipse.jgit:${project.jgit_version}")

Expand Down
2 changes: 2 additions & 0 deletions gradle.properties
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,8 @@ mcdev_annotations_version = 2.1.0
occlusionculling_version = 0.0.8-SNAPSHOT
## neu repoparser (https://repo.nea.moe/#/releases/moe/nea/neurepoparser/)
repoparser_version = 1.5.0
## Networth Calculator (https://github.com/AzureAaron/networth-calculator)
networth_calculator_version = 1.0.0

# Other Libraries
## JGit (https://mvnrepository.com/artifact/org.eclipse.jgit/org.eclipse.jgit)
Expand Down
2 changes: 1 addition & 1 deletion src/main/java/de/hysky/skyblocker/SkyblockerMod.java
Original file line number Diff line number Diff line change
Expand Up @@ -118,7 +118,7 @@ public void onInitializeClient() {
NEURepoManager.init();
//ImageRepoLoader.init();
ItemRepository.init();
PlayerHeadHashCache.init();
SkyblockItemData.init();
HotbarSlotLock.init();
ItemTooltip.init();
AccessoriesHelper.init();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -229,6 +229,14 @@ public static ConfigCategory create(SkyblockerConfig defaults, SkyblockerConfig
newValue -> config.general.itemTooltip.showEssenceCost = newValue)
.controller(ConfigUtils::createBooleanController)
.build())
.option(Option.<Boolean>createBuilder()
.name(Text.translatable("skyblocker.config.general.itemTooltip.enableEstimatedItemValue"))
.description(OptionDescription.of(Text.translatable("skyblocker.config.general.itemTooltip.enableEstimatedItemValue.@Tooltip")))
.binding(defaults.general.itemTooltip.enableEstimatedItemValue,
() -> config.general.itemTooltip.enableEstimatedItemValue,
newValue -> config.general.itemTooltip.enableEstimatedItemValue = newValue)
.controller(ConfigUtils::createBooleanController)
.build())
.build())

//Item Info Display
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -135,6 +135,9 @@ public static class ItemTooltip {

@SerialEntry
public boolean showEssenceCost = false;

@SerialEntry
public boolean enableEstimatedItemValue = true;
}

public enum Average {
Expand Down
26 changes: 17 additions & 9 deletions src/main/java/de/hysky/skyblocker/debug/Debug.java
Original file line number Diff line number Diff line change
Expand Up @@ -8,11 +8,14 @@
import de.hysky.skyblocker.utils.Constants;
import de.hysky.skyblocker.utils.ItemUtils;
import de.hysky.skyblocker.utils.datafixer.ItemStackComponentizationFixer;
import de.hysky.skyblocker.utils.networth.NetworthCalculator;
import net.azureaaron.networth.Calculation;
import net.fabricmc.fabric.api.client.command.v2.ClientCommandRegistrationCallback;
import net.fabricmc.fabric.api.client.command.v2.FabricClientCommandSource;
import net.fabricmc.fabric.api.client.screen.v1.ScreenEvents;
import net.fabricmc.fabric.api.client.screen.v1.ScreenKeyboardEvents;
import net.fabricmc.loader.api.FabricLoader;
import net.minecraft.client.gui.screen.Screen;
import net.minecraft.client.gui.screen.ingame.HandledScreen;
import net.minecraft.entity.decoration.ArmorStandEntity;
import net.minecraft.item.ItemStack;
Expand Down Expand Up @@ -49,20 +52,25 @@ public static void init() {
ClientCommandRegistrationCallback.EVENT.register((dispatcher, registryAccess) -> dispatcher.register(literal(SkyblockerMod.NAMESPACE).then(literal("debug")
.then(dumpPlayersCommand())
.then(ItemUtils.dumpHeldItemCommand())
.then(ItemUtils.dumpHeldItemNetworthCalculationsCommand())
.then(toggleShowingInvisibleArmorStands())
.then(dumpArmorStandHeadTextures())
.then(toggleWebSocketDebug())
)));
ScreenEvents.BEFORE_INIT.register((client, screen, scaledWidth, scaledHeight) -> {
if (screen instanceof HandledScreen<?> handledScreen) {
ScreenKeyboardEvents.afterKeyPress(screen).register((_screen, key, scancode, modifier) -> {
Slot focusedSlot = ((HandledScreenAccessor) handledScreen).getFocusedSlot();
if (key == GLFW.GLFW_KEY_U && client.player != null && focusedSlot != null && focusedSlot.hasStack()) {
client.player.sendMessage(Text.literal("[Skyblocker Debug] Hovered Item: " + SkyblockerMod.GSON_COMPACT.toJson(ItemStack.CODEC.encodeStart(ItemStackComponentizationFixer.getRegistryLookup().getOps(JsonOps.INSTANCE), focusedSlot.getStack()).getOrThrow())));
}
});
}
});
ScreenKeyboardEvents.afterKeyPress(screen).register((_screen, key, scancode, modifier) -> {
Slot focusedSlot = ((HandledScreenAccessor) handledScreen).getFocusedSlot();
if (key == GLFW.GLFW_KEY_U && client.player != null && focusedSlot != null && focusedSlot.hasStack()) {
if (!Screen.hasShiftDown()) {
client.player.sendMessage(Text.literal("[Skyblocker Debug] Hovered Item: " + SkyblockerMod.GSON_COMPACT.toJson(ItemStack.CODEC.encodeStart(ItemStackComponentizationFixer.getRegistryLookup().getOps(JsonOps.INSTANCE), focusedSlot.getStack()).getOrThrow())));
} else {
client.player.sendMessage(Text.literal("[Skyblocker Debug] Held Item NW Calcs: " + SkyblockerMod.GSON_COMPACT.toJson(Calculation.LIST_CODEC.encodeStart(JsonOps.INSTANCE, NetworthCalculator.getItemNetworth(focusedSlot.getStack()).calculations()).getOrThrow())));
}
}
});
}
});
}
}

Expand Down Expand Up @@ -108,4 +116,4 @@ private static LiteralArgumentBuilder<FabricClientCommandSource> dumpArmorStandH
return Command.SINGLE_SUCCESS;
});
}
}
}
3 changes: 2 additions & 1 deletion src/main/java/de/hysky/skyblocker/skyblock/ChestValue.java
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
import de.hysky.skyblocker.mixins.accessors.ScreenAccessor;
import de.hysky.skyblocker.utils.ItemUtils;
import de.hysky.skyblocker.utils.Utils;
import de.hysky.skyblocker.utils.networth.NetworthCalculator;
import it.unimi.dsi.fastutil.doubles.DoubleBooleanPair;
import net.fabricmc.fabric.api.client.screen.v1.ScreenEvents;
import net.fabricmc.fabric.api.client.screen.v1.Screens;
Expand Down Expand Up @@ -192,7 +193,7 @@ public static void init() {

if (!priceData.rightBoolean()) hasIncompleteData = true;

value += priceData.leftDouble() * stack.getCount();
value += NetworthCalculator.getItemNetworth(stack).price();
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@

import java.net.URI;
import java.util.Base64;
import java.util.concurrent.CompletableFuture;

import org.apache.commons.io.FilenameUtils;
import org.slf4j.Logger;
Expand All @@ -12,22 +11,14 @@
import com.google.gson.JsonParser;
import com.mojang.logging.LogUtils;

import de.hysky.skyblocker.utils.Http;
import it.unimi.dsi.fastutil.ints.IntOpenHashSet;

public class PlayerHeadHashCache {
private static final Logger LOGGER = LogUtils.getLogger();
private static final IntOpenHashSet CACHE = new IntOpenHashSet();

public static void init() {
CompletableFuture.runAsync(PlayerHeadHashCache::loadSkins);
}

private static void loadSkins() {
static void loadSkins(JsonArray items) {
try {
String response = Http.sendGetRequest("https://api.hypixel.net/v2/resources/skyblock/items");
JsonArray items = JsonParser.parseString(response).getAsJsonObject().getAsJsonArray("items");

items.asList().stream()
.map(JsonElement::getAsJsonObject)
.filter(item -> item.get("material").getAsString().equals("SKULL_ITEM"))
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@
package de.hysky.skyblocker.skyblock.item;

import java.util.concurrent.CompletableFuture;

import org.slf4j.Logger;

import com.google.gson.JsonArray;
import com.google.gson.JsonObject;
import com.google.gson.JsonParser;
import com.mojang.logging.LogUtils;

import de.hysky.skyblocker.utils.Http;
import de.hysky.skyblocker.utils.networth.NetworthDataSuppliers;

public class SkyblockItemData {
private static final Logger LOGGER = LogUtils.getLogger();

public static void init() {
updateItems().thenAcceptAsync(items -> {
PlayerHeadHashCache.loadSkins(items);
NetworthDataSuppliers.updateSkyblockItemData(items);
});
}

private static CompletableFuture<JsonArray> updateItems() {
return CompletableFuture.supplyAsync(() -> {
try {
String response = Http.sendGetRequest("https://api.hypixel.net/v2/resources/skyblock/items");
JsonObject itemsData = JsonParser.parseString(response).getAsJsonObject();

return itemsData.getAsJsonArray("items");
} catch (Exception e) {
LOGGER.error("[Skyblocker Item Data Loader] Failed to load items data from the Hypixel API!", e);
}

//Complete the future exceptionally so that the other things don't run
throw new IllegalStateException();
});
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -42,16 +42,20 @@ public static void nullWarning() {
}

public static Text getCoinsMessage(double price, int count) {
return getCoinsMessage(price, count, false);
}

public static Text getCoinsMessage(double price, int count, boolean preCounted) {
// Format the price string once
String priceString = String.format(Locale.ENGLISH, "%1$,.1f", price);
String priceString = String.format(Locale.ENGLISH, "%1$,.1f", preCounted ? price / count : price);

// If count is 1, return a simple message
if (count == 1) {
return Text.literal(priceString + " Coins").formatted(Formatting.DARK_AQUA);
}

// If count is greater than 1, include the "each" information
String priceStringTotal = String.format(Locale.ENGLISH, "%1$,.1f", price * count);
String priceStringTotal = String.format(Locale.ENGLISH, "%1$,.1f", preCounted ? price : price * count);

return Text.literal(priceStringTotal + " Coins ").formatted(Formatting.DARK_AQUA)
.append(Text.literal("(" + priceString + " each)").formatted(Formatting.GRAY));
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,15 +17,16 @@

public enum TooltipInfoType implements Runnable {
NPC("https://hysky.de/api/npcprice", itemTooltip -> itemTooltip.enableNPCPrice, true),
BAZAAR("https://hysky.de/api/bazaar", itemTooltip -> itemTooltip.enableBazaarPrice || itemTooltip.enableCraftingCost.getOrder() != null || SkyblockerConfigManager.get().dungeons.dungeonChestProfit.enableProfitCalculator || SkyblockerConfigManager.get().dungeons.dungeonChestProfit.croesusProfit || SkyblockerConfigManager.get().uiAndVisuals.chestValue.enableChestValue || itemTooltip.showEssenceCost, itemTooltip -> itemTooltip.enableBazaarPrice, false, EssenceShopPrice::refreshEssencePrices),
LOWEST_BINS("https://hysky.de/api/auctions/lowestbins", itemTooltip -> itemTooltip.enableLowestBIN || itemTooltip.enableCraftingCost.getOrder() != null || SkyblockerConfigManager.get().dungeons.dungeonChestProfit.enableProfitCalculator || SkyblockerConfigManager.get().dungeons.dungeonChestProfit.croesusProfit || SkyblockerConfigManager.get().uiAndVisuals.chestValue.enableChestValue, itemTooltip -> itemTooltip.enableLowestBIN, false),
BAZAAR("https://hysky.de/api/bazaar", itemTooltip -> itemTooltip.enableBazaarPrice || itemTooltip.enableCraftingCost.getOrder() != null || itemTooltip.enableEstimatedItemValue || SkyblockerConfigManager.get().dungeons.dungeonChestProfit.enableProfitCalculator || SkyblockerConfigManager.get().dungeons.dungeonChestProfit.croesusProfit || SkyblockerConfigManager.get().uiAndVisuals.chestValue.enableChestValue || itemTooltip.showEssenceCost, itemTooltip -> itemTooltip.enableBazaarPrice, false, EssenceShopPrice::refreshEssencePrices),
LOWEST_BINS("https://hysky.de/api/auctions/lowestbins", itemTooltip -> itemTooltip.enableLowestBIN || itemTooltip.enableCraftingCost.getOrder() != null || itemTooltip.enableEstimatedItemValue || SkyblockerConfigManager.get().dungeons.dungeonChestProfit.enableProfitCalculator || SkyblockerConfigManager.get().dungeons.dungeonChestProfit.croesusProfit || SkyblockerConfigManager.get().uiAndVisuals.chestValue.enableChestValue, itemTooltip -> itemTooltip.enableLowestBIN, false),
ONE_DAY_AVERAGE("https://hysky.de/api/auctions/lowestbins/average/1day.json", itemTooltip -> itemTooltip.enableAvgBIN, false),
THREE_DAY_AVERAGE("https://hysky.de/api/auctions/lowestbins/average/3day.json", itemTooltip -> itemTooltip.enableAvgBIN || SkyblockerConfigManager.get().uiAndVisuals.searchOverlay.enableAuctionHouse, itemTooltip -> itemTooltip.enableAvgBIN, false),
MOTES("https://hysky.de/api/motesprice", itemTooltip -> itemTooltip.enableMotesPrice, itemTooltip -> itemTooltip.enableMotesPrice && Utils.isInTheRift(), true),
OBTAINED(itemTooltip -> itemTooltip.enableObtainedDate),
MUSEUM("https://hysky.de/api/museum", itemTooltip -> itemTooltip.enableMuseumInfo, true),
COLOR("https://hysky.de/api/color", itemTooltip -> itemTooltip.enableExoticTooltip, true),
ACCESSORIES("https://hysky.de/api/accessories", itemTooltip -> itemTooltip.enableAccessoriesHelper, true, AccessoriesHelper::refreshData);
ACCESSORIES("https://hysky.de/api/accessories", itemTooltip -> itemTooltip.enableAccessoriesHelper, true, AccessoriesHelper::refreshData),
ESTIMATED_ITEM_VALUE(itemTooltip -> itemTooltip.enableEstimatedItemValue);

private final String address;
private final Predicate<GeneralConfig.ItemTooltip> dataEnabled;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -34,12 +34,13 @@ public class TooltipManager {
new AvgBinTooltip(4),
new EssenceShopPrice(5),
new CraftPriceTooltip(6),
new DungeonQualityTooltip(7),
new MotesTooltip(8),
new ObtainedDateTooltip(9),
new MuseumTooltip(10),
new ColorTooltip(11),
new AccessoryTooltip(12),
new EstimatedItemValueTooltip(7),
new DungeonQualityTooltip(8),
new MotesTooltip(9),
new ObtainedDateTooltip(10),
new MuseumTooltip(11),
new ColorTooltip(12),
new AccessoryTooltip(13),
};
private static final ArrayList<TooltipAdder> currentScreenAdders = new ArrayList<>();

Expand Down
Loading

0 comments on commit 9b95005

Please sign in to comment.