From a9ead0aa573b5a522bba94cecf18176f12078263 Mon Sep 17 00:00:00 2001 From: sin ender Date: Tue, 28 May 2024 21:29:07 -0400 Subject: [PATCH] Some code improvements, bug fixes, plus other things I think? --- .../llc/redstone/hysentials/Hysentials.java | 1 - .../hysentials/command/ClubCommand.java | 26 +- .../hysentials/command/HysentialsCommand.java | 15 +- .../cosmetics/AbstractCosmetic.java | 3 + .../hysentials/cosmetics/Cosmetic.java | 37 +++ .../cosmetics/backpack/BackpackCosmetic.java | 28 +- .../cosmetics/capes/CapeHandler.java | 6 +- .../cosmetics/cubit/CubitCompanion.java | 30 +- .../cosmetics/hamster/HamsterCompanion.java | 28 +- .../cosmetics/hats/blackcat/BlackCat.java | 25 +- .../hysentials/cosmetics/hats/cat/CatHat.java | 27 +- .../hats/technocrown/TechnoCrown.java | 28 +- .../cosmetics/kzero/KzeroBundle.java | 6 +- .../cosmetics/miya/MiyaCompanion.java | 28 +- .../cosmetics/pepper/PepperCompanion.java | 28 +- .../wings/dragon/DragonCosmetic.java | 27 +- .../wings/tdarth/LayerTdarthWings.java | 2 +- .../wings/tdarth/TdarthCosmetic.java | 31 +- .../guis/container/PaginationContainer.java | 2 +- .../chat/modules/bwranks/BWSReplace.java | 6 +- .../handlers/imageicons/ImageIcon.java | 4 +- .../hysentials/util/BlockWAPIUtils.java | 31 +- .../hysentials/util/ImageIconRenderer.java | 4 +- .../hysentials/cosmetic/CosmeticGui.kt | 93 +++--- .../hysentials/cosmetic/CosmeticTab.kt | 21 ++ .../hysentials/cosmetic/CosmeticUtils.kt | 293 +++++++++++------- .../hysentials/cosmetic/PreviewHandler.kt | 114 +++++++ .../macrowheel/overlay/MacroWheelOverlay.kt | 29 +- .../profileviewer/DefaultProfileGui.kt | 2 +- .../hysentials/schema/HysentialsSchema.kt | 32 +- 30 files changed, 754 insertions(+), 253 deletions(-) create mode 100644 src/main/java/llc/redstone/hysentials/cosmetics/Cosmetic.java create mode 100644 src/main/kotlin/llc/redstone/hysentials/cosmetic/PreviewHandler.kt diff --git a/src/main/java/llc/redstone/hysentials/Hysentials.java b/src/main/java/llc/redstone/hysentials/Hysentials.java index 8f251e7..2746e78 100644 --- a/src/main/java/llc/redstone/hysentials/Hysentials.java +++ b/src/main/java/llc/redstone/hysentials/Hysentials.java @@ -109,7 +109,6 @@ public class Hysentials { private final ChatHandler chatHandler = new ChatHandler(); public final GuiDisplayHandler guiDisplayHandler = new GuiDisplayHandler(); - public final CosmeticManager cosmeticManager = new CosmeticManager(); public static List commands; public ModAPIHandler hypixelModAPI; diff --git a/src/main/java/llc/redstone/hysentials/command/ClubCommand.java b/src/main/java/llc/redstone/hysentials/command/ClubCommand.java index aeb1db4..c508608 100644 --- a/src/main/java/llc/redstone/hysentials/command/ClubCommand.java +++ b/src/main/java/llc/redstone/hysentials/command/ClubCommand.java @@ -250,18 +250,20 @@ public void dashboard() { UChat.chat("&cYou must be linked to a Discord account to use this feature."); return; } - try { - String s = NetworkUtils.getString(getHYSENTIALS_API() + "/club?uuid=" - + Minecraft.getMinecraft().getSession().getProfile().getId().toString() - + "&key=" + Socket.serverId); - JsonObject clubData = new JsonParser().parse(s).getAsJsonObject(); - if (!clubData.get("success").getAsBoolean()) { - UChat.chat(HysentialsConfig.chatPrefix + " &c" + clubData.get("message").getAsString()); - return; + Multithreading.runAsync(() -> { + try { + String s = NetworkUtils.getString(getHYSENTIALS_API() + "/club?uuid=" + + Minecraft.getMinecraft().getSession().getProfile().getId().toString() + + "&key=" + Socket.serverId); + JsonObject clubData = new JsonParser().parse(s).getAsJsonObject(); + if (!clubData.get("success").getAsBoolean()) { + UChat.chat(HysentialsConfig.chatPrefix + " &c" + clubData.get("message").getAsString()); + return; + } + new ClubDashboard(clubData).open(Minecraft.getMinecraft().thePlayer); + } catch (Exception e) { + e.printStackTrace(); } - new ClubDashboard(clubData).open(Minecraft.getMinecraft().thePlayer); - } catch (Exception e) { - e.printStackTrace(); - } + }); } } diff --git a/src/main/java/llc/redstone/hysentials/command/HysentialsCommand.java b/src/main/java/llc/redstone/hysentials/command/HysentialsCommand.java index 5dcc17b..c34bb2c 100644 --- a/src/main/java/llc/redstone/hysentials/command/HysentialsCommand.java +++ b/src/main/java/llc/redstone/hysentials/command/HysentialsCommand.java @@ -1,9 +1,13 @@ package llc.redstone.hysentials.command; +import cc.polyfrost.oneconfig.gui.OneConfigGui; +import cc.polyfrost.oneconfig.gui.pages.ModConfigPage; +import cc.polyfrost.oneconfig.gui.pages.ModsPage; import cc.polyfrost.oneconfig.libs.universal.UChat; import cc.polyfrost.oneconfig.libs.universal.wrappers.message.UTextComponent; import cc.polyfrost.oneconfig.utils.Multithreading; import cc.polyfrost.oneconfig.utils.NetworkUtils; +import cc.polyfrost.oneconfig.utils.gui.GuiUtils; import com.google.gson.JsonArray; import llc.redstone.hysentials.Hysentials; import llc.redstone.hysentials.HysentialsUtilsKt; @@ -94,7 +98,12 @@ public void processCommand(ICommandSender sender, String[] args) throws CommandE } case "config": { - Hysentials.INSTANCE.getConfig().openGui(); + ModConfigPage page = new ModConfigPage(Hysentials.INSTANCE.getConfig().mod.defaultPage); + ModsPage page2 = new ModsPage(); + page.parents.add(page2); + page.parents.add(page); + + GuiUtils.displayScreen(new OneConfigGui(page)); break; } @@ -255,7 +264,7 @@ public static void handleLeaderboard(String command, String[] args) { break; } default: { - UChat.chat(HysentialsConfig.chatPrefix + " §cUnknown leaderboard type! Use /hysentials leaderboard for a list of types."); + UChat.chat(HysentialsConfig.chatPrefix + " §cUnknown leaderboard type! Use /hysentials leaderboard for a list of types."); break; } @@ -344,7 +353,7 @@ public void helpPage(int page) { text.appendText("&e/hysentials online &7- &bShows the online players.\n"); text.appendText("&e/hysentials menu &7- &bOpens the Hysentials menu.\n"); text.appendText("&e/hysentials discord &7- &bShows the discord invite link.\n"); - text.appendText("&e/hysentials leaderboard &7- Leaderboard.\n"); + text.appendText("&e/hs leaderboard &7- &bLeaderboard.\n"); text.appendText("§9&m "); break; } diff --git a/src/main/java/llc/redstone/hysentials/cosmetics/AbstractCosmetic.java b/src/main/java/llc/redstone/hysentials/cosmetics/AbstractCosmetic.java index 0b879f9..22085b0 100644 --- a/src/main/java/llc/redstone/hysentials/cosmetics/AbstractCosmetic.java +++ b/src/main/java/llc/redstone/hysentials/cosmetics/AbstractCosmetic.java @@ -14,12 +14,15 @@ import net.minecraftforge.fml.common.eventhandler.SubscribeEvent; import net.minecraftforge.fml.common.gameevent.TickEvent; +import java.util.ArrayList; +import java.util.List; import java.util.Map; import java.util.UUID; import static java.lang.Thread.sleep; public abstract class AbstractCosmetic { + public static List cosmetics = new ArrayList<>(); private final boolean selfOnly; public AbstractCosmetic(boolean selfOnly) { diff --git a/src/main/java/llc/redstone/hysentials/cosmetics/Cosmetic.java b/src/main/java/llc/redstone/hysentials/cosmetics/Cosmetic.java new file mode 100644 index 0000000..03a0c32 --- /dev/null +++ b/src/main/java/llc/redstone/hysentials/cosmetics/Cosmetic.java @@ -0,0 +1,37 @@ +package llc.redstone.hysentials.cosmetics; + +import net.minecraft.client.Minecraft; +import net.minecraft.client.model.ModelBase; +import net.minecraft.client.renderer.GlStateManager; +import net.minecraft.entity.player.EntityPlayer; +import net.minecraft.util.ResourceLocation; + +import java.util.ArrayList; +import java.util.List; + +public interface Cosmetic { + boolean canUse(EntityPlayer player); + ModelBase getModel(); + ResourceLocation getTexture(); + String getName(); + + default void renderPreview(int x, int y, int ticks) { + EntityPlayer player = Minecraft.getMinecraft().thePlayer; + if (!canUse(player)) return; + Minecraft.getMinecraft().getTextureManager().bindTexture(getTexture()); + GlStateManager.pushMatrix(); + + GlStateManager.rotate(toRadians(ticks /20f), 0f, 1.0F, 0.0F); +// GlStateManager.translate(x, y, 0); + float n = 1; + GlStateManager.scale(n, n, n); + + getModel().render(player, 0, 0, 0, 0, 0, n); + + GlStateManager.popMatrix(); + } + + default float toRadians(float degrees) { + return (float) (degrees * (Math.PI / 180)); + } +} diff --git a/src/main/java/llc/redstone/hysentials/cosmetics/backpack/BackpackCosmetic.java b/src/main/java/llc/redstone/hysentials/cosmetics/backpack/BackpackCosmetic.java index a4afb9a..2e11454 100644 --- a/src/main/java/llc/redstone/hysentials/cosmetics/backpack/BackpackCosmetic.java +++ b/src/main/java/llc/redstone/hysentials/cosmetics/backpack/BackpackCosmetic.java @@ -1,24 +1,30 @@ package llc.redstone.hysentials.cosmetics.backpack; import llc.redstone.hysentials.cosmetic.CosmeticGui; -import llc.redstone.hysentials.cosmetic.CosmeticUtilsKt; +import llc.redstone.hysentials.cosmetic.CosmeticManager; import llc.redstone.hysentials.cosmetics.AbstractCosmetic; +import llc.redstone.hysentials.cosmetics.Cosmetic; import llc.redstone.hysentials.cosmetics.hats.cat.CatHat; import llc.redstone.hysentials.cosmetics.hats.cat.CatModel; import llc.redstone.hysentials.cosmetic.CosmeticGui; +import net.minecraft.client.Minecraft; +import net.minecraft.client.model.ModelBase; +import net.minecraft.client.renderer.GlStateManager; import net.minecraft.entity.player.EntityPlayer; import net.minecraft.util.ResourceLocation; import java.util.ArrayList; import java.util.List; -public class BackpackCosmetic { +public class BackpackCosmetic implements Cosmetic { public static List backpacks = new ArrayList<>(); + boolean catpack; BackpackModel model; CatPackModel catModel; String name; ResourceLocation texture; public BackpackCosmetic(String name, boolean catpack) { + this.catpack = catpack; if (catpack) { catModel = new CatPackModel(); } else { @@ -26,10 +32,24 @@ public BackpackCosmetic(String name, boolean catpack) { } this.name = name; texture = new ResourceLocation("hysentials:backpacks/" + name + ".png"); + AbstractCosmetic.cosmetics.add(this); } public boolean canUse(EntityPlayer player) { - return CosmeticUtilsKt.equippedCosmetic(player.getUniqueID(), name) - && CosmeticUtilsKt.hasCosmetic(player.getUniqueID(), name); + return CosmeticManager.equippedCosmetic(player.getUniqueID(), name) + && CosmeticManager.hasCosmetic(player.getUniqueID(), name); + } + + public ModelBase getModel() { + return catpack ? catModel : model; + } + + public ResourceLocation getTexture() { + return texture; + } + + @Override + public String getName() { + return name; } public static void loadBackpacks() { diff --git a/src/main/java/llc/redstone/hysentials/cosmetics/capes/CapeHandler.java b/src/main/java/llc/redstone/hysentials/cosmetics/capes/CapeHandler.java index 85f3338..d5e7ec4 100644 --- a/src/main/java/llc/redstone/hysentials/cosmetics/capes/CapeHandler.java +++ b/src/main/java/llc/redstone/hysentials/cosmetics/capes/CapeHandler.java @@ -1,6 +1,6 @@ package llc.redstone.hysentials.cosmetics.capes; -import llc.redstone.hysentials.cosmetic.CosmeticUtilsKt; +import llc.redstone.hysentials.cosmetic.CosmeticManager; import llc.redstone.hysentials.schema.HysentialsSchema; import llc.redstone.hysentials.websocket.Socket; import net.minecraft.client.Minecraft; @@ -25,11 +25,11 @@ public void onTickEvent(TickEvent.ClientTickEvent event) { for (String id : Socket.cachedUsers.keySet()) { UUID uuid = UUID.fromString(id); boolean wearingCape = false; - for (HysentialsSchema.Cosmetic cosmetic : CosmeticUtilsKt.getEquippedCosmetics(uuid)) { + for (HysentialsSchema.Cosmetic cosmetic : CosmeticManager.getEquippedCosmetics(uuid)) { if (cosmetic.getSubType() != null && cosmetic.getSubType().equals("cape")) { wearingCape = true; String name = cosmetic.getName(); - if (CosmeticUtilsKt.hasCosmetic(uuid, name)) { + if (CosmeticManager.hasCosmetic(uuid, name)) { ResourceLocation location = new ResourceLocation(cosmetic.getResource()); resourceMap.put(uuid, cosmetic.getResource()); try { diff --git a/src/main/java/llc/redstone/hysentials/cosmetics/cubit/CubitCompanion.java b/src/main/java/llc/redstone/hysentials/cosmetics/cubit/CubitCompanion.java index bce025e..c30a5c6 100644 --- a/src/main/java/llc/redstone/hysentials/cosmetics/cubit/CubitCompanion.java +++ b/src/main/java/llc/redstone/hysentials/cosmetics/cubit/CubitCompanion.java @@ -2,8 +2,9 @@ import cc.polyfrost.oneconfig.libs.universal.UChat; import llc.redstone.hysentials.cosmetic.CosmeticGui; -import llc.redstone.hysentials.cosmetic.CosmeticUtilsKt; +import llc.redstone.hysentials.cosmetic.CosmeticManager; import llc.redstone.hysentials.cosmetics.AbstractCosmetic; +import llc.redstone.hysentials.cosmetics.Cosmetic; import llc.redstone.hysentials.util.BUtils; import llc.redstone.hysentials.websocket.Socket; import llc.redstone.hysentials.cosmetic.CosmeticGui; @@ -11,20 +12,26 @@ import llc.redstone.hysentials.util.BUtils; import llc.redstone.hysentials.websocket.Socket; import net.minecraft.client.Minecraft; +import net.minecraft.client.model.ModelBase; import net.minecraft.client.multiplayer.WorldClient; +import net.minecraft.client.renderer.EntityRenderer; +import net.minecraft.client.renderer.GlStateManager; import net.minecraft.entity.Entity; import net.minecraft.entity.item.EntityArmorStand; import net.minecraft.entity.player.EntityPlayer; +import net.minecraft.util.ResourceLocation; import java.util.HashMap; import java.util.Map; import java.util.UUID; -public class CubitCompanion extends AbstractCosmetic { +public class CubitCompanion extends AbstractCosmetic implements Cosmetic { private Map cubits = new HashMap<>(); + private CubitModel model = new CubitModel(); public CubitCompanion() { super(false); + AbstractCosmetic.cosmetics.add(this); } @Override @@ -34,11 +41,26 @@ public Map getEntities() { @Override public boolean canUse(EntityPlayer player) { - return CosmeticUtilsKt.equippedCosmetic(player.getUniqueID(), "cubit") - && CosmeticUtilsKt.hasCosmetic(player.getUniqueID(), "cubit") + return CosmeticManager.equippedCosmetic(player.getUniqueID(), "cubit") + && CosmeticManager.hasCosmetic(player.getUniqueID(), "cubit") && !player.isInvisible(); } + @Override + public ModelBase getModel() { + return model; + } + + @Override + public ResourceLocation getTexture() { + return new ResourceLocation("hysentials:pets/cubit.png"); + } + + @Override + public String getName() { + return "cubit"; + } + public static long cooldown = 0; @Override public void interact(EntityCubit entity) { diff --git a/src/main/java/llc/redstone/hysentials/cosmetics/hamster/HamsterCompanion.java b/src/main/java/llc/redstone/hysentials/cosmetics/hamster/HamsterCompanion.java index 22c4054..74d22e6 100644 --- a/src/main/java/llc/redstone/hysentials/cosmetics/hamster/HamsterCompanion.java +++ b/src/main/java/llc/redstone/hysentials/cosmetics/hamster/HamsterCompanion.java @@ -18,25 +18,30 @@ package llc.redstone.hysentials.cosmetics.hamster; import llc.redstone.hysentials.cosmetic.CosmeticGui; -import llc.redstone.hysentials.cosmetic.CosmeticUtilsKt; +import llc.redstone.hysentials.cosmetic.CosmeticManager; import llc.redstone.hysentials.cosmetics.AbstractCosmetic; +import llc.redstone.hysentials.cosmetics.Cosmetic; import llc.redstone.hysentials.event.InvokeEvent; import llc.redstone.hysentials.cosmetic.CosmeticGui; import llc.redstone.hysentials.cosmetics.AbstractCosmetic; import net.minecraft.client.Minecraft; +import net.minecraft.client.model.ModelBase; import net.minecraft.client.multiplayer.WorldClient; import net.minecraft.entity.Entity; import net.minecraft.entity.item.EntityArmorStand; import net.minecraft.entity.player.EntityPlayer; +import net.minecraft.util.ResourceLocation; import net.minecraft.world.World; import java.util.*; -public class HamsterCompanion extends AbstractCosmetic { +public class HamsterCompanion extends AbstractCosmetic implements Cosmetic { private Map hamsters = new HashMap<>(); + private HamsterModel model = new HamsterModel(); public HamsterCompanion() { super(false); + AbstractCosmetic.cosmetics.add(this); } @@ -65,11 +70,26 @@ public Map getEntities() { @Override public boolean canUse(EntityPlayer player) { - return CosmeticUtilsKt.equippedCosmetic(player.getUniqueID(), "hamster") - && CosmeticUtilsKt.hasCosmetic(player.getUniqueID(), "hamster") + return CosmeticManager.equippedCosmetic(player.getUniqueID(), "hamster") + && CosmeticManager.hasCosmetic(player.getUniqueID(), "hamster") && !player.isInvisible(); } + @Override + public ModelBase getModel() { + return model; + } + + @Override + public ResourceLocation getTexture() { + return new ResourceLocation("hysentials:pets/hamsterbrown.png"); + } + + @Override + public String getName() { + return "hamster"; + } + @Override public void interact(EntityHamster entity) { diff --git a/src/main/java/llc/redstone/hysentials/cosmetics/hats/blackcat/BlackCat.java b/src/main/java/llc/redstone/hysentials/cosmetics/hats/blackcat/BlackCat.java index af05425..72318ae 100644 --- a/src/main/java/llc/redstone/hysentials/cosmetics/hats/blackcat/BlackCat.java +++ b/src/main/java/llc/redstone/hysentials/cosmetics/hats/blackcat/BlackCat.java @@ -1,17 +1,34 @@ package llc.redstone.hysentials.cosmetics.hats.blackcat; import llc.redstone.hysentials.cosmetic.CosmeticGui; -import llc.redstone.hysentials.cosmetic.CosmeticUtilsKt; +import llc.redstone.hysentials.cosmetic.CosmeticManager; +import llc.redstone.hysentials.cosmetics.AbstractCosmetic; +import llc.redstone.hysentials.cosmetics.Cosmetic; import llc.redstone.hysentials.cosmetics.hats.technocrown.TechnoCrownModel; import net.minecraft.entity.player.EntityPlayer; +import net.minecraft.util.ResourceLocation; -public class BlackCat { +public class BlackCat implements Cosmetic { BlackCatModel model; public BlackCat() { model = new BlackCatModel(); + AbstractCosmetic.cosmetics.add(this); } public boolean canUse(EntityPlayer player) { - return CosmeticUtilsKt.equippedCosmetic(player.getUniqueID(), "black cat") - && CosmeticUtilsKt.hasCosmetic(player.getUniqueID(), "black cat"); + return CosmeticManager.equippedCosmetic(player.getUniqueID(), "black cat") + && CosmeticManager.hasCosmetic(player.getUniqueID(), "black cat"); + } + + public BlackCatModel getModel() { + return model; + } + + public ResourceLocation getTexture() { + return new ResourceLocation("hysentials:hats/blackcat.png"); + } + + @Override + public String getName() { + return "black cat"; } } diff --git a/src/main/java/llc/redstone/hysentials/cosmetics/hats/cat/CatHat.java b/src/main/java/llc/redstone/hysentials/cosmetics/hats/cat/CatHat.java index c9807dd..7e39658 100644 --- a/src/main/java/llc/redstone/hysentials/cosmetics/hats/cat/CatHat.java +++ b/src/main/java/llc/redstone/hysentials/cosmetics/hats/cat/CatHat.java @@ -1,14 +1,17 @@ package llc.redstone.hysentials.cosmetics.hats.cat; import llc.redstone.hysentials.cosmetic.CosmeticGui; -import llc.redstone.hysentials.cosmetic.CosmeticUtilsKt; +import llc.redstone.hysentials.cosmetic.CosmeticManager; +import llc.redstone.hysentials.cosmetics.AbstractCosmetic; +import llc.redstone.hysentials.cosmetics.Cosmetic; +import net.minecraft.client.model.ModelBase; import net.minecraft.entity.player.EntityPlayer; import net.minecraft.util.ResourceLocation; import java.util.ArrayList; import java.util.List; -public class CatHat { +public class CatHat implements Cosmetic { public static List catHats = new ArrayList<>(); CatModel model; String name; @@ -17,10 +20,26 @@ public CatHat(String name) { model = new CatModel(); this.name = name; texture = new ResourceLocation("hysentials:hats/" + name + ".png"); + AbstractCosmetic.cosmetics.add(this); } public boolean canUse(EntityPlayer player) { - return CosmeticUtilsKt.equippedCosmetic(player.getUniqueID(), name) - && CosmeticUtilsKt.hasCosmetic(player.getUniqueID(), name); + return CosmeticManager.equippedCosmetic(player.getUniqueID(), name) + && CosmeticManager.hasCosmetic(player.getUniqueID(), name); + } + + @Override + public ModelBase getModel() { + return model; + } + + @Override + public ResourceLocation getTexture() { + return texture; + } + + @Override + public String getName() { + return name; } public static void loadCatHats() { diff --git a/src/main/java/llc/redstone/hysentials/cosmetics/hats/technocrown/TechnoCrown.java b/src/main/java/llc/redstone/hysentials/cosmetics/hats/technocrown/TechnoCrown.java index 1791122..d737e7b 100644 --- a/src/main/java/llc/redstone/hysentials/cosmetics/hats/technocrown/TechnoCrown.java +++ b/src/main/java/llc/redstone/hysentials/cosmetics/hats/technocrown/TechnoCrown.java @@ -1,16 +1,36 @@ package llc.redstone.hysentials.cosmetics.hats.technocrown; import llc.redstone.hysentials.cosmetic.CosmeticGui; -import llc.redstone.hysentials.cosmetic.CosmeticUtilsKt; +import llc.redstone.hysentials.cosmetic.CosmeticManager; +import llc.redstone.hysentials.cosmetics.AbstractCosmetic; +import llc.redstone.hysentials.cosmetics.Cosmetic; +import net.minecraft.client.model.ModelBase; import net.minecraft.entity.player.EntityPlayer; +import net.minecraft.util.ResourceLocation; -public class TechnoCrown { +public class TechnoCrown implements Cosmetic { TechnoCrownModel model; public TechnoCrown() { model = new TechnoCrownModel(); + AbstractCosmetic.cosmetics.add(this); } public boolean canUse(EntityPlayer player) { - return CosmeticUtilsKt.equippedCosmetic(player.getUniqueID(), "techno crown") - && CosmeticUtilsKt.hasCosmetic(player.getUniqueID(), "techno crown"); + return CosmeticManager.equippedCosmetic(player.getUniqueID(), "techno crown") + && CosmeticManager.hasCosmetic(player.getUniqueID(), "techno crown"); + } + + @Override + public ModelBase getModel() { + return model; + } + + @Override + public ResourceLocation getTexture() { + return new ResourceLocation("hysentials:hats/technocrown.png"); + } + + @Override + public String getName() { + return "techno crown"; } } diff --git a/src/main/java/llc/redstone/hysentials/cosmetics/kzero/KzeroBundle.java b/src/main/java/llc/redstone/hysentials/cosmetics/kzero/KzeroBundle.java index 31014f6..0d3f15a 100644 --- a/src/main/java/llc/redstone/hysentials/cosmetics/kzero/KzeroBundle.java +++ b/src/main/java/llc/redstone/hysentials/cosmetics/kzero/KzeroBundle.java @@ -2,7 +2,7 @@ import llc.redstone.hysentials.cosmetic.CosmeticGui; import llc.redstone.hysentials.cosmetic.CosmeticGui; -import llc.redstone.hysentials.cosmetic.CosmeticUtilsKt; +import llc.redstone.hysentials.cosmetic.CosmeticManager; import net.minecraft.client.entity.AbstractClientPlayer; public class KzeroBundle { @@ -19,8 +19,8 @@ public KzeroBundle() { } public static boolean canUse(AbstractClientPlayer player, Type type) { - return CosmeticUtilsKt.equippedCosmetic(player.getUniqueID(), "kzero " + type.name().toLowerCase()) - && CosmeticUtilsKt.hasCosmetic(player.getUniqueID(), "kzero " + type.name().toLowerCase()); + return CosmeticManager.equippedCosmetic(player.getUniqueID(), "kzero " + type.name().toLowerCase()) + && CosmeticManager.hasCosmetic(player.getUniqueID(), "kzero " + type.name().toLowerCase()); } public enum Type { diff --git a/src/main/java/llc/redstone/hysentials/cosmetics/miya/MiyaCompanion.java b/src/main/java/llc/redstone/hysentials/cosmetics/miya/MiyaCompanion.java index 9dcad1c..cd6e0ba 100644 --- a/src/main/java/llc/redstone/hysentials/cosmetics/miya/MiyaCompanion.java +++ b/src/main/java/llc/redstone/hysentials/cosmetics/miya/MiyaCompanion.java @@ -1,25 +1,30 @@ package llc.redstone.hysentials.cosmetics.miya; import llc.redstone.hysentials.cosmetic.CosmeticGui; -import llc.redstone.hysentials.cosmetic.CosmeticUtilsKt; +import llc.redstone.hysentials.cosmetic.CosmeticManager; import llc.redstone.hysentials.cosmetics.AbstractCosmetic; import llc.redstone.hysentials.cosmetic.CosmeticGui; import llc.redstone.hysentials.cosmetics.AbstractCosmetic; +import llc.redstone.hysentials.cosmetics.Cosmetic; import net.minecraft.client.Minecraft; +import net.minecraft.client.model.ModelBase; import net.minecraft.client.multiplayer.WorldClient; import net.minecraft.entity.Entity; import net.minecraft.entity.item.EntityArmorStand; import net.minecraft.entity.player.EntityPlayer; +import net.minecraft.util.ResourceLocation; import java.util.HashMap; import java.util.Map; import java.util.UUID; -public class MiyaCompanion extends AbstractCosmetic { +public class MiyaCompanion extends AbstractCosmetic implements Cosmetic { private Map miyas = new HashMap<>(); + private MiyaModel model = new MiyaModel(); public MiyaCompanion() { super(false); + AbstractCosmetic.cosmetics.add(this); } @Override @@ -29,11 +34,26 @@ public Map getEntities() { @Override public boolean canUse(EntityPlayer player) { - return CosmeticUtilsKt.equippedCosmetic(player.getUniqueID(), "miya") - && CosmeticUtilsKt.hasCosmetic(player.getUniqueID(), "miya") + return CosmeticManager.equippedCosmetic(player.getUniqueID(), "miya") + && CosmeticManager.hasCosmetic(player.getUniqueID(), "miya") && !player.isInvisible(); } + @Override + public ModelBase getModel() { + return model; + } + + @Override + public ResourceLocation getTexture() { + return new ResourceLocation("hysentials:pets/miya.png"); + } + + @Override + public String getName() { + return "miya"; + } + public static long cooldown = 0; @Override public void interact(EntityMiya entity) { diff --git a/src/main/java/llc/redstone/hysentials/cosmetics/pepper/PepperCompanion.java b/src/main/java/llc/redstone/hysentials/cosmetics/pepper/PepperCompanion.java index 65cc5fe..871b0e1 100644 --- a/src/main/java/llc/redstone/hysentials/cosmetics/pepper/PepperCompanion.java +++ b/src/main/java/llc/redstone/hysentials/cosmetics/pepper/PepperCompanion.java @@ -2,28 +2,33 @@ import cc.polyfrost.oneconfig.libs.universal.UChat; import llc.redstone.hysentials.cosmetic.CosmeticGui; -import llc.redstone.hysentials.cosmetic.CosmeticUtilsKt; +import llc.redstone.hysentials.cosmetic.CosmeticManager; import llc.redstone.hysentials.cosmetics.AbstractCosmetic; +import llc.redstone.hysentials.cosmetics.Cosmetic; import llc.redstone.hysentials.cosmetics.cubit.EntityCubit; import llc.redstone.hysentials.util.BUtils; import llc.redstone.hysentials.websocket.Socket; import llc.redstone.hysentials.cosmetic.CosmeticGui; import llc.redstone.hysentials.cosmetics.AbstractCosmetic; import net.minecraft.client.Minecraft; +import net.minecraft.client.model.ModelBase; import net.minecraft.client.multiplayer.WorldClient; import net.minecraft.entity.Entity; import net.minecraft.entity.item.EntityArmorStand; import net.minecraft.entity.player.EntityPlayer; +import net.minecraft.util.ResourceLocation; import java.util.HashMap; import java.util.Map; import java.util.UUID; -public class PepperCompanion extends AbstractCosmetic { +public class PepperCompanion extends AbstractCosmetic implements Cosmetic { private Map peppers = new HashMap<>(); + private PepperModel model = new PepperModel(); public PepperCompanion() { super(false); + AbstractCosmetic.cosmetics.add(this); } @Override @@ -33,11 +38,26 @@ public Map getEntities() { @Override public boolean canUse(EntityPlayer player) { - return CosmeticUtilsKt.equippedCosmetic(player.getUniqueID(), "pepper") - && CosmeticUtilsKt.hasCosmetic(player.getUniqueID(), "pepper") + return CosmeticManager.equippedCosmetic(player.getUniqueID(), "pepper") + && CosmeticManager.hasCosmetic(player.getUniqueID(), "pepper") && !player.isInvisible(); } + @Override + public ModelBase getModel() { + return model; + } + + @Override + public ResourceLocation getTexture() { + return new ResourceLocation("hysentials:pets/pepper.png"); + } + + @Override + public String getName() { + return "pepper"; + } + public static long cooldown = 0; @Override public void interact(EntityPepper entity) { diff --git a/src/main/java/llc/redstone/hysentials/cosmetics/wings/dragon/DragonCosmetic.java b/src/main/java/llc/redstone/hysentials/cosmetics/wings/dragon/DragonCosmetic.java index 04e555a..d259272 100644 --- a/src/main/java/llc/redstone/hysentials/cosmetics/wings/dragon/DragonCosmetic.java +++ b/src/main/java/llc/redstone/hysentials/cosmetics/wings/dragon/DragonCosmetic.java @@ -1,18 +1,37 @@ package llc.redstone.hysentials.cosmetics.wings.dragon; -import llc.redstone.hysentials.cosmetic.CosmeticUtilsKt; +import llc.redstone.hysentials.cosmetic.CosmeticManager; +import llc.redstone.hysentials.cosmetics.AbstractCosmetic; +import llc.redstone.hysentials.cosmetics.Cosmetic; import llc.redstone.hysentials.cosmetics.wings.tdarth.TdarthModel; +import net.minecraft.client.model.ModelBase; import net.minecraft.entity.player.EntityPlayer; import net.minecraft.util.ResourceLocation; -public class DragonCosmetic { +public class DragonCosmetic implements Cosmetic { ResourceLocation texture; DragonWingsModel model = new DragonWingsModel(); public DragonCosmetic() { texture = new ResourceLocation("hysentials:wings/dragon.png"); + AbstractCosmetic.cosmetics.add(this); } public boolean canUse(EntityPlayer player) { - return CosmeticUtilsKt.equippedCosmetic(player.getUniqueID(), "dragon") - && CosmeticUtilsKt.hasCosmetic(player.getUniqueID(), "dragon"); + return CosmeticManager.equippedCosmetic(player.getUniqueID(), "dragon") + && CosmeticManager.hasCosmetic(player.getUniqueID(), "dragon"); + } + + @Override + public ModelBase getModel() { + return model; + } + + @Override + public ResourceLocation getTexture() { + return texture; + } + + @Override + public String getName() { + return "dragon"; } } diff --git a/src/main/java/llc/redstone/hysentials/cosmetics/wings/tdarth/LayerTdarthWings.java b/src/main/java/llc/redstone/hysentials/cosmetics/wings/tdarth/LayerTdarthWings.java index d0f465b..d06596c 100644 --- a/src/main/java/llc/redstone/hysentials/cosmetics/wings/tdarth/LayerTdarthWings.java +++ b/src/main/java/llc/redstone/hysentials/cosmetics/wings/tdarth/LayerTdarthWings.java @@ -19,7 +19,7 @@ public void doRenderLayer(AbstractClientPlayer entitylivingbaseIn, float f, floa if (wings == null) { return; } - if (!wings.canUse(entitylivingbaseIn.getUniqueID())) { + if (!wings.canUse(entitylivingbaseIn)) { return; } if (entitylivingbaseIn.isInvisible()) return; diff --git a/src/main/java/llc/redstone/hysentials/cosmetics/wings/tdarth/TdarthCosmetic.java b/src/main/java/llc/redstone/hysentials/cosmetics/wings/tdarth/TdarthCosmetic.java index e9311c3..8e9651b 100644 --- a/src/main/java/llc/redstone/hysentials/cosmetics/wings/tdarth/TdarthCosmetic.java +++ b/src/main/java/llc/redstone/hysentials/cosmetics/wings/tdarth/TdarthCosmetic.java @@ -1,9 +1,12 @@ package llc.redstone.hysentials.cosmetics.wings.tdarth; -import llc.redstone.hysentials.cosmetic.CosmeticUtilsKt; +import llc.redstone.hysentials.cosmetic.CosmeticManager; +import llc.redstone.hysentials.cosmetics.Cosmetic; import llc.redstone.hysentials.websocket.Socket; import net.minecraft.client.Minecraft; +import net.minecraft.client.model.ModelBase; import net.minecraft.client.renderer.texture.DynamicTexture; +import net.minecraft.entity.player.EntityPlayer; import net.minecraft.util.ResourceLocation; import net.minecraftforge.fml.common.eventhandler.SubscribeEvent; import net.minecraftforge.fml.common.gameevent.TickEvent; @@ -13,7 +16,7 @@ import java.util.HashMap; import java.util.UUID; -public class TdarthCosmetic { +public class TdarthCosmetic implements Cosmetic { ResourceLocation texture; TdarthModel model = new TdarthModel(); public static HashMap textureMap = new HashMap<>(); @@ -57,7 +60,27 @@ public void onTickEvent(TickEvent.ClientTickEvent event) { } catch (Exception ignored) {} } public boolean canUse(UUID uuid) { - return CosmeticUtilsKt.equippedCosmetic(uuid, "tdarth") - && CosmeticUtilsKt.hasCosmetic(uuid, "tdarth"); + return CosmeticManager.equippedCosmetic(uuid, "tdarth") + && CosmeticManager.hasCosmetic(uuid, "tdarth"); + } + + @Override + public boolean canUse(EntityPlayer player) { + return canUse(player.getUniqueID()); + } + + @Override + public ModelBase getModel() { + return model; + } + + @Override + public ResourceLocation getTexture() { + return texture; + } + + @Override + public String getName() { + return "tdarth"; } } diff --git a/src/main/java/llc/redstone/hysentials/guis/container/PaginationContainer.java b/src/main/java/llc/redstone/hysentials/guis/container/PaginationContainer.java index 5561613..938a842 100644 --- a/src/main/java/llc/redstone/hysentials/guis/container/PaginationContainer.java +++ b/src/main/java/llc/redstone/hysentials/guis/container/PaginationContainer.java @@ -45,7 +45,7 @@ public void setItems() { newItems.sort(Comparator.comparing(ItemStack::getDisplayName)); paginationList = new PaginationList<>(newItems, ((rows - 2) * 7)); - maxPages = paginationList.size(); + maxPages = paginationList.getPageCount(); if (page > maxPages) { page = maxPages; } diff --git a/src/main/java/llc/redstone/hysentials/handlers/chat/modules/bwranks/BWSReplace.java b/src/main/java/llc/redstone/hysentials/handlers/chat/modules/bwranks/BWSReplace.java index b0ce21e..277bf63 100644 --- a/src/main/java/llc/redstone/hysentials/handlers/chat/modules/bwranks/BWSReplace.java +++ b/src/main/java/llc/redstone/hysentials/handlers/chat/modules/bwranks/BWSReplace.java @@ -5,7 +5,7 @@ import llc.redstone.hysentials.config.hysentialmods.ChatConfig; import llc.redstone.hysentials.config.hysentialmods.FormattingConfig; import llc.redstone.hysentials.config.hysentialmods.HousingConfig; -import llc.redstone.hysentials.cosmetic.CosmeticUtilsKt; +import llc.redstone.hysentials.cosmetic.CosmeticManager; import llc.redstone.hysentials.schema.HysentialsSchema; import llc.redstone.hysentials.util.*; import cc.polyfrost.oneconfig.libs.universal.wrappers.message.UTextComponent; @@ -209,12 +209,12 @@ public void onMessageReceived(@NotNull ClientChatReceivedEvent event) { } private static String bold(UUID id) { - boolean bold = id != null && CosmeticUtilsKt.equippedCosmetic(id, "bold messages"); + boolean bold = id != null && CosmeticManager.equippedCosmetic(id, "bold messages"); return bold ? "§l" : ""; } private static String italic(UUID id) { - boolean italic = id != null && CosmeticUtilsKt.equippedCosmetic(id, "italic messages"); + boolean italic = id != null && CosmeticManager.equippedCosmetic(id, "italic messages"); return italic ? "§o" : ""; } diff --git a/src/main/java/llc/redstone/hysentials/handlers/imageicons/ImageIcon.java b/src/main/java/llc/redstone/hysentials/handlers/imageicons/ImageIcon.java index a473c32..07aa78c 100644 --- a/src/main/java/llc/redstone/hysentials/handlers/imageicons/ImageIcon.java +++ b/src/main/java/llc/redstone/hysentials/handlers/imageicons/ImageIcon.java @@ -1,7 +1,7 @@ package llc.redstone.hysentials.handlers.imageicons; import llc.redstone.hysentials.cosmetic.CosmeticGui; -import llc.redstone.hysentials.cosmetic.CosmeticUtilsKt; +import llc.redstone.hysentials.cosmetic.CosmeticManager; import llc.redstone.hysentials.util.MUtils; import llc.redstone.hysentials.util.ImageIconRenderer; import net.minecraft.client.Minecraft; @@ -138,7 +138,7 @@ public int getHeight() { public static Pattern stringPattern = Pattern.compile(":([a-z_\\-0-9?]+):", 2); public int renderImage(float x, float y, boolean shadow, int oldColor, UUID uuid, float alpha) { - if (emoji && uuid != null && !CosmeticUtilsKt.hasCosmetic(uuid, "hymojis")) { + if (emoji && uuid != null && !CosmeticManager.hasCosmetic(uuid, "hymojis")) { return -1; } int width = this.getWidth(); diff --git a/src/main/java/llc/redstone/hysentials/util/BlockWAPIUtils.java b/src/main/java/llc/redstone/hysentials/util/BlockWAPIUtils.java index 33f88c2..e662d7a 100644 --- a/src/main/java/llc/redstone/hysentials/util/BlockWAPIUtils.java +++ b/src/main/java/llc/redstone/hysentials/util/BlockWAPIUtils.java @@ -4,6 +4,9 @@ import llc.redstone.hysentials.HysentialsUtilsKt; import llc.redstone.hysentials.config.hysentialmods.FormattingConfig; import llc.redstone.hysentials.config.hysentialmods.rank.RankStuff; +import llc.redstone.hysentials.cosmetic.CosmeticGui; +import llc.redstone.hysentials.cosmetics.AbstractCosmetic; +import llc.redstone.hysentials.cosmetics.Cosmetic; import llc.redstone.hysentials.handlers.imageicons.ImageIcon; import llc.redstone.hysentials.handlers.redworks.BwRanksUtils; import llc.redstone.hysentials.schema.HysentialsSchema; @@ -14,6 +17,7 @@ import java.util.ArrayList; import java.util.List; import java.util.UUID; +import java.util.stream.Collectors; public class BlockWAPIUtils { public static List actions = new ArrayList<>(); @@ -26,9 +30,11 @@ public class BlockWAPIUtils { public static void getOnline() { if (Socket.CLIENT == null || !Socket.CLIENT.isOpen()) return; try { - JsonElement cosmetics; + JsonElement cosmetics = null; try { - cosmetics = NetworkUtils.getJsonElement(HysentialsUtilsKt.getHYSENTIALS_API() + "/cosmetic", true); + if (!(Minecraft.getMinecraft().currentScreen instanceof CosmeticGui)) { + cosmetics = NetworkUtils.getJsonElement(HysentialsUtilsKt.getHYSENTIALS_API() + "/cosmetic", true); + } JsonElement a = NetworkUtils.getJsonElement(HysentialsUtilsKt.getHYSENTIALS_API() + "/actions", true); JsonObject json = a.getAsJsonObject(); @@ -38,6 +44,7 @@ public static void getOnline() { actions.add(a1); }); + if (cosmetics == null) return; JsonObject object = cosmetics.getAsJsonObject(); JsonArray array = object.getAsJsonArray("cosmetics"); BlockWAPIUtils.cosmetics = new ArrayList<>(); @@ -45,6 +52,7 @@ public static void getOnline() { HysentialsSchema.Cosmetic cosmetic = HysentialsSchema.Cosmetic.Companion.deserialize(cosmeticObj.getAsJsonObject()); BlockWAPIUtils.cosmetics.add(cosmetic); } + } catch (Exception ignored) { ignored.printStackTrace(); } @@ -54,6 +62,14 @@ public static void getOnline() { } } + public static void setCosmeticInstance() { + for (HysentialsSchema.Cosmetic cosmetic : cosmetics) { + for (Cosmetic c: AbstractCosmetic.cosmetics) { + + } + } + } + public static boolean isOnline(UUID uuid) { return Socket.cachedUsers.containsKey(uuid.toString()); } @@ -73,6 +89,11 @@ public static List getCosmetics() { return cosmetics; } + public static List getCosmetic(String type) { + if (cosmetics == null) return new ArrayList<>(); + return cosmetics.stream().filter(c -> c.getType().equals(type)).collect(Collectors.toList()); + } + public static String getRequest(String endpoint) { return HysentialsUtilsKt.getHYSENTIALS_API() + "/" + endpoint + "?key=" + Socket.serverId + "&uuid=" + Minecraft.getMinecraft().thePlayer.getGameProfile().getId().toString(); } @@ -87,11 +108,11 @@ public static Rank getRank(String uuid) { } public static Rank getRank(UUID uuid) { - BlockWAPIUtils.Rank rank; + Rank rank; try { - rank = BlockWAPIUtils.Rank.valueOf(Socket.cachedUsers.get(uuid.toString()).getRank().toUpperCase()); + rank = Rank.valueOf(Socket.cachedUsers.get(uuid.toString()).getRank().toUpperCase()); } catch (Exception e) { - rank = BlockWAPIUtils.Rank.DEFAULT; + rank = Rank.DEFAULT; } return rank; } diff --git a/src/main/java/llc/redstone/hysentials/util/ImageIconRenderer.java b/src/main/java/llc/redstone/hysentials/util/ImageIconRenderer.java index f95cb0a..128e8be 100644 --- a/src/main/java/llc/redstone/hysentials/util/ImageIconRenderer.java +++ b/src/main/java/llc/redstone/hysentials/util/ImageIconRenderer.java @@ -1,7 +1,7 @@ package llc.redstone.hysentials.util; import llc.redstone.hysentials.Hysentials; -import llc.redstone.hysentials.cosmetic.CosmeticUtilsKt; +import llc.redstone.hysentials.cosmetic.CosmeticManager; import llc.redstone.hysentials.handlers.imageicons.ImageIcon; import llc.redstone.hysentials.hook.FontRendererAcessor; import com.ibm.icu.text.ArabicShaping; @@ -368,7 +368,7 @@ public int getStringWidth(String text) { int height = icon.getHeight(); float scaledHeight = (float) 9 / height; int scaledWidth = (int) (width * scaledHeight); - if (icon.emoji && uuid != null && CosmeticUtilsKt.hasCosmetic(uuid, "hymojis")) { + if (icon.emoji && uuid != null && CosmeticManager.hasCosmetic(uuid, "hymojis")) { j += str.length() + 1; i += scaledWidth; continue; diff --git a/src/main/kotlin/llc/redstone/hysentials/cosmetic/CosmeticGui.kt b/src/main/kotlin/llc/redstone/hysentials/cosmetic/CosmeticGui.kt index 23ddc98..4413797 100644 --- a/src/main/kotlin/llc/redstone/hysentials/cosmetic/CosmeticGui.kt +++ b/src/main/kotlin/llc/redstone/hysentials/cosmetic/CosmeticGui.kt @@ -12,6 +12,17 @@ import llc.redstone.hysentials.util.* import llc.redstone.hysentials.utils.splitToWords import llc.redstone.hysentials.websocket.Socket import com.google.common.collect.Lists +import llc.redstone.hysentials.cosmetic.CosmeticManager.drawSlot +import llc.redstone.hysentials.cosmetic.CosmeticManager.equipCosmetic +import llc.redstone.hysentials.cosmetic.CosmeticManager.equippedCosmetic +import llc.redstone.hysentials.cosmetic.CosmeticManager.getOwnedCosmetics +import llc.redstone.hysentials.cosmetic.CosmeticManager.hasCosmetic +import llc.redstone.hysentials.cosmetic.CosmeticManager.indexFromRarity +import llc.redstone.hysentials.cosmetic.CosmeticManager.purchaseCosmetic +import llc.redstone.hysentials.cosmetic.CosmeticManager.tabFromType +import llc.redstone.hysentials.cosmetic.CosmeticManager.unEquipCosmetic +import llc.redstone.hysentials.cosmetic.CosmeticManager.updateCosmetics +import llc.redstone.hysentials.cosmetic.CosmeticTab.Companion.tabs import llc.redstone.hysentials.utils.drawEntityOnScreen import net.minecraft.client.Minecraft import net.minecraft.client.audio.PositionedSoundRecord @@ -38,26 +49,6 @@ open class CosmeticGui : UScreen(), HysentialsGui { var type: String = "owned" var inventorySlots: ArrayList = Lists.newArrayList() var paginationList: PaginationList? = null - - var ownedTabReal = CosmeticTab("owned", "Owned", ResourceLocation("hysentials:gui/wardrobe/tab/owned.png"), "32a852", 10.0, 10.0, 5.0, 4.0) - var headTabReal = CosmeticTab("head", "Headwear", ResourceLocation("hysentials:gui/wardrobe/tab/headwear.png"), "1787e3", 9.0, 10.0, 5.0, 22.0) - var backTabReal = CosmeticTab("back", "Chestwear", ResourceLocation("hysentials:gui/wardrobe/tab/chestwear.png"), "e69927", 9.0, 9.0, 5.0, 38.0) - var pantaloonsTabReal = CosmeticTab("pantaloons", "Pantaloons", ResourceLocation("hysentials:gui/wardrobe/tab/pantaloons.png"), "8327e6", 9.0, 11.0, 5.0, 53.0) - var bootsTabReal = CosmeticTab("boots", "Boots", ResourceLocation("hysentials:gui/wardrobe/tab/boots.png"), "ea323b", 11.0, 7.0, 4.0, 70.0) - var petsTabReal = CosmeticTab("pet", "Pets", ResourceLocation("hysentials:gui/wardrobe/tab/pets.png"), "e4ea32", 9.0, 10.0, 5.0, 83.0) - var chatTabReal = CosmeticTab("chat", "Chatbox", ResourceLocation("hysentials:gui/wardrobe/tab/chatbox.png"), "32eade", 9.0, 7.0, 5.0, 99.0) - var bundlesTabReal = CosmeticTab("bundle", "Bundles", ResourceLocation("hysentials:gui/wardrobe/tab/bundles.png"), "e832e6", 9.0, 10.0, 5.0, 112.0) - - var tabs = listOf( - ownedTabReal, - headTabReal, - backTabReal, - pantaloonsTabReal, - bootsTabReal, - petsTabReal, - chatTabReal, - bundlesTabReal - ) } var xSize = 290 @@ -76,6 +67,8 @@ open class CosmeticGui : UScreen(), HysentialsGui { var focused: Boolean = false var blinkTimer: Int = 0 + var hoverTimer: Int = 0 + var currentHover: Int = -1 val input: Input = Input(0, 0, 0, 0).let { it.setEnabled(true) @@ -108,23 +101,17 @@ open class CosmeticGui : UScreen(), HysentialsGui { } } try { - if (HysentialsConfig.wardrobeDarkMode) { - Renderer.drawImage(cosmeticBackground, guiLeft.toDouble(), guiTop.toDouble(), xSize.toDouble(), ySize.toDouble()) - } else { - Renderer.drawImage(lightBackground, guiLeft.toDouble(), guiTop.toDouble(), xSize.toDouble(), ySize.toDouble()) - } + // Draw the background (dark and light) + Renderer.drawImage(if (HysentialsConfig.wardrobeDarkMode) cosmeticBackground else lightBackground, guiLeft.toDouble(), guiTop.toDouble(), xSize.toDouble(), ySize.toDouble()) val emerald = Socket.cachedUser?.emeralds ?: 0 - - for (tab in tabs) { tab.draw(guiLeft, guiTop) } - + // Draw the selected tab val typeFinal = tabFromType(type)?.displayName ?: "Owned" mcFive.drawStringShadow(" > ${typeFinal.splitToWords().uppercase()} ($page/$maxPage)", guiLeft + 71f, guiTop + 5f, 0xFFFFFF) - - + // Draw the emerald count var largeFormat = DecimalFormat("#,###") mcFive.drawStringShadow(" ${largeFormat.format(emerald)}", guiLeft + 71f, guiTop + 149f, 0x55FF55) @@ -132,10 +119,15 @@ open class CosmeticGui : UScreen(), HysentialsGui { GlStateManager.enableDepth() RenderHelper.enableStandardItemLighting() GlStateManager.enableRescaleNormal() + //Draw player entity drawEntityOnScreen(guiLeft + 256, guiTop + 124, 40, xAngle, -yAngle, mc.thePlayer) for (slot in inventorySlots) { - drawSlot(slot, mouseX, mouseY, partialTicks) + val page = paginationList!!.getPage(CosmeticGui.page) + if (page.size > slot.slotIndex) { + val cosmetic = page[slot.slotIndex] + drawSlot(slot, cosmetic) + } if (getSlot( mouseX.toFloat() - guiLeft, mouseY.toFloat() - guiTop @@ -168,6 +160,22 @@ open class CosmeticGui : UScreen(), HysentialsGui { } this.drawHoveringText(list, mouseX, mouseY, fontRenderer) +// val page = paginationList!!.getPage(CosmeticGui.page) +// if (page.size > theSlot!!.slotIndex) { +// val cosmetic = page[theSlot!!.slotIndex] +// if (currentHover == -1) { +// currentHover = theSlot!!.slotIndex +// hoverTimer = 0 +// } else if (currentHover == theSlot!!.slotIndex) { +// hoverTimer++ +// if (hoverTimer >= 200) { +// cosmetic.renderPreview(mouseX, mouseY, hoverTimer - 200) +// } +// } else { +// currentHover = theSlot!!.slotIndex +// hoverTimer = 0 +// } +// } } var rX = mouseX.toFloat() - guiLeft @@ -308,25 +316,24 @@ open class CosmeticGui : UScreen(), HysentialsGui { val uuid = Minecraft.getMinecraft().thePlayer.uniqueID val emerald = Socket.cachedUser?.emeralds ?: 0 if (equippedCosmetic(uuid, cosmeticName) && hasCosmetic(uuid, cosmeticName)) { - Hysentials.INSTANCE.cosmeticManager.unEquipCosmetic(cosmeticName) { - if (!(JSONObject(it)["success"] as Boolean)) return@unEquipCosmetic - initScreen(width, height) - } + unEquipCosmetic(cosmeticName) + initScreen(width, height) } else if (hasCosmetic(uuid, cosmeticName)) { - Hysentials.INSTANCE.cosmeticManager.equipCosmetic(cosmeticName) { - if (!(JSONObject(it)["success"] as Boolean)) return@equipCosmetic - initScreen(width, height) - } + equipCosmetic(cosmeticName) + initScreen(width, height) } else if (!hasCosmetic(uuid, cosmeticName) && emerald >= cosmetic.cost) { - Hysentials.INSTANCE.cosmeticManager.purchaseCosmetic(cosmeticName) { - if (!(JSONObject(it)["success"] as Boolean)) return@purchaseCosmetic - initScreen(width, height) - } + purchaseCosmetic(cosmeticName) + initScreen(width, height) } } } } + override fun onScreenClose() { + super.onScreenClose() + updateCosmetics() + } + override fun onMouseReleased(mouseX: Double, mouseY: Double, state: Int) { super.onMouseReleased(mouseX, mouseY, state) if (state == 0) { diff --git a/src/main/kotlin/llc/redstone/hysentials/cosmetic/CosmeticTab.kt b/src/main/kotlin/llc/redstone/hysentials/cosmetic/CosmeticTab.kt index 709b9fc..3360891 100644 --- a/src/main/kotlin/llc/redstone/hysentials/cosmetic/CosmeticTab.kt +++ b/src/main/kotlin/llc/redstone/hysentials/cosmetic/CosmeticTab.kt @@ -13,6 +13,27 @@ class CosmeticTab( val x: Double, val y: Double) { + companion object { + var ownedTabReal = CosmeticTab("owned", "Owned", ResourceLocation("hysentials:gui/wardrobe/tab/owned.png"), "32a852", 10.0, 10.0, 5.0, 4.0) + var headTabReal = CosmeticTab("head", "Headwear", ResourceLocation("hysentials:gui/wardrobe/tab/headwear.png"), "1787e3", 9.0, 10.0, 5.0, 22.0) + var backTabReal = CosmeticTab("back", "Chestwear", ResourceLocation("hysentials:gui/wardrobe/tab/chestwear.png"), "e69927", 9.0, 9.0, 5.0, 38.0) + var pantaloonsTabReal = CosmeticTab("pantaloons", "Pantaloons", ResourceLocation("hysentials:gui/wardrobe/tab/pantaloons.png"), "8327e6", 9.0, 11.0, 5.0, 53.0) + var bootsTabReal = CosmeticTab("boots", "Boots", ResourceLocation("hysentials:gui/wardrobe/tab/boots.png"), "ea323b", 11.0, 7.0, 4.0, 70.0) + var petsTabReal = CosmeticTab("pet", "Pets", ResourceLocation("hysentials:gui/wardrobe/tab/pets.png"), "e4ea32", 9.0, 10.0, 5.0, 83.0) + var chatTabReal = CosmeticTab("chat", "Chatbox", ResourceLocation("hysentials:gui/wardrobe/tab/chatbox.png"), "32eade", 9.0, 7.0, 5.0, 99.0) + var bundlesTabReal = CosmeticTab("bundle", "Bundles", ResourceLocation("hysentials:gui/wardrobe/tab/bundles.png"), "e832e6", 9.0, 10.0, 5.0, 112.0) + val tabs: List = listOf( + ownedTabReal, + headTabReal, + backTabReal, + pantaloonsTabReal, + bootsTabReal, + petsTabReal, + chatTabReal, + bundlesTabReal + ) + } + fun draw (guiLeft: Int, guiTop: Int) { if (CosmeticGui.type == name) { Renderer.drawImage( diff --git a/src/main/kotlin/llc/redstone/hysentials/cosmetic/CosmeticUtils.kt b/src/main/kotlin/llc/redstone/hysentials/cosmetic/CosmeticUtils.kt index 87c9fb3..9f20c18 100644 --- a/src/main/kotlin/llc/redstone/hysentials/cosmetic/CosmeticUtils.kt +++ b/src/main/kotlin/llc/redstone/hysentials/cosmetic/CosmeticUtils.kt @@ -1,46 +1,62 @@ package llc.redstone.hysentials.cosmetic +import cc.polyfrost.oneconfig.utils.Multithreading +import com.google.gson.JsonElement import llc.redstone.hysentials.HYSENTIALS_API -import llc.redstone.hysentials.IO -import llc.redstone.hysentials.util.BlockWAPIUtils -import llc.redstone.hysentials.util.NetworkUtils -import llc.redstone.hysentials.websocket.Socket -import kotlinx.coroutines.launch +import llc.redstone.hysentials.Hysentials import llc.redstone.hysentials.cosmetic.CosmeticGui.Companion.paginationList import llc.redstone.hysentials.schema.HysentialsSchema +import llc.redstone.hysentials.schema.HysentialsSchema.Cosmetic.Companion.deserialize +import llc.redstone.hysentials.util.BlockWAPIUtils +import llc.redstone.hysentials.util.NetworkUtils import llc.redstone.hysentials.util.Renderer +import llc.redstone.hysentials.websocket.Socket import net.minecraft.client.Minecraft import net.minecraft.client.renderer.GlStateManager import net.minecraft.client.resources.model.IBakedModel import net.minecraft.inventory.Slot import net.minecraft.item.ItemStack import net.minecraft.util.ResourceLocation +import org.json.JSONObject import java.util.* -class CosmeticManager { - fun unEquipCosmetic(name: String, cb: (response: String) -> Unit) { - IO.launch { - if (name == "kzero bundle") kzero(false) - val name = name.replace(" ", "%20") - val response = - NetworkUtils.postString(HYSENTIALS_API + "/cosmetic?name=$name&function=unequip&uuid=${Minecraft.getMinecraft().thePlayer.uniqueID}&key=${Socket.serverId}") - BlockWAPIUtils.getOnline() - cb(response) +object CosmeticManager { + var actions = mapOf( + "equip" to mutableListOf(), + "unequip" to mutableListOf(), + "purchase" to mutableListOf() + ) + + fun unEquipCosmetic(name: String) { + if (name == "kzero bundle") return kzero(false) + val cosmetics = BlockWAPIUtils.getCosmetics() + val cosmetic = cosmetics.find { it.name == name } + cosmetic?.let { + if (it.equipped.contains(Minecraft.getMinecraft().thePlayer.uniqueID.toString())) { + it.equipped.remove(Minecraft.getMinecraft().thePlayer.uniqueID.toString()) + } + actions["unequip"]?.add(name) } } - fun equipCosmetic(name: String, cb: (response: String) -> Unit) { - IO.launch { - if (name == "kzero bundle") kzero(true) - val name = name.replace(" ", "%20") - val response = - NetworkUtils.postString(HYSENTIALS_API + "/cosmetic?name=$name&function=equip&uuid=${Minecraft.getMinecraft().thePlayer.uniqueID}&key=${Socket.serverId}") - BlockWAPIUtils.getOnline() - cb(response) + fun equipCosmetic(name: String) { + if (name == "kzero bundle") return kzero(true) + val cosmetics = BlockWAPIUtils.getCosmetics() + val cosmetic = cosmetics.find { it.name == name } + cosmetic?.let { + if (BlockWAPIUtils.getCosmetic(it.type).isNotEmpty()) { + BlockWAPIUtils.getCosmetic(it.type).forEach { cosmetic -> + unEquipCosmetic(cosmetic.name) + } + } + if (!it.equipped.contains(Minecraft.getMinecraft().thePlayer.uniqueID.toString())) { + it.equipped.add(Minecraft.getMinecraft().thePlayer.uniqueID.toString()) + } + actions["equip"]?.add(name) } } - suspend fun kzero (equip: Boolean) { + fun kzero(equip: Boolean) { var list = listOf( "kzero hair", "kzero robe", @@ -49,125 +65,176 @@ class CosmeticManager { for (cosmetic in list) { val name = cosmetic.replace(" ", "%20") if (equip) { - NetworkUtils.postString(HYSENTIALS_API + "/cosmetic?name=$name&function=equip&uuid=${Minecraft.getMinecraft().thePlayer.uniqueID}&key=${Socket.serverId}") + equipCosmetic(name) } else { - NetworkUtils.postString(HYSENTIALS_API + "/cosmetic?name=$name&function=unequip&uuid=${Minecraft.getMinecraft().thePlayer.uniqueID}&key=${Socket.serverId}") + unEquipCosmetic(name) + } + } + } + + fun purchaseCosmetic(cosmeticName: String) { + val cosmetics = BlockWAPIUtils.getCosmetics() + val cosmetic = cosmetics.find { it.name == cosmeticName } + cosmetic?.let { + if (!it.users.contains(Minecraft.getMinecraft().thePlayer.uniqueID.toString())) { + it.users.add(Minecraft.getMinecraft().thePlayer.uniqueID.toString()) + Socket.cachedUser.amountSpent = Socket.cachedUser.amountSpent?.plus(it.cost) + Socket.cachedUser.emeralds = Socket.cachedUser.emeralds.minus(it.cost) + actions["purchase"]?.add(cosmeticName) } } } - fun purchaseCosmetic(cosmeticName: String, cb: (response: String) -> Unit) { - IO.launch { - val cosmeticName = cosmeticName.replace(" ", "%20") - val response = - NetworkUtils.postString(HYSENTIALS_API + "/cosmetic?name=$cosmeticName&function=purchase&uuid=${Minecraft.getMinecraft().thePlayer.uniqueID}&key=${Socket.serverId}") - BlockWAPIUtils.getOnline() - cb(response) + fun updateCosmetics() { + Multithreading.runAsync { + for (action in actions) { + val list = action.value + val func = action.key + + for (name in list) { + val response = + NetworkUtils.postString(HYSENTIALS_API + "/cosmetic?name=$name&function=${func}&uuid=${Minecraft.getMinecraft().thePlayer.uniqueID}&key=${Socket.serverId}") + val json = JSONObject(response) + if (json.get("success") == false) { + Hysentials.INSTANCE.sendMessage( + "&cFailed to $func $name: ${json.get("message")}", + ) + } + } + } + actions = mapOf( + "equip" to mutableListOf(), + "unequip" to mutableListOf(), + "purchase" to mutableListOf() + ) + var cosmetics: JsonElement? = + NetworkUtils.getJsonElement("$HYSENTIALS_API/cosmetic", true) ?: return@runAsync + val `object` = cosmetics!!.asJsonObject + val array = `object`.getAsJsonArray("cosmetics") + BlockWAPIUtils.cosmetics = ArrayList() + for (cosmeticObj in array) { + val cosmetic = deserialize(cosmeticObj.asJsonObject) + BlockWAPIUtils.cosmetics.add(cosmetic) + } } } -} - -val slotResource = ResourceLocation("hysentials:gui/wardrobe/selected_slot.png") -fun drawSlot(slotIn: Slot, mouseX: Int, mouseY: Int, partialTicks: Float) { - val i: Int = slotIn.xDisplayPosition - val j: Int = slotIn.yDisplayPosition - GlStateManager.disableLighting() - GlStateManager.disableDepth() - GlStateManager.colorMask(true, true, true, false) - val page = paginationList!!.getPage(CosmeticGui.page) - if (page.size > slotIn.slotIndex) { - val cosmetic = page[slotIn.slotIndex] + + val slotResource = ResourceLocation("hysentials:gui/wardrobe/selected_slot.png") + + fun drawSlot(slotIn: Slot, cosmetic: HysentialsSchema.Cosmetic) { + val i: Int = slotIn.xDisplayPosition + val j: Int = slotIn.yDisplayPosition + GlStateManager.disableLighting() + GlStateManager.disableDepth() + GlStateManager.colorMask(true, true, true, false) val name = cosmetic.name val uuid = Minecraft.getMinecraft().thePlayer.uniqueID if (equippedCosmetic(uuid, name)) { Renderer.drawImage(slotResource, i.toDouble(), j.toDouble(), 25.0, 26.0) } + + val itemstack: ItemStack = slotIn.stack ?: return + + val ibakedmodel: IBakedModel = Minecraft.getMinecraft().renderItem.itemModelMesher.getItemModel(itemstack) + val width = ibakedmodel.particleTexture.iconWidth + val height = ibakedmodel.particleTexture.iconHeight + Minecraft.getMinecraft().renderItem.renderItemAndEffectIntoGUI( + itemstack, + i + (25 - width) / 2, + j + (26 - height) / 2 + ) + Minecraft.getMinecraft().renderItem.renderItemOverlayIntoGUI( + Minecraft.getMinecraft().fontRendererObj, + itemstack, + i + (25 - width) / 2, + j + (26 - height) / 2, + "" + ) + + Minecraft.getMinecraft().renderItem.zLevel = 0.0f + GlStateManager.enableLighting() + GlStateManager.enableDepth() + GlStateManager.colorMask(true, true, true, true) + + } - val itemstack: ItemStack = slotIn.stack ?: return - val ibakedmodel: IBakedModel = Minecraft.getMinecraft().renderItem.itemModelMesher.getItemModel(itemstack) - val width = ibakedmodel.particleTexture.iconWidth - val height = ibakedmodel.particleTexture.iconHeight - Minecraft.getMinecraft().renderItem.renderItemAndEffectIntoGUI(itemstack, i + (25 - width) / 2, j + (26 - height) / 2) - Minecraft.getMinecraft().renderItem.renderItemOverlayIntoGUI(Minecraft.getMinecraft().fontRendererObj, itemstack, i + (25 - width) / 2, j + (26 - height) / 2, "") - Minecraft.getMinecraft().renderItem.zLevel = 0.0f - GlStateManager.enableLighting() - GlStateManager.enableDepth() - GlStateManager.colorMask(true, true, true, true) -} + @JvmStatic + fun equippedCosmetic(uuid: UUID, name: String): Boolean { + try { + val cosmetics = BlockWAPIUtils.getCosmetics() + cosmetics.find { it.name == name }?.let { + if (it.equipped.contains(uuid.toString())) { + return true + } + } + } catch (_: Exception) { + } + return false + } + @JvmStatic + fun hasCosmetic(uuid: UUID, name: String): Boolean { + try { + val cosmetics = BlockWAPIUtils.getCosmetics() + cosmetics.find { it.name == name }?.let { + if (it.users.contains(uuid.toString())) { + return true + } + } + } catch (_: Exception) { + } + return false + } -fun equippedCosmetic(uuid: UUID, name: String): Boolean { - try { + @JvmStatic + fun getOwnedCosmetics(uuid: UUID): ArrayList { val cosmetics = BlockWAPIUtils.getCosmetics() - cosmetics.find { it.name == name }?.let { - if (it.equipped.contains(uuid.toString())) { - return true + val ownedCosmetics = ArrayList() + for (cosmetic in cosmetics) { + if (cosmetic.users.contains(uuid.toString())) { + ownedCosmetics.add(cosmetic) } } - } catch (_: Exception) { + return ownedCosmetics } - return false -} -fun hasCosmetic(uuid: UUID, name: String): Boolean { - try { + @JvmStatic + fun getEquippedCosmetics(uuid: UUID): ArrayList { val cosmetics = BlockWAPIUtils.getCosmetics() - cosmetics.find { it.name == name }?.let { - if (it.users.contains(uuid.toString())) { - return true + val equippedCosmetics = ArrayList() + for (cosmetic in cosmetics) { + if (cosmetic.equipped.contains(uuid.toString())) { + equippedCosmetics.add(cosmetic) } } - } catch (_: Exception) { + return equippedCosmetics } - return false -} - -fun getOwnedCosmetics(uuid: UUID): ArrayList { - val cosmetics = BlockWAPIUtils.getCosmetics() - val ownedCosmetics = ArrayList() - for (cosmetic in cosmetics) { - if (cosmetic.users.contains(uuid.toString())) { - ownedCosmetics.add(cosmetic) + + fun colorFromRarity(rarity: String): String { + return when (rarity) { + "COMMON" -> "#828282" + "RARE" -> "#0099DB" + "EPIC" -> "#8B5CF6" + "LEGENDARY" -> "#F49E0B" + "EXCLUSIVE" -> "#EA323C" + else -> "#FFFFFF" } } - return ownedCosmetics -} - -fun getEquippedCosmetics(uuid: UUID): ArrayList { - val cosmetics = BlockWAPIUtils.getCosmetics() - val equippedCosmetics = ArrayList() - for (cosmetic in cosmetics) { - if (cosmetic.equipped.contains(uuid.toString())) { - equippedCosmetics.add(cosmetic) + + fun indexFromRarity(rarity: String): Int { + return when (rarity) { + "COMMON" -> 0 + "RARE" -> 1 + "EPIC" -> 2 + "LEGENDARY" -> 3 + "EXCLUSIVE" -> 4 + else -> 0 } } - return equippedCosmetics -} - -fun colorFromRarity(rarity: String): String { - return when (rarity) { - "COMMON" -> "#828282" - "RARE" -> "#0099DB" - "EPIC" -> "#8B5CF6" - "LEGENDARY" -> "#F49E0B" - "EXCLUSIVE" -> "#EA323C" - else -> "#FFFFFF" - } -} - -fun indexFromRarity(rarity: String): Int { - return when (rarity) { - "COMMON" -> 0 - "RARE" -> 1 - "EPIC" -> 2 - "LEGENDARY" -> 3 - "EXCLUSIVE" -> 4 - else -> 0 - } -} -fun tabFromType(type: String): CosmeticTab? { - return CosmeticGui.tabs.filter { it.name == type }.firstOrNull() + fun tabFromType(type: String): CosmeticTab? { + return CosmeticTab.tabs.filter { it.name == type }.firstOrNull() + } } \ No newline at end of file diff --git a/src/main/kotlin/llc/redstone/hysentials/cosmetic/PreviewHandler.kt b/src/main/kotlin/llc/redstone/hysentials/cosmetic/PreviewHandler.kt new file mode 100644 index 0000000..61fe575 --- /dev/null +++ b/src/main/kotlin/llc/redstone/hysentials/cosmetic/PreviewHandler.kt @@ -0,0 +1,114 @@ +package llc.redstone.hysentials.cosmetic + +import cc.polyfrost.oneconfig.utils.InputHandler +import llc.redstone.hysentials.cosmetics.AbstractCosmetic +import llc.redstone.hysentials.schema.HysentialsSchema +import net.minecraft.client.renderer.GlStateManager +import net.minecraft.client.renderer.RenderHelper +import net.minecraftforge.fml.client.config.GuiUtils + +fun HysentialsSchema.Cosmetic.renderPreview(mouseX: Int, mouseY: Int, tick: Int) { + val cosmeticModel = this.cosmeticModel?: return + GlStateManager.disableRescaleNormal() + RenderHelper.disableStandardItemLighting() + GlStateManager.disableLighting() + GlStateManager.disableDepth() + + val tooltipX = (mouseX + 12).toInt() + val tooltipY = (mouseY - 12).toInt() + val tooltipTextWidth = 300 + val tooltipHeight = 300 + + val zLevel = 300 + val backgroundColor = -0xfeffff0 + GuiUtils.drawGradientRect( + zLevel, + tooltipX - 3, + tooltipY - 4, + tooltipX + tooltipTextWidth + 3, + tooltipY - 3, + backgroundColor, + backgroundColor + ) + GuiUtils.drawGradientRect( + zLevel, + tooltipX - 3, + tooltipY + tooltipHeight + 3, + tooltipX + tooltipTextWidth + 3, + tooltipY + tooltipHeight + 4, + backgroundColor, + backgroundColor + ) + GuiUtils.drawGradientRect( + zLevel, + tooltipX - 3, + tooltipY - 3, + tooltipX + tooltipTextWidth + 3, + tooltipY + tooltipHeight + 3, + backgroundColor, + backgroundColor + ) + GuiUtils.drawGradientRect( + zLevel, + tooltipX - 4, + tooltipY - 3, + tooltipX - 3, + tooltipY + tooltipHeight + 3, + backgroundColor, + backgroundColor + ) + GuiUtils.drawGradientRect( + zLevel, + tooltipX + tooltipTextWidth + 3, + tooltipY - 3, + tooltipX + tooltipTextWidth + 4, + tooltipY + tooltipHeight + 3, + backgroundColor, + backgroundColor + ) + val borderColorStart = 0x505000FF + val borderColorEnd = (borderColorStart and 0xFEFEFE) shr 1 or (borderColorStart and -0x1000000) + GuiUtils.drawGradientRect( + zLevel, + tooltipX - 3, + tooltipY - 3 + 1, + tooltipX - 3 + 1, + tooltipY + tooltipHeight + 3 - 1, + borderColorStart, + borderColorEnd + ) + GuiUtils.drawGradientRect( + zLevel, + tooltipX + tooltipTextWidth + 2, + tooltipY - 3 + 1, + tooltipX + tooltipTextWidth + 3, + tooltipY + tooltipHeight + 3 - 1, + borderColorStart, + borderColorEnd + ) + GuiUtils.drawGradientRect( + zLevel, + tooltipX - 3, + tooltipY - 3, + tooltipX + tooltipTextWidth + 3, + tooltipY - 3 + 1, + borderColorStart, + borderColorStart + ) + GuiUtils.drawGradientRect( + zLevel, + tooltipX - 3, + tooltipY + tooltipHeight + 2, + tooltipX + tooltipTextWidth + 3, + tooltipY + tooltipHeight + 3, + borderColorEnd, + borderColorEnd + ) + + cosmeticModel.renderPreview(tooltipX, tooltipY, tick) + + GlStateManager.enableLighting() + GlStateManager.enableDepth() + RenderHelper.enableStandardItemLighting() + GlStateManager.enableRescaleNormal() +} \ No newline at end of file diff --git a/src/main/kotlin/llc/redstone/hysentials/macrowheel/overlay/MacroWheelOverlay.kt b/src/main/kotlin/llc/redstone/hysentials/macrowheel/overlay/MacroWheelOverlay.kt index 101555a..c9db2b5 100644 --- a/src/main/kotlin/llc/redstone/hysentials/macrowheel/overlay/MacroWheelOverlay.kt +++ b/src/main/kotlin/llc/redstone/hysentials/macrowheel/overlay/MacroWheelOverlay.kt @@ -18,8 +18,10 @@ import net.minecraft.item.Item import net.minecraft.item.ItemStack import net.minecraftforge.client.ClientCommandHandler import net.minecraftforge.client.event.GuiScreenEvent +import net.minecraftforge.fml.client.config.GuiUtils var stopped = false; + class MacroWheelOverlay( val x: Float, val y: Float, @@ -27,7 +29,7 @@ class MacroWheelOverlay( val background: OneColor ) { companion object { - fun newI (): MacroWheelOverlay { + fun newI(): MacroWheelOverlay { val hudConfig = Hysentials.INSTANCE.config.macroWheelHud hudConfig.position.setSize(34f * hudConfig.scale, 34f * hudConfig.scale) val hud = MacroWheelOverlay( @@ -39,6 +41,7 @@ class MacroWheelOverlay( return hud } } + fun drawPost(event: GuiScreenEvent.DrawScreenEvent.Post, inputHandler: InputHandler) { GlStateManager.pushMatrix() for (i in 0 until 8) { @@ -70,7 +73,7 @@ class MacroWheelOverlay( GlStateManager.enableRescaleNormal() GlStateManager.enableColorMaterial() GlStateManager.enableLighting() - val otherScale = 2 * (scale/5f) + val otherScale = 2 * (scale / 5f) GlStateManager.scale(otherScale, otherScale, otherScale) Minecraft.getMinecraft().renderItem.renderItemIntoGUI( @@ -81,7 +84,9 @@ class MacroWheelOverlay( GlStateManager.popMatrix() } } + GlStateManager.popMatrix() + GlStateManager.pushMatrix() for (i in 0 until 8) { val macro = Hysentials.INSTANCE.macroJson.getMacro(i) @@ -109,9 +114,9 @@ class MacroWheelOverlay( C.translate(it) }) - val otherScale = 1 * (scale/5f) + val otherScale = 1 * (scale / 5f) GlStateManager.scale(otherScale, otherScale, otherScale) - net.minecraftforge.fml.client.config.GuiUtils.drawHoveringText( + GuiUtils.drawHoveringText( lore, inputHandler.mouseX().toInt().toScaled(otherScale), inputHandler.mouseY().toInt().toScaled(otherScale), @@ -123,7 +128,10 @@ class MacroWheelOverlay( if (inputHandler.isMouseDown(0)) { for (command in Hysentials.commands) { - if (command.commandName == macro.command.split(" ")[0]) { + if (command.commandName == macro.command.split(" ")[0] || command.commandAliases.contains( + macro.command.split(" ")[0] + ) + ) { command.processCommand( Minecraft.getMinecraft().thePlayer, macro.command.substring(macro.command.indexOf(" ") + 1).split(" ").toTypedArray() @@ -158,7 +166,7 @@ class MacroWheelOverlay( GlStateManager.popMatrix() } - fun stop () { + fun stop() { stopped = true MacroWheelData.MacroWheel.wasMacroWheelActive = false if (Minecraft.getMinecraft().currentScreen == null) { @@ -167,13 +175,15 @@ class MacroWheelOverlay( } fun Float.toScaled(scale: Float): Float { - return this * 1/scale + return this * 1 / scale } + fun Int.toScaled(scale: Int): Int { - return this * 1/scale + return this * 1 / scale } + fun Int.toScaled(scale: Float): Int { - return (this * 1/scale).toInt() + return (this * 1 / scale).toInt() } fun draw(it: Long, partialTicks: Float, inputHandler: InputHandler?) { @@ -220,7 +230,6 @@ class MacroWheelOverlay( } - fun drawCross(it: Long, x: Float, y: Float, color: Int) { val nvg = NanoVGHelper.INSTANCE var x = x + 4.5f * scale diff --git a/src/main/kotlin/llc/redstone/hysentials/profileviewer/DefaultProfileGui.kt b/src/main/kotlin/llc/redstone/hysentials/profileviewer/DefaultProfileGui.kt index a054c76..224c425 100644 --- a/src/main/kotlin/llc/redstone/hysentials/profileviewer/DefaultProfileGui.kt +++ b/src/main/kotlin/llc/redstone/hysentials/profileviewer/DefaultProfileGui.kt @@ -7,7 +7,7 @@ import cc.polyfrost.oneconfig.utils.Multithreading import cc.polyfrost.oneconfig.utils.hypixel.LocrawUtil import com.google.common.collect.Lists import llc.redstone.hysentials.Hysentials -import llc.redstone.hysentials.cosmetic.getEquippedCosmetics +import llc.redstone.hysentials.cosmetic.CosmeticManager.getEquippedCosmetics import llc.redstone.hysentials.guis.misc.HysentialsLevel import llc.redstone.hysentials.handlers.lobby.TabChanger import llc.redstone.hysentials.handlers.redworks.BwRanksUtils diff --git a/src/main/kotlin/llc/redstone/hysentials/schema/HysentialsSchema.kt b/src/main/kotlin/llc/redstone/hysentials/schema/HysentialsSchema.kt index 97cbb51..e415944 100644 --- a/src/main/kotlin/llc/redstone/hysentials/schema/HysentialsSchema.kt +++ b/src/main/kotlin/llc/redstone/hysentials/schema/HysentialsSchema.kt @@ -5,13 +5,16 @@ import com.google.gson.JsonPrimitive import com.neovisionaries.ws.client.WebSocket import kotlinx.serialization.Serializable import kotlinx.serialization.Transient -import llc.redstone.hysentials.cosmetic.colorFromRarity -import llc.redstone.hysentials.cosmetic.equippedCosmetic -import llc.redstone.hysentials.cosmetic.hasCosmetic +import llc.redstone.hysentials.cosmetic.CosmeticManager.colorFromRarity +import llc.redstone.hysentials.cosmetic.CosmeticManager.equippedCosmetic +import llc.redstone.hysentials.cosmetic.CosmeticManager.hasCosmetic +import llc.redstone.hysentials.cosmetics.AbstractCosmetic +import llc.redstone.hysentials.cosmetics.Cosmetic import llc.redstone.hysentials.guis.container.GuiItem import llc.redstone.hysentials.util.Material import llc.redstone.hysentials.utils.formatCapitalize import llc.redstone.hysentials.websocket.Socket +import net.minecraft.client.model.ModelBase import net.minecraft.item.ItemStack import org.json.JSONArray import org.json.JSONObject @@ -50,10 +53,10 @@ class HysentialsSchema { obj["firstJoin"].asDouble, obj["lastJoin"].asDouble, obj["rank"].asString, - obj["hasPlus"]?.asBoolean?: false, - obj["online"]?.asBoolean?: false, - obj["isBoosting"]?.asBoolean?: false, - obj["isEarlySupporter"]?.asBoolean?: false, + obj["hasPlus"]?.asBoolean ?: false, + obj["online"]?.asBoolean ?: false, + obj["isBoosting"]?.asBoolean ?: false, + obj["isEarlySupporter"]?.asBoolean ?: false, obj["emeralds"]?.asInt ?: 0, obj["exp"].asInt, obj["givenLevel"].asInt, @@ -103,10 +106,11 @@ class HysentialsSchema { var material: String?, var skullOwner: String? = null, @Transient var item: ItemStack? = null, + @Transient var cosmeticModel: llc.redstone.hysentials.cosmetics.Cosmetic? = null, ) { companion object { fun deserialize(obj: JsonObject): Cosmetic { - return Cosmetic( + val cos = Cosmetic( obj["name"].asString, obj["displayName"].asString, obj["users"].asJsonArray.map { it.asString }.toCollection(ArrayList()), @@ -124,6 +128,13 @@ class HysentialsSchema { obj["material"]?.asString, obj["skullOwner"]?.asString, ) + for (cosmetic in AbstractCosmetic.cosmetics) { + if (cosmetic.name == cos.name) { + + cos.cosmeticModel = cosmetic + } + } + return cos } } @@ -159,7 +170,7 @@ class HysentialsSchema { lore.add(if (emerald >= cost) "&aClick to purchase!" else "&cNot enough emeralds!") } else if (cost == 0) { lore.add("&eClick to purchase!") - } else if (cost == -1){ + } else if (cost == -1) { lore.add("") lore.add("&cNot purchasable!") } @@ -295,6 +306,7 @@ class HysentialsSchema { ) } } + fun sendWithAuth(method: String, data: JSONObject) { data.put("method", method) data.put("serverId", serverId) @@ -425,7 +437,7 @@ class HysentialsSchema { ), obj.get("name").asString, obj.get("description").asString, - obj.get("type")?.asString?: "cluster", + obj.get("type")?.asString ?: "cluster", obj.get("createTime").asDouble, ) }