Skip to content

Commit

Permalink
Pets overlay done
Browse files Browse the repository at this point in the history
  • Loading branch information
Cephetir committed Jan 4, 2022
1 parent f2b08a3 commit 6dcae4c
Show file tree
Hide file tree
Showing 2 changed files with 92 additions and 40 deletions.
6 changes: 3 additions & 3 deletions src/main/java/me/cephetir/skyskipped/config/Config.java
Original file line number Diff line number Diff line change
Expand Up @@ -160,8 +160,8 @@ public class Config extends Vigilant {
@Property(
type = PropertyType.NUMBER,
name = "AMOUNT OF COINS DO YOU WANT",
category = "SUPER SECRETS SETTINGS §4!(!DO NOT OPEN!)!", subcategory = "SUPER SECRETS SETTINGS §4!(!DO NOT ENABLE!)!",
description = kAMOUNT OF COINS YOU WANT",
category = "SUPER SECRETS SETTINGS §4!(!DO NOT OPEN!)!", subcategory = "§4SUPER SECRETS SETTINGS!",
description = 4AMOUNT OF COINS YOU WANT",
max = Integer.MAX_VALUE,
increment = 10000000
)
Expand All @@ -187,7 +187,7 @@ public class Config extends Vigilant {
type = PropertyType.SWITCH,
name = "Pets Overlay",
category = "Visual", subcategory = "Visual",
description = "Good looking overlay for pets menu."
description = "Good looking overlay for pets menu.\n§cDon't use with small window size"
)
public static boolean petsOverlay = true;

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,9 +17,6 @@

package me.cephetir.skyskipped.features.impl.visual;

import com.google.gson.JsonObject;
import io.github.moulberry.notenoughupdates.NotEnoughUpdates;
import io.github.moulberry.notenoughupdates.miscfeatures.PetInfoOverlay;
import me.cephetir.skyskipped.config.Config;
import me.cephetir.skyskipped.features.Feature;
import me.cephetir.skyskipped.mixins.IMixinGuiContainer;
Expand All @@ -36,12 +33,10 @@
import net.minecraft.nbt.NBTTagCompound;
import net.minecraftforge.client.event.GuiOpenEvent;
import net.minecraftforge.client.event.GuiScreenEvent;
import net.minecraftforge.fml.common.Loader;
import net.minecraftforge.fml.common.eventhandler.EventPriority;
import net.minecraftforge.fml.common.eventhandler.SubscribeEvent;
import net.minecraftforge.fml.common.gameevent.TickEvent;
import org.lwjgl.input.Mouse;
import skytils.skytilsmod.features.impl.misc.PetFeatures;

import java.awt.*;
import java.util.ArrayList;
Expand All @@ -66,7 +61,7 @@ public void onGuiOpen(GuiOpenEvent event) {
GuiChest chest = (GuiChest) event.gui;
ContainerChest container = (ContainerChest) chest.inventorySlots;
String containerName = container.getLowerChestInventory().getDisplayName().getUnformattedText();
if (!containerName.equals("Pets")) return;
if (!containerName.endsWith("Pets")) return;
petsOverlay = new GuiPetsOverlay(chest);
new Thread(() -> {
try {
Expand Down Expand Up @@ -106,7 +101,7 @@ public void onTick(TickEvent.ClientTickEvent event) {
if (!Config.petsOverlay) return;
if (petsOverlay == null) return;
ticks++;
if (ticks == 20) {
if (ticks == 10) {
ticks = 0;
petsOverlay.getPets();
}
Expand All @@ -116,13 +111,17 @@ public class GuiPetsOverlay {
private GuiChest chest;
private List<Pet> pets = new ArrayList<>();
private int width, height;
private int j = 4;
private int rectWidth;
private int rectWidth1;
private int rectHeight;
private int rectHeight1;

private Slot autopet;
private Slot close;
private Slot convert;
private Slot hide;
private Slot page;
private Slot nextPage;
private Slot previousPage;

private final Pattern PET_PATTERN = Pattern.compile("§7\\[Lvl \\d+] (?<color>§[0-9a-fk-or]).+");

Expand All @@ -143,54 +142,63 @@ public void getPets() {
NBTTagCompound compound = slot.getStack().getTagCompound().getCompoundTag("display");
String displayName = compound.getString("Name");
if (displayName.toLowerCase().contains("[lvl ")) {
if (width / 2 / 3 + 5 + k * 32 > width / 2 - width / 2 / 3) {
if (rectWidth1 + 5 + k * 32 > width / 2 - rectWidth1) {
k = 0;
j++;
}
pets1.add(new Pet(width / 2 / 3 + 5 + k * 32, height / 2 / 4 + 5 + j * 32, displayName, slot, i, slot.getStack()));
pets1.add(new Pet(rectWidth1 + 5 + k * 32, rectHeight1 + 5 + j * 32, displayName, slot, i, slot.getStack()));
i++;
k++;

for (String text : slot.getStack().getTooltip(mc.thePlayer, false)) {
if (text.contains("Click to summon")) {
pets1.get(i - 1).last = false;
break;
} else if (text.contains("Click to despawn")) {
pets1.get(i - 1).last = true;
break;
}
}


Matcher m = PET_PATTERN.matcher(displayName);
if (m.matches())
pets1.get(i - 1).rarity = Objects.requireNonNull(RarityUtils.byBaseColor(m.group("color"))).getColorToRender().getRGB();

if (Loader.isModLoaded("skytils") && PetFeatures.Companion.getLastPet() != null && displayName.contains(PetFeatures.Companion.getLastPet()))
pets1.get(i - 1).last = true;
else if (Loader.isModLoaded("notenoughupdates") && NotEnoughUpdates.VERSION.equals("2.0.0-REL") && PetInfoOverlay.getCurrentPet() != null) {
JsonObject petItem = NotEnoughUpdates.INSTANCE.manager.getItemInformation().get(PetInfoOverlay.getCurrentPet().petType + ";" + PetInfoOverlay.getCurrentPet().rarity.petId);
ItemStack itemStack = NotEnoughUpdates.INSTANCE.manager.jsonToStack(petItem);
NBTTagCompound compoundd = itemStack.getTagCompound().getCompoundTag("display");
String name = compoundd.getString("Name");
if (displayName.equals(name)) pets1.get(i - 1).last = true;
}
} else if (displayName.toLowerCase().contains("autopet")) this.autopet = slot;
else if (displayName.toLowerCase().contains("close")) this.close = slot;
else if (displayName.toLowerCase().contains("convert pet")) this.convert = slot;
else if (displayName.toLowerCase().contains("hide pets")) this.hide = slot;
else if (displayName.toLowerCase().contains("page idk")) this.page = slot;
else if (displayName.toLowerCase().contains("next page")) this.nextPage = slot;
else if (displayName.toLowerCase().contains("previous page")) this.previousPage = slot;
}
}

pets = pets1;
this.j = j;
}

public void onDrawScreen(int mouseX, int mouseY) {
GlStateManager.pushMatrix();
GlStateManager.enableBlend();
GlStateManager.disableTexture2D();

int h = Math.max(height / 4 + 5 + j * 32 + 21, height - height / 3);
Gui.drawRect(width / 4 - 20, height / 4, width - width / 4 + 20, h, new Color(0, 0, 0, 105).getRGB());
rectWidth = width < 900 ? 0 : width / 5;
rectWidth1 = width < 900 ? 0 : width / 2 / 5;
rectHeight = height < 460 ? 0 : height / 5;
rectHeight1 = height < 460 ? 0 : height / 2 / 5;
Gui.drawRect(rectWidth - 20, rectHeight, width - rectWidth + 20, height - rectHeight, new Color(0, 0, 0, 105).getRGB());

GlStateManager.scale(2f, 2f, 2f);
GlStateManager.scale(1.5f, 1.5f, 1.5f);
mc.fontRendererObj.drawString("PETS", (rectWidth - 20 + 3) / 1.5f, (rectHeight - 15) / 1.5f, new Color(0, 0, 0).getRGB(), false);

GlStateManager.scale(2f / 1.5f, 2f / 1.5f, 2f / 1.5f);
if (!pets.isEmpty()) for (Pet pet : pets) {
renderItem(pet.itemStack, pet.x, pet.y);

if (pet.last)
if (pet.last) {
RoundUtils.drawRoundedRect(pet.x - 0.3f, pet.y - 0.3f, pet.x + 16.3f, pet.y + 16.3f, 6, pet.rarity);
RoundUtils.drawRoundedOutline(pet.x - 1f, pet.y - 1f, pet.x + 17f, pet.y + 17f, 6, 3f, new Color(23, 217, 7, 255).getRGB());
}
RoundUtils.drawRoundedOutline(pet.x - 0.5f, pet.y - 0.5f, pet.x + 16.5f, pet.y + 16.5f, 6, 2.5f, pet.rarity);

GlStateManager.scale(0.25f, 0.25f, 0.25f);
Expand All @@ -201,17 +209,50 @@ public void onDrawScreen(int mouseX, int mouseY) {
GlStateManager.scale(0.5f, 0.5f, 0.5f);

GlStateManager.resetColor();
Gui.drawRect(width / 2 - 50 - 12 - 100, h - 25, width / 2 - 50 - 12, h - 25 + 20, new Color(255, 255, 255, 150).getRGB());
mc.fontRendererObj.drawString("Auto Pet", width / 2 - 50 - 15 - 50 - mc.fontRendererObj.getStringWidth("Auto Pet") / 2, h - 25 + 10 - mc.fontRendererObj.FONT_HEIGHT / 2, new Color(0, 0, 0, 255).getRGB());

Gui.drawRect(width / 2 - 50, h - 25, width / 2 + 50, h - 25 + 20, new Color(255, 255, 255, 150).getRGB());
mc.fontRendererObj.drawString("Close", width / 2 - mc.fontRendererObj.getStringWidth("Close") / 2, h - 25 + 10 - mc.fontRendererObj.FONT_HEIGHT / 2, new Color(0, 0, 0, 255).getRGB());

Gui.drawRect(width / 2 + 50 + 12, h - 25, width / 2 + 50 + 12 + 100, h - 25 + 20, new Color(255, 255, 255, 150).getRGB());
mc.fontRendererObj.drawString("Convert Pet", width / 2 + 50 + 15 + 50 - mc.fontRendererObj.getStringWidth("Convert Pet") / 2, h - 25 + 10 - mc.fontRendererObj.FONT_HEIGHT / 2, new Color(0, 0, 0, 255).getRGB());
if (autopet != null) {
int h = height - rectHeight;

if (nextPage != null) {
Gui.drawRect(width / 2 - 50 - 12 - 100 - 12 - 100, h - 25, width / 2 - 50 - 12 - 100 - 12, h - 25 + 20, new Color(255, 255, 255, 150).getRGB());
mc.fontRendererObj.drawStringWithShadow("NEXT", width / 2f - 50 - 12 - 100 - 12 - 50 - mc.fontRendererObj.getStringWidth("NEXT") / 2f, h - 25 - 3, -1);
GlStateManager.scale(2f, 2f, 2f);
renderItem(nextPage.getStack(), (width / 2 - 50 - 12 - 100 - 12 - 66) / 2, (h - 25 - 6) / 2);
GlStateManager.scale(0.5f, 0.5f, 0.5f);
if (previousPage != null) {
Gui.drawRect(width / 2 - 50 - 12 - 100 - 12 - 100, h - 25 - 30, width / 2 - 50 - 12 - 100 - 12, h - 25 - 30 + 20, new Color(255, 255, 255, 150).getRGB());
mc.fontRendererObj.drawStringWithShadow("PREVIOUS", width / 2f - 50 - 12 - 100 - 12 - 50 - mc.fontRendererObj.getStringWidth("PREVIOUS") / 2f, h - 25 - 30 - 3, -1);
GlStateManager.scale(2f, 2f, 2f);
renderItem(previousPage.getStack(), (width / 2 - 50 - 12 - 100 - 12 - 66) / 2, (h - 25 - 30 - 6) / 2);
GlStateManager.scale(0.5f, 0.5f, 0.5f);
}
} else if (previousPage != null) {
Gui.drawRect(width / 2 - 50 - 12 - 100 - 12 - 100, h - 25, width / 2 - 50 - 12 - 100 - 12, h - 25 + 20, new Color(255, 255, 255, 150).getRGB());
mc.fontRendererObj.drawStringWithShadow("PREVIOUS", width / 2f - 50 - 12 - 100 - 12 - 50 - mc.fontRendererObj.getStringWidth("PREVIOUS") / 2f, h - 25 - 3, -1);
GlStateManager.scale(2f, 2f, 2f);
renderItem(previousPage.getStack(), (width / 2 - 50 - 12 - 100 - 12 - 66) / 2, (h - 25 - 6) / 2);
GlStateManager.scale(0.5f, 0.5f, 0.5f);
}

Gui.drawRect(width / 2 + 50 + 12 + 100 + 12, h - 25, width / 2 + 50 + 12 + 100 + 12 + 100, h - 25 + 20, new Color(255, 255, 255, 150).getRGB());
mc.fontRendererObj.drawString("Hide Pets", width / 2 + 50 + 15 + 100 + 15 + 50 - mc.fontRendererObj.getStringWidth("Hide Pets") / 2, h - 25 + 10 - mc.fontRendererObj.FONT_HEIGHT / 2, new Color(0, 0, 0, 255).getRGB());
Gui.drawRect(width / 2 - 50 - 12 - 100, h - 25, width / 2 - 50 - 12, h - 25 + 20, new Color(255, 255, 255, 150).getRGB());
GlStateManager.scale(2f, 2f, 2f);
renderItem(autopet.getStack(), (width / 2 - 50 - 12 - 66) / 2, (h - 25 - 6) / 2);
GlStateManager.scale(0.5f, 0.5f, 0.5f);

Gui.drawRect(width / 2 - 50, h - 25, width / 2 + 50, h - 25 + 20, new Color(255, 255, 255, 150).getRGB());
GlStateManager.scale(2f, 2f, 2f);
renderItem(close.getStack(), (width / 2 - 50 + 50 - 16) / 2, (h - 25 - 6) / 2);
GlStateManager.scale(0.5f, 0.5f, 0.5f);

Gui.drawRect(width / 2 + 50 + 12, h - 25, width / 2 + 50 + 12 + 100, h - 25 + 20, new Color(255, 255, 255, 150).getRGB());
GlStateManager.scale(2f, 2f, 2f);
renderItem(convert.getStack(), (width / 2 + 50 + 12 + 50 - 16) / 2, (h - 25 - 6) / 2);
GlStateManager.scale(0.5f, 0.5f, 0.5f);

Gui.drawRect(width / 2 + 50 + 12 + 100 + 12, h - 25, width / 2 + 50 + 12 + 100 + 12 + 100, h - 25 + 20, new Color(255, 255, 255, 150).getRGB());
GlStateManager.scale(2f, 2f, 2f);
renderItem(hide.getStack(), (width / 2 + 50 + 12 + 100 + 12 + 50 - 16) / 2, (h - 25 - 6) / 2);
GlStateManager.scale(0.5f, 0.5f, 0.5f);
}

GlStateManager.resetColor();
onHover(mouseX, mouseY);
Expand All @@ -235,7 +276,7 @@ public void onMouseClicked(double mouseX, double mouseY, int button) {

mouseX *= 2;
mouseY *= 2;
int h = Math.max(height / 4 + 5 + j * 32 + 21, height - height / 3);
int h = height - rectHeight;
if (mouseX > width / 2f - 50 - 12 - 100 && mouseY > h - 25 && mouseX < width / 2f - 50 - 12 && mouseY < h - 25 + 20)
container.handleMouseClick(autopet, autopet.slotNumber, button, 0);
else if (mouseX > width / 2f - 50 && mouseY > h - 25 && mouseX < width / 2f + 50 && mouseY < h - 25 + 20)
Expand All @@ -244,6 +285,17 @@ else if (mouseX > width / 2f + 50 + 12 && mouseY > h - 25 && mouseX < width / 2f
container.handleMouseClick(convert, convert.slotNumber, button, 0);
else if (mouseX > width / 2f + 50 + 12 + 100 + 12 && mouseY > h - 25 && mouseX < width / 2f + 50 + 12 + 100 + 12 + 100 && mouseY < h - 25 + 20)
container.handleMouseClick(hide, hide.slotNumber, button, 0);
else if (nextPage != null) {
if (mouseX > width / 2f - 50 - 12 - 100 - 12 - 100 && mouseY > h - 25 && mouseX < width / 2f - 50 - 12 - 100 - 12 && mouseY < h - 25 + 20)
container.handleMouseClick(nextPage, nextPage.slotNumber, button, 0);
if (previousPage != null) {
if (mouseX > width / 2f - 50 - 12 - 100 - 12 - 100 && mouseY > h - 25 - 30 && mouseX < width / 2f - 50 - 12 - 100 - 12 && mouseY < h - 25 - 30 + 20)
container.handleMouseClick(previousPage, previousPage.slotNumber, button, 0);
}
} else if (previousPage != null) {
if (mouseX > width / 2f - 50 - 12 - 100 - 12 - 100 && mouseY > h - 25 && mouseX < width / 2f - 50 - 12 - 100 - 12 && mouseY < h - 25 + 20)
container.handleMouseClick(previousPage, previousPage.slotNumber, button, 0);
}
}

public void onHover(int mouseX, int mouseY) {
Expand Down

0 comments on commit 6dcae4c

Please sign in to comment.