diff options
author | Lulonaut <67191924+Lulonaut@users.noreply.github.com> | 2022-05-25 07:30:26 +0200 |
---|---|---|
committer | GitHub <noreply@github.com> | 2022-05-25 07:30:26 +0200 |
commit | 097542b6f2dfb0edb63afa00136f1fe610d57550 (patch) | |
tree | 8ba35a5e1f1fcd5d4269d800acb4dc6700cdf2ca /src | |
parent | 07444d592fdb41371734056798e3a44e25b8a3e3 (diff) | |
download | NotEnoughUpdates-097542b6f2dfb0edb63afa00136f1fe610d57550.tar.gz NotEnoughUpdates-097542b6f2dfb0edb63afa00136f1fe610d57550.tar.bz2 NotEnoughUpdates-097542b6f2dfb0edb63afa00136f1fe610d57550.zip |
Update pet in /equipment (#147)
* please don't delete everything Intellij
* working
* debug print
* use XPInformation#getPetLevel
Diffstat (limited to 'src')
-rw-r--r-- | src/main/java/io/github/moulberry/notenoughupdates/NEUOverlay.java | 4 | ||||
-rw-r--r-- | src/main/java/io/github/moulberry/notenoughupdates/miscfeatures/PetInfoOverlay.java | 65 |
2 files changed, 61 insertions, 8 deletions
diff --git a/src/main/java/io/github/moulberry/notenoughupdates/NEUOverlay.java b/src/main/java/io/github/moulberry/notenoughupdates/NEUOverlay.java index fcdb9b9c..d7b6db4b 100644 --- a/src/main/java/io/github/moulberry/notenoughupdates/NEUOverlay.java +++ b/src/main/java/io/github/moulberry/notenoughupdates/NEUOverlay.java @@ -1190,7 +1190,7 @@ public class NEUOverlay extends Gui { updateSearch(); } - String[] rarityArr = new String[]{ + public static String[] rarityArr = new String[]{ EnumChatFormatting.WHITE + EnumChatFormatting.BOLD.toString() + "COMMON", EnumChatFormatting.GREEN + EnumChatFormatting.BOLD.toString() + "UNCOMMON", EnumChatFormatting.BLUE + EnumChatFormatting.BOLD.toString() + "RARE", @@ -1211,7 +1211,7 @@ public class NEUOverlay extends Gui { * 5 = MYTHIC * 6 = SPECIAL */ - public int getRarity(JsonArray lore) { + public static int getRarity(JsonArray lore) { for (int i = lore.size() - 1; i >= 0; i--) { String line = lore.get(i).getAsString(); diff --git a/src/main/java/io/github/moulberry/notenoughupdates/miscfeatures/PetInfoOverlay.java b/src/main/java/io/github/moulberry/notenoughupdates/miscfeatures/PetInfoOverlay.java index 6203a36d..056cf0a4 100644 --- a/src/main/java/io/github/moulberry/notenoughupdates/miscfeatures/PetInfoOverlay.java +++ b/src/main/java/io/github/moulberry/notenoughupdates/miscfeatures/PetInfoOverlay.java @@ -1,10 +1,17 @@ package io.github.moulberry.notenoughupdates.miscfeatures; import com.google.common.collect.Lists; -import com.google.gson.*; +import com.google.gson.Gson; +import com.google.gson.GsonBuilder; +import com.google.gson.JsonArray; +import com.google.gson.JsonElement; +import com.google.gson.JsonNull; +import com.google.gson.JsonObject; +import com.google.gson.JsonParser; import io.github.moulberry.notenoughupdates.NEUOverlay; import io.github.moulberry.notenoughupdates.NotEnoughUpdates; import io.github.moulberry.notenoughupdates.core.config.Position; +import io.github.moulberry.notenoughupdates.core.util.StringUtils; import io.github.moulberry.notenoughupdates.core.util.lerp.LerpUtils; import io.github.moulberry.notenoughupdates.listener.RenderListener; import io.github.moulberry.notenoughupdates.options.NEUConfig; @@ -23,6 +30,7 @@ import net.minecraft.init.Items; import net.minecraft.inventory.ContainerChest; import net.minecraft.inventory.IInventory; import net.minecraft.item.ItemStack; +import net.minecraft.nbt.NBTTagCompound; import net.minecraft.util.ChatComponentText; import net.minecraft.util.EnumChatFormatting; import net.minecraftforge.client.event.ClientChatReceivedEvent; @@ -34,12 +42,25 @@ import net.minecraftforge.fml.common.gameevent.TickEvent; import org.apache.commons.lang3.text.WordUtils; import org.lwjgl.util.vector.Vector2f; -import java.io.*; +import java.io.BufferedReader; +import java.io.BufferedWriter; +import java.io.File; +import java.io.FileInputStream; +import java.io.FileOutputStream; +import java.io.InputStreamReader; +import java.io.OutputStreamWriter; import java.nio.charset.StandardCharsets; import java.text.DecimalFormat; import java.text.DecimalFormatSymbols; import java.text.NumberFormat; -import java.util.*; +import java.util.ArrayList; +import java.util.HashMap; +import java.util.HashSet; +import java.util.LinkedList; +import java.util.List; +import java.util.Locale; +import java.util.Map; +import java.util.Set; import java.util.function.Supplier; import java.util.regex.Matcher; import java.util.regex.Pattern; @@ -216,7 +237,7 @@ public class PetInfoOverlay extends TextOverlay { } }}; - if (pets == null || pets.isEmpty()) { + if (pets.isEmpty()) { return null; } @@ -726,7 +747,6 @@ public class PetInfoOverlay extends TextOverlay { JsonObject petTypes = Constants.PETS.get("pet_types").getAsJsonObject(); pet.petXpType = petTypes.has(pet.petType) ? petTypes.get(pet.petType.toUpperCase()).getAsString().toLowerCase() : "unknown"; - return pet; } @@ -761,7 +781,6 @@ public class PetInfoOverlay extends TextOverlay { } } } - if (isPets) { boolean hasItem = false; for (int i = 0; i < lower.getSizeInventory(); i++) { @@ -829,6 +848,40 @@ public class PetInfoOverlay extends TextOverlay { } } removeMap.keySet().retainAll(removeSet); + } else if (containerName.equals("Your Equipment")) { + ItemStack petStack = lower.getStackInSlot(47); + if (petStack != null && petStack.getItem() == Items.skull) { + NBTTagCompound tag = petStack.getTagCompound(); + + if (tag.hasKey("ExtraAttributes", 10)) { + NBTTagCompound ea = tag.getCompoundTag("ExtraAttributes"); + if (ea.hasKey("petInfo")) { + JsonParser jsonParser = new JsonParser(); + + JsonObject petInfoObject = jsonParser.parse(ea.getString("petInfo")).getAsJsonObject(); + + JsonObject jsonStack = NotEnoughUpdates.INSTANCE.manager.getJsonForItem(petStack); + if (jsonStack == null || !jsonStack.has("lore") || !petInfoObject.has("exp")) { + return; + } + + int rarity = NEUOverlay.getRarity(jsonStack.get("lore").getAsJsonArray()); + String rarityString = Utils.getRarityFromInt(rarity); + + String name = StringUtils.cleanColour(petStack.getDisplayName()); + name = name.substring(name.indexOf(']') + 1).trim().replace(' ', '_').toUpperCase(); + + float petXp = petInfoObject.get("exp").getAsFloat(); + + double petLevel = XPInformation.getInstance().getPetLevel(name, petXp, rarityString); + int index = getClosestPetIndex(name, rarity, "", (float) petLevel); + if (index != config.selectedPet) { + clearPet(); + setCurrentPet(index); + } + } + } + } } } } |