diff --git a/src/main/java/llc/redstone/hysentials/command/HysentialsCommand.java b/src/main/java/llc/redstone/hysentials/command/HysentialsCommand.java index c34bb2c..bf4bd92 100644 --- a/src/main/java/llc/redstone/hysentials/command/HysentialsCommand.java +++ b/src/main/java/llc/redstone/hysentials/command/HysentialsCommand.java @@ -415,6 +415,7 @@ private static void handleTest(String command, String args) { break; } + case "locraw": { LocrawInfo info = LocrawUtil.INSTANCE.getLocrawInfo(); if (info != null) { diff --git a/src/main/java/llc/redstone/hysentials/command/QwestiiTestCommand.java b/src/main/java/llc/redstone/hysentials/command/QwestiiTestCommand.java index a8099d4..d97f140 100644 --- a/src/main/java/llc/redstone/hysentials/command/QwestiiTestCommand.java +++ b/src/main/java/llc/redstone/hysentials/command/QwestiiTestCommand.java @@ -39,8 +39,7 @@ public void processCommand(ICommandSender sender, String[] args) throws CommandE Thread.sleep(1000); UChat.chat("\n&4K A B O O M\n"); Thread.sleep(3000); - Minecraft.getMinecraft().crashed(new CrashReport("Kaboom", new Throwable()) - ); + Minecraft.getMinecraft().crashed(new CrashReport("Kaboom", new Throwable())); } catch (InterruptedException ignored) { } }); diff --git a/src/main/java/llc/redstone/hysentials/cosmetics/Cosmetic.java b/src/main/java/llc/redstone/hysentials/cosmetics/Cosmetic.java index 03a0c32..c1fd558 100644 --- a/src/main/java/llc/redstone/hysentials/cosmetics/Cosmetic.java +++ b/src/main/java/llc/redstone/hysentials/cosmetics/Cosmetic.java @@ -1,33 +1,86 @@ package llc.redstone.hysentials.cosmetics; import net.minecraft.client.Minecraft; +import net.minecraft.client.gui.GuiEnchantment; +import net.minecraft.client.gui.ScaledResolution; import net.minecraft.client.model.ModelBase; import net.minecraft.client.renderer.GlStateManager; +import net.minecraft.client.renderer.RenderHelper; +import net.minecraft.entity.Entity; import net.minecraft.entity.player.EntityPlayer; +import net.minecraft.util.MathHelper; import net.minecraft.util.ResourceLocation; +import org.lwjgl.opengl.GL11; +import org.lwjgl.util.glu.Project; 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()); + Minecraft mc = Minecraft.getMinecraft(); + float zLevel = 350; +// if (!canUse(player)) return; GlStateManager.pushMatrix(); + GlStateManager.matrixMode(5889); + GlStateManager.pushMatrix(); + GlStateManager.loadIdentity(); + GlStateManager.translate(x, y, 0.0F); + Project.gluPerspective(90.0F, 1.3333334F, 9.0F, zLevel); + float f = 1.0F; + GlStateManager.matrixMode(5888); + GlStateManager.loadIdentity(); + RenderHelper.enableStandardItemLighting(); + GlStateManager.translate(0.0F, 3.3F, -16.0F); + GlStateManager.scale(f, f, f); + float g = 5.0F; + GlStateManager.scale(g, g, g); + GlStateManager.rotate(180.0F, 0.0F, 0.0F, 1.0F); + mc.getTextureManager().bindTexture(getTexture()); + GlStateManager.rotate(20.0F, 1.0F, 0.0F, 0.0F); +// float h = this.field_147076_A + (this.field_147080_z - this.field_147076_A) * ticks; +// GlStateManager.translate((1.0F - h) * 0.2F, (1.0F - h) * 0.1F, (1.0F - h) * 0.25F); +// GlStateManager.rotate(-(1.0F - h) * 90.0F - 90.0F, 0.0F, 1.0F, 0.0F); +// GlStateManager.rotate(180.0F, 1.0F, 0.0F, 0.0F); +// float k = this.field_147069_w + (this.field_147071_v - this.field_147069_w) * ticks + 0.25F; +// float l = this.field_147069_w + (this.field_147071_v - this.field_147069_w) * ticks + 0.75F; +// k = (k - (float) MathHelper.truncateDoubleToInt((double)k)) * 1.6F - 0.3F; +// l = (l - (float)MathHelper.truncateDoubleToInt((double)l)) * 1.6F - 0.3F; +// if (k < 0.0F) { +// k = 0.0F; +// } +// +// if (l < 0.0F) { +// l = 0.0F; +// } +// +// if (k > 1.0F) { +// k = 1.0F; +// } +// +// if (l > 1.0F) { +// l = 1.0F; +// } - 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.enableRescaleNormal(); + //2d rendering + GL11.glEnable(GL11.GL_TEXTURE_2D); + getModel().render(null, 0.0F, 0, 0, 0, 0.0F, 0.0625F); + GlStateManager.disableRescaleNormal(); + RenderHelper.disableStandardItemLighting(); + GlStateManager.matrixMode(5889); + GlStateManager.viewport(0, 0, mc.displayWidth, mc.displayHeight); + GlStateManager.popMatrix(); + GlStateManager.matrixMode(5888); GlStateManager.popMatrix(); } 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 2e11454..ca92637 100644 --- a/src/main/java/llc/redstone/hysentials/cosmetics/backpack/BackpackCosmetic.java +++ b/src/main/java/llc/redstone/hysentials/cosmetics/backpack/BackpackCosmetic.java @@ -36,7 +36,7 @@ public BackpackCosmetic(String name, boolean catpack) { } public boolean canUse(EntityPlayer player) { return CosmeticManager.equippedCosmetic(player.getUniqueID(), name) - && CosmeticManager.hasCosmetic(player.getUniqueID(), name); + && (CosmeticManager.hasCosmetic(player.getUniqueID(), name) || CosmeticManager.isPreviewing(player.getUniqueID(), name)); } public ModelBase getModel() { 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 d5e7ec4..3158205 100644 --- a/src/main/java/llc/redstone/hysentials/cosmetics/capes/CapeHandler.java +++ b/src/main/java/llc/redstone/hysentials/cosmetics/capes/CapeHandler.java @@ -29,7 +29,7 @@ public void onTickEvent(TickEvent.ClientTickEvent event) { if (cosmetic.getSubType() != null && cosmetic.getSubType().equals("cape")) { wearingCape = true; String name = cosmetic.getName(); - if (CosmeticManager.hasCosmetic(uuid, name)) { + if (CosmeticManager.hasCosmetic(uuid, name) || CosmeticManager.isPreviewing(uuid, name)) { ResourceLocation location = new ResourceLocation(cosmetic.getResource()); resourceMap.put(uuid, cosmetic.getResource()); try { 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 72318ae..5322e56 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 @@ -16,7 +16,7 @@ public BlackCat() { } public boolean canUse(EntityPlayer player) { return CosmeticManager.equippedCosmetic(player.getUniqueID(), "black cat") - && CosmeticManager.hasCosmetic(player.getUniqueID(), "black cat"); + && (CosmeticManager.hasCosmetic(player.getUniqueID(), "black cat") || CosmeticManager.isPreviewing(player.getUniqueID(), "black cat")); } public BlackCatModel getModel() { 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 7e39658..c556231 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 @@ -24,7 +24,7 @@ public CatHat(String name) { } public boolean canUse(EntityPlayer player) { return CosmeticManager.equippedCosmetic(player.getUniqueID(), name) - && CosmeticManager.hasCosmetic(player.getUniqueID(), name); + && (CosmeticManager.hasCosmetic(player.getUniqueID(), name) || CosmeticManager.isPreviewing(player.getUniqueID(), name)); } @Override 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 d737e7b..853c082 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 @@ -16,7 +16,7 @@ public TechnoCrown() { } public boolean canUse(EntityPlayer player) { return CosmeticManager.equippedCosmetic(player.getUniqueID(), "techno crown") - && CosmeticManager.hasCosmetic(player.getUniqueID(), "techno crown"); + && (CosmeticManager.hasCosmetic(player.getUniqueID(), "techno crown") || CosmeticManager.isPreviewing(player.getUniqueID(), "techno crown")); } @Override 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 0d3f15a..2abbf8f 100644 --- a/src/main/java/llc/redstone/hysentials/cosmetics/kzero/KzeroBundle.java +++ b/src/main/java/llc/redstone/hysentials/cosmetics/kzero/KzeroBundle.java @@ -20,7 +20,8 @@ public KzeroBundle() { public static boolean canUse(AbstractClientPlayer player, Type type) { return CosmeticManager.equippedCosmetic(player.getUniqueID(), "kzero " + type.name().toLowerCase()) - && CosmeticManager.hasCosmetic(player.getUniqueID(), "kzero " + type.name().toLowerCase()); + && (CosmeticManager.hasCosmetic(player.getUniqueID(), "kzero " + type.name().toLowerCase()) || + CosmeticManager.isPreviewing(player.getUniqueID(), "kzero " + type.name().toLowerCase())); } public enum Type { 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 d259272..e28f474 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 @@ -17,7 +17,7 @@ public DragonCosmetic() { } public boolean canUse(EntityPlayer player) { return CosmeticManager.equippedCosmetic(player.getUniqueID(), "dragon") - && CosmeticManager.hasCosmetic(player.getUniqueID(), "dragon"); + && (CosmeticManager.hasCosmetic(player.getUniqueID(), "dragon") || CosmeticManager.isPreviewing(player.getUniqueID(), "dragon")); } @Override 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 8e9651b..3aa57c6 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 @@ -61,7 +61,7 @@ public void onTickEvent(TickEvent.ClientTickEvent event) { } public boolean canUse(UUID uuid) { return CosmeticManager.equippedCosmetic(uuid, "tdarth") - && CosmeticManager.hasCosmetic(uuid, "tdarth"); + && (CosmeticManager.hasCosmetic(uuid, "tdarth") || CosmeticManager.isPreviewing(uuid, "tdarth")); } @Override diff --git a/src/main/java/llc/redstone/hysentials/mixin/GuiIngameForgeMixin.java b/src/main/java/llc/redstone/hysentials/mixin/GuiIngameForgeMixin.java index 3c97a09..cab3b64 100644 --- a/src/main/java/llc/redstone/hysentials/mixin/GuiIngameForgeMixin.java +++ b/src/main/java/llc/redstone/hysentials/mixin/GuiIngameForgeMixin.java @@ -13,6 +13,7 @@ import net.minecraft.client.Minecraft; import net.minecraft.client.gui.Gui; import net.minecraft.client.gui.ScaledResolution; +import net.minecraft.client.renderer.GlStateManager; import net.minecraftforge.client.GuiIngameForge; import net.minecraftforge.client.event.GuiScreenEvent; import net.minecraftforge.client.event.RenderGameOverlayEvent; @@ -73,6 +74,7 @@ private void cancelSelectedItem(CallbackInfo ci) { @Inject(method = "renderGameOverlay", at = @At(value = "INVOKE", target = "Lnet/minecraft/client/renderer/GlStateManager;enableAlpha()V", shift = At.Shift.AFTER)) public void hysentials$renderMacroWheel(float partialTicks, CallbackInfo ci) { + GlStateManager.pushMatrix(); if (HysentialsConfig.macroWheelKeyBind.isActive() && Minecraft.getMinecraft().currentScreen == null && MacroWheelData.MacroWheel.getCooldown() < System.currentTimeMillis()) { if (!MacroWheelOverlayKt.getStopped()) { MacroWheelOverlay overlay = MacroWheelOverlay.Companion.newI(); @@ -101,6 +103,7 @@ private void cancelSelectedItem(CallbackInfo ci) { Minecraft.getMinecraft().mouseHelper.grabMouseCursor(); } } + GlStateManager.popMatrix(); } @Unique diff --git a/src/main/java/llc/redstone/hysentials/mixin/GuiIngameMixin.java b/src/main/java/llc/redstone/hysentials/mixin/GuiIngameMixin.java index c9c8ba2..e4baf1a 100644 --- a/src/main/java/llc/redstone/hysentials/mixin/GuiIngameMixin.java +++ b/src/main/java/llc/redstone/hysentials/mixin/GuiIngameMixin.java @@ -5,11 +5,17 @@ import llc.redstone.hysentials.config.HysentialsConfig; import net.minecraft.client.gui.Gui; import net.minecraft.client.gui.GuiIngame; +import net.minecraft.scoreboard.Score; +import net.minecraft.scoreboard.ScoreObjective; +import net.minecraft.scoreboard.Scoreboard; import org.spongepowered.asm.mixin.Mixin; import org.spongepowered.asm.mixin.injection.At; import org.spongepowered.asm.mixin.injection.Inject; +import org.spongepowered.asm.mixin.injection.Redirect; import org.spongepowered.asm.mixin.injection.callback.CallbackInfo; +import java.util.Collection; + @Mixin(value = GuiIngame.class, priority = 9001) public class GuiIngameMixin { @Inject(method = "renderBossHealth", at = @At("HEAD"), cancellable = true) @@ -21,6 +27,11 @@ private void cancelBossBar(CallbackInfo ci) { } } + @Redirect(method = "renderScoreboard", at = @At(value = "INVOKE", target = "Lnet/minecraft/scoreboard/Scoreboard;getSortedScores(Lnet/minecraft/scoreboard/ScoreObjective;)Ljava/util/Collection;")) + private Collection injectScore(Scoreboard scoreboard, ScoreObjective scoreObjective) { + return scoreboard.getSortedScores(scoreObjective); + } + @Inject(method = "renderSelectedItem", at = @At("HEAD"), cancellable = true) private void cancelSelectedItem(CallbackInfo ci) { if (HysentialsConfig.heldItemTooltipHUD.isEnabled()) { diff --git a/src/main/kotlin/llc/redstone/hysentials/cosmetic/CosmeticGui.kt b/src/main/kotlin/llc/redstone/hysentials/cosmetic/CosmeticGui.kt index 4413797..7a72ca9 100644 --- a/src/main/kotlin/llc/redstone/hysentials/cosmetic/CosmeticGui.kt +++ b/src/main/kotlin/llc/redstone/hysentials/cosmetic/CosmeticGui.kt @@ -18,6 +18,7 @@ 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.previewing import llc.redstone.hysentials.cosmetic.CosmeticManager.purchaseCosmetic import llc.redstone.hysentials.cosmetic.CosmeticManager.tabFromType import llc.redstone.hysentials.cosmetic.CosmeticManager.unEquipCosmetic @@ -29,6 +30,8 @@ import net.minecraft.client.audio.PositionedSoundRecord import net.minecraft.client.renderer.GlStateManager import net.minecraft.client.renderer.RenderHelper import net.minecraft.inventory.Slot +import net.minecraft.scoreboard.Score +import net.minecraft.scoreboard.ScoreDummyCriteria import net.minecraft.util.EnumChatFormatting import net.minecraft.util.ResourceLocation import org.json.JSONObject @@ -67,8 +70,6 @@ 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) @@ -102,7 +103,13 @@ open class CosmeticGui : UScreen(), HysentialsGui { } try { // Draw the background (dark and light) - Renderer.drawImage(if (HysentialsConfig.wardrobeDarkMode) cosmeticBackground else lightBackground, guiLeft.toDouble(), guiTop.toDouble(), xSize.toDouble(), ySize.toDouble()) + 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) { @@ -110,7 +117,12 @@ open class CosmeticGui : UScreen(), HysentialsGui { } // Draw the selected tab val typeFinal = tabFromType(type)?.displayName ?: "Owned" - mcFive.drawStringShadow(" > ${typeFinal.splitToWords().uppercase()} ($page/$maxPage)", guiLeft + 71f, guiTop + 5f, 0xFFFFFF) + 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) @@ -160,22 +172,6 @@ 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 @@ -183,7 +179,12 @@ open class CosmeticGui : UScreen(), HysentialsGui { for (tab in tabs) { if (tab.isHovered(rX.toDouble(), rY.toDouble())) { - drawHoveringText(listOf("§8➔ <#${tab.color}>${tab.displayName} Cosmetics"), mouseX, mouseY, fontRenderer) + drawHoveringText( + listOf("§8➔ <#${tab.color}>${tab.displayName} Cosmetics"), + mouseX, + mouseY, + fontRenderer + ) } } @@ -254,7 +255,6 @@ open class CosmeticGui : UScreen(), HysentialsGui { } - override fun onMouseClicked(mouseX: Double, mouseY: Double, mouseButton: Int) { super.onMouseClicked(mouseX, mouseY, mouseButton) buttons.forEach { @@ -326,6 +326,25 @@ open class CosmeticGui : UScreen(), HysentialsGui { initScreen(width, height) } } + } else if (mouseButton == 1) { // Right click to preview + val slot = getSlot( + mouseX.toFloat() - guiLeft, + mouseY.toFloat() - guiTop + ) + if (slot != -1 && slot < inventorySlots.size && inventoryMap.containsKey(type)) { + val cosmetics: List = inventoryMap[type]!! + val paginationList = PaginationList(cosmetics, 32) + val page = paginationList.getPage(page) + if (slot >= page.size) return + val cosmetic = page[slot] + val cosmeticName = cosmetic.name + if (!previewing.contains(cosmeticName)) { + equipCosmetic(cosmeticName, true) + } else { + unEquipCosmetic(cosmeticName, true) + } + initScreen(width, height) + } } } @@ -468,29 +487,49 @@ open class CosmeticGui : UScreen(), HysentialsGui { if (page > 1) { page-- updatePage() - this.mc.soundHandler.playSound(PositionedSoundRecord.create(ResourceLocation("gui.button.press"), 1.0f)) + this.mc.soundHandler.playSound( + PositionedSoundRecord.create( + ResourceLocation("gui.button.press"), + 1.0f + ) + ) } }) it.add(Button(192, 126, 29, 20, "hysentials:gui/wardrobe/right.png", instance, - onHover = { _, _ -> page < maxPage }) { _, _, _ -> - if (page < maxPage) { - page++ - updatePage() - this.mc.soundHandler.playSound(PositionedSoundRecord.create(ResourceLocation("gui.button.press"), 1.0f)) - } - }) + onHover = { _, _ -> page < maxPage }) { _, _, _ -> + if (page < maxPage) { + page++ + updatePage() + this.mc.soundHandler.playSound( + PositionedSoundRecord.create( + ResourceLocation("gui.button.press"), + 1.0f + ) + ) + } + }) it.add(Button(18, 126, 29, 20, "hysentials:gui/wardrobe/left-light.png", instance) { _, _, _ -> if (page > 1) { page-- updatePage() - this.mc.soundHandler.playSound(PositionedSoundRecord.create(ResourceLocation("gui.button.press"), 1.0f)) + this.mc.soundHandler.playSound( + PositionedSoundRecord.create( + ResourceLocation("gui.button.press"), + 1.0f + ) + ) } }) it.add(Button(192, 126, 29, 20, "hysentials:gui/wardrobe/right-light.png", instance) { _, _, _ -> if (page < maxPage) { page++ updatePage() - this.mc.soundHandler.playSound(PositionedSoundRecord.create(ResourceLocation("gui.button.press"), 1.0f)) + this.mc.soundHandler.playSound( + PositionedSoundRecord.create( + ResourceLocation("gui.button.press"), + 1.0f + ) + ) } }) } diff --git a/src/main/kotlin/llc/redstone/hysentials/cosmetic/CosmeticUtils.kt b/src/main/kotlin/llc/redstone/hysentials/cosmetic/CosmeticUtils.kt index 9f20c18..a543ae5 100644 --- a/src/main/kotlin/llc/redstone/hysentials/cosmetic/CosmeticUtils.kt +++ b/src/main/kotlin/llc/redstone/hysentials/cosmetic/CosmeticUtils.kt @@ -4,7 +4,6 @@ import cc.polyfrost.oneconfig.utils.Multithreading import com.google.gson.JsonElement import llc.redstone.hysentials.HYSENTIALS_API 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 @@ -22,37 +21,48 @@ import java.util.* object CosmeticManager { var actions = mapOf( - "equip" to mutableListOf(), - "unequip" to mutableListOf(), - "purchase" to mutableListOf() + "equip" to mutableSetOf(), + "unequip" to mutableSetOf(), + "purchase" to mutableSetOf() ) - fun unEquipCosmetic(name: String) { - if (name == "kzero bundle") return kzero(false) + var previewing = mutableListOf() + + fun unEquipCosmetic(name: String, preview: Boolean = false) { + if (name == "kzero bundle") 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) + if (preview) { + previewing.remove(name) + } else { + actions["unequip"] + } } } - fun equipCosmetic(name: String) { - if (name == "kzero bundle") return kzero(true) + fun equipCosmetic(name: String, preview: Boolean = false) { + if (name == "kzero bundle") 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) + previewing.remove(cosmetic.name) } } if (!it.equipped.contains(Minecraft.getMinecraft().thePlayer.uniqueID.toString())) { it.equipped.add(Minecraft.getMinecraft().thePlayer.uniqueID.toString()) } - actions["equip"]?.add(name) + if (preview) { + previewing.add(name) + } else { + actions["equip"]?.add(name) + } } } @@ -63,11 +73,10 @@ object CosmeticManager { "kzero slipper" ) for (cosmetic in list) { - val name = cosmetic.replace(" ", "%20") if (equip) { - equipCosmetic(name) + equipCosmetic(cosmetic) } else { - unEquipCosmetic(name) + unEquipCosmetic(cosmetic) } } } @@ -102,10 +111,11 @@ object CosmeticManager { } } } + previewing.clear() actions = mapOf( - "equip" to mutableListOf(), - "unequip" to mutableListOf(), - "purchase" to mutableListOf() + "equip" to mutableSetOf(), + "unequip" to mutableSetOf(), + "purchase" to mutableSetOf() ) var cosmetics: JsonElement? = NetworkUtils.getJsonElement("$HYSENTIALS_API/cosmetic", true) ?: return@runAsync @@ -165,7 +175,7 @@ object CosmeticManager { try { val cosmetics = BlockWAPIUtils.getCosmetics() cosmetics.find { it.name == name }?.let { - if (it.equipped.contains(uuid.toString())) { + if (it.equipped.contains(uuid.toString()) && it.users.contains(uuid.toString())) { return true } } @@ -188,6 +198,12 @@ object CosmeticManager { return false } + @JvmStatic + fun isPreviewing(uuid: UUID, name: String): Boolean { + if (uuid != Minecraft.getMinecraft().thePlayer.uniqueID) return false + return previewing.contains(name) + } + @JvmStatic fun getOwnedCosmetics(uuid: UUID): ArrayList { val cosmetics = BlockWAPIUtils.getCosmetics() diff --git a/src/main/kotlin/llc/redstone/hysentials/cosmetic/PreviewHandler.kt b/src/main/kotlin/llc/redstone/hysentials/cosmetic/PreviewHandler.kt deleted file mode 100644 index 61fe575..0000000 --- a/src/main/kotlin/llc/redstone/hysentials/cosmetic/PreviewHandler.kt +++ /dev/null @@ -1,114 +0,0 @@ -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 c9db2b5..713ea8d 100644 --- a/src/main/kotlin/llc/redstone/hysentials/macrowheel/overlay/MacroWheelOverlay.kt +++ b/src/main/kotlin/llc/redstone/hysentials/macrowheel/overlay/MacroWheelOverlay.kt @@ -115,6 +115,7 @@ class MacroWheelOverlay( }) val otherScale = 1 * (scale / 5f) + GlStateManager.pushMatrix() GlStateManager.scale(otherScale, otherScale, otherScale) GuiUtils.drawHoveringText( lore, @@ -125,6 +126,7 @@ class MacroWheelOverlay( -1, Minecraft.getMinecraft().fontRendererObj ) + GlStateManager.popMatrix() if (inputHandler.isMouseDown(0)) { for (command in Hysentials.commands) { diff --git a/src/main/kotlin/llc/redstone/hysentials/schema/HysentialsSchema.kt b/src/main/kotlin/llc/redstone/hysentials/schema/HysentialsSchema.kt index e415944..c6a1c96 100644 --- a/src/main/kotlin/llc/redstone/hysentials/schema/HysentialsSchema.kt +++ b/src/main/kotlin/llc/redstone/hysentials/schema/HysentialsSchema.kt @@ -8,6 +8,7 @@ import kotlinx.serialization.Transient 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.cosmetic.CosmeticManager.previewing import llc.redstone.hysentials.cosmetics.AbstractCosmetic import llc.redstone.hysentials.cosmetics.Cosmetic import llc.redstone.hysentials.guis.container.GuiItem @@ -174,6 +175,11 @@ class HysentialsSchema { lore.add("") lore.add("&cNot purchasable!") } + if (previewing.contains(name)) { + lore.add("&cRight-Click to remove preview!") + } else { + lore.add("&bRight-Click to preview!") + } } when (subType) { "pet" -> { diff --git a/src/main/kotlin/llc/redstone/hysentials/utils/Utils.kt b/src/main/kotlin/llc/redstone/hysentials/utils/Utils.kt index d0e3ae6..d084bba 100644 --- a/src/main/kotlin/llc/redstone/hysentials/utils/Utils.kt +++ b/src/main/kotlin/llc/redstone/hysentials/utils/Utils.kt @@ -70,6 +70,7 @@ object Utils { } return previous } + @JvmStatic fun getLevel(exp: Int): Float { var level = 0f @@ -81,12 +82,14 @@ object Utils { level += exp / getExpForLevel(level.toInt()).toFloat() return level } + + //new @JvmStatic fun getExpStart(exp: Int): Int { var level = 0f var remainingExp = exp - while (remainingExp >= getExpForLevel(level.toInt())) { - remainingExp -= getExpForLevel(level.toInt()) + while (remainingExp >= getExpForLevel(level.toInt() + 1)) { + remainingExp -= getExpForLevel(level.toInt() + 1) level++ } return remainingExp