diff --git a/src/main/java/com/github/lunatrius/ingameinfo/client/gui/Info.java b/src/main/java/com/github/lunatrius/ingameinfo/client/gui/Info.java index 253b8a2..71c6606 100644 --- a/src/main/java/com/github/lunatrius/ingameinfo/client/gui/Info.java +++ b/src/main/java/com/github/lunatrius/ingameinfo/client/gui/Info.java @@ -17,6 +17,9 @@ public abstract class Info { public int offsetX; public int offsetY; private String identifier = ""; + private String iconSpacing = ""; + public boolean hasPosition = false; + private int oldWidth; protected Info(int x, int y) { this.x = x; @@ -46,6 +49,14 @@ public int getY() { return this.y + this.offsetY; } + public String getIconSpacing() { + if (oldWidth != getWidth()) { + setIconSpacing(); + oldWidth = getWidth(); + } + return iconSpacing; + } + public int getWidth() { return 0; } @@ -64,6 +75,14 @@ public String getIdentifier() { return this.identifier; } + private void setIconSpacing() { + String str = ""; + for (int i = 0; i < getWidth() && fontRenderer.getStringWidth(str) < getWidth(); i++) { + str += " "; + } + iconSpacing = str; + } + @Override public String toString() { return "Info"; diff --git a/src/main/java/com/github/lunatrius/ingameinfo/client/gui/InfoText.java b/src/main/java/com/github/lunatrius/ingameinfo/client/gui/InfoText.java index 45ad8dd..6078595 100644 --- a/src/main/java/com/github/lunatrius/ingameinfo/client/gui/InfoText.java +++ b/src/main/java/com/github/lunatrius/ingameinfo/client/gui/InfoText.java @@ -21,8 +21,6 @@ public class InfoText extends Info { private final List values; private final Alignment alignment; private final int index; - private int scaledWidth, scaledHeight; - private boolean updatePos = true; public InfoText(int index, Alignment alignment, List values) { super(0, 0); @@ -35,15 +33,6 @@ public InfoText(int index, Alignment alignment, List values) { } public void update() { - int newHeight = InGameInfoCore.INSTANCE.scaledHeight; - int newWidth = InGameInfoCore.INSTANCE.scaledWidth; - if (newHeight != scaledHeight || newWidth != scaledWidth) { - scaledHeight = newHeight; - scaledWidth = newWidth; - updatePos = true; - attachedValues.clear(); - } - StringBuilder builder = new StringBuilder(); for (Value value : this.values) { builder.append(getValue(value)); @@ -76,32 +65,21 @@ private void updateChildren(StringBuilder builder) { } for (Info child : attachedValues.values()) { - int index = builder.indexOf(ICON_START); - child.x = fontRenderer.getStringWidth(builder.substring(0, index)); - int end = builder.indexOf("}", index) + 1; - builder.replace(index, end + 1, ""); - updatePos = true; + if (child.hasPosition) continue; + int iconStart = builder.indexOf(ICON_START); + int widthStart = builder.indexOf("|", iconStart) + 1; + child.hasPosition = true; + child.x = fontRenderer.getStringWidth(builder.substring(0, iconStart)); + builder.replace(iconStart, widthStart, ""); + builder.deleteCharAt(builder.indexOf("}")); } } private void updatePosition() { - if (!updatePos) return; - updatePos = false; + int scaledWidth = InGameInfoCore.INSTANCE.scaledWidth; + int scaledHeight = InGameInfoCore.INSTANCE.scaledHeight; x = alignment.getX(scaledWidth, fontRenderer.getStringWidth(text)); y = alignment.getY(scaledHeight, getHeight()); - - for (Info child : attachedValues.values()) { - if (child.x == 0) { - offsetX = child.getWidth(); - } - - int actualX = child.x + x + child.getWidth(); - if (actualX > scaledWidth) { - int diff = actualX + 1 - scaledWidth; - child.x = child.x - diff; - offsetX = -diff; - } - } } public @Nullable Info getAttachedValue(String tag) { diff --git a/src/main/java/com/github/lunatrius/ingameinfo/tag/Tag.java b/src/main/java/com/github/lunatrius/ingameinfo/tag/Tag.java index 92fc577..a55bf68 100644 --- a/src/main/java/com/github/lunatrius/ingameinfo/tag/Tag.java +++ b/src/main/java/com/github/lunatrius/ingameinfo/tag/Tag.java @@ -130,10 +130,6 @@ public static void releaseResources() { } public static String getIconTag(Info info) { - String str = ""; - for (int i = 0; i < info.getWidth() && minecraft.fontRenderer.getStringWidth(str) < info.getWidth(); i++) { - str += " "; - } - return String.format("{ICON|%s}", str); + return String.format("{ICON|%s}", info.getIconSpacing()); } } diff --git a/src/main/java/com/github/lunatrius/ingameinfo/tag/TagMisc.java b/src/main/java/com/github/lunatrius/ingameinfo/tag/TagMisc.java index 77cd3f5..b7e1858 100644 --- a/src/main/java/com/github/lunatrius/ingameinfo/tag/TagMisc.java +++ b/src/main/java/com/github/lunatrius/ingameinfo/tag/TagMisc.java @@ -4,7 +4,6 @@ import net.minecraft.client.gui.GuiPlayerInfo; import net.minecraft.client.resources.ResourcePackRepository; -import net.minecraft.util.EnumChatFormatting; import org.jetbrains.annotations.NotNull; @@ -174,31 +173,24 @@ public String getValue() { public static class PingIcon extends TagMisc { - private boolean needsUpdate(InfoText caller, int ping) { - Info value = caller.getAttachedValue(getName()); - if (value == null) return true; - return Integer.parseInt(value.getIdentifier()) != ping; - } - @Override public @NotNull String getValue(@NotNull InfoText caller) { - List list = player.sendQueue.playerInfoList; - for (GuiPlayerInfo playerInfo : list) { - if (player.getGameProfile().getName() - .equals(EnumChatFormatting.getTextWithoutFormattingCodes(playerInfo.name))) { - int pingIndex = getPingIndex(playerInfo); - if (needsUpdate(caller, playerInfo.responseTime)) { - InfoIcon icon = new InfoIcon("textures/gui/icons.png"); - icon.setIdentifier(String.valueOf(playerInfo.responseTime)); - icon.setDisplayDimensions(0, 0, 10, 8); - icon.setTextureData(0, 176 + pingIndex * 8, 10, 8, 256, 256); - caller.attachValue(getName(), icon); - return getIconTag(icon); - } - return ""; - } + GuiPlayerInfo playerInfo = (GuiPlayerInfo) player.sendQueue.playerInfoMap + .get(player.getCommandSenderName()); + if (playerInfo == null) return "-1"; + int pingIndex = getPingIndex(playerInfo); + Info value = caller.getAttachedValue(getName()); + if (value == null) { + InfoIcon icon = new InfoIcon("textures/gui/icons.png"); + icon.setIdentifier(String.valueOf(playerInfo.responseTime)); + icon.setDisplayDimensions(0, 0, 10, 8); + icon.setTextureData(0, 176 + pingIndex * 8, 10, 8, 256, 256); + caller.attachValue(getName(), icon); + return getIconTag(icon); + } else { + ((InfoIcon) value).setTextureData(0, 176 + pingIndex * 8, 10, 8, 256, 256); + return value.getIconSpacing(); } - return "-1"; } private static int getPingIndex(GuiPlayerInfo playerInfo) { diff --git a/src/main/java/com/github/lunatrius/ingameinfo/tag/TagPlayerEquipment.java b/src/main/java/com/github/lunatrius/ingameinfo/tag/TagPlayerEquipment.java index 6181aad..febf2a6 100644 --- a/src/main/java/com/github/lunatrius/ingameinfo/tag/TagPlayerEquipment.java +++ b/src/main/java/com/github/lunatrius/ingameinfo/tag/TagPlayerEquipment.java @@ -147,7 +147,7 @@ public Icon(int slot, boolean large) { if (value != null) { value.setValue(itemStack); - return ""; + return value.getIconSpacing(); } InfoItem item = new InfoItem(itemStack, this.large); diff --git a/src/main/java/com/github/lunatrius/ingameinfo/tag/TagPlayerPotion.java b/src/main/java/com/github/lunatrius/ingameinfo/tag/TagPlayerPotion.java index 7c668fa..a0a6688 100644 --- a/src/main/java/com/github/lunatrius/ingameinfo/tag/TagPlayerPotion.java +++ b/src/main/java/com/github/lunatrius/ingameinfo/tag/TagPlayerPotion.java @@ -157,10 +157,11 @@ public Icon(int index, boolean large) { @Override public @NotNull String getValue(@NotNull InfoText parent) { updatePotionEffects(); - Info value = parent.getAttachedValue(getName()); if (potionEffects.length > this.index) { + Info value = parent.getAttachedValue(getName()); Potion potion = Potion.potionTypes[potionEffects[this.index].getPotionID()]; - if (potion.hasStatusIcon() && shouldUpdate(value, potion.id)) { + if (!potion.hasStatusIcon()) return ""; + if (shouldUpdate(value, potion.id)) { InfoIcon icon; if (value == null) { icon = new InfoIcon("textures/gui/container/inventory.png"); @@ -179,11 +180,13 @@ public Icon(int index, boolean large) { icon.setTextureData((i % 8) * 18, 198 + (i / 8) * 18, 18, 18, 256, 256); if (value != null) { - return ""; + return value.getIconSpacing(); } parent.attachValue(getName(), icon); return getIconTag(icon); + } else { + return value.getIconSpacing(); } } diff --git a/src/main/java/com/github/lunatrius/ingameinfo/value/ValueComplex.java b/src/main/java/com/github/lunatrius/ingameinfo/value/ValueComplex.java index f087ae6..0cbb8e9 100644 --- a/src/main/java/com/github/lunatrius/ingameinfo/value/ValueComplex.java +++ b/src/main/java/com/github/lunatrius/ingameinfo/value/ValueComplex.java @@ -265,7 +265,7 @@ public String getValue() { Info value = parent.getAttachedValue(getName()); if (value != null && value.getIdentifier().equals(what)) { - return ""; + return value.getIconSpacing(); } if ((size == 1 || size == 2) && !what.endsWith(".png")) { @@ -294,7 +294,7 @@ public String getValue() { } else { value.setIdentifier(what); value.setValue(itemStack); - return ""; + return value.getIconSpacing(); } } @@ -331,7 +331,7 @@ public String getValue() { return Tag.getIconTag(icon); } else { value.setValue(what); - return ""; + return value.getIconSpacing(); } } catch (Exception e) { return "?"; diff --git a/src/main/resources/META-INF/igi_at.cfg b/src/main/resources/META-INF/igi_at.cfg index 2369b1b..c1bcaff 100644 --- a/src/main/resources/META-INF/igi_at.cfg +++ b/src/main/resources/META-INF/igi_at.cfg @@ -1,3 +1,4 @@ # InGameInfoXML public net.minecraft.client.multiplayer.PlayerControllerMP field_78779_k # currentGameType public net.minecraft.util.FoodStats field_75126_c # foodExhaustionLevel +public net.minecraft.client.network.NetHandlerPlayClient field_147310_i # playerInfoMap