Skip to content

Commit

Permalink
feat: Add open guild bank keybind [skip ci] (#2470)
Browse files Browse the repository at this point in the history
  • Loading branch information
kristofbolyai committed May 7, 2024
1 parent 1d83ba3 commit 9267c1e
Show file tree
Hide file tree
Showing 3 changed files with 57 additions and 0 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -65,6 +65,7 @@
import com.wynntils.features.inventory.EmeraldPouchFillArcFeature;
import com.wynntils.features.inventory.EmeraldPouchHotkeyFeature;
import com.wynntils.features.inventory.ExtendedItemCountFeature;
import com.wynntils.features.inventory.GuildBankHotkeyFeature;
import com.wynntils.features.inventory.HightlightDuplicateCosmeticsFeature;
import com.wynntils.features.inventory.IngredientPouchHotkeyFeature;
import com.wynntils.features.inventory.InventoryEmeraldCountFeature;
Expand Down Expand Up @@ -256,6 +257,7 @@ public void init() {
registerFeature(new EmeraldPouchFillArcFeature());
registerFeature(new EmeraldPouchHotkeyFeature());
registerFeature(new ExtendedItemCountFeature());
registerFeature(new GuildBankHotkeyFeature());
registerFeature(new HightlightDuplicateCosmeticsFeature());
registerFeature(new IngredientPouchHotkeyFeature());
registerFeature(new InventoryEmeraldCountFeature());
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,53 @@
/*
* Copyright © Wynntils 2024.
* This file is released under LGPLv3. See LICENSE for full license details.
*/
package com.wynntils.features.inventory;

import com.wynntils.core.components.Handlers;
import com.wynntils.core.consumers.features.Feature;
import com.wynntils.core.consumers.features.properties.RegisterKeyBind;
import com.wynntils.core.keybinds.KeyBind;
import com.wynntils.core.persisted.config.Category;
import com.wynntils.core.persisted.config.ConfigCategory;
import com.wynntils.core.text.StyledText;
import com.wynntils.mc.event.MenuEvent;
import com.wynntils.utils.mc.McUtils;
import com.wynntils.utils.wynn.ContainerUtils;
import java.util.regex.Pattern;
import net.minecraft.world.inventory.AbstractContainerMenu;
import net.minecraftforge.eventbus.api.SubscribeEvent;
import org.lwjgl.glfw.GLFW;

@ConfigCategory(Category.INVENTORY)
public class GuildBankHotkeyFeature extends Feature {
private static final Pattern MANAGE_TITLE_PATTERN = Pattern.compile(".+: Manage");
private static final int GUILD_BANK_SLOT = 15;

@RegisterKeyBind
private final KeyBind guildBankKeybind =
new KeyBind("Open Guild Bank", GLFW.GLFW_KEY_P, true, this::onOpenGuildBankKeyPress);

private boolean openGuildBank = false;

@SubscribeEvent
public void onMenuOpenPre(MenuEvent.MenuOpenedEvent.Pre event) {
if (!openGuildBank) return;

openGuildBank = false;

// We cannot use ContainerModel here, as it is too early in the event chain.
StyledText title = StyledText.fromComponent(event.getTitle());
if (title.matches(MANAGE_TITLE_PATTERN)) {
event.setCanceled(true);

AbstractContainerMenu container = event.getMenuType().create(event.getContainerId(), McUtils.inventory());
ContainerUtils.clickOnSlot(GUILD_BANK_SLOT, event.getContainerId(), 0, container.getItems());
}
}

private void onOpenGuildBankKeyPress() {
openGuildBank = true;
Handlers.Command.sendCommandImmediately("guild manage");
}
}
2 changes: 2 additions & 0 deletions common/src/main/resources/assets/wynntils/lang/en_us.json
Original file line number Diff line number Diff line change
Expand Up @@ -532,6 +532,8 @@
"feature.wynntils.gammabright.name": "Gammabright Keybind",
"feature.wynntils.gearViewer.description": "Adds the ability to view other players' gear in a GUI.",
"feature.wynntils.gearViewer.name": "Gear Viewer",
"feature.wynntils.guildBankHotkey.description": "Adds a hotkey to open the guild bank.",
"feature.wynntils.guildBankHotkey.name": "Guild Bank Hotkey",
"feature.wynntils.guildMap.description": "Adds a guild map to view territories.",
"feature.wynntils.guildMap.name": "Guild Map",
"feature.wynntils.guildMap.pointerColor.description": "What color should the main map pointer be?",
Expand Down

0 comments on commit 9267c1e

Please sign in to comment.