From cde383d3af47532b62bd8aa13b57f962b43ad55d Mon Sep 17 00:00:00 2001 From: Linnea Gräf Date: Sun, 17 Mar 2024 16:55:09 +0100 Subject: Add /ec warning to storage overlay (#1053) --- .../miscfeatures/StorageManager.java | 11 +++++-- .../notenoughupdates/miscgui/StorageOverlay.java | 28 +++++++++++++---- .../moulberry/notenoughupdates/util/Utils.java | 36 +++++++++++++++++----- 3 files changed, 58 insertions(+), 17 deletions(-) diff --git a/src/main/java/io/github/moulberry/notenoughupdates/miscfeatures/StorageManager.java b/src/main/java/io/github/moulberry/notenoughupdates/miscfeatures/StorageManager.java index 985ed11a..48968e29 100644 --- a/src/main/java/io/github/moulberry/notenoughupdates/miscfeatures/StorageManager.java +++ b/src/main/java/io/github/moulberry/notenoughupdates/miscfeatures/StorageManager.java @@ -175,15 +175,20 @@ public class StorageManager { } private static void fixPetInfo(ItemStack src) { - if (src.getTagCompound() == null || !src.getTagCompound().hasKey("ExtraAttributes") || !src.getTagCompound().getCompoundTag("ExtraAttributes").hasKey("petInfo")) return; - PetInfo oldPetInfo = GSON.fromJson(src.getTagCompound().getCompoundTag("ExtraAttributes").getString("petInfo"), PetInfo.class); + if (src.getTagCompound() == null || !src.getTagCompound().hasKey("ExtraAttributes") || + !src.getTagCompound().getCompoundTag("ExtraAttributes").hasKey("petInfo")) return; + PetInfo oldPetInfo = GSON.fromJson( + src.getTagCompound().getCompoundTag("ExtraAttributes").getString("petInfo"), + PetInfo.class + ); src.getTagCompound().getCompoundTag("ExtraAttributes").removeTag("petInfo"); try { src.getTagCompound().getCompoundTag("ExtraAttributes").setTag( "petInfo", JsonToNBT.getTagFromJson(oldPetInfo.toString()) ); - } catch (NBTException | NullPointerException ignored) {} + } catch (NBTException | NullPointerException ignored) { + } } private static JsonElement loadJson(NBTBase tag) { diff --git a/src/main/java/io/github/moulberry/notenoughupdates/miscgui/StorageOverlay.java b/src/main/java/io/github/moulberry/notenoughupdates/miscgui/StorageOverlay.java index 13cafd98..1c4bd867 100644 --- a/src/main/java/io/github/moulberry/notenoughupdates/miscgui/StorageOverlay.java +++ b/src/main/java/io/github/moulberry/notenoughupdates/miscgui/StorageOverlay.java @@ -1198,12 +1198,24 @@ public class StorageOverlay extends GuiElement { if (fastRender) { fontRendererObj.drawString( "Fast render and antialiasing do not work with Storage overlay.", - sizeX / 2 - fontRendererObj.getStringWidth("Fast render and antialiasing do not work with Storage overlay.") / 2, + sizeX / 2 - + fontRendererObj.getStringWidth("Fast render and antialiasing do not work with Storage overlay.") / 2, -10, 0xFFFF0000 ); } + if (StorageManager.getInstance().storageConfig.displayToStorageIdMapRender.isEmpty()) { + Utils.drawStringScaledFillWidth( + "Please open /storage instead of /ec", + sizeX / 2, + sizeY / 3, + false, + 0xFFFF0000, + sizeX - 30 + ); + } + //Inventory Text fontRendererObj.drawString("Inventory", 180, storageViewSize + 6, textColour); searchBar.setCustomTextColour(searchTextColour); @@ -1887,8 +1899,10 @@ public class StorageOverlay extends GuiElement { "You just disabled the custom storage gui, did you mean to do that? If not click this message to turn it back on."); storageMessage.setChatStyle(Utils.createClickStyle(ClickEvent.Action.RUN_COMMAND, "/neuenablestorage")); storageMessage.setChatStyle(storageMessage.getChatStyle().setChatHoverEvent( - new HoverEvent(HoverEvent.Action.SHOW_TEXT, - new ChatComponentText(EnumChatFormatting.YELLOW + "Click to enable the custom storage gui.")))); + new HoverEvent( + HoverEvent.Action.SHOW_TEXT, + new ChatComponentText(EnumChatFormatting.YELLOW + "Click to enable the custom storage gui.") + ))); ChatComponentText storageChatMessage = new ChatComponentText(""); storageChatMessage.appendSibling(storageMessage); Minecraft.getMinecraft().thePlayer.addChatMessage(storageChatMessage); @@ -2126,15 +2140,17 @@ public class StorageOverlay extends GuiElement { } if (!searchBar.getFocus() && !renameStorageField.getFocus() && - (Keyboard.getEventKey() == manager.keybindViewRecipe.getKeyCode() || + (Keyboard.getEventKey() == manager.keybindViewRecipe.getKeyCode() || Keyboard.getEventKey() == manager.keybindViewUsages.getKeyCode())) { for (Slot slot : container.inventorySlots.inventorySlots) { if (slot != null && ((AccessorGuiContainer) container).doIsMouseOverSlot(slot, mouseX, mouseY)) { - String internalName = manager.createItemResolutionQuery().withItemStack(slot.getStack()).resolveInternalName(); + String internalName = + manager.createItemResolutionQuery().withItemStack(slot.getStack()).resolveInternalName(); if (internalName == null) continue; JsonObject item = manager.getItemInformation().get(internalName); if (Keyboard.getEventKey() == manager.keybindViewRecipe.getKeyCode()) manager.showRecipe(item); - if (Keyboard.getEventKey() == manager.keybindViewUsages.getKeyCode()) manager.displayGuiItemUsages(internalName); + if (Keyboard.getEventKey() == manager.keybindViewUsages.getKeyCode()) manager.displayGuiItemUsages( + internalName); } } } diff --git a/src/main/java/io/github/moulberry/notenoughupdates/util/Utils.java b/src/main/java/io/github/moulberry/notenoughupdates/util/Utils.java index 6d44e4b7..2878406e 100644 --- a/src/main/java/io/github/moulberry/notenoughupdates/util/Utils.java +++ b/src/main/java/io/github/moulberry/notenoughupdates/util/Utils.java @@ -30,6 +30,7 @@ import io.github.moulberry.notenoughupdates.NotEnoughUpdates; import io.github.moulberry.notenoughupdates.TooltipTextScrolling; import io.github.moulberry.notenoughupdates.miscfeatures.SlotLocking; import io.github.moulberry.notenoughupdates.profileviewer.GuiProfileViewer; +import lombok.var; import net.minecraft.block.Block; import net.minecraft.client.Minecraft; import net.minecraft.client.audio.PositionedSoundRecord; @@ -1225,6 +1226,23 @@ public class Utils { drawStringScaled(str, x - fr.getStringWidth(str) * factor, y, shadow, colour, factor); } + public static void drawStringScaledFillWidth( + String str, + float x, float y, + boolean shadow, + int colour, + int availableSpace + ) { + GlStateManager.pushMatrix(); + GlStateManager.translate(x, y, 0); + var fr = Minecraft.getMinecraft().fontRendererObj; + var width = fr.getStringWidth(str); + float scale = ((float) availableSpace) / width; + GlStateManager.scale(scale, scale, 1f); + fr.drawString(str, -width / 2F, 0, colour, shadow); + GlStateManager.popMatrix(); + } + public static void drawStringScaledMax( String str, float x, @@ -1575,6 +1593,7 @@ public class Utils { if (!prim.isNumber()) return def; return prim.getAsInt(); } + public static long getElementAsLong(JsonElement element, long def) { if (element == null) return def; if (!element.isJsonPrimitive()) return def; @@ -1984,6 +2003,7 @@ public class Utils { /** * Draws a solid color rectangle with the specified coordinates and color (ARGB format). Args: x1, y1, x2, y2, color + * * @see Gui#drawRect */ public static void drawRect(float left, float top, float right, float bottom, int color) { @@ -1998,10 +2018,10 @@ public class Utils { top = bottom; bottom = i; } - float f = (float)(color >> 24 & 0xFF) / 255.0f; - float g = (float)(color >> 16 & 0xFF) / 255.0f; - float h = (float)(color >> 8 & 0xFF) / 255.0f; - float j = (float)(color & 0xFF) / 255.0f; + float f = (float) (color >> 24 & 0xFF) / 255.0f; + float g = (float) (color >> 16 & 0xFF) / 255.0f; + float h = (float) (color >> 8 & 0xFF) / 255.0f; + float j = (float) (color & 0xFF) / 255.0f; Tessellator tessellator = Tessellator.getInstance(); WorldRenderer worldRenderer = tessellator.getWorldRenderer(); GlStateManager.enableBlend(); @@ -2018,7 +2038,6 @@ public class Utils { GlStateManager.disableBlend(); } - /** * Draws a default-size 16 by 16 item-overlay at x and y. * @@ -2032,9 +2051,9 @@ public class Utils { /** * Draws an item-overlay of given width and height at x and y. * - * @param x position of the overlay - * @param y position of the overlay - * @param width width of the overlay + * @param x position of the overlay + * @param y position of the overlay + * @param width width of the overlay * @param height height of the overlay */ public static void drawHoverOverlay(int x, int y, int width, int height) { @@ -2239,6 +2258,7 @@ public class Utils { } private static long lastError = -1; + public static void showOutdatedRepoNotification(String missingFile) { if (NotEnoughUpdates.INSTANCE.config.notifications.outdatedRepo) { NotificationHandler.displayNotification(Lists.newArrayList( -- cgit