aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorCow <cow@volloeko.de>2021-08-02 13:34:00 +0200
committerCow <cow@volloeko.de>2021-08-02 13:34:00 +0200
commitc72efee51fa8fe97708faf39f43d631f79d8984a (patch)
tree1eed95afb5114c6b0850d2698dd723dac9985249
parentd2490aad11dec8227b132d55b5afd9a65834011b (diff)
downloadCowlection-c72efee51fa8fe97708faf39f43d631f79d8984a.tar.gz
Cowlection-c72efee51fa8fe97708faf39f43d631f79d8984a.tar.bz2
Cowlection-c72efee51fa8fe97708faf39f43d631f79d8984a.zip
Changed method to get item tooltip
- prevents other mods from modifying the tooltip
-rw-r--r--CHANGELOG.md1
-rw-r--r--src/main/java/de/cowtipper/cowlection/listener/skyblock/DungeonsListener.java12
-rw-r--r--src/main/java/de/cowtipper/cowlection/listener/skyblock/SkyBlockListener.java2
-rw-r--r--src/main/java/de/cowtipper/cowlection/util/Utils.java26
4 files changed, 34 insertions, 7 deletions
diff --git a/CHANGELOG.md b/CHANGELOG.md
index 3da1145..2429668 100644
--- a/CHANGELOG.md
+++ b/CHANGELOG.md
@@ -38,6 +38,7 @@ The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/).
### Fixed
- 'Show Dungeon item base stats' feature now works with HPB'd items and master stars
- Fixed Mythic pets level in player lookup
+- Parsing of item tooltips should no longer be affected by other mods
## [1.8.9-0.13.0] - 25.04.2021
### Added
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<String> itemTooltip = item.getTooltip(Minecraft.getMinecraft().thePlayer, false);
+ List<String> 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<String> itemToolTip = hoveredSlot.getStack().getTooltip(Minecraft.getMinecraft().thePlayer, false);
+ List<String> 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<String> itemToolTip = selectedFloorItem.getTooltip(Minecraft.getMinecraft().thePlayer, false);
+ List<String> 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<String> lore = itemStack.getTooltip(Minecraft.getMinecraft().thePlayer, false);
+ List<String> 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<String> getItemTooltip(ItemStack item) {
+ List<String> 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()) {