Skip to content

Commit

Permalink
Fixes capes, adds HudEditor labels to potion effects for the player &…
Browse files Browse the repository at this point in the history
… enemy if there are no effects currently on them
  • Loading branch information
uoil committed Nov 2, 2020
1 parent d6eaac9 commit 4c40e70
Show file tree
Hide file tree
Showing 3 changed files with 47 additions and 32 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -94,7 +94,7 @@ public void render(int mouseX, int mouseY, float partialTicks) {

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);
Expand All @@ -105,4 +105,4 @@ public void render(int mouseX, int mouseY, float partialTicks) {
this.setW(maxWidth);
this.setH(Math.abs(yOffset));
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
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;
Expand All @@ -25,13 +26,15 @@ public PotionEffectsComponent() {
public void render(int mouseX, int mouseY, float partialTicks) {
super.render(mouseX, mouseY, partialTicks);

final Minecraft mc = Minecraft.getMinecraft();

final List<PotionEffect> effects =
new ArrayList<>(Minecraft.getMinecraft().player.getActivePotionEffects());
new ArrayList<>(mc.player.getActivePotionEffects());

final Comparator<PotionEffect> 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);
};

Expand All @@ -45,7 +48,7 @@ public void render(int mouseX, int mouseY, float partialTicks) {
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;
Expand All @@ -54,15 +57,15 @@ public void render(int mouseX, int mouseY, float partialTicks) {
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:
xOffset = 0;
break;
case TOP_RIGHT:
case BOTTOM_RIGHT:
xOffset = this.getW() - Minecraft.getMinecraft().fontRenderer.getStringWidth(effect);
xOffset = this.getW() - mc.fontRenderer.getStringWidth(effect);
break;
}
}
Expand All @@ -72,24 +75,34 @@ public void render(int mouseX, int mouseY, float partialTicks) {
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));
}

}
}
Original file line number Diff line number Diff line change
Expand Up @@ -12,15 +12,16 @@
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;
import java.util.List;
import java.util.Map;

/**
* Author Seth
* 7/9/2019 @ 5:47 PM.
* @author Seth
* @author noil
*/
public final class CapeManager {

Expand Down Expand Up @@ -51,20 +52,18 @@ public void displayCape(EventCapeLocation event) {
*/
protected void downloadCapes() {
try {
if (Minecraft.getMinecraft().getTextureManager() != null) {
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);
}
}
}
Minecraft.getMinecraft().getTextureManager();
for (CapeUser user : this.capeUserList) {
if (user != null) {
final ResourceLocation cape = this.findResource(user.getCape());

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);
}
}
}
Expand Down Expand Up @@ -93,7 +92,10 @@ public ResourceLocation findResource(String key) {
*/
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) {
Expand Down Expand Up @@ -169,4 +171,4 @@ public HashMap<String, ResourceLocation> getCapesMap() {
public void setCapesMap(HashMap<String, ResourceLocation> capesMap) {
this.capesMap = capesMap;
}
}
}

0 comments on commit 4c40e70

Please sign in to comment.