aboutsummaryrefslogtreecommitdiff
path: root/src/main/java/io/github/moulberry/notenoughupdates/miscgui
diff options
context:
space:
mode:
authorRoman / Nea <roman.graef@gmail.com>2022-02-18 14:57:06 +0100
committerGitHub <noreply@github.com>2022-02-18 14:57:06 +0100
commitf035ce00967bce495390bf4d7bc8ad17ab74073a (patch)
tree44a172a8087ba1ded8c80b8a978832bbac5dee68 /src/main/java/io/github/moulberry/notenoughupdates/miscgui
parent393f3c8f9279f5d8f5e33933ce6ef985d65a92f0 (diff)
downloadnotenoughupdates-f035ce00967bce495390bf4d7bc8ad17ab74073a.tar.gz
notenoughupdates-f035ce00967bce495390bf4d7bc8ad17ab74073a.tar.bz2
notenoughupdates-f035ce00967bce495390bf4d7bc8ad17ab74073a.zip
kat sitter overlay (#83)
* kat sitter overlay * Remove unused scan function
Diffstat (limited to 'src/main/java/io/github/moulberry/notenoughupdates/miscgui')
-rw-r--r--src/main/java/io/github/moulberry/notenoughupdates/miscgui/KatSitterOverlay.java88
1 files changed, 88 insertions, 0 deletions
diff --git a/src/main/java/io/github/moulberry/notenoughupdates/miscgui/KatSitterOverlay.java b/src/main/java/io/github/moulberry/notenoughupdates/miscgui/KatSitterOverlay.java
new file mode 100644
index 00000000..39d3a673
--- /dev/null
+++ b/src/main/java/io/github/moulberry/notenoughupdates/miscgui/KatSitterOverlay.java
@@ -0,0 +1,88 @@
+package io.github.moulberry.notenoughupdates.miscgui;
+
+import com.google.gson.JsonObject;
+import io.github.moulberry.notenoughupdates.NotEnoughUpdates;
+import io.github.moulberry.notenoughupdates.util.Utils;
+import io.github.moulberry.notenoughupdates.util.XPInformation;
+import net.minecraft.client.Minecraft;
+import net.minecraft.client.gui.FontRenderer;
+import net.minecraft.client.gui.inventory.GuiChest;
+import net.minecraft.client.renderer.GlStateManager;
+import net.minecraft.init.Blocks;
+import net.minecraft.inventory.ContainerChest;
+import net.minecraft.inventory.Slot;
+import net.minecraft.item.Item;
+import net.minecraft.item.ItemStack;
+import net.minecraft.nbt.NBTTagCompound;
+import net.minecraftforge.client.event.GuiScreenEvent;
+import net.minecraftforge.common.MinecraftForge;
+import net.minecraftforge.fml.common.eventhandler.SubscribeEvent;
+
+public class KatSitterOverlay {
+ public KatSitterOverlay() {
+ MinecraftForge.EVENT_BUS.register(this);
+ }
+
+ @SubscribeEvent
+ public void onGuiDrawn(GuiScreenEvent.DrawScreenEvent.Post event) {
+ if (!(event.gui instanceof GuiChest)) return;
+ if (!NotEnoughUpdates.INSTANCE.config.petOverlay.showKatSitting) return;
+ GuiChest gui = (GuiChest) event.gui;
+ ContainerChest container = (ContainerChest) gui.inventorySlots;
+ if (!"Pet Sitter".equals(container.getLowerChestInventory().getDisplayName().getUnformattedText())) return;
+ Slot slot = container.getSlot(13);
+ if (slot == null || !slot.getHasStack() || slot.getStack() == null) return;
+ ItemStack item = slot.getStack();
+ NBTTagCompound tagCompound = item.getTagCompound();
+ if (tagCompound == null || !tagCompound.hasKey("ExtraAttributes", 10)) return;
+ NBTTagCompound extra = tagCompound.getCompoundTag("ExtraAttributes");
+ if (extra == null || !extra.hasKey("id", 8) ||
+ !"PET".equals(extra.getString("id")) || !extra.hasKey("petInfo", 8))
+ return;
+ JsonObject petInfo = NotEnoughUpdates.INSTANCE.manager.gson.fromJson(extra.getString("petInfo"), JsonObject.class);
+ if (petInfo == null || !petInfo.has("exp") || !petInfo.has("tier") || !petInfo.has("type")) return;
+ String petId = petInfo.get("type").getAsString();
+ double xp = petInfo.get("exp").getAsDouble();
+ String rarity = petInfo.get("tier").getAsString();
+ Slot katSlot = container.getSlot(22);
+ String upgradedRarity = nextRarity(rarity);
+ boolean nextRarityPresent = katSlot.getStack() != null && katSlot.getStack().getItem() != Item.getItemFromBlock(Blocks.barrier) && upgradedRarity != null;
+ renderPetInformation(
+ (int) XPInformation.getInstance().getPetLevel(petId, xp, rarity),
+ nextRarityPresent ? (int) XPInformation.getInstance().getPetLevel(petId, xp, upgradedRarity) : null,
+ gui
+ );
+ }
+
+
+ public void renderPetInformation(int currentLevel, Integer upgradedLevel, GuiChest gui) {
+ FontRenderer font = Minecraft.getMinecraft().fontRendererObj;
+ String currentText = "Current pet level: " + currentLevel;
+ int currentWidth = font.getStringWidth(currentText);
+ String upgradedText = "Upgraded pet level: " + upgradedLevel;
+ int upgradedWidth = font.getStringWidth(upgradedText);
+ int left = gui.guiLeft - 30 - (upgradedLevel == null ? Math.max(upgradedWidth, currentWidth) : currentWidth);
+ GlStateManager.disableLighting();
+ GlStateManager.color(1F, 1F, 1F, 1F);
+ Utils.drawStringScaled(currentText, font, left, gui.guiTop + 25, false, 0xFFD700, 1F);
+ if (upgradedLevel != null)
+ Utils.drawStringScaled(upgradedText, font, left, gui.guiTop + 45, false, 0xFFD700, 1F);
+ }
+
+ public String nextRarity(String currentRarity) {
+ switch (currentRarity.intern()) {
+ case "COMMON":
+ return "UNCOMMON";
+ case "UNCOMMON":
+ return "RARE";
+ case "RARE":
+ return "EPIC";
+ case "EPIC":
+ return "LEGENDARY";
+ case "LEGENDARY":
+ return "MYTHIC";
+ }
+ return null;
+ }
+
+}