From 26eda0660aa41994f39d4fd10d2d7c010b309cf9 Mon Sep 17 00:00:00 2001 From: Lorenz Date: Wed, 7 Sep 2022 05:23:02 +0200 Subject: typo --- CHANGELOG.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'CHANGELOG.md') diff --git a/CHANGELOG.md b/CHANGELOG.md index 0628286b1..58b6298fb 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -22,7 +22,7 @@ - Added highlight corrupted mobs in purple color - Added command /shmarkplayer (marking a player with yellow color) - Added highlight slayer miniboss in blue color -- Added option to hide the death messages of other players, except for players who are close to the player, inside dungeon or doing a Kuudra fight. +- Added option to hide the death messages of other players, except for players who are close to the player, inside dungeon or during a Kuudra fight. - Added highlight the enderman slayer Yang Glyph (Beacon) in red color (supports beacon in hand and beacon flying) ### Fixes -- cgit From 163cc857b0b1e6f52d56e663b8cb1c55f5e1bff2 Mon Sep 17 00:00:00 2001 From: Lorenz Date: Wed, 7 Sep 2022 11:42:48 +0200 Subject: Hiding the flame particles when using the Fire Veil Wand ability. --- CHANGELOG.md | 8 +++- FEATURES.md | 3 +- .../java/at/hannibal2/skyhanni/SkyHanniMod.java | 4 +- .../skyhanni/config/features/Abilities.java | 5 +++ .../hannibal2/skyhanni/data/EntityMovementData.kt | 47 ++++++++++++++++++++ .../skyhanni/data/EntityMovementHelper.kt | 47 -------------------- .../at/hannibal2/skyhanni/data/ItemClickData.kt | 32 ++++++++++++++ .../skyhanni/events/ItemClickInHandEvent.kt | 10 +++++ .../skyhanni/features/FireVeilWandParticles.kt | 50 ++++++++++++++++++++++ .../skyhanni/features/diana/GriffinBurrowFinder.kt | 5 +-- .../skyhanni/features/dungeon/DungeonHideItems.kt | 8 ++-- .../java/at/hannibal2/skyhanni/utils/LorenzVec.kt | 5 ++- 12 files changed, 165 insertions(+), 59 deletions(-) create mode 100644 src/main/java/at/hannibal2/skyhanni/data/EntityMovementData.kt delete mode 100644 src/main/java/at/hannibal2/skyhanni/data/EntityMovementHelper.kt create mode 100644 src/main/java/at/hannibal2/skyhanni/data/ItemClickData.kt create mode 100644 src/main/java/at/hannibal2/skyhanni/events/ItemClickInHandEvent.kt create mode 100644 src/main/java/at/hannibal2/skyhanni/features/FireVeilWandParticles.kt (limited to 'CHANGELOG.md') diff --git a/CHANGELOG.md b/CHANGELOG.md index 58b6298fb..c51a2d55d 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,8 +1,14 @@ # SkyHanni - Change Log +## Version 0.7.1 + +### Misc +- Added hiding the flame particles when using the Fire Veil Wand ability + + ## Version 0.7 - Dungeon and Colored Highlight -## New Dungeon Features +### New Dungeon Features - Added highlight deathmites in dungeon in red color - Added hide Superboom TNT laying around in dungeon - Added hide Blessings laying around in dungeon diff --git a/FEATURES.md b/FEATURES.md index bc99fb35f..d813239f4 100644 --- a/FEATURES.md +++ b/FEATURES.md @@ -47,9 +47,10 @@ - Added compact star counter on all items (not only on items with dungeon stars and master stars but also on crimson armors, cloaks and fishing rods) - RNG meter features (in the catacombs RNG meter inventory show the dungeon floor number and highlight floors without a drop selected and highlighting the selected drop in the RNG meter inventory for slayer or catacombs) -## Item Cooldown +## Item Abilities - Show the cooldown of items in the inventory - Option to change the item background according to the cooldown +- Hiding the flame particles when using the Fire Veil Wand ability. ## Summoning Mobs - Summoning Soul Display (Show the name of dropped soul laying on the ground, not working in dungeon when Skytils' "Hide Non-Starred Mobs Nametags" is enabled) diff --git a/src/main/java/at/hannibal2/skyhanni/SkyHanniMod.java b/src/main/java/at/hannibal2/skyhanni/SkyHanniMod.java index 353a00614..51dcd490a 100644 --- a/src/main/java/at/hannibal2/skyhanni/SkyHanniMod.java +++ b/src/main/java/at/hannibal2/skyhanni/SkyHanniMod.java @@ -60,7 +60,8 @@ public class SkyHanniMod { registerEvent(new SeaCreatureManager()); registerEvent(new ItemRenderBackground()); registerEvent(new EntityData()); - registerEvent(new EntityMovementHelper()); + registerEvent(new EntityMovementData()); + registerEvent(new ItemClickData()); registerEvent(new BazaarOrderHelper()); registerEvent(new ChatFilter()); @@ -107,6 +108,7 @@ public class SkyHanniMod { registerEvent(new DungeonHideItems()); registerEvent(new DungeonCopilot()); registerEvent(new EndermanSlayerBeacon()); + registerEvent(new FireVeilWandParticles()); Commands.init(); diff --git a/src/main/java/at/hannibal2/skyhanni/config/features/Abilities.java b/src/main/java/at/hannibal2/skyhanni/config/features/Abilities.java index a6c9c50f4..4e93679d4 100644 --- a/src/main/java/at/hannibal2/skyhanni/config/features/Abilities.java +++ b/src/main/java/at/hannibal2/skyhanni/config/features/Abilities.java @@ -50,4 +50,9 @@ public class Abilities { @ConfigEditorBoolean @ConfigAccordionId(id = 0) public boolean summoningMobColored = false; + + @Expose + @ConfigOption(name = "Fire Veil Particles", desc = "Hiding the flame particles when using the Fire Veil Wand ability.") + @ConfigEditorBoolean + public boolean fireVeilWandHider = false; } diff --git a/src/main/java/at/hannibal2/skyhanni/data/EntityMovementData.kt b/src/main/java/at/hannibal2/skyhanni/data/EntityMovementData.kt new file mode 100644 index 000000000..1e07a6eaa --- /dev/null +++ b/src/main/java/at/hannibal2/skyhanni/data/EntityMovementData.kt @@ -0,0 +1,47 @@ +package at.hannibal2.skyhanni.data + +import at.hannibal2.skyhanni.events.EntityMoveEvent +import at.hannibal2.skyhanni.utils.LorenzUtils +import at.hannibal2.skyhanni.utils.LorenzVec +import at.hannibal2.skyhanni.utils.getLorenzVec +import net.minecraft.entity.Entity +import net.minecraftforge.event.world.WorldEvent +import net.minecraftforge.fml.common.eventhandler.SubscribeEvent +import net.minecraftforge.fml.common.gameevent.TickEvent + +class EntityMovementData { + + companion object { + private val entityLocation = mutableMapOf() + + fun addToTrack(entity: Entity) { + if (entity !in entityLocation) { + entityLocation[entity] = entity.getLorenzVec() + } + } + } + + var tick = 0 + + @SubscribeEvent + fun onTick(event: TickEvent.ClientTickEvent) { + if (!LorenzUtils.inSkyblock) return + + for (entity in entityLocation.keys) { + if (entity.isDead) continue + + val newLocation = entity.getLorenzVec() + val oldLocation = entityLocation[entity]!! + val distance = newLocation.distance(oldLocation) + if (distance > 0.01) { + entityLocation[entity] = newLocation + EntityMoveEvent(entity).postAndCatch() + } + } + } + + @SubscribeEvent + fun onWorldChange(event: WorldEvent.Load) { + entityLocation.clear() + } +} \ No newline at end of file diff --git a/src/main/java/at/hannibal2/skyhanni/data/EntityMovementHelper.kt b/src/main/java/at/hannibal2/skyhanni/data/EntityMovementHelper.kt deleted file mode 100644 index 908aae388..000000000 --- a/src/main/java/at/hannibal2/skyhanni/data/EntityMovementHelper.kt +++ /dev/null @@ -1,47 +0,0 @@ -package at.hannibal2.skyhanni.data - -import at.hannibal2.skyhanni.events.EntityMoveEvent -import at.hannibal2.skyhanni.utils.LorenzUtils -import at.hannibal2.skyhanni.utils.LorenzVec -import at.hannibal2.skyhanni.utils.getLorenzVec -import net.minecraft.entity.Entity -import net.minecraftforge.event.world.WorldEvent -import net.minecraftforge.fml.common.eventhandler.SubscribeEvent -import net.minecraftforge.fml.common.gameevent.TickEvent - -class EntityMovementHelper { - - companion object { - private val entityLocation = mutableMapOf() - - fun addToTrack(entity: Entity) { - if (entity !in entityLocation) { - entityLocation[entity] = entity.getLorenzVec() - } - } - } - - var tick = 0 - - @SubscribeEvent - fun onTick(event: TickEvent.ClientTickEvent) { - if (!LorenzUtils.inSkyblock) return - - for (entity in entityLocation.keys) { - if (entity.isDead) continue - - val newLocation = entity.getLorenzVec() - val oldLocation = entityLocation[entity]!! - val distance = newLocation.distance(oldLocation) - if (distance > 0.01) { - entityLocation[entity] = newLocation - EntityMoveEvent(entity).postAndCatch() - } - } - } - - @SubscribeEvent - fun onWorldChange(event: WorldEvent.Load) { - entityLocation.clear() - } -} \ No newline at end of file diff --git a/src/main/java/at/hannibal2/skyhanni/data/ItemClickData.kt b/src/main/java/at/hannibal2/skyhanni/data/ItemClickData.kt new file mode 100644 index 000000000..e359c619e --- /dev/null +++ b/src/main/java/at/hannibal2/skyhanni/data/ItemClickData.kt @@ -0,0 +1,32 @@ +package at.hannibal2.skyhanni.data + +import at.hannibal2.skyhanni.events.ItemClickInHandEvent +import net.minecraft.client.Minecraft +import net.minecraftforge.fml.common.eventhandler.SubscribeEvent +import net.minecraftforge.fml.common.gameevent.InputEvent +import org.lwjgl.input.Mouse + +class ItemClickData { + + @SubscribeEvent + fun onClick(event: InputEvent.MouseInputEvent) { + if (!Mouse.getEventButtonState()) return + + val clickType = when (Mouse.getEventButton()) { + 0 -> { + ItemClickInHandEvent.ClickType.LEFT_CLICK + } + + 1 -> { + ItemClickInHandEvent.ClickType.RIGHT_CLICK + } + + else -> { + return + } + } + + val itemStack = Minecraft.getMinecraft().thePlayer.heldItem + ItemClickInHandEvent(clickType, itemStack).postAndCatch() + } +} \ No newline at end of file diff --git a/src/main/java/at/hannibal2/skyhanni/events/ItemClickInHandEvent.kt b/src/main/java/at/hannibal2/skyhanni/events/ItemClickInHandEvent.kt new file mode 100644 index 000000000..e1271b0a3 --- /dev/null +++ b/src/main/java/at/hannibal2/skyhanni/events/ItemClickInHandEvent.kt @@ -0,0 +1,10 @@ +package at.hannibal2.skyhanni.events + +import net.minecraft.item.ItemStack + +class ItemClickInHandEvent(val clickType: ClickType, val itemInHand: ItemStack?): LorenzEvent() { + + enum class ClickType { + LEFT_CLICK, RIGHT_CLICK + } +} \ No newline at end of file diff --git a/src/main/java/at/hannibal2/skyhanni/features/FireVeilWandParticles.kt b/src/main/java/at/hannibal2/skyhanni/features/FireVeilWandParticles.kt new file mode 100644 index 000000000..1205c202b --- /dev/null +++ b/src/main/java/at/hannibal2/skyhanni/features/FireVeilWandParticles.kt @@ -0,0 +1,50 @@ +package at.hannibal2.skyhanni.features + +import at.hannibal2.skyhanni.SkyHanniMod +import at.hannibal2.skyhanni.events.ItemClickInHandEvent +import at.hannibal2.skyhanni.events.PacketEvent +import at.hannibal2.skyhanni.utils.ItemUtils.getInternalName +import at.hannibal2.skyhanni.utils.LorenzUtils +import net.minecraft.network.play.server.S2APacketParticles +import net.minecraft.util.EnumParticleTypes +import net.minecraftforge.fml.common.eventhandler.SubscribeEvent + +class FireVeilWandParticles { + + var lastClick = 0L + + @SubscribeEvent + fun onChatPacket(event: PacketEvent.ReceiveEvent) { + if (!isEnabled()) return + + val packet = event.packet + if (packet !is S2APacketParticles) return + + if (System.currentTimeMillis() > lastClick + 5_500) return + + if (packet.particleType == EnumParticleTypes.FLAME && packet.particleCount == 1 && packet.particleSpeed == 0f && + packet.xOffset == 0f && + packet.yOffset == 0f && + packet.zOffset == 0f + ) { + event.isCanceled = true + } + } + + @SubscribeEvent + fun onItemClick(event: ItemClickInHandEvent) { + if (!isEnabled()) return + if (event.clickType != ItemClickInHandEvent.ClickType.RIGHT_CLICK) return + + val itemInHand = event.itemInHand ?: return + + val internalName = itemInHand.getInternalName() + if (internalName == "FIRE_VEIL_WAND") { + lastClick = System.currentTimeMillis() + } + } + + private fun isEnabled(): Boolean { + return LorenzUtils.inSkyblock && SkyHanniMod.feature.abilities.fireVeilWandHider + } +} \ No newline at end of file diff --git a/src/main/java/at/hannibal2/skyhanni/features/diana/GriffinBurrowFinder.kt b/src/main/java/at/hannibal2/skyhanni/features/diana/GriffinBurrowFinder.kt index d98f46100..524a94259 100644 --- a/src/main/java/at/hannibal2/skyhanni/features/diana/GriffinBurrowFinder.kt +++ b/src/main/java/at/hannibal2/skyhanni/features/diana/GriffinBurrowFinder.kt @@ -71,10 +71,7 @@ class GriffinBurrowFinder { fun onChatPacket(event: PacketEvent.ReceiveEvent) { val packet = event.packet if (packet is S2APacketParticles) { - val x = packet.xCoordinate - val y = packet.yCoordinate - val z = packet.zCoordinate - val distance = LorenzVec(x, y, z).distance(LocationUtils.playerLocation()) + val distance = packet.toLorenzVec().distance(LocationUtils.playerLocation()) if (distance < 20) { // LorenzDebug.log("") // LorenzDebug.log("S2APacketParticles close") diff --git a/src/main/java/at/hannibal2/skyhanni/features/dungeon/DungeonHideItems.kt b/src/main/java/at/hannibal2/skyhanni/features/dungeon/DungeonHideItems.kt index faf48e95c..acc0de8a0 100644 --- a/src/main/java/at/hannibal2/skyhanni/features/dungeon/DungeonHideItems.kt +++ b/src/main/java/at/hannibal2/skyhanni/features/dungeon/DungeonHideItems.kt @@ -1,14 +1,14 @@ package at.hannibal2.skyhanni.features.dungeon import at.hannibal2.skyhanni.SkyHanniMod -import at.hannibal2.skyhanni.data.EntityMovementHelper +import at.hannibal2.skyhanni.data.EntityMovementData import at.hannibal2.skyhanni.events.* import at.hannibal2.skyhanni.utils.ItemUtils.cleanName import at.hannibal2.skyhanni.utils.ItemUtils.getSkullTexture import at.hannibal2.skyhanni.utils.LorenzColor import at.hannibal2.skyhanni.utils.LorenzUtils -import at.hannibal2.skyhanni.utils.LorenzVec import at.hannibal2.skyhanni.utils.getLorenzVec +import at.hannibal2.skyhanni.utils.toLorenzVec import net.minecraft.entity.item.EntityArmorStand import net.minecraft.entity.item.EntityItem import net.minecraft.network.play.server.S2APacketParticles @@ -121,7 +121,7 @@ class DungeonHideItems { } if (isSkeletonSkull(entity)) { - EntityMovementHelper.addToTrack(entity) + EntityMovementData.addToTrack(entity) if (SkyHanniMod.feature.dungeon.hideSkeletonSkull) { val lastMove = movingSkeletonSkulls.getOrDefault(entity, 0) if (lastMove + 100 > System.currentTimeMillis()) { @@ -139,7 +139,7 @@ class DungeonHideItems { val packet = event.packet if (packet is S2APacketParticles) { - val packetLocation = LorenzVec(packet.xCoordinate, packet.yCoordinate, packet.zCoordinate) + val packetLocation = packet.toLorenzVec() for (armorStand in hideParticles.filter { it.value + 100 > System.currentTimeMillis() }.map { it.key }) { val distance = packetLocation.distance(armorStand.getLorenzVec()) if (distance < 2) { diff --git a/src/main/java/at/hannibal2/skyhanni/utils/LorenzVec.kt b/src/main/java/at/hannibal2/skyhanni/utils/LorenzVec.kt index 95ab29433..117a35f77 100644 --- a/src/main/java/at/hannibal2/skyhanni/utils/LorenzVec.kt +++ b/src/main/java/at/hannibal2/skyhanni/utils/LorenzVec.kt @@ -1,6 +1,7 @@ package at.hannibal2.skyhanni.utils import net.minecraft.entity.Entity +import net.minecraft.network.play.server.S2APacketParticles import net.minecraft.util.BlockPos import net.minecraft.util.Rotations import net.minecraft.util.Vec3 @@ -107,4 +108,6 @@ fun Entity.getLorenzVec(): LorenzVec = LorenzVec(posX, posY, posZ) fun Vec3.toLorenzVec(): LorenzVec = LorenzVec(xCoord, yCoord, zCoord) -fun Rotations.toLorenzVec(): LorenzVec = LorenzVec(x, y, z) \ No newline at end of file +fun Rotations.toLorenzVec(): LorenzVec = LorenzVec(x, y, z) + +fun S2APacketParticles.toLorenzVec(): LorenzVec = LorenzVec(xCoordinate, yCoordinate, zCoordinate) \ No newline at end of file -- cgit From e1c1b44f1ab432827233ba44b0f03d67340f994a Mon Sep 17 00:00:00 2001 From: Lorenz Date: Wed, 7 Sep 2022 12:51:29 +0200 Subject: Fixed enchanted books in bazaar. --- CHANGELOG.md | 3 + .../skyhanni/features/bazaar/BazaarApi.kt | 9 +- .../skyhanni/features/bazaar/BazaarDataGrabber.kt | 12 +- .../features/items/HideNotClickableItems.kt | 3 +- .../skyhanni/utils/ItemResolutionQuery.java | 201 +++++++++++++++++++++ .../java/at/hannibal2/skyhanni/utils/ItemUtils.kt | 51 +----- 6 files changed, 226 insertions(+), 53 deletions(-) create mode 100644 src/main/java/at/hannibal2/skyhanni/utils/ItemResolutionQuery.java (limited to 'CHANGELOG.md') diff --git a/CHANGELOG.md b/CHANGELOG.md index c51a2d55d..4022db3b5 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -5,6 +5,9 @@ ### Misc - Added hiding the flame particles when using the Fire Veil Wand ability +### Fixes +- Fixed enchanted books in bazaar + ## Version 0.7 - Dungeon and Colored Highlight diff --git a/src/main/java/at/hannibal2/skyhanni/features/bazaar/BazaarApi.kt b/src/main/java/at/hannibal2/skyhanni/features/bazaar/BazaarApi.kt index 5ae100ac2..c2c8bcb18 100644 --- a/src/main/java/at/hannibal2/skyhanni/features/bazaar/BazaarApi.kt +++ b/src/main/java/at/hannibal2/skyhanni/features/bazaar/BazaarApi.kt @@ -1,7 +1,9 @@ package at.hannibal2.skyhanni.features.bazaar +import at.hannibal2.skyhanni.utils.ItemUtils.getInternalName import at.hannibal2.skyhanni.utils.LorenzUtils import at.hannibal2.skyhanni.utils.StringUtils.removeColor +import net.minecraft.item.ItemStack class BazaarApi { @@ -44,9 +46,10 @@ class BazaarApi { return null } - fun isBazaarItem(name: String): Boolean { - val bazaarName = getCleanBazaarName(name) - return bazaarMap.containsKey(bazaarName) + fun isBazaarItem(stack: ItemStack): Boolean { + val internalName = stack.getInternalName() + return bazaarMap.any { it.value.apiName == internalName } + } } diff --git a/src/main/java/at/hannibal2/skyhanni/features/bazaar/BazaarDataGrabber.kt b/src/main/java/at/hannibal2/skyhanni/features/bazaar/BazaarDataGrabber.kt index 01f01015c..642298ba5 100644 --- a/src/main/java/at/hannibal2/skyhanni/features/bazaar/BazaarDataGrabber.kt +++ b/src/main/java/at/hannibal2/skyhanni/features/bazaar/BazaarDataGrabber.kt @@ -85,7 +85,7 @@ internal class BazaarDataGrabber(private var bazaarMap: MutableMap PET_RARITIES = Arrays.asList( + "COMMON", + "UNCOMMON", + "RARE", + "EPIC", + "LEGENDARY", + "MYTHIC" + ); + private ItemStack stack; + private Item itemType; + private int stackSize = -1; + private Gui guiContext; + private String knownInternalName; + + public ItemResolutionQuery withItemStack(ItemStack stack) { + if (stack == null) return this; + this.itemType = stack.getItem(); + this.stack = stack; + this.stackSize = stack.stackSize; + return this; + } + + public ItemResolutionQuery withGuiContext(Gui gui) { + this.guiContext = gui; + return this; + } + + public ItemResolutionQuery withCurrentGuiContext() { + this.guiContext = Minecraft.getMinecraft().currentScreen; + return this; + } + + public ItemResolutionQuery withKnownInternalName(String knownInternalName) { + this.knownInternalName = knownInternalName; + return this; + } + + @Nullable + public String resolveInternalName() { + if (knownInternalName != null) { + return knownInternalName; + } + String resolvedName = resolveFromSkyblock(); + if (resolvedName == null) { + resolvedName = resolveContextualName(); + } else { + switch (resolvedName.intern()) { + case "PET": + resolvedName = resolvePetName(); + break; + case "RUNE": + resolvedName = resolveRuneName(); + break; + case "ENCHANTED_BOOK": + resolvedName = resolveEnchantedBookNameFromNBT(); + break; + case "PARTY_HAT_CRAB": + resolvedName = resolveCrabHatName(); + break; + } + } + + return resolvedName; + } + + // + private boolean isBazaar(IInventory chest) { + if (chest.getDisplayName().getFormattedText().startsWith("Bazaar ➜ ")) { + return true; + } + int bazaarSlot = chest.getSizeInventory() - 5; + if (bazaarSlot < 0) return false; + ItemStack stackInSlot = chest.getStackInSlot(bazaarSlot); + if (stackInSlot == null || stackInSlot.stackSize == 0) return false; + // NBT lore, we do not care about rendered lore + List lore = ItemUtils.INSTANCE.getLore(stackInSlot); + return lore.contains("§7To Bazaar"); + } + + private String resolveContextualName() { + if (!(guiContext instanceof GuiChest)) { + return null; + } + GuiChest chest = (GuiChest) guiContext; + ContainerChest inventorySlots = (ContainerChest) chest.inventorySlots; + String guiName = inventorySlots.getLowerChestInventory().getDisplayName().getUnformattedText(); + boolean isOnBazaar = isBazaar(inventorySlots.getLowerChestInventory()); + String displayName = ItemUtils.INSTANCE.getName(stack); + if (displayName == null) return null; + if (itemType == Items.enchanted_book && isOnBazaar) { + return resolveEnchantmentByName(displayName); + } + if (displayName.endsWith("Enchanted Book") && guiName.startsWith("Superpairs")) { + for (String loreLine : ItemUtils.INSTANCE.getLore(stack)) { + String enchantmentIdCandidate = resolveEnchantmentByName(loreLine); + if (enchantmentIdCandidate != null) return enchantmentIdCandidate; + } + return null; + } + return null; + } + + private String getDisplayName(NBTTagCompound compound) { + if (compound == null) return null; + String string = compound.getCompoundTag("display").getString("Name"); + if (string == null || string.isEmpty()) + return null; + return string; + } + + private String resolveEnchantmentByName(String name) { + Matcher matcher = ENCHANTED_BOOK_NAME_PATTERN.matcher(name); + if (!matcher.matches()) return null; + String format = matcher.group(1).toLowerCase(Locale.ROOT); + String enchantmentName = matcher.group(2).trim(); + String romanLevel = matcher.group(3); + boolean ultimate = (format.contains("§l")); + + return (ultimate ? "ULTIMATE_" : "") + + enchantmentName.replace(" ", "_").toUpperCase(Locale.ROOT) + + ";" + NumberUtil.INSTANCE.romanToDecimal(romanLevel); + } + + private String resolveCrabHatName() { + String color = getExtraAttributes().getString("party_hat_color"); + return "PARTY_HAT_CRAB_" + color.toUpperCase(Locale.ROOT); + } + + private String resolveEnchantedBookNameFromNBT() { + NBTTagCompound enchantments = getExtraAttributes().getCompoundTag("enchantments"); + String enchantName = Iterables.getOnlyElement(enchantments.getKeySet(), null); + if (enchantName == null || enchantName.isEmpty()) return null; + return enchantName.toUpperCase(Locale.ROOT) + ";" + enchantments.getInteger(enchantName); + } + + private String resolveRuneName() { + NBTTagCompound runes = getExtraAttributes().getCompoundTag("runes"); + String runeName = Iterables.getOnlyElement(runes.getKeySet(), null); + if (runeName == null || runeName.isEmpty()) return null; + return runeName.toUpperCase(Locale.ROOT) + "_RUNE;" + runes.getInteger(runeName); + } + + private String resolvePetName() { + String petInfo = getExtraAttributes().getString("petInfo"); + if (petInfo == null || petInfo.isEmpty()) return null; + try { + JsonObject petInfoObject = ConfigManager.Companion.getGson().fromJson(petInfo, JsonObject.class); + String petId = petInfoObject.get("type").getAsString(); + String petTier = petInfoObject.get("tier").getAsString(); + int rarityIndex = PET_RARITIES.indexOf(petTier); + return petId.toUpperCase(Locale.ROOT) + ";" + rarityIndex; + } catch (JsonParseException | ClassCastException ex) { + /* This happens if Hypixel changed the pet json format; + I still log this exception, since this case *is* exceptional and cannot easily be recovered from */ + ex.printStackTrace(); + return null; + } + } + + private NBTTagCompound getExtraAttributes() { + NBTTagCompound compound = stack.getTagCompound(); + if (compound == null) return new NBTTagCompound(); + return compound.getCompoundTag(EXTRA_ATTRIBUTES); + } + + private String resolveFromSkyblock() { + String internalName = getExtraAttributes().getString("id"); + if (internalName == null || internalName.isEmpty()) return null; + return internalName.toUpperCase(Locale.ROOT); + } + + // + +} diff --git a/src/main/java/at/hannibal2/skyhanni/utils/ItemUtils.kt b/src/main/java/at/hannibal2/skyhanni/utils/ItemUtils.kt index 3b38bd84a..ca0e6728c 100644 --- a/src/main/java/at/hannibal2/skyhanni/utils/ItemUtils.kt +++ b/src/main/java/at/hannibal2/skyhanni/utils/ItemUtils.kt @@ -113,53 +113,10 @@ object ItemUtils { } fun ItemStack.getInternalName(): String { - val tag = tagCompound - if (tag == null || !tag.hasKey("ExtraAttributes", 10)) return "" - - val extraAttributes = tag.getCompoundTag("ExtraAttributes") - var internalName = if (extraAttributes.hasKey("id", 8)) { - extraAttributes.getString("id").replace(":".toRegex(), "-") - } else { - return "" - } - - if (internalName == "PET") { - val petInfo = extraAttributes.getString("petInfo") - if (petInfo.isNotEmpty()) { - val petInfoObject: JsonObject = gson.fromJson(petInfo, JsonObject::class.java) - internalName = petInfoObject["type"].asString - return when (petInfoObject["tier"].asString) { - "COMMON" -> "$internalName;0" - "UNCOMMON" -> "$internalName;1" - "RARE" -> "$internalName;2" - "EPIC" -> "$internalName;3" - "LEGENDARY" -> "$internalName;4" - "MYTHIC" -> "$internalName;5" - else -> internalName - } - } - } - - if (internalName == "ENCHANTED_BOOK" && extraAttributes.hasKey("enchantments", 10)) { - val enchants = extraAttributes.getCompoundTag("enchantments") - for (enchantment in enchants.keySet) { - return enchantment.uppercase(Locale.getDefault()) + ";" + enchants.getInteger(enchantment) - } - } - - if (internalName == "RUNE" && extraAttributes.hasKey("runes", 10)) { - val rune = extraAttributes.getCompoundTag("runes") - for (enchantment in rune.keySet) { - return enchantment.uppercase(Locale.getDefault()) + "_RUNE" + ";" + rune.getInteger(enchantment) - } - } - - if (internalName == "PARTY_HAT_CRAB" && extraAttributes.getString("party_hat_color") != null) { - val crabHat = extraAttributes.getString("party_hat_color") - return "PARTY_HAT_CRAB" + "_" + crabHat.uppercase(Locale.getDefault()) - } - - return internalName + return ItemResolutionQuery() + .withCurrentGuiContext() + .withItemStack(this) + .resolveInternalName() ?: "" } fun ItemStack.getSkullTexture(): String? { -- cgit