Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Bazaar Lookup/Misc Options #792

Merged
merged 14 commits into from
Jul 29, 2024
2 changes: 2 additions & 0 deletions src/main/java/de/hysky/skyblocker/SkyblockerMod.java
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
import de.hysky.skyblocker.config.datafixer.ConfigDataFixer;
import de.hysky.skyblocker.debug.Debug;
import de.hysky.skyblocker.skyblock.*;
import de.hysky.skyblocker.skyblock.bazaar.BazaarHelper;
import de.hysky.skyblocker.skyblock.calculators.CalculatorCommand;
import de.hysky.skyblocker.skyblock.chat.ChatRuleAnnouncementScreen;
import de.hysky.skyblocker.skyblock.chat.ChatRulesHandler;
Expand Down Expand Up @@ -200,6 +201,7 @@ public void onInitializeClient() {
JerryTimer.init();
TooltipManager.init();
SlotTextManager.init();
BazaarHelper.init();

Scheduler.INSTANCE.scheduleCyclic(Utils::update, 20);
Scheduler.INSTANCE.scheduleCyclic(DiscordRPCManager::updateDataAndPresence, 200);
Expand Down
12 changes: 12 additions & 0 deletions src/main/java/de/hysky/skyblocker/config/ConfigUtils.java
Original file line number Diff line number Diff line change
@@ -1,8 +1,11 @@
package de.hysky.skyblocker.config;

import dev.isxander.yacl3.api.ButtonOption;
import dev.isxander.yacl3.api.Option;
import dev.isxander.yacl3.api.OptionDescription;
import dev.isxander.yacl3.api.controller.*;
import net.minecraft.client.MinecraftClient;
import net.minecraft.client.gui.screen.option.KeybindsScreen;
import net.minecraft.text.Text;
import net.minecraft.util.Formatting;
import net.minecraft.util.Identifier;
Expand Down Expand Up @@ -45,6 +48,15 @@ public static <E extends Enum<E>> Function<Option<E>, ControllerBuilder<E>> getE
return opt -> EnumDropdownControllerBuilder.create(opt).formatValue(formatter);
}

public static ButtonOption createShortcutToKeybindsScreen() {
MinecraftClient client = MinecraftClient.getInstance();
return ButtonOption.createBuilder()
.name(Text.translatable("skyblocker.config.shortcutToKeybindsSettings"))
.action((screen, opt) -> client.setScreen(new KeybindsScreen(screen, client.options)))
.text(Text.translatable("skyblocker.config.shortcutToKeybindsSettings.@Text"))
.build();
}

/**
* Creates an {@link OptionDescription} with an image and text.
*/
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,13 +4,12 @@
import de.hysky.skyblocker.config.ConfigUtils;
import de.hysky.skyblocker.config.SkyblockerConfig;
import de.hysky.skyblocker.config.configs.GeneralConfig;
import de.hysky.skyblocker.skyblock.item.tooltip.adders.CraftPriceTooltip;
import de.hysky.skyblocker.skyblock.item.slottext.SlotTextMode;
import de.hysky.skyblocker.skyblock.item.tooltip.adders.CraftPriceTooltip;
import de.hysky.skyblocker.skyblock.shortcut.ShortcutsConfigScreen;
import dev.isxander.yacl3.api.*;
import dev.isxander.yacl3.api.controller.FloatSliderControllerBuilder;
import net.minecraft.client.MinecraftClient;
import net.minecraft.client.gui.screen.option.KeybindsScreen;
import net.minecraft.text.Text;
import net.minecraft.util.Formatting;

Expand Down Expand Up @@ -244,11 +243,7 @@ public static ConfigCategory create(SkyblockerConfig defaults, SkyblockerConfig
newValue -> config.general.itemInfoDisplay.slotTextMode = newValue)
.controller(ConfigUtils::createEnumCyclingListController)
.build())
.option(ButtonOption.createBuilder()
.name(Text.translatable("skyblocker.config.shortcutToKeybindsSettings"))
.action((screen, opt) -> MinecraftClient.getInstance().setScreen(new KeybindsScreen(screen, MinecraftClient.getInstance().options)))
.text(Text.translatable("skyblocker.config.shortcutToKeybindsSettings.@Text"))
.build())
.option(ConfigUtils.createShortcutToKeybindsScreen())
.option(Option.<Boolean>createBuilder()
.name(Text.translatable("skyblocker.config.general.itemInfoDisplay.attributeShardInfo"))
.description(OptionDescription.of(Text.translatable("skyblocker.config.general.itemInfoDisplay.attributeShardInfo.@Tooltip")))
Expand Down Expand Up @@ -308,11 +303,7 @@ public static ConfigCategory create(SkyblockerConfig defaults, SkyblockerConfig
newValue -> config.general.wikiLookup.enableWikiLookup = newValue)
.controller(ConfigUtils::createBooleanController)
.build())
.option(ButtonOption.createBuilder()
.name(Text.translatable("skyblocker.config.shortcutToKeybindsSettings"))
.action((screen, opt) -> MinecraftClient.getInstance().setScreen(new KeybindsScreen(screen, MinecraftClient.getInstance().options)))
.text(Text.translatable("skyblocker.config.shortcutToKeybindsSettings.@Text"))
.build())
.option(ConfigUtils.createShortcutToKeybindsScreen())
.option(Option.<Boolean>createBuilder()
.name(Text.translatable("skyblocker.config.general.wikiLookup.officialWiki"))
.description(OptionDescription.of(Text.translatable("skyblocker.config.general.wikiLookup.officialWiki.@Tooltip")))
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -219,8 +219,24 @@ public static ConfigCategory create(SkyblockerConfig defaults, SkyblockerConfig
newValue -> config.helpers.bazaar.enableBazaarHelper = newValue)
.controller(ConfigUtils::createBooleanController)
.build())
.option(Option.<Boolean>createBuilder()
.name(Text.translatable("skyblocker.config.helpers.bazaar.enableBazaarLookup"))
.description(OptionDescription.of(Text.translatable("skyblocker.config.helpers.bazaar.enableBazaarLookup.@Tooltip")))
.binding(defaults.helpers.bazaar.enableBazaarLookup,
() -> config.helpers.bazaar.enableBazaarLookup,
newValue -> config.helpers.bazaar.enableBazaarLookup = newValue)
.controller(ConfigUtils::createBooleanController)
.build())
.option(Option.<Boolean>createBuilder()
.name(Text.translatable("skyblocker.config.helpers.bazaar.enableRefreshItemPrices"))
.description(OptionDescription.of(Text.translatable("skyblocker.config.helpers.bazaar.enableRefreshItemPrices.@Tooltip")))
.binding(defaults.helpers.bazaar.enableBazaarRefresh,
() -> config.helpers.bazaar.enableBazaarRefresh,
newValue -> config.helpers.bazaar.enableBazaarRefresh = newValue)
.controller(ConfigUtils::createBooleanController)
.build())
.option(ConfigUtils.createShortcutToKeybindsScreen())
.build())

.build();
}
}
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

why comment out =[

Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@ public static ConfigCategory create(SkyblockerConfig defaults, SkyblockerConfig
//Discord RPC
.group(OptionGroup.createBuilder()
.name(Text.translatable("skyblocker.config.misc.richPresence"))
.collapsed(true)
.option(Option.<Boolean>createBuilder()
.name(Text.translatable("skyblocker.config.misc.richPresence.enableRichPresence"))
.binding(defaults.misc.richPresence.enableRichPresence,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -101,5 +101,11 @@ public static class ChocolateFactory {
public static class Bazaar {
@SerialEntry
public boolean enableBazaarHelper = true;

@SerialEntry
public boolean enableBazaarLookup = true;

@SerialEntry
public boolean enableBazaarRefresh = true;
}
}
17 changes: 14 additions & 3 deletions src/main/java/de/hysky/skyblocker/mixins/HandledScreenMixin.java
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,10 @@
import com.llamalad7.mixinextras.sugar.Local;
import com.mojang.blaze3d.systems.RenderSystem;
import de.hysky.skyblocker.SkyblockerMod;
import de.hysky.skyblocker.config.SkyblockerConfig;
import de.hysky.skyblocker.config.SkyblockerConfigManager;
import de.hysky.skyblocker.skyblock.PetCache;
import de.hysky.skyblocker.skyblock.bazaar.BazaarHelper;
import de.hysky.skyblocker.skyblock.experiment.ChronomatronSolver;
import de.hysky.skyblocker.skyblock.experiment.ExperimentSolver;
import de.hysky.skyblocker.skyblock.experiment.SuperpairsSolver;
Expand Down Expand Up @@ -117,15 +119,24 @@ protected HandledScreenMixin(Text title) {

@Inject(at = @At("HEAD"), method = "keyPressed")
public void skyblocker$keyPressed(int keyCode, int scanCode, int modifiers, CallbackInfoReturnable<Boolean> cir) {
if (this.client != null && this.focusedSlot != null && keyCode != 256) {
if (this.client != null && this.client.player != null && this.focusedSlot != null && keyCode != 256 && !this.client.options.inventoryKey.matchesKey(keyCode, scanCode) && Utils.isOnSkyblock()) {
SkyblockerConfig config = SkyblockerConfigManager.get();
//wiki lookup
if (!this.client.options.inventoryKey.matchesKey(keyCode, scanCode) && WikiLookup.wikiLookup.matchesKey(keyCode, scanCode) && client.player != null) {
if (config.general.wikiLookup.enableWikiLookup && WikiLookup.wikiLookup.matchesKey(keyCode, scanCode)) {
WikiLookup.openWiki(this.focusedSlot, client.player);
}
//item protection
if (!this.client.options.inventoryKey.matchesKey(keyCode, scanCode) && ItemProtection.itemProtection.matchesKey(keyCode, scanCode)) {
if (ItemProtection.itemProtection.matchesKey(keyCode, scanCode)) {
ItemProtection.handleKeyPressed(this.focusedSlot.getStack());
}
//Bazaar Lookup
if (config.helpers.bazaar.enableBazaarLookup && BazaarHelper.BAZAAR_LOOKUP.matchesKey(keyCode, scanCode)) {
BazaarHelper.bazaarLookup(client.player, this.focusedSlot);
}
//Refresh Item Prices
if (config.helpers.bazaar.enableBazaarRefresh && BazaarHelper.BAZAAR_REFRESH.matchesKey(keyCode, scanCode)) {
BazaarHelper.refreshItemPrices(this.client.player);
}
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,15 @@
import de.hysky.skyblocker.config.SkyblockerConfigManager;
import de.hysky.skyblocker.skyblock.item.slottext.SimpleSlotTextAdder;
import de.hysky.skyblocker.skyblock.item.slottext.SlotText;
import de.hysky.skyblocker.skyblock.item.tooltip.ItemTooltip;
import de.hysky.skyblocker.skyblock.item.tooltip.TooltipInfoType;
import de.hysky.skyblocker.skyblock.itemlist.ItemRepository;
import de.hysky.skyblocker.utils.Constants;
import de.hysky.skyblocker.utils.ItemUtils;
import de.hysky.skyblocker.utils.scheduler.MessageScheduler;
import net.fabricmc.fabric.api.client.keybinding.v1.KeyBindingHelper;
import net.minecraft.client.network.ClientPlayerEntity;
import net.minecraft.client.option.KeyBinding;
import net.minecraft.item.ItemStack;
import net.minecraft.screen.slot.Slot;
import net.minecraft.text.MutableText;
Expand All @@ -12,8 +20,11 @@
import org.apache.commons.lang3.math.NumberUtils;
import org.jetbrains.annotations.NotNull;
import org.jetbrains.annotations.Nullable;
import org.lwjgl.glfw.GLFW;

import java.util.ArrayList;
import java.util.List;
import java.util.concurrent.CompletableFuture;
import java.util.regex.Matcher;
import java.util.regex.Pattern;

Expand All @@ -23,10 +34,23 @@ public class BazaarHelper extends SimpleSlotTextAdder {
private static final int YELLOW = 0xe6ba0b;
private static final int GREEN = 0x1ee60b;

public BazaarHelper() {
public static final KeyBinding BAZAAR_LOOKUP = KeyBindingHelper.registerKeyBinding(new KeyBinding(
"key.bazaarLookup",
GLFW.GLFW_KEY_F6,
"key.categories.skyblocker"
));
public static final KeyBinding BAZAAR_REFRESH = KeyBindingHelper.registerKeyBinding(new KeyBinding(
"key.bazaarRefresh",
GLFW.GLFW_KEY_Z,
"key.categories.skyblocker"
));

public BazaarHelper() {
super("(?:Co-op|Your) Bazaar Orders");
}

public static void init() {}

@Override
public boolean isEnabled() {
return SkyblockerConfigManager.get().helpers.bazaar.enableBazaarHelper;
Expand Down Expand Up @@ -76,4 +100,32 @@ public boolean isEnabled() {
if (filled < 100) return Text.literal("%").withColor(YELLOW).formatted(Formatting.BOLD);
return Text.literal("✅").withColor(GREEN).formatted(Formatting.BOLD);
}

// ======== Other Bazaar Features ========

public static void bazaarLookup(ClientPlayerEntity player, @NotNull Slot slot) {
ItemStack stack = ItemRepository.getItemStack(slot.getStack().getNeuName());
if (stack != null && !stack.isEmpty()) {
MessageScheduler.INSTANCE.sendMessageAfterCooldown("/bz " + Formatting.strip(stack.getName().getString()));
} else {
player.sendMessage(Constants.PREFIX.get().append(Text.translatable("skyblocker.config.helpers.bazaar.bazaarLookupFailed")));
}
}

public static void refreshItemPrices(ClientPlayerEntity player) {
player.sendMessage(Constants.PREFIX.get().append(Text.translatable("skyblocker.config.helpers.bazaar.refreshingItemPrices")));
List<CompletableFuture<Void>> futureList = new ArrayList<>();
TooltipInfoType.NPC.downloadIfEnabled(futureList);
TooltipInfoType.BAZAAR.downloadIfEnabled(futureList);
TooltipInfoType.LOWEST_BINS.downloadIfEnabled(futureList);
TooltipInfoType.ONE_DAY_AVERAGE.downloadIfEnabled(futureList);
TooltipInfoType.THREE_DAY_AVERAGE.downloadIfEnabled(futureList);
CompletableFuture.allOf(futureList.toArray(CompletableFuture[]::new))
.thenAccept(_void -> player.sendMessage(Constants.PREFIX.get().append(Text.translatable("skyblocker.config.helpers.bazaar.refreshedItemPrices"))))
.exceptionally(e -> {
ItemTooltip.LOGGER.error("[Skyblocker] Failed to refresh item prices", e);
player.sendMessage(Constants.PREFIX.get().append(Text.translatable("skyblocker.config.helpers.bazaar.refreshItemPricesFailed")));
return null;
});
}
}
Original file line number Diff line number Diff line change
@@ -1,10 +1,8 @@
package de.hysky.skyblocker.skyblock.item;

import de.hysky.skyblocker.config.SkyblockerConfigManager;
import de.hysky.skyblocker.skyblock.itemlist.ItemRepository;
import de.hysky.skyblocker.utils.Constants;
import de.hysky.skyblocker.utils.ItemUtils;
import de.hysky.skyblocker.utils.Utils;
import net.fabricmc.fabric.api.client.keybinding.v1.KeyBindingHelper;
import net.minecraft.client.option.KeyBinding;
import net.minecraft.client.util.InputUtil;
Expand Down Expand Up @@ -33,8 +31,6 @@ public static void init() {
}

public static void openWiki(@NotNull Slot slot, @NotNull PlayerEntity player) {
if (!Utils.isOnSkyblock() || !SkyblockerConfigManager.get().general.wikiLookup.enableWikiLookup) return;

ItemUtils.getItemIdOptional(slot.getStack())
.map(ItemRepository::getWikiLink)
.ifPresentOrElse(wikiLink -> CompletableFuture.runAsync(() -> Util.getOperatingSystem().open(wikiLink)).exceptionally(e -> {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@
import java.util.concurrent.CompletableFuture;

public class ItemTooltip {
protected static final Logger LOGGER = LoggerFactory.getLogger(ItemTooltip.class.getName());
public static final Logger LOGGER = LoggerFactory.getLogger(ItemTooltip.class.getName());
private static final MinecraftClient client = MinecraftClient.getInstance();
public static final GeneralConfig.ItemTooltip config = SkyblockerConfigManager.get().general.itemTooltip;
private static volatile boolean sentNullWarning = false;
Expand Down Expand Up @@ -127,7 +127,7 @@ public static void init() {
TooltipInfoType.ACCESSORIES.downloadIfEnabled(futureList);

CompletableFuture.allOf(futureList.toArray(CompletableFuture[]::new)).exceptionally(e -> {
LOGGER.error("Encountered unknown error while downloading tooltip data", e);
LOGGER.error("[Skyblocker] Encountered unknown error while downloading tooltip data", e);
return null;
});

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -68,8 +68,8 @@ private static void loadRecipes(NEUItem item) {
}
}

public static String getWikiLink(String internalName) {
NEUItem item = NEURepoManager.NEU_REPO.getItems().getItemBySkyblockId(internalName);
public static String getWikiLink(String neuId) {
NEUItem item = NEURepoManager.NEU_REPO.getItems().getItemBySkyblockId(neuId);
if (item == null || item.getInfo() == null || item.getInfo().isEmpty()) {
return null;
}
Expand All @@ -86,14 +86,14 @@ public static String getWikiLink(String internalName) {
return null;
}

public static List<SkyblockCraftingRecipe> getRecipes(String internalName) {
public static List<SkyblockCraftingRecipe> getRecipes(String neuId) {
List<SkyblockCraftingRecipe> result = new ArrayList<>();
for (SkyblockCraftingRecipe recipe : recipes) {
if (ItemUtils.getItemId(recipe.getResult()).equals(internalName)) result.add(recipe);
if (ItemUtils.getItemId(recipe.getResult()).equals(neuId)) result.add(recipe);
}
for (SkyblockCraftingRecipe recipe : recipes) {
for (ItemStack ingredient : recipe.getGrid()) {
if (!ingredient.getItem().equals(Items.AIR) && ItemUtils.getItemId(ingredient).equals(internalName)) {
if (!ingredient.getItem().equals(Items.AIR) && ItemUtils.getItemId(ingredient).equals(neuId)) {
result.add(recipe);
break;
}
Expand Down
3 changes: 1 addition & 2 deletions src/main/java/de/hysky/skyblocker/utils/Utils.java
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,6 @@
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;
Expand Down Expand Up @@ -523,7 +522,7 @@ private static void tickMayorCache() {
}).exceptionally(throwable -> {
LOGGER.error("[Skyblocker] Failed to get mayor status!", throwable.getCause());
if (mayorTickRetryAttempts < 5) {
int minutes = 5 * 1 << mayorTickRetryAttempts; //5, 10, 20, 40, 80 minutes
int minutes = 5 << mayorTickRetryAttempts; //5, 10, 20, 40, 80 minutes
mayorTickRetryAttempts++;
LOGGER.warn("[Skyblocker] Retrying in {} minutes.", minutes);
Scheduler.INSTANCE.schedule(Utils::tickMayorCache, minutes * 60 * 20);
Expand Down
Loading