Skip to content

Commit

Permalink
Pet overlay fixes (Moulberry#290)
Browse files Browse the repository at this point in the history
* fixed pet overlay going to level 100

* fixed transparent pet and equip overlay not using the special texture

fixed pet overlay showing a pet when you remove your pet

* made pet overlay show the current stats of your pet

* Fixed pet overlay showing Until level 100.0

* Fixed pet stats not showing decimal

* Made pet overlay show xp to next level

* 2.1.md slight smile

* Try to generify pet lore replacements a tiny bit

Also move pets page to use the same code as the pet overlay

Co-authored-by: hannibal2 <[email protected]>
Co-authored-by: nea <[email protected]>
  • Loading branch information
3 people authored Sep 23, 2022
1 parent 21a353f commit 61c53c0
Show file tree
Hide file tree
Showing 8 changed files with 368 additions and 285 deletions.
1 change: 1 addition & 0 deletions Update Notes/2.1.md
Original file line number Diff line number Diff line change
Expand Up @@ -157,6 +157,7 @@
- Fixed skill average calculation to include carpentry in /peek - whalker
- Fixed middle clicking on pets not registering pet swap - nopo
- Fixed middle clicking on an item with no id searching for it - nopo
- Fixed pets with decimal stats not showing in pv - nopo

### **Other:**

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -1380,7 +1380,7 @@ public HashMap<String, String> getLoreReplacements(String petname, String tier,
float statMax = entry.getValue().getAsFloat();
float statMin = min.get("statNums").getAsJsonObject().get(entry.getKey()).getAsFloat();
float val = statMin * minMix + statMax * maxMix;
String statStr = (statMin > 0 ? "+" : "") + (int) Math.floor(val);
String statStr = (statMin > 0 ? "+" : "") + removeUnusedDecimal(Math.floor(val * 10) / 10);
replacements.put(entry.getKey(), statStr);
}
}
Expand Down Expand Up @@ -1457,6 +1457,7 @@ public ItemStack jsonToStack(JsonObject json, boolean useCache, boolean useRepla
}

public ItemStack jsonToStack(JsonObject json, boolean useCache, boolean useReplacements, boolean copyStack) {
if (useReplacements) useCache = false;
if (json == null) return new ItemStack(Items.painting, 1, 10);
String internalname = json.get("internalname").getAsString();

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,6 @@
import java.text.DecimalFormat;
import java.text.NumberFormat;
import java.util.ArrayList;
import java.util.Collections;
import java.util.HashMap;
import java.util.HashSet;
import java.util.List;
Expand All @@ -67,7 +66,7 @@
import java.util.regex.Pattern;

public class ItemTooltipListener {
private static final String petToolTipRegex =
public static final String petToolTipRegex =
"((Farming)|(Combat)|(Fishing)|(Mining)|(Foraging)|(Enchanting)|(Alchemy)) ((Mount)|(Pet)|(Morph)).*";
private final NotEnoughUpdates neu;
private final Pattern xpLevelPattern = Pattern.compile("(.*) (\\xA7e(.*)\\xA76/\\xA7e(.*))");
Expand Down Expand Up @@ -711,45 +710,44 @@ public void onItemTooltipLow(ItemTooltipEvent event) {
}

private void petToolTipXPExtendPetMenu(ItemTooltipEvent event) {
if (NotEnoughUpdates.INSTANCE.config.tooltipTweaks.petExtendExp) {
//7 is just a random number i chose, prob no pets with less lines than 7
if (event.toolTip.size() > 7) {
if (Utils.cleanColour(event.toolTip.get(1)).matches(petToolTipRegex)) {
GuiProfileViewer.PetLevel petLevel;

int xpLine = -1;
for (int i = event.toolTip.size() - 1; i >= 0; i--) {
Matcher matcher = xpLevelPattern.matcher(event.toolTip.get(i));
if (matcher.matches()) {
xpLine = i;
event.toolTip.set(xpLine, matcher.group(1));
break;
} else if (event.toolTip.get(i).matches("MAX LEVEL")) {
return;
}
}
if (!NotEnoughUpdates.INSTANCE.config.tooltipTweaks.petExtendExp) return;
//7 is just a random number i chose, prob no pets with less lines than 7
if (event.toolTip.size() < 7) return;
if (event.itemStack.getTagCompound().hasKey("NEUHIDEPETTOOLTIP")) return;
if (Utils.cleanColour(event.toolTip.get(1)).matches(petToolTipRegex)) {
GuiProfileViewer.PetLevel petLevel;

int xpLine = -1;
for (int i = event.toolTip.size() - 1; i >= 0; i--) {
Matcher matcher = xpLevelPattern.matcher(event.toolTip.get(i));
if (matcher.matches()) {
xpLine = i;
event.toolTip.set(xpLine, matcher.group(1));
break;
} else if (event.toolTip.get(i).matches("MAX LEVEL")) {
return;
}
}

PetInfoOverlay.Pet pet = PetInfoOverlay.getPetFromStack(
event.itemStack.getTagCompound()
);
if (pet == null) {
return;
}
petLevel = pet.petLevel;
PetInfoOverlay.Pet pet = PetInfoOverlay.getPetFromStack(
event.itemStack.getTagCompound()
);
if (pet == null) {
return;
}
petLevel = pet.petLevel;

if (petLevel == null || xpLine == -1) {
return;
}
if (petLevel == null || xpLine == -1) {
return;
}

event.toolTip.add(
xpLine + 1,
EnumChatFormatting.GRAY + "EXP: " + EnumChatFormatting.YELLOW + myFormatter.format(petLevel.levelXp) +
EnumChatFormatting.GOLD + "/" + EnumChatFormatting.YELLOW +
myFormatter.format(petLevel.currentLevelRequirement)
);
event.toolTip.add(
xpLine + 1,
EnumChatFormatting.GRAY + "EXP: " + EnumChatFormatting.YELLOW + myFormatter.format(petLevel.levelXp) +
EnumChatFormatting.GOLD + "/" + EnumChatFormatting.YELLOW +
myFormatter.format(petLevel.currentLevelRequirement)
);

}
}
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -133,10 +133,11 @@ public static class Pet {
public String petXpType;
public String petItem;
public String skin;
public int candyUsed;

public String getPetId(boolean withoutBoost) {
return petType + ";" + (withoutBoost ? rarity.petId - 1 : rarity.petId);

boolean shouldDecreaseRarity = withoutBoost && "PET_ITEM_TIER_BOOST".equals(petItem);
return petType + ";" + (shouldDecreaseRarity ? rarity.petId - 1 : rarity.petId);
}

}
Expand Down Expand Up @@ -466,10 +467,10 @@ private List<String> createStringsForPet(Pet currentPet, boolean secondPet) {
float remainingMax = currentPet.petLevel.maxXP - currentPet.petLevel.totalXp;
if (remaining > 0) {
if (xpGain < 1000) {
etaMaxStr = EnumChatFormatting.AQUA + "Until L" + currentPet.petLevel.maxLevel + ": " +
etaMaxStr = EnumChatFormatting.AQUA + "Until L" + (int) currentPet.petLevel.maxLevel + ": " +
EnumChatFormatting.YELLOW + "N/A";
} else {
etaMaxStr = EnumChatFormatting.AQUA + "Until L" + currentPet.petLevel.maxLevel + ": " +
etaMaxStr = EnumChatFormatting.AQUA + "Until L" + (int) currentPet.petLevel.maxLevel + ": " +
EnumChatFormatting.YELLOW + Utils.prettyTime((long) (remainingMax) * 1000 * 60 * 60 / (long) xpGain);
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -106,7 +106,7 @@ public ResourceLocation getCustomEquipmentTexture(boolean isPetRendering) {
case 2:
return ARMOR_DISPLAY_DARK;
case 3:
return isPetRendering ? ARMOR_DISPLAY_TRANSPARENT_PET : ARMOR_DISPLAY_TRANSPARENT;
return NotEnoughUpdates.INSTANCE.config.petOverlay.colourStyle == 3 && isPetRendering ? ARMOR_DISPLAY_TRANSPARENT_PET : ARMOR_DISPLAY_TRANSPARENT;
case 4:
return ARMOR_DISPLAY_FSR;
}
Expand Down Expand Up @@ -191,7 +191,7 @@ public void renderEquipmentGui(GuiInventory guiScreen, int mouseX, int mouseY, i
int overlayLeft = container.getGuiLeft() - ARMOR_OVERLAY_OVERHAND_WIDTH;
int overlayTop = container.getGuiTop();

ResourceLocation equipmentTexture = getCustomEquipmentTexture(isRenderingPet);
ResourceLocation equipmentTexture = getCustomEquipmentTexture(shouldRenderPets);
Minecraft.getMinecraft().getTextureManager().bindTexture(equipmentTexture);

Utils.drawTexturedRect(overlayLeft, overlayTop, ARMOR_OVERLAY_WIDTH, ARMOR_OVERLAY_HEIGHT, GL11.GL_NEAREST);
Expand Down Expand Up @@ -243,7 +243,10 @@ private ItemStack getRepoPetStack() {
NEUManager manager = NotEnoughUpdates.INSTANCE.manager;
PetInfoOverlay.Pet currentPet = PetInfoOverlay.getCurrentPet();
if (currentPet == null) return null;
ItemStack item = manager.createItem(currentPet.getPetId(false));

ItemStack item = ItemUtils.createPetItemstackFromPetInfo(currentPet);
item = ItemUtils.petToolTipXPExtendPetOverlay(item);

if (item != null) {
return item;
}
Expand All @@ -259,7 +262,7 @@ private void updateGuiInfo(GuiScreen screen) {
slot4 = getWardrobeSlot(37);
}

if (screen instanceof GuiChest) {
if (screen instanceof GuiChest || screen instanceof GuiInventory) {
petStack = getRepoPetStack();
}
if ((!(screen instanceof GuiInventory) && !(screen instanceof GuiInvButtonEditor))
Expand Down
Loading

0 comments on commit 61c53c0

Please sign in to comment.