Skip to content

Commit

Permalink
Added support for accessory bag reforging to the reforge matcher
Browse files Browse the repository at this point in the history
  • Loading branch information
ILikePlayingGames authored and biscuut committed Sep 16, 2020
1 parent 192406f commit 55a2f35
Show file tree
Hide file tree
Showing 7 changed files with 82 additions and 52 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@
import codes.biscuit.skyblockaddons.gui.IslandWarpGui;
import codes.biscuit.skyblockaddons.gui.elements.CraftingPatternSelection;
import codes.biscuit.skyblockaddons.utils.ColorCode;
import lombok.Setter;
import net.minecraft.client.Minecraft;
import net.minecraft.client.gui.FontRenderer;
import net.minecraft.client.gui.GuiTextField;
Expand All @@ -36,6 +37,7 @@ public class GuiChestHook {

private static GuiTextField textFieldMatch = null;
private static GuiTextField textFieldExclusions = null;
@Setter private static String lastAccessoryBagReforge = null;
private static CraftingPatternSelection craftingPatternSelection = null;

private static Pattern warpPattern = Pattern.compile("(?:§5§o)?§8/warp ([a-z_]*)");
Expand All @@ -52,8 +54,12 @@ public static void updateScreen() {
}
}

/**
* Resets variables when the chest is closed
*/
public static void onGuiClosed() {
SkyblockAddons.getInstance().getInventoryUtils().updateInventoryType();
lastAccessoryBagReforge = null;
if (textFieldMatch != null && textFieldExclusions != null) {
Keyboard.enableRepeatEvents(false);
}
Expand Down Expand Up @@ -147,10 +153,11 @@ public static void drawScreen(int guiLeft, int guiTop) {
InventoryType inventoryType = SkyblockAddons.getInstance().getInventoryUtils().updateInventoryType();

if (textFieldMatch != null && (inventoryType == InventoryType.ENCHANTMENT_TABLE ||
inventoryType== InventoryType.BASIC_REFORGING)) {
inventoryType== InventoryType.BASIC_REFORGING || inventoryType == InventoryType.BASIC_ACCESSORY_BAG_REFORGING)) {
Minecraft mc = Minecraft.getMinecraft();
SkyblockAddons main = SkyblockAddons.getInstance();
String inventoryMessage = inventoryType.getMessage();
String typeToMatch = inventoryType == InventoryType.ENCHANTMENT_TABLE ? Message.MESSAGE_ENCHANTS.getMessage()
: Message.MESSAGE_REFORGES.getMessage();
String inclusionExample;
String exclusionExample;
int defaultBlue = main.getUtils().getDefaultBlue(255);
Expand All @@ -172,10 +179,10 @@ public static void drawScreen(int guiLeft, int guiTop) {
GlStateManager.color(1F, 1F, 1F);
GlStateManager.pushMatrix();
GlStateManager.scale(scale, scale, 1);
mc.fontRendererObj.drawString(Message.MESSAGE_TYPE_ENCHANTMENTS.getMessage(inventoryMessage), Math.round(x/scale), Math.round((guiTop+40)/scale), defaultBlue);
mc.fontRendererObj.drawString(Message.MESSAGE_TYPE_ENCHANTMENTS.getMessage(typeToMatch), Math.round(x/scale), Math.round((guiTop+40)/scale), defaultBlue);
mc.fontRendererObj.drawString(Message.MESSAGE_SEPARATE_ENCHANTMENTS.getMessage(), Math.round(x/scale), Math.round((guiTop + 50)/scale), defaultBlue);
mc.fontRendererObj.drawString(Message.MESSAGE_ENCHANTS_TO_MATCH.getMessage(inventoryMessage), Math.round(x/scale), Math.round((guiTop + 70)/scale), defaultBlue);
mc.fontRendererObj.drawString(Message.MESSAGE_ENCHANTS_TO_EXCLUDE.getMessage(inventoryMessage), Math.round(x/scale), Math.round((guiTop + 110)/scale), defaultBlue);
mc.fontRendererObj.drawString(Message.MESSAGE_ENCHANTS_TO_MATCH.getMessage(typeToMatch), Math.round(x/scale), Math.round((guiTop + 70)/scale), defaultBlue);
mc.fontRendererObj.drawString(Message.MESSAGE_ENCHANTS_TO_EXCLUDE.getMessage(typeToMatch), Math.round(x/scale), Math.round((guiTop + 110)/scale), defaultBlue);
GlStateManager.popMatrix();

textFieldMatch.drawTextBox();
Expand Down Expand Up @@ -251,7 +258,8 @@ public static void initGui(IInventory lowerChestInventory, int guiLeft, int guiT
if (SkyblockAddons.getInstance().getUtils().isOnSkyblock()) {
InventoryType inventoryType = SkyblockAddons.getInstance().getInventoryUtils().getInventoryType();

if ((inventoryType == InventoryType.ENCHANTMENT_TABLE || inventoryType == InventoryType.BASIC_REFORGING)) {
if (inventoryType == InventoryType.ENCHANTMENT_TABLE || inventoryType== InventoryType.BASIC_REFORGING ||
inventoryType == InventoryType.BASIC_ACCESSORY_BAG_REFORGING) {
if (keyCode != Minecraft.getMinecraft().gameSettings.keyBindInventory.getKeyCode() ||
(!textFieldMatch.isFocused() && !textFieldExclusions.isFocused())) {
processTextFields(typedChar, keyCode);
Expand Down Expand Up @@ -308,18 +316,27 @@ public static void handleMouseClick(Slot slotIn, Container slots, IInventory low
}
}
}
} else if (slotIn.getSlotIndex() == 22 && main.getInventoryUtils().getInventoryType() == InventoryType.BASIC_REFORGING) {
} else if (slotIn.getSlotIndex() == 22 && (main.getInventoryUtils().getInventoryType() ==
InventoryType.BASIC_REFORGING || main.getInventoryUtils().getInventoryType() ==
InventoryType.BASIC_ACCESSORY_BAG_REFORGING)) {
Slot itemSlot = slots.getSlot(13);
if (itemSlot != null && itemSlot.getHasStack()) {
ItemStack item = itemSlot.getStack();
if (item.hasDisplayName()) {
String reforge = main.getUtils().getReforgeFromItem(item);
if (reforge != null) {
if (main.getUtils().enchantReforgeMatches(reforge)) {
main.getUtils().playLoudSound("random.orb", 0.1);
returnValue.cancel();
if (main.getInventoryUtils().getInventoryType() == InventoryType.BASIC_REFORGING) {
ItemStack item = itemSlot.getStack();
if (item.hasDisplayName()) {
String reforge = main.getUtils().getReforgeFromItem(item);
if (reforge != null) {
if (main.getUtils().enchantReforgeMatches(reforge)) {
main.getUtils().playLoudSound("random.orb", 0.1);
returnValue.cancel();
}
}
}
} else {
if (lastAccessoryBagReforge != null && main.getUtils().enchantReforgeMatches(lastAccessoryBagReforge)) {
main.getUtils().playLoudSound("random.orb", 0.1);
returnValue.cancel();
}
}
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -48,13 +48,16 @@ public class GuiContainerHook {

public static void showEnchantments(Slot slotIn, int x, int y, ItemStack item) {
SkyblockAddons main = SkyblockAddons.getInstance();

if (main.getConfigValues().isEnabled(Feature.SHOW_ENCHANTMENTS_REFORGES)) {
Minecraft mc = Minecraft.getMinecraft();

if (item != null && item.hasDisplayName()) {
if (item.getDisplayName().startsWith(ColorCode.GREEN + "Enchant Item")) {
List<String> toolip = item.getTooltip(mc.thePlayer, false);
if (toolip.size() > 2) {
String enchantLine = toolip.get(2);
List<String> tooltip = item.getTooltip(mc.thePlayer, false);

if (tooltip.size() > 2) {
String enchantLine = tooltip.get(2);
String[] lines = enchantLine.split(Pattern.quote("* "));
if (lines.length >= 2) {
String toMatch = lines[1];
Expand Down
20 changes: 8 additions & 12 deletions src/main/java/codes/biscuit/skyblockaddons/core/InventoryType.java
Original file line number Diff line number Diff line change
Expand Up @@ -11,22 +11,18 @@
* This is an enum containing different menus in Skyblock. It's used in logic where the menu the player is in matters.
*/
public enum InventoryType {
ENCHANTMENT_TABLE(INVENTORY_TYPE_ENCHANTS, "Enchant Item"),
BASIC_REFORGING(INVENTORY_TYPE_REFORGES, "Reforge Item"),
ADVANCED_REFORGING(INVENTORY_TYPE_REFORGES, "Reforge Item"),
BAKER(null, "Baker"),
CRAFTING_TABLE(INVENTORY_TYPE_CRAFTING, CraftingPattern.CRAFTING_TABLE_DISPLAYNAME);
ENCHANTMENT_TABLE("Enchant Item"),
BASIC_REFORGING("Reforge Item"),
ADVANCED_REFORGING("Reforge Item"),
BASIC_ACCESSORY_BAG_REFORGING("Reforge Accessory Bag"),
ADVANCED_ACCESSORY_BAG_REFORGING("Reforge Accessory Bag"),
BAKER("Baker"),
CRAFTING_TABLE(CraftingPattern.CRAFTING_TABLE_DISPLAYNAME);

private final Message message;
@Getter
private final String inventoryName;

InventoryType(Message message, String inventoryName) {
this.message = message;
InventoryType(String inventoryName) {
this.inventoryName = inventoryName;
}

public String getMessage() {
return message.getMessage();
}
}
6 changes: 2 additions & 4 deletions src/main/java/codes/biscuit/skyblockaddons/core/Message.java
Original file line number Diff line number Diff line change
Expand Up @@ -133,6 +133,8 @@ public enum Message {
BACKPACK_STYLE_REGULAR(MessageObject.BACKPACK_STYLE, "regular"),
BACKPACK_STYLE_COMPACT(MessageObject.BACKPACK_STYLE, "compact"),

MESSAGE_ENCHANTS(MessageObject.INVENTORY_TYPE, "enchants"),
MESSAGE_REFORGES(MessageObject.INVENTORY_TYPE, "reforges"),
MESSAGE_DROP_CONFIRMATION(MessageObject.MESSAGES, "dropConfirmation"),
MESSAGE_MAGMA_BOSS_WARNING(MessageObject.MESSAGES, "magmaBossWarning"),
MESSAGE_FULL_INVENTORY(MessageObject.MESSAGES, "fullInventory"),
Expand Down Expand Up @@ -211,10 +213,6 @@ public enum Message {
@Deprecated TAB_GUI_FEATURES(MessageObject.TAB, "guiFeatures"),
TAB_GENERAL_SETTINGS(MessageObject.TAB, "generalSettings"),

INVENTORY_TYPE_ENCHANTS(MessageObject.INVENTORY_TYPE, "enchants"),
INVENTORY_TYPE_REFORGES(MessageObject.INVENTORY_TYPE, "reforges"),
INVENTORY_TYPE_CRAFTING(MessageObject.INVENTORY_TYPE, "crafting"),

POWER_ORB_DISPLAY_STYLE_DETAILED(MessageObject.POWER_ORB_STYLE, "detailed"),
POWER_ORB_DISPLAY_STYLE_COMPACT(MessageObject.POWER_ORB_STYLE, "compact"),

Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
package codes.biscuit.skyblockaddons.listeners;

import codes.biscuit.skyblockaddons.SkyblockAddons;
import codes.biscuit.skyblockaddons.asm.hooks.GuiChestHook;
import codes.biscuit.skyblockaddons.core.Attribute;
import codes.biscuit.skyblockaddons.core.Feature;
import codes.biscuit.skyblockaddons.core.Location;
Expand Down Expand Up @@ -71,15 +72,19 @@
import java.util.regex.Matcher;
import java.util.regex.Pattern;

//TODO Fix for Hypixel localization
public class PlayerListener {

private static final Pattern NO_ARROWS_LEFT_PATTERN = Pattern.compile("(?:§r)?§cYou don't have any more Arrows left in your Quiver!§r");
private static final Pattern ONLY_HAVE_ARROWS_LEFT_PATTERN = Pattern.compile("(?:§r)?§cYou only have (?<arrows>[0-9]+) Arrows left in your Quiver!§r");
private final static Pattern ENCHANTMENT_TOOLTIP_PATTERN = Pattern.compile("§.§.(§9[\\w ]+(, )?)+");
private final static Pattern ABILITY_CHAT_PATTERN = Pattern.compile("§r§aUsed §r§6[A-Za-z ]+§r§a! §r§b\\([0-9]+ Mana\\)§r");
private final static Pattern PROFILE_CHAT_PATTERN = Pattern.compile("§aYou are playing on profile: §e([A-Za-z]+).*");
private final static Pattern SWITCH_PROFILE_CHAT_PATTERN = Pattern.compile("§aYour profile was changed to: §e([A-Za-z]+).*");
private final static Pattern MINION_CANT_REACH_PATTERN = Pattern.compile("§cI can't reach any (?<mobName>[A-Za-z]*)(?:s)");
private static final Pattern ENCHANTMENT_TOOLTIP_PATTERN = Pattern.compile("§.§.(§9[\\w ]+(, )?)+");
private static final Pattern ABILITY_CHAT_PATTERN = Pattern.compile("§r§aUsed §r§6[A-Za-z ]+§r§a! §r§b\\([0-9]+ Mana\\)§r");
private static final Pattern PROFILE_CHAT_PATTERN = Pattern.compile("§aYou are playing on profile: §e([A-Za-z]+).*");
private static final Pattern SWITCH_PROFILE_CHAT_PATTERN = Pattern.compile("§aYour profile was changed to: §e([A-Za-z]+).*");
private static final Pattern MINION_CANT_REACH_PATTERN = Pattern.compile("§cI can't reach any (?<mobName>[A-Za-z]*)(?:s)");
private static final Pattern DEATH_MESSAGE_PATTERN = Pattern.compile("§r§c ☠ §r(?:§[\\da-fk-or])(?<playerName>\\w+)(?<afterNameFormatting>§r§7)* (?<causeOfDeath>.+)§r§7\\.§r");
private static final Pattern REVIVE_MESSAGE_PATTERN = Pattern.compile("§r§a ❣ §r(?:§[\\da-fk-or])(?<revivedPlayer>\\w+)§r§a was revived(?: by §r(?:§[\\da-fk-or])(?<reviver>\\w+)§r§a)*!§r");
private static final Pattern ACCESSORY_BAG_REFORGE_PATTERN = Pattern.compile("You applied the (?<reforge>\\w+) reforge to (?:\\d+) accessories in your Accessory Bag!");

private final static Set<String> SOUP_RANDOM_MESSAGES = new HashSet<>(Arrays.asList("I feel like I can fly!", "What was in that soup?",
"Hmm… tasty!", "Hmm... tasty!", "You can now fly for 2 minutes.", "Your flight has been extended for 2 extra minutes.",
Expand Down Expand Up @@ -168,8 +173,10 @@ public void onChunkLoad(ChunkEvent.Load e) {
@SubscribeEvent(priority = EventPriority.HIGH)
public void onChatReceive(ClientChatReceivedEvent e) {
String unformattedText = e.message.getUnformattedText();

// Type 2 means it's an action bar message.
if (e.type == 2) {
// action bar message, parse using ActionBarParser and display the rest message instead
// Parse using ActionBarParser and display the rest message instead
String restMessage = actionBarParser.parseActionBar(unformattedText);
if (main.isUsingOofModv1() && restMessage.trim().length() == 0) {
e.setCanceled(true);
Expand All @@ -178,6 +185,8 @@ public void onChatReceive(ClientChatReceivedEvent e) {
} else {
String formattedText = e.message.getFormattedText();

Matcher matcher;

if (main.getRenderListener().isPredictMana() && unformattedText.startsWith("Used ") && unformattedText.endsWith("Mana)")) {
int manaLost = Integer.parseInt(unformattedText.split(Pattern.quote("! ("))[1].split(Pattern.quote(" Mana)"))[0]);
changeMana(-manaLost);
Expand Down Expand Up @@ -229,10 +238,12 @@ public void onChatReceive(ClientChatReceivedEvent e) {
} else {
this.rainmakerTimeEnd += (1000*60); // Extend the timer one minute.
}
} else if (main.getConfigValues().isEnabled(Feature.SHOW_ENCHANTMENTS_REFORGES) &&
(matcher = ACCESSORY_BAG_REFORGE_PATTERN.matcher(unformattedText)).matches()) {
GuiChestHook.setLastAccessoryBagReforge(matcher.group("reforge"));
}

if (main.getConfigValues().isEnabled(Feature.NO_ARROWS_LEFT_ALERT)) {
Matcher matcher;
if (NO_ARROWS_LEFT_PATTERN.matcher(formattedText).matches()) {
main.getUtils().playLoudSound("random.orb", 0.5);
main.getRenderListener().setSubtitleFeature(Feature.NO_ARROWS_LEFT_ALERT);
Expand All @@ -248,7 +259,7 @@ public void onChatReceive(ClientChatReceivedEvent e) {
}
}

Matcher matcher = ABILITY_CHAT_PATTERN.matcher(formattedText);
matcher = ABILITY_CHAT_PATTERN.matcher(formattedText);
if (matcher.matches()) {
CooldownManager.put(Minecraft.getMinecraft().thePlayer.getHeldItem());
} else {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -332,7 +332,7 @@ public InventoryType updateInventoryType() {

for (InventoryType inventoryType : InventoryType.values()) {
if (inventoryType.getInventoryName().equals(inventory.getDisplayName().getUnformattedText())) {
if (inventoryType == InventoryType.BASIC_REFORGING) {
if (inventoryType == InventoryType.BASIC_REFORGING || inventoryType == InventoryType.BASIC_ACCESSORY_BAG_REFORGING) {
return this.inventoryType = getReforgeInventoryType(inventory);
}
else {
Expand All @@ -344,12 +344,18 @@ public InventoryType updateInventoryType() {
return this.inventoryType = null;
}

// Gets the reforge inventory type (basic/advanced) from a given reforge inventory
// Gets the reforge inventory type from a given reforge inventory
private InventoryType getReforgeInventoryType(IInventory inventory) {
if (!inventory.getDisplayName().getUnformattedText().equals(InventoryType.BASIC_REFORGING.getInventoryName())) {
if (!inventory.getDisplayName().getUnformattedText().equals(InventoryType.BASIC_REFORGING.getInventoryName()) &&
!inventory.getDisplayName().getUnformattedText().equals(InventoryType.BASIC_ACCESSORY_BAG_REFORGING.
getInventoryName())) {
throw new IllegalArgumentException("The given inventory is not a reforge inventory!");
}

// This records whether the inventory is for reforging a single item or the accessory bag
InventoryType baseType = inventory.getDisplayName().getUnformattedText().equals(InventoryType.BASIC_REFORGING.
getInventoryName()) ? InventoryType.BASIC_REFORGING : InventoryType.BASIC_ACCESSORY_BAG_REFORGING;

// This is the barrier item that's present in the advanced reforging menu. This slot is empty in the basic reforging menu.
ItemStack barrier = inventory.getStackInSlot(13);
// This is the stained glass pane to the right of the barrier.
Expand All @@ -358,14 +364,16 @@ private InventoryType getReforgeInventoryType(IInventory inventory) {
/*
If the barrier is there, it's the advanced reforging menu. If it's not there (since the player placed an item in
the menu), check if the glass pane next to the slot is named "Reforge Stone." That indicates it's the advanced
reforging menu. Otherwise, it's the basic menu.
reforging menu. Otherwise, it's the basic menu. Finally, check if it's the single item or accessory bag menu.
*/
if (barrier != null && barrier.getItem().equals(Item.getByNameOrId("barrier")) || glassPane != null &&
glassPane.hasDisplayName() && TextUtils.stripColor(glassPane.getDisplayName()).equals("Reforge Stone")) {
return InventoryType.ADVANCED_REFORGING;
return baseType == InventoryType.BASIC_REFORGING ? InventoryType.ADVANCED_REFORGING :
InventoryType.ADVANCED_ACCESSORY_BAG_REFORGING;
}
else {
return InventoryType.BASIC_REFORGING;
return baseType == InventoryType.BASIC_REFORGING ? InventoryType.BASIC_REFORGING :
InventoryType.BASIC_ACCESSORY_BAG_REFORGING;
}
}
}
7 changes: 2 additions & 5 deletions src/main/resources/lang/en_us.json
Original file line number Diff line number Diff line change
Expand Up @@ -132,6 +132,8 @@
"turnAllFeaturesChroma": "Turn All Features Chroma"
},
"messages": {
"enchants": "Enchants",
"reforges": "Reforges",
"dropConfirmation": "Drop this item again to confirm!",
"magmaBossWarning": "Magma Cube Boss!",
"fullInventory": "Full Inventory!",
Expand All @@ -142,11 +144,6 @@
"separateMultiple": "Separate Multiple With Commas.",
"enchantsToMatch": "%type% To Match:",
"enchantsToExclude": "%type% To Exclude:",
"inventoryTypes": {
"enchants": "Enchants",
"reforges": "Reforges",
"crafting": "Crafting"
},
"wantToViewPatchNotes": "Need support or want to read the full changelog?",
"downloadLink": "VIDEO/UPDATE LINK",
"directDownload": "DIRECT DOWNLOAD LINK",
Expand Down

0 comments on commit 55a2f35

Please sign in to comment.