From c72efee51fa8fe97708faf39f43d631f79d8984a Mon Sep 17 00:00:00 2001 From: Cow Date: Mon, 2 Aug 2021 13:34:00 +0200 Subject: Changed method to get item tooltip - prevents other mods from modifying the tooltip --- .../listener/skyblock/DungeonsListener.java | 12 +++++----- .../listener/skyblock/SkyBlockListener.java | 2 +- .../java/de/cowtipper/cowlection/util/Utils.java | 26 ++++++++++++++++++++++ 3 files changed, 33 insertions(+), 7 deletions(-) (limited to 'src') diff --git a/src/main/java/de/cowtipper/cowlection/listener/skyblock/DungeonsListener.java b/src/main/java/de/cowtipper/cowlection/listener/skyblock/DungeonsListener.java index bdf7553..57afdb1 100644 --- a/src/main/java/de/cowtipper/cowlection/listener/skyblock/DungeonsListener.java +++ b/src/main/java/de/cowtipper/cowlection/listener/skyblock/DungeonsListener.java @@ -269,7 +269,7 @@ public class DungeonsListener { // couldn't detect dungeon class indicator return; } - for (String toolTipLine : dungeonClassIndicator.getTooltip(Minecraft.getMinecraft().thePlayer, false)) { + for (String toolTipLine : Utils.getItemTooltip(dungeonClassIndicator)) { String line = EnumChatFormatting.getTextWithoutFormattingCodes(toolTipLine); if (line.startsWith("Currently Selected: ")) { String selectedClassName = line.substring(line.lastIndexOf(' ') + 1); @@ -312,7 +312,7 @@ public class DungeonsListener { } DataHelper.PartyType partyType = DataHelper.PartyType.SUITABLE; - List itemTooltip = item.getTooltip(Minecraft.getMinecraft().thePlayer, false); + List itemTooltip = Utils.getItemTooltip(item); if (itemTooltip.size() < 5) { // not a valid dungeon party tooltip return; @@ -474,7 +474,7 @@ public class DungeonsListener { } // an update might have moved the item to another slot, search for it: for (int checkedSlot = 0; checkedSlot < inventory.getSizeInventory(); checkedSlot++) { - item = inventory.getStackInSlot(slot); + item = inventory.getStackInSlot(checkedSlot); if (item != null && item.hasDisplayName() && itemDisplayName.equals(EnumChatFormatting.getTextWithoutFormattingCodes(item.getDisplayName()))) { return item; } @@ -609,7 +609,7 @@ public class DungeonsListener { Slot hoveredSlot = GuiHelper.getSlotUnderMouse(guiChest); if (hoveredSlot != null && hoveredSlot.getHasStack()) { // clicked on an item - List itemToolTip = hoveredSlot.getStack().getTooltip(Minecraft.getMinecraft().thePlayer, false); + List itemToolTip = Utils.getItemTooltip(hoveredSlot.getStack()); if (itemToolTip.size() < 5 || hoveredSlot.getStack().getItem() != Items.skull) { // not a valid dungeon party tooltip return; @@ -636,9 +636,9 @@ public class DungeonsListener { String clickedItemName = EnumChatFormatting.getTextWithoutFormattingCodes(hoveredSlot.getStack().getDisplayName()); if (clickedItemName.equals("Confirm Group")) { // created dungeon party group - ItemStack selectedFloorItem = getStackInSlotOrByName(inventory, 12, "Select Floor"); + ItemStack selectedFloorItem = getStackInSlotOrByName(inventory, 13, "Select Floor"); if (selectedFloorItem != null) { - List itemToolTip = selectedFloorItem.getTooltip(Minecraft.getMinecraft().thePlayer, false); + List itemToolTip = Utils.getItemTooltip(selectedFloorItem); if (itemToolTip.size() < 5) { // not a valid dungeon floor tooltip return; diff --git a/src/main/java/de/cowtipper/cowlection/listener/skyblock/SkyBlockListener.java b/src/main/java/de/cowtipper/cowlection/listener/skyblock/SkyBlockListener.java index df716dc..4f38872 100644 --- a/src/main/java/de/cowtipper/cowlection/listener/skyblock/SkyBlockListener.java +++ b/src/main/java/de/cowtipper/cowlection/listener/skyblock/SkyBlockListener.java @@ -139,7 +139,7 @@ public class SkyBlockListener { } } else { // check if item is inside Bazaar - List lore = itemStack.getTooltip(Minecraft.getMinecraft().thePlayer, false); + List lore = Utils.getItemTooltip(itemStack); if (lore.size() > 5 && lore.get(1).endsWith(" commodity")) { // item is a Bazaar commodity itemBaseName = itemStack.getDisplayName(); diff --git a/src/main/java/de/cowtipper/cowlection/util/Utils.java b/src/main/java/de/cowtipper/cowlection/util/Utils.java index 2db72d1..9a07ab8 100644 --- a/src/main/java/de/cowtipper/cowlection/util/Utils.java +++ b/src/main/java/de/cowtipper/cowlection/util/Utils.java @@ -4,9 +4,12 @@ import com.mojang.realmsclient.util.Pair; import de.cowtipper.cowlection.Cowlection; import de.cowtipper.cowlection.config.MooConfig; import net.minecraft.client.gui.GuiScreen; +import net.minecraft.item.ItemStack; import net.minecraft.nbt.NBTBase; import net.minecraft.nbt.NBTTagCompound; +import net.minecraft.nbt.NBTTagList; import net.minecraft.util.EnumChatFormatting; +import net.minecraftforge.common.util.Constants; import org.apache.commons.lang3.StringUtils; import org.apache.commons.lang3.text.WordUtils; import org.apache.commons.lang3.time.DateFormatUtils; @@ -400,6 +403,29 @@ public final class Utils { } } + /** + * Replacement for ItemStack#getTooltip that doesn't get affected by other mods + */ + public static List getItemTooltip(ItemStack item) { + List tooltip = new ArrayList<>(); + // display name: + tooltip.add(item.getDisplayName()); + + // lore: + if (item.hasTagCompound() && item.getTagCompound().hasKey("display", Constants.NBT.TAG_COMPOUND)) { + NBTTagCompound nbtTagCompound = item.getTagCompound().getCompoundTag("display"); + if (nbtTagCompound.getTagId("Lore") == Constants.NBT.TAG_LIST) { + NBTTagList nbtLore = nbtTagCompound.getTagList("Lore", Constants.NBT.TAG_STRING); + if (nbtLore.tagCount() > 0) { + for (int line = 0; line < nbtLore.tagCount(); ++line) { + tooltip.add(nbtLore.getStringTagAt(line)); + } + } + } + } + return tooltip; + } + public static void copyToClipboardOrSaveAsFile(String what, String fileName, NBTBase data, boolean sortData) { String nbt = GsonUtils.toJson(data, sortData); if (MooConfig.copyWailaAndInventoryDataToClipboard()) { -- cgit