diff options
| author | Roman / Nea <roman.graef@gmail.com> | 2021-12-30 14:37:02 +0100 |
|---|---|---|
| committer | GitHub <noreply@github.com> | 2021-12-30 14:37:02 +0100 |
| commit | b0b0b7567ec0656c60f2f3e4730c0edace353fb7 (patch) | |
| tree | 0e2b23fe4c52b0242cefc8caee9ed887797542b2 /src/main/java/io/github/moulberry/notenoughupdates/util/HotmInformation.java | |
| parent | fc642887639d1918d68f4706e27ea59605a16fcb (diff) | |
| download | notenoughupdates-b0b0b7567ec0656c60f2f3e4730c0edace353fb7.tar.gz notenoughupdates-b0b0b7567ec0656c60f2f3e4730c0edace353fb7.tar.bz2 notenoughupdates-b0b0b7567ec0656c60f2f3e4730c0edace353fb7.zip | |
Adding support for more recipe types and forge recipes (#40)
* Foundations for support of different crafting recipe types.
NeuRecipe is now a base class for a recipe which provides common
concepts, such as inputs, outputs and a rendering task.
GuiItemRecipe has been reworked to work with this new NeuRecipe.
NeuManager now parses said recipes. This should be reworked to be a two
step process (first register items, then register recipes).
To keep compatibility with older repo versions, NeuRecipes are parse
lenient and default to a crafting recipe. New recipes should be added in
the `recipes` json field which is an array of json dictionaries, which
have a `type` and other fields depending on the `type` of that recipe.
This also adds support for having multiple recipes for a single item
(e.g. uncrafting storage blocks).
* Remove references in existing code
* Recipe Generation
* ring recipes
* recipe generator v2
* quick forge
* bugfixes and performance improvements
* fix raw craft cost
* reload hotm if you open the hotm tree inv
* add myself to the changelog
* replace quickforge formular with lookup table
* do not crash anymore when opening recipes outside of skyblock
* format coins differently
* remove debug logs
* change recipe generator so that it doesnt crash old versions
Diffstat (limited to 'src/main/java/io/github/moulberry/notenoughupdates/util/HotmInformation.java')
| -rw-r--r-- | src/main/java/io/github/moulberry/notenoughupdates/util/HotmInformation.java | 179 |
1 files changed, 179 insertions, 0 deletions
diff --git a/src/main/java/io/github/moulberry/notenoughupdates/util/HotmInformation.java b/src/main/java/io/github/moulberry/notenoughupdates/util/HotmInformation.java new file mode 100644 index 00000000..9ca53b5d --- /dev/null +++ b/src/main/java/io/github/moulberry/notenoughupdates/util/HotmInformation.java @@ -0,0 +1,179 @@ +package io.github.moulberry.notenoughupdates.util; + +import com.google.gson.JsonArray; +import com.google.gson.JsonElement; +import com.google.gson.JsonObject; +import io.github.moulberry.notenoughupdates.NotEnoughUpdates; +import net.minecraft.client.Minecraft; +import net.minecraft.client.gui.inventory.GuiChest; +import net.minecraft.inventory.ContainerChest; +import net.minecraftforge.client.event.ClientChatReceivedEvent; +import net.minecraftforge.client.event.GuiOpenEvent; +import net.minecraftforge.common.MinecraftForge; +import net.minecraftforge.event.world.WorldEvent; +import net.minecraftforge.fml.common.eventhandler.SubscribeEvent; + +import java.util.HashMap; +import java.util.Map; +import java.util.Optional; +import java.util.Set; +import java.util.concurrent.CompletableFuture; +import java.util.concurrent.ConcurrentHashMap; + +public class HotmInformation { + private final NotEnoughUpdates neu; + public static final int[] EXPERIENCE_FOR_HOTM_LEVEL = { + // Taken from the wiki: https://hypixel-skyblock.fandom.com/wiki/Heart_of_the_Mountain#Experience_for_Each_Tier + 0, 3000, 12000, 37000, 97000, 197000, 347000 + }; + public static final int[] QUICK_FORGE_MULTIPLIERS = { + 985, + 970, + 955, + 940, + 925, + 910, + 895, + 880, + 865, + 850, + 845, + 840, + 835, + 830, + 825, + 820, + 815, + 810, + 805, + 700 + }; + private final Map<String, Tree> profiles = new ConcurrentHashMap<>(); + + public static class Tree { + private Map<String, Integer> levels = new HashMap<>(); + private int totalMithrilPowder; + private int totalGemstonePowder; + private int hotmExp; + + public int getHotmExp() { + return hotmExp; + } + + public int getTotalGemstonePowder() { + return totalGemstonePowder; + } + + public int getTotalMithrilPowder() { + return totalMithrilPowder; + } + + public Set<String> getAllUnlockedNodes() { + return levels.keySet(); + } + + public int getHotmLevel() { + for (int i = EXPERIENCE_FOR_HOTM_LEVEL.length - 1; i >= 0; i--) { + if (EXPERIENCE_FOR_HOTM_LEVEL[i] >= this.hotmExp) + return i; + } + return 0; + } + + public int getLevel(String node) { + return levels.getOrDefault(node, 0); + } + + } + + private CompletableFuture<Void> updateTask = CompletableFuture.completedFuture(null); + + private boolean shouldReloadSoon = false; + + public HotmInformation(NotEnoughUpdates neu) { + this.neu = neu; + MinecraftForge.EVENT_BUS.register(this); + } + + public Optional<Tree> getInformationOn(String profile) { + if (profile == null) { + return Optional.empty(); + } + return Optional.ofNullable(this.profiles.get(profile)); + } + + public Optional<Tree> getInformationOnCurrentProfile() { + return getInformationOn(neu.manager.getCurrentProfile()); + } + + + @SubscribeEvent + public synchronized void onLobbyJoin(WorldEvent.Load event) { + if (shouldReloadSoon) { + shouldReloadSoon = false; + requestUpdate(false); + } + } + + @SubscribeEvent + public synchronized void onGuiOpen(GuiOpenEvent event) { + if (event.gui instanceof GuiChest) { + String containerName = ((ContainerChest) ((GuiChest) event.gui).inventorySlots).getLowerChestInventory().getDisplayName().getUnformattedText(); + if (containerName.equals("Heart of the Mountain")) + shouldReloadSoon = true; + } + } + + @SubscribeEvent + public synchronized void onChat(ClientChatReceivedEvent event) { + if (event.message.getUnformattedText().equals("Welcome to Hypixel SkyBlock!")) + requestUpdate(false); + } + + public synchronized void requestUpdate(boolean force) { + if (updateTask.isDone() || force) { + updateTask = neu.manager.hypixelApi.getHypixelApiAsync(neu.config.apiKey.apiKey, "skyblock/profiles", new HashMap<String, String>() {{ + put("uuid", Minecraft.getMinecraft().thePlayer.getUniqueID().toString().replace("-", "")); + }}).thenAccept(this::updateInformation); + } + } + + /* + * 1000 = 100% of the time left + * 700 = 70% of the time left + * */ + public static int getQuickForgeMultiplier(int level) { + if (level <= 0) return 1000; + if (level > 20) return -1; + return QUICK_FORGE_MULTIPLIERS[level - 1]; + } + + public void updateInformation(JsonObject entireApiResponse) { + if (!entireApiResponse.has("success") || !entireApiResponse.get("success").getAsBoolean()) return; + JsonArray profiles = entireApiResponse.getAsJsonArray("profiles"); + for (JsonElement element : profiles) { + JsonObject profile = element.getAsJsonObject(); + String profileName = profile.get("cute_name").getAsString(); + JsonObject player = profile.getAsJsonObject("members").getAsJsonObject(Minecraft.getMinecraft().thePlayer.getUniqueID().toString().replace("-", "")); + if (!player.has("mining_core")) + continue; + JsonObject miningCore = player.getAsJsonObject("mining_core"); + Tree tree = new Tree(); + JsonObject nodes = miningCore.getAsJsonObject("nodes"); + for (Map.Entry<String, JsonElement> node : nodes.entrySet()) { + tree.levels.put(node.getKey(), node.getValue().getAsInt()); + } + if (miningCore.has("powder_mithril_total")) { + tree.totalMithrilPowder = miningCore.get("powder_mithril_total").getAsInt(); + } + if (miningCore.has("powder_gemstone_total")) { + tree.totalGemstonePowder = miningCore.get("powder_gemstone_total").getAsInt(); + } + if (miningCore.has("experience")) { + tree.hotmExp = miningCore.get("experience").getAsInt(); + } + this.profiles.put(profileName, tree); + } + } + +} |
