From 4c40e70ed9eb2c8caca9ddd8d0707d4c50c741b8 Mon Sep 17 00:00:00 2001 From: noil Date: Sun, 1 Nov 2020 20:34:51 -0500 Subject: [PATCH] Fixes capes, adds HudEditor labels to potion effects for the player & enemy if there are no effects currently on them --- .../hud/component/EnemyPotionsComponent.java | 4 +- .../hud/component/PotionEffectsComponent.java | 37 +++++++++++++------ .../seppuku/impl/management/CapeManager.java | 36 +++++++++--------- 3 files changed, 46 insertions(+), 31 deletions(-) diff --git a/src/main/java/me/rigamortis/seppuku/impl/gui/hud/component/EnemyPotionsComponent.java b/src/main/java/me/rigamortis/seppuku/impl/gui/hud/component/EnemyPotionsComponent.java index 60f8dc5..3ca088b 100644 --- a/src/main/java/me/rigamortis/seppuku/impl/gui/hud/component/EnemyPotionsComponent.java +++ b/src/main/java/me/rigamortis/seppuku/impl/gui/hud/component/EnemyPotionsComponent.java @@ -94,7 +94,7 @@ public final class EnemyPotionsComponent extends DraggableHudComponent { if (Minecraft.getMinecraft().currentScreen instanceof GuiHudEditor) { if (effectCount == 0) { - final String placeholder = "Enemy Potions"; + final String placeholder = "(enemy potion effects)"; this.setW(mc.fontRenderer.getStringWidth(placeholder)); this.setH(mc.fontRenderer.FONT_HEIGHT); mc.fontRenderer.drawStringWithShadow(placeholder, this.getX(), this.getY(), 0xFFFFFFFF); @@ -105,4 +105,4 @@ public final class EnemyPotionsComponent extends DraggableHudComponent { this.setW(maxWidth); this.setH(Math.abs(yOffset)); } -} +} \ No newline at end of file diff --git a/src/main/java/me/rigamortis/seppuku/impl/gui/hud/component/PotionEffectsComponent.java b/src/main/java/me/rigamortis/seppuku/impl/gui/hud/component/PotionEffectsComponent.java index 7879c21..9616873 100644 --- a/src/main/java/me/rigamortis/seppuku/impl/gui/hud/component/PotionEffectsComponent.java +++ b/src/main/java/me/rigamortis/seppuku/impl/gui/hud/component/PotionEffectsComponent.java @@ -3,6 +3,7 @@ package me.rigamortis.seppuku.impl.gui.hud.component; import com.mojang.realmsclient.gui.ChatFormatting; import me.rigamortis.seppuku.api.gui.hud.component.DraggableHudComponent; import me.rigamortis.seppuku.api.util.PotionUtil; +import me.rigamortis.seppuku.impl.gui.hud.GuiHudEditor; import net.minecraft.client.Minecraft; import net.minecraft.potion.Potion; import net.minecraft.potion.PotionEffect; @@ -25,13 +26,15 @@ public final class PotionEffectsComponent extends DraggableHudComponent { public void render(int mouseX, int mouseY, float partialTicks) { super.render(mouseX, mouseY, partialTicks); + final Minecraft mc = Minecraft.getMinecraft(); + final List effects = - new ArrayList<>(Minecraft.getMinecraft().player.getActivePotionEffects()); + new ArrayList<>(mc.player.getActivePotionEffects()); final Comparator comparator = (first, second) -> { final String firstEffect = PotionUtil.getFriendlyPotionName(first) + " " + ChatFormatting.GRAY + Potion.getPotionDurationString(first, 1.0F); final String secondEffect = PotionUtil.getFriendlyPotionName(second) + " " + ChatFormatting.GRAY + Potion.getPotionDurationString(second, 1.0F); - final float dif = Minecraft.getMinecraft().fontRenderer.getStringWidth(secondEffect) - Minecraft.getMinecraft().fontRenderer.getStringWidth(firstEffect); + final float dif = mc.fontRenderer.getStringWidth(secondEffect) - mc.fontRenderer.getStringWidth(firstEffect); return dif != 0 ? (int) dif : secondEffect.compareTo(firstEffect); }; @@ -45,7 +48,7 @@ public final class PotionEffectsComponent extends DraggableHudComponent { if (potionEffect != null) { final String effect = PotionUtil.getFriendlyPotionName(potionEffect) + " " + ChatFormatting.GRAY + Potion.getPotionDurationString(potionEffect, 1.0F); - final float width = Minecraft.getMinecraft().fontRenderer.getStringWidth(effect); + final float width = mc.fontRenderer.getStringWidth(effect); if (width >= maxWidth) { maxWidth = width; @@ -54,7 +57,7 @@ public final class PotionEffectsComponent extends DraggableHudComponent { if (this.getAnchorPoint() != null) { switch (this.getAnchorPoint().getPoint()) { case TOP_CENTER: - xOffset = (this.getW() - Minecraft.getMinecraft().fontRenderer.getStringWidth(effect)) / 2; + xOffset = (this.getW() - mc.fontRenderer.getStringWidth(effect)) / 2; break; case TOP_LEFT: case BOTTOM_LEFT: @@ -62,7 +65,7 @@ public final class PotionEffectsComponent extends DraggableHudComponent { break; case TOP_RIGHT: case BOTTOM_RIGHT: - xOffset = this.getW() - Minecraft.getMinecraft().fontRenderer.getStringWidth(effect); + xOffset = this.getW() - mc.fontRenderer.getStringWidth(effect); break; } } @@ -72,24 +75,34 @@ public final class PotionEffectsComponent extends DraggableHudComponent { case TOP_CENTER: case TOP_LEFT: case TOP_RIGHT: - Minecraft.getMinecraft().fontRenderer.drawStringWithShadow(effect, this.getX() + xOffset, this.getY() + yOffset, potionEffect.getPotion().getLiquidColor()); - yOffset += (Minecraft.getMinecraft().fontRenderer.FONT_HEIGHT + 1); + mc.fontRenderer.drawStringWithShadow(effect, this.getX() + xOffset, this.getY() + yOffset, potionEffect.getPotion().getLiquidColor()); + yOffset += (mc.fontRenderer.FONT_HEIGHT + 1); break; case BOTTOM_LEFT: case BOTTOM_RIGHT: - Minecraft.getMinecraft().fontRenderer.drawStringWithShadow(effect, this.getX() + xOffset, this.getY() + (this.getH() - Minecraft.getMinecraft().fontRenderer.FONT_HEIGHT) + yOffset, potionEffect.getPotion().getLiquidColor()); - yOffset -= (Minecraft.getMinecraft().fontRenderer.FONT_HEIGHT + 1); + mc.fontRenderer.drawStringWithShadow(effect, this.getX() + xOffset, this.getY() + (this.getH() - mc.fontRenderer.FONT_HEIGHT) + yOffset, potionEffect.getPotion().getLiquidColor()); + yOffset -= (mc.fontRenderer.FONT_HEIGHT + 1); break; } } else { - Minecraft.getMinecraft().fontRenderer.drawStringWithShadow(effect, this.getX() + xOffset, this.getY() + yOffset, potionEffect.getPotion().getLiquidColor()); - yOffset += (Minecraft.getMinecraft().fontRenderer.FONT_HEIGHT + 1); + mc.fontRenderer.drawStringWithShadow(effect, this.getX() + xOffset, this.getY() + yOffset, potionEffect.getPotion().getLiquidColor()); + yOffset += (mc.fontRenderer.FONT_HEIGHT + 1); } } } + if (mc.currentScreen instanceof GuiHudEditor) { + if (effects.size() <= 0) { + final String placeholder = "(my potion effects)"; + this.setW(mc.fontRenderer.getStringWidth(placeholder)); + this.setH(mc.fontRenderer.FONT_HEIGHT); + mc.fontRenderer.drawStringWithShadow(placeholder, this.getX(), this.getY(), 0xFFFFFFFF); + return; + } + } + this.setW(maxWidth); this.setH(Math.abs(yOffset)); } -} +} \ No newline at end of file diff --git a/src/main/java/me/rigamortis/seppuku/impl/management/CapeManager.java b/src/main/java/me/rigamortis/seppuku/impl/management/CapeManager.java index 5112d24..89f6430 100644 --- a/src/main/java/me/rigamortis/seppuku/impl/management/CapeManager.java +++ b/src/main/java/me/rigamortis/seppuku/impl/management/CapeManager.java @@ -12,6 +12,7 @@ import team.stiff.pomelo.impl.annotated.handler.annotation.Listener; import javax.imageio.ImageIO; import java.io.BufferedReader; import java.io.InputStreamReader; +import java.net.HttpURLConnection; import java.net.URL; import java.util.ArrayList; import java.util.HashMap; @@ -19,8 +20,8 @@ import java.util.List; import java.util.Map; /** - * Author Seth - * 7/9/2019 @ 5:47 PM. + * @author Seth + * @author noil */ public final class CapeManager { @@ -51,20 +52,18 @@ public final class CapeManager { */ protected void downloadCapes() { try { - if (Minecraft.getMinecraft().getTextureManager() != null) { - for (CapeUser user : this.capeUserList) { - if (user != null) { - final ResourceLocation cape = this.findResource(user.getCape()); + Minecraft.getMinecraft().getTextureManager(); + for (CapeUser user : this.capeUserList) { + if (user != null) { + final ResourceLocation cape = this.findResource(user.getCape()); - if (cape == null) { - final DynamicTexture texture = new DynamicTexture(ImageIO.read(new URL("https://seppuku.pw/files/" + user.getCape()))); - if (texture != null) { - final ResourceLocation location = Minecraft.getMinecraft().getTextureManager().getDynamicTextureLocation("seppuku/capes", texture); - if (location != null) { - this.capesMap.put(user.getCape(), location); - } - } - } + if (cape == null) { + URL url = new URL("https://seppuku.pw/files/" + user.getCape()); + HttpURLConnection httpURLConnection = (HttpURLConnection) url.openConnection(); + httpURLConnection.addRequestProperty("User-Agent", "Mozilla/4.76"); + final DynamicTexture texture = new DynamicTexture(ImageIO.read(httpURLConnection.getInputStream())); + final ResourceLocation location = Minecraft.getMinecraft().getTextureManager().getDynamicTextureLocation("seppuku/capes", texture); + this.capesMap.put(user.getCape(), location); } } } @@ -93,7 +92,10 @@ public final class CapeManager { */ protected void downloadCapeUsers() { try { - final BufferedReader reader = new BufferedReader(new InputStreamReader(new URL("https://seppuku.pw/files/capes.txt").openStream())); + URL url = new URL("https://seppuku.pw/files/capes.txt"); + HttpURLConnection httpURLConnection = (HttpURLConnection) url.openConnection(); + httpURLConnection.addRequestProperty("User-Agent", "Mozilla/4.76"); + final BufferedReader reader = new BufferedReader(new InputStreamReader(httpURLConnection.getInputStream())); String line; while ((line = reader.readLine()) != null) { @@ -169,4 +171,4 @@ public final class CapeManager { public void setCapesMap(HashMap capesMap) { this.capesMap = capesMap; } -} +} \ No newline at end of file