diff --git a/README.md b/README.md index ed4fca1d..51a6d686 100644 --- a/README.md +++ b/README.md @@ -1,5 +1,7 @@ # NotEnoughItems Unofficial - By the GTNH Team +🌐 **Languages:** [English](README.md) | [Українська](README_uk.md) + A continuation of NotEnoughItems for 1.7.10 by the developers of Gregtech: New Horizons modpack, with features either inspired and/or backported from JustEnoughItems We've tested this against all of the mods included in GTNH, as well as a limited set of other mods (like Reika's mods). Every effort has been made to maintain backwards compatibility, however the focus is on the mods contained in the GTNH modpack. diff --git a/README_uk.md b/README_uk.md new file mode 100644 index 00000000..d05d6ac1 --- /dev/null +++ b/README_uk.md @@ -0,0 +1,93 @@ +# NotEnoughItems Unofficial — від команди GTNH + +🌐 **Мови:** [English](README.md) | [Українська](README_uk.md) + +Продовження модифікації NotEnoughItems для 1.7.10 від розробників збірки GregTech: New Horizons із функціями, натхненними та/або бекпортованими з JustEnoughItems. + +Ми протестували цю версію з усіма модами, що входять до GTNH, а також із обмеженим набором інших модів (як-от моди від Reika). Було докладено всіх зусиль для збереження зворотної сумісності, однак основну увагу приділено модам зі збірки GTNH. + +Якщо у вас виникли проблеми з NEI за межами збірки GTNH, ви можете повідомити про них у [GitHub-репозиторії GTNH NEI](https://github.com/GTNewHorizons/NotEnoughItems). + +## Нові можливості: + +* Швидкодія + - Використовує паралельний потік для пошуку у списку предметів на кількох ядрах процесора, що в середньому пришвидшує пошук у 2–6 разів. + - Завантажує обробники рецептів паралельно. +* Текстове поле пошуку з більшістю очікуваних функцій — переміщення курсора вперед/назад, виділення тексту тощо. +* Закладки! Перебуваєте у процесі крафту? Додайте потрібний рецепт до закладок за допомогою клавіші «A» або налаштуйте власну клавішу. +* Перемикання видимості панелі закладок. Гаряча клавіша за замовчуванням — `B`. Меню «Підгрупи предметів» доступне лише тоді, коли панель закладок прихована. +* Кнопки утиліт та читів вирівнюються в ряд та переносяться на новий рядок залежно від розміру графічного інтерфейсу. +* Список предметів (`ItemList`) більше не генерується повторно з `ItemRegistry` під час кожного відкриття інвентарю. +* Вкладки у стилі JEI (або творчого режиму) [За бажанням]. Примітка: вимагає явної підтримки для рендерингу `ItemStack`, інакше використовуються перші дві літери назви обробника. +* Вкладки/обробники завантажуються з конфігураційного CSV-файлу в JAR-архіві (або за бажанням з папки `config`). Для авторів модів доступні IMC-повідомлення з NBT-даними `registerHandlerInfo` та `removeHandlerInfo` для додавання інформації про обробники з використанням тих самих полів, що й у CSV-файлі. +* Пошук за допомогою синтаксису `@[Мод]->[предмет]`. Наприклад: `@Mod.gregtech->iron ingot`. +* Перемикання між режимами рецептів, утиліт та читів за допомогою CTRL + ЛКМ по іконці гайкового ключа. +* Інструменти/предмети з GT5u та інструменти з GT6 тепер мають коректно працювати з функцією накладення та перенесення рецепта. + +### Обробник інформаційних сторінок +Хочете додати інформацію про блок чи предмет, не створюючи для нього величезну підказку? Ви можете додати інформацію про будь-який блок чи предмет, зареєструвавши його в обробнику інформації. + +Інформаційні сторінки відображаються під час пошуку рецептів або способів використання відповідного предмета. Усі відповідні предмети будуть циклічно змінюватися у верхній частині інформаційної сторінки. + +Ваш мод може викликати: +```java +FMLInterModComms.sendMessage("NotEnoughItems", "addItemInfo", nbt); +``` +Де `nbt` — це `NBTTagCompound`, відформатований, як описано нижче. + +| Тег | Тип | Опис | +|------------------|--------------------------------|----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------| +| `filter` | `String` | Текстовий фільтр для визначення предметів, для яких має відображатися ця інформаційна сторінка.
Можна використовувати `modname:itemname`, метадані, теги OreDictionary та регулярні вирази. Повний формат можна переглянути у `config/NEI/collapsibleitems.cfg`. | +| `page` / `pages` | `String` / `String NBTTagList` | Безпосередньо текст для відображення. Різницю між одно- та багатосторінковими повідомленнями див. нижче.
Обидва формати підтримують автоматичний переклад наданих рядків. | + +#### Односторінковий формат + +Використовуйте текстовий тег `"page"`, якщо хочете додати лише одну сторінку інформації: +```java +NBTTagCompound tag = new NBTTagCompound(); +tag.setString("filter", "minecraft:log 3"); +tag.setString("page", "Exotic wood found in tropical climates."); + +FMLInterModComms.sendMessage("NotEnoughItems", "addItemInfo", tag); +``` + +#### Багатосторінковий формат + +Використовуйте тег `"pages"` як `NBTTagList` із рядків, якщо потрібно додати понад одну сторінку: +```java +NBTTagCompound tag = new NBTTagCompound(); +tag.setString("filter", "minecraft:diamond_sword"); + +NBTTagList pages = new NBTTagList(); +pages.appendTag(new NBTTagString("A powerful melee weapon.")); +pages.appendTag(new NBTTagString("Can be enchanted for extra effects.")); + +tag.setTag("pages", pages); + +FMLInterModComms.sendMessage("NotEnoughItems", "addItemInfo", tag); +``` +* Кожен елемент списку — це одна сторінка. +* Сторінки з’являтимуться в NEI з кнопками для їх гортання. + +#### Відповідність предметів + +Усі предмети, що відповідають фільтру `filter`, відображатимуть вашу інформаційну сторінку. Повний формат фільтра див. у `config/NEI/collapsibleitems.cfg`. + +#### Файл конфігурації інформації про предмети + +Якщо ви творець збірки модів і хочете створити власні інформаційні сторінки для предметів, їх можна легко додати у файлі `config/NEI/informationpages.cfg`, де також наведено ще кілька прикладів. + +## Інші примітки: + +* Вилучено стиль TMI +* Вилучено збереження/завантаження стану інвентарю + +## Ліцензія + +Авторські права на модифікації від команди GTNH (c) 2019-2024 належать mitchej123 та команді GTNH. + +Поширюється за ліцензією LGPL-3.0 або новішої версії — використовуйте цей код на власний розсуд, але, будь ласка, діліться з розробниками будь-якими внесеними вами змінами. + +Окремі частини коду натхненні, запозичені або бекпортовані з [JEI](https://github.com/mezz/JustEnoughItems/tree/1.12) за ліцензією MIT. + +Авторські права на оригінальний код (c) 2014-2015 належать mezz; код поширювався за ліцензією MIT. diff --git a/src/main/java/codechicken/nei/BookmarkPanel.java b/src/main/java/codechicken/nei/BookmarkPanel.java index ac300bb5..9ffc7b71 100644 --- a/src/main/java/codechicken/nei/BookmarkPanel.java +++ b/src/main/java/codechicken/nei/BookmarkPanel.java @@ -1048,15 +1048,9 @@ public class BookmarkPanel extends PanelWidget { final BookmarksGridSlot slot = this.grid.getSlotMouseOver(mousex, mousey); if (slot != null) { - int multiplier = 1; - - if (NEIClientUtils.altKey()) { - multiplier = NEIClientConfig.showItemQuantityWidget() ? NEIClientConfig.getItemQuantity() : 0; - if (multiplier == 0) { - multiplier = StackInfo.itemStackToNBT(slot.getItemStack()).hasKey("gtFluidName") ? 144 - : slot.getItemStack().getMaxStackSize(); - } - } + final long multiplier = NEIClientUtils.altKey() + ? NEIClientUtils.getScrollMultiplier(slot.getItemStack()) + : 1; this.grid.shiftItemAmount(slot.itemIndex, multiplier * shift); return true; diff --git a/src/main/java/codechicken/nei/ClientHandler.java b/src/main/java/codechicken/nei/ClientHandler.java index 2de5f576..3d229532 100644 --- a/src/main/java/codechicken/nei/ClientHandler.java +++ b/src/main/java/codechicken/nei/ClientHandler.java @@ -48,6 +48,7 @@ import codechicken.nei.api.API; import codechicken.nei.api.GuiInfo; import codechicken.nei.api.IConfigureNEI; import codechicken.nei.api.ItemInfo; +import codechicken.nei.bookmark.tree.GuiCraftingTree; import codechicken.nei.guihook.GuiContainerManager; import codechicken.nei.recipe.GuiRecipeTab; import codechicken.nei.recipe.StackInfo; @@ -279,6 +280,7 @@ public class ClientHandler { PacketCustom.assignHandler(NEICPH.channel, new NEICPH()); FMLCommonHandler.instance().bus().register(instance); MinecraftForge.EVENT_BUS.register(instance); + MinecraftForge.EVENT_BUS.register(new GuiCraftingTree.EventHandler()); API.registerHighlightHandler(new DefaultHighlightHandler(), ItemInfo.Layout.HEADER); HUDRenderer.load(); diff --git a/src/main/java/codechicken/nei/ColorUtils.java b/src/main/java/codechicken/nei/ColorUtils.java index 6459dea4..ec5012e9 100644 --- a/src/main/java/codechicken/nei/ColorUtils.java +++ b/src/main/java/codechicken/nei/ColorUtils.java @@ -17,6 +17,8 @@ public class ColorUtils { buttonLabelNormal = color.rgb("buttonLabelNormal", "0xE0E0E0"), buttonLabelHover = color.rgb("buttonLabelHover", "0xFFFFA0"), buttonLabelDisabled = color.rgb("buttonLabelDisabled", "0x601010"), - buttonLabelInactive = color.rgb("buttonLabelInactive", "0xA0A0A0"); + buttonLabelInactive = color.rgb("buttonLabelInactive", "0xA0A0A0"), + + craftingTreeLine = color.argb("craftingTreeLine", "0xFF888888"); // spotless:on } diff --git a/src/main/java/codechicken/nei/ItemCraftablesPanel.java b/src/main/java/codechicken/nei/ItemCraftablesPanel.java index 30b7dec1..af2627ff 100644 --- a/src/main/java/codechicken/nei/ItemCraftablesPanel.java +++ b/src/main/java/codechicken/nei/ItemCraftablesPanel.java @@ -39,7 +39,7 @@ public class ItemCraftablesPanel public CraftablesGridSlot(int slotIndex, int itemIndex, ItemStack itemStack, RecipeId recipeId) { super(slotIndex, itemIndex, itemStack); this.realAmount = StackInfo.getAmount(itemStack); - this.isFluidDisplay = StackInfo.itemStackToNBT(itemStack).hasKey("gtFluidName"); + this.isFluidDisplay = StackInfo.isFluidDisplayItem(itemStack); this.recipeId = recipeId; } diff --git a/src/main/java/codechicken/nei/ItemQuantityField.java b/src/main/java/codechicken/nei/ItemQuantityField.java index 8189597d..e0122ba5 100644 --- a/src/main/java/codechicken/nei/ItemQuantityField.java +++ b/src/main/java/codechicken/nei/ItemQuantityField.java @@ -83,11 +83,7 @@ public class ItemQuantityField extends TextField { } if (amount == 0) { - amount = NEIClientConfig.showItemQuantityWidget() ? NEIClientConfig.getItemQuantity() : 0; - - if (amount == 0) { - amount = StackInfo.itemStackToNBT(stack).hasKey("gtFluidName") ? 144 : stack.getMaxStackSize(); - } + amount = NEIClientUtils.getScrollMultiplier(stack); } return StackInfo.withAmount(stack, amount); diff --git a/src/main/java/codechicken/nei/ItemsGrid.java b/src/main/java/codechicken/nei/ItemsGrid.java index dc0777c4..e8595585 100644 --- a/src/main/java/codechicken/nei/ItemsGrid.java +++ b/src/main/java/codechicken/nei/ItemsGrid.java @@ -19,6 +19,7 @@ import org.lwjgl.opengl.GL30; import codechicken.lib.vec.Rectangle4i; import codechicken.nei.api.GuiInfo; +import codechicken.nei.api.INEIGuiHandler; import codechicken.nei.guihook.GuiContainerManager; import codechicken.nei.recipe.Recipe.RecipeId; import codechicken.nei.recipe.StackInfo; @@ -348,16 +349,24 @@ public abstract class ItemsGrid= 0 && idx < invalidSlotMap.length && !invalidSlotMap[idx] - && GuiInfo.hideItemPanelSlot(gui, getSlotRect(r, c))) { + && GuiInfo.hideItemPanelSlot(gui, getSlotRect(r, c), handlers)) { invalidSlotMap[idx] = true; validColumn = false; perPage--; diff --git a/src/main/java/codechicken/nei/ItemsTooltipLineHandler.java b/src/main/java/codechicken/nei/ItemsTooltipLineHandler.java index cf5625aa..2ff46a40 100644 --- a/src/main/java/codechicken/nei/ItemsTooltipLineHandler.java +++ b/src/main/java/codechicken/nei/ItemsTooltipLineHandler.java @@ -79,6 +79,10 @@ public class ItemsTooltipLineHandler implements ITooltipLineHandler { return this.activeStackIndex == -1 ? null : this.items.get(this.activeStackIndex); } + public List getItems() { + return this.items; + } + public boolean isEmpty() { return this.items.isEmpty(); } @@ -163,9 +167,10 @@ public class ItemsTooltipLineHandler implements ITooltipLineHandler { for (Map.Entry entry : ItemStackAmount.of(items).entrySet()) { final ItemStack stack = StackInfo.loadFromNBT(entry.getKey(), Math.max(0, entry.getValue())); - if (entry.getKey().hasKey("gtFluidName")) { + if (stack != null && StackInfo.isFluidDisplayItem(stack)) { stack.stackSize = 0; } + result.add(stack); } diff --git a/src/main/java/codechicken/nei/LayoutManager.java b/src/main/java/codechicken/nei/LayoutManager.java index f5944bb2..bb10c9d6 100644 --- a/src/main/java/codechicken/nei/LayoutManager.java +++ b/src/main/java/codechicken/nei/LayoutManager.java @@ -43,6 +43,7 @@ import net.minecraft.client.gui.GuiButton; import net.minecraft.client.gui.inventory.GuiContainer; import net.minecraft.client.gui.inventory.GuiContainerCreative; import net.minecraft.client.renderer.InventoryEffectRenderer; +import net.minecraft.client.renderer.Tessellator; import net.minecraft.inventory.Slot; import net.minecraft.item.Item; import net.minecraft.item.ItemStack; @@ -118,11 +119,6 @@ public class LayoutManager implements IContainerInputHandler, IContainerTooltipH */ public static boolean itemsLoaded = false; - /** - * Not present, Present - */ - public static Image[] itemPresenceOverlays = new Image[2]; - public static void load() { API.addLayoutStyle(0, new LayoutStyleMinecraft()); @@ -907,30 +903,35 @@ public class LayoutManager implements IContainerInputHandler, IContainerTooltipH GL11.glEnable(GL11.GL_TEXTURE_2D); changeTexture("textures/gui/widgets.png"); - drawTexturedModalRect(x, y, tx1, ty1, w1, h1); // top left - drawTexturedModalRect(x, y2, tx1, ty2, w1, h2); // bottom left + final Tessellator tessellator = Tessellator.instance; + tessellator.startDrawingQuads(); + addTexturedModalRect(tessellator, x, y, tx1, ty1, w1, h1); // top left + addTexturedModalRect(tessellator, x, y2, tx1, ty2, w1, h2); // bottom left for (int tile = 0; tile < wTiles; tile++) { final int tileX = x + w1 + 50 * tile; - drawTexturedModalRect(tileX, y, tx3, ty1, 50, h1); // top - drawTexturedModalRect(tileX, y2, tx3, ty2, 50, h2); // bottom + addTexturedModalRect(tessellator, tileX, y, tx3, ty1, 50, h1); // top + addTexturedModalRect(tessellator, tileX, y2, tx3, ty2, 50, h2); // bottom } - drawTexturedModalRect(x2, y, tx2, ty1, w2, h1); // top right - drawTexturedModalRect(x2, y2, tx2, ty2, w2, h2); // bottom right + addTexturedModalRect(tessellator, x2, y, tx2, ty1, w2, h1); // top right + addTexturedModalRect(tessellator, x2, y2, tx2, ty2, w2, h2); // bottom right + tessellator.draw(); if (!is2DTexture) GL11.glDisable(GL11.GL_TEXTURE_2D); } - public static void drawItemPresenceOverlay(int slotX, int slotY, boolean isPresent, boolean slotHighlight) { - - if (slotHighlight) { - NEIClientUtils.gl2DRenderContext(() -> drawRect(slotX, slotY, 16, 16, isPresent ? 0x8000AA00 : 0x80AA0000)); - } else { - Image icon = itemPresenceOverlays[isPresent ? 1 : 0]; - drawIcon(slotX + 16 - icon.width, slotY + 16 - icon.height, icon); - } - + private static void addTexturedModalRect(Tessellator tessellator, int x, int y, int textureX, int textureY, + int width, int height) { + final double z = GuiDraw.gui.getZLevel(); + final double u = textureX / 256D; + final double v = textureY / 256D; + final double maxU = (textureX + width) / 256D; + final double maxV = (textureY + height) / 256D; + tessellator.addVertexWithUV(x, y + height, z, u, maxV); + tessellator.addVertexWithUV(x + width, y + height, z, maxU, maxV); + tessellator.addVertexWithUV(x + width, y, z, maxU, v); + tessellator.addVertexWithUV(x, y, z, u, v); } public static LayoutManager instance() { diff --git a/src/main/java/codechicken/nei/LayoutStyleMinecraft.java b/src/main/java/codechicken/nei/LayoutStyleMinecraft.java index 7d8bda93..14cc9cf8 100644 --- a/src/main/java/codechicken/nei/LayoutStyleMinecraft.java +++ b/src/main/java/codechicken/nei/LayoutStyleMinecraft.java @@ -8,7 +8,6 @@ import org.lwjgl.opengl.GL11; import codechicken.lib.vec.Rectangle4i; import codechicken.nei.api.LayoutStyle; -import codechicken.nei.drawable.DrawableBuilder; public class LayoutStyleMinecraft extends LayoutStyle { @@ -38,10 +37,6 @@ public class LayoutStyleMinecraft extends LayoutStyle { LayoutManager.timeButtons[2].icon = new Image(144, 24, 12, 12); LayoutManager.timeButtons[3].icon = new Image(156, 24, 12, 12); LayoutManager.heal.icon = new Image(168, 24, 12, 12); - LayoutManager.itemPresenceOverlays[0] = new DrawableBuilder("nei:textures/nei_tabbed_sprites.png", 0, 40, 8, 8) - .build(); - LayoutManager.itemPresenceOverlays[1] = new DrawableBuilder("nei:textures/nei_tabbed_sprites.png", 8, 40, 8, 8) - .build(); } @Override diff --git a/src/main/java/codechicken/nei/NEIClientConfig.java b/src/main/java/codechicken/nei/NEIClientConfig.java index ef3a68b3..7f1a3ed2 100644 --- a/src/main/java/codechicken/nei/NEIClientConfig.java +++ b/src/main/java/codechicken/nei/NEIClientConfig.java @@ -387,6 +387,13 @@ public class NEIClientConfig { setFavoriteDefaults(tag); + tag.getTag("inventory.tooltip.showFluidTemperature").setComment("Enabled show Fluid Temperature") + .getBooleanValue(true); + API.addOption(new OptionToggleButton("inventory.tooltip.showFluidTemperature", true)); + + tag.getTag("inventory.tooltip.showFluidState").setComment("Enabled show Fluid State").getBooleanValue(true); + API.addOption(new OptionToggleButton("inventory.tooltip.showFluidState", true)); + tag.getTag("inventory.itemIDs").getIntValue(1); API.addOption(new OptionCycled("inventory.itemIDs", 3, true)); @@ -866,6 +873,7 @@ public class NEIClientConfig { API.addKeyBind("bookmark.remove_recipe", Keyboard.KEY_A); API.addKeyBind("bookmark.pull_items", Keyboard.KEY_V); API.addKeyBind("bookmark.chat_link", Keyboard.KEY_L); + API.addKeyBind("bookmark.open_crafting_tree", Keyboard.KEY_T); API.addKeyBind("bookmark.hide", Keyboard.KEY_B); API.addKeyBind("itemzoom.toggle", Keyboard.KEY_Z); diff --git a/src/main/java/codechicken/nei/NEIClientUtils.java b/src/main/java/codechicken/nei/NEIClientUtils.java index 8a3caed3..d103f500 100644 --- a/src/main/java/codechicken/nei/NEIClientUtils.java +++ b/src/main/java/codechicken/nei/NEIClientUtils.java @@ -20,6 +20,7 @@ import java.util.ArrayList; import java.util.Arrays; import java.util.Collections; import java.util.HashMap; +import java.util.IdentityHashMap; import java.util.LinkedList; import java.util.List; import java.util.Locale; @@ -41,6 +42,7 @@ import net.minecraft.item.ItemStack; import net.minecraft.nbt.NBTTagCompound; import net.minecraft.util.IChatComponent; import net.minecraft.util.ResourceLocation; +import net.minecraftforge.fluids.FluidStack; import org.lwjgl.input.Keyboard; import org.lwjgl.opengl.GL11; @@ -56,6 +58,8 @@ import codechicken.lib.vec.Rectangle4i; import codechicken.nei.api.GuiInfo; import codechicken.nei.api.IInfiniteItemHandler; import codechicken.nei.api.ItemInfo; +import codechicken.nei.recipe.GuiOverlayButton.ItemOverlayState; +import codechicken.nei.recipe.StackInfo; import codechicken.nei.util.NEIKeyboardUtils; public class NEIClientUtils extends NEIServerUtils { @@ -293,6 +297,83 @@ public class NEIClientUtils extends NEIServerUtils { return InventoryUtils.getInsertibleQuantity(new InventoryRange(player.inventory, 0, 36), itemstack) > 0; } + public static List presenceOverlay(List ingredients, List invStacks) { + final List states = new ArrayList<>(); + final Map remainingFluid = new IdentityHashMap<>(); + + for (PositionedStack stack : ingredients) { + boolean found; + + if (StackInfo.isFluidDisplayItem(stack.item)) { + final FluidStack requiredFluid = StackInfo.getFluid(stack.item); + found = requiredFluid != null && consumeFluid(invStacks, remainingFluid, requiredFluid); + } else { + found = false; + + for (ItemStack is : invStacks) { + if (is.stackSize > 0 && stack.contains(is)) { + is.stackSize--; + found = true; + break; + } + } + } + + states.add(new ItemOverlayState(stack, found)); + } + + return states; + } + + private static boolean consumeFluid(List invStacks, Map remainingFluid, + FluidStack requiredFluid) { + long need = requiredFluid.amount; + final List matched = new ArrayList<>(); + + for (ItemStack is : invStacks) { + if (need <= 0) { + break; + } + + if (is.stackSize <= 0) { + continue; + } + + final FluidStack invFluid = StackInfo.getFluid(is); + + if (invFluid == null || !invFluid.isFluidEqual(requiredFluid)) { + continue; + } + + final long available = remainingFluid.computeIfAbsent(is, k -> (long) invFluid.amount * is.stackSize); + if (available <= 0) { + continue; + } + + matched.add(is); + need -= available; + } + + if (need > 0) { + return false; + } + + long remainingNeed = requiredFluid.amount; + for (ItemStack is : matched) { + final long available = remainingFluid.get(is); + final long consumed = Math.min(available, remainingNeed); + + remainingFluid.put(is, available - consumed); + remainingNeed -= consumed; + + if (remainingNeed <= 0) { + break; + } + } + + return true; + } + public static boolean shiftKey() { return Keyboard.isKeyDown(Keyboard.KEY_LSHIFT) || Keyboard.isKeyDown(Keyboard.KEY_RSHIFT); } @@ -483,6 +564,16 @@ public class NEIClientUtils extends NEIServerUtils { } } + public static long getScrollMultiplier(ItemStack stack) { + final long multiplier = NEIClientConfig.showItemQuantityWidget() ? NEIClientConfig.getItemQuantity() : 0; + + if (multiplier != 0) { + return multiplier; + } + + return StackInfo.isFluidDisplayItem(stack) ? 144 : stack.getMaxStackSize(); + } + public static void drawRect(double left, double top, double width, double height, Color color) { final boolean is2DTexture = GL11.glGetBoolean(GL11.GL_TEXTURE_2D); final boolean isBlend = GL11.glGetBoolean(GL11.GL_BLEND); @@ -525,6 +616,7 @@ public class NEIClientUtils extends NEIServerUtils { GuiDraw.fontRenderer.drawString(text, 0, 0, color, shadow); GL11.glScaled(1 / smallTextScale, 1 / smallTextScale, 1); GL11.glTranslated(-1 * offsetX, -1 * offsetY, 0); + GL11.glColor4f(1, 1, 1, 1); }); } diff --git a/src/main/java/codechicken/nei/NEIPotionGuiHandler.java b/src/main/java/codechicken/nei/NEIPotionGuiHandler.java index bbce8874..cd7ac6e7 100644 --- a/src/main/java/codechicken/nei/NEIPotionGuiHandler.java +++ b/src/main/java/codechicken/nei/NEIPotionGuiHandler.java @@ -1,14 +1,10 @@ package codechicken.nei; -import java.util.Collection; - import net.minecraft.client.Minecraft; import net.minecraft.client.entity.EntityPlayerSP; import net.minecraft.client.gui.inventory.GuiContainer; import net.minecraft.client.renderer.InventoryEffectRenderer; -import net.minecraft.potion.PotionEffect; -import codechicken.lib.vec.Rectangle4i; import codechicken.nei.api.INEIGuiAdapter; /** @@ -18,35 +14,37 @@ public class NEIPotionGuiHandler extends INEIGuiAdapter { @Override public boolean hideItemPanelSlot(GuiContainer guiContainer, int slotX, int slotY, int slotW, int slotH) { - if (NEIClientConfig.ignorePotionOverlap()) { + if (!(guiContainer instanceof InventoryEffectRenderer)) { return false; } - if (guiContainer instanceof InventoryEffectRenderer) { - int x = guiContainer.guiLeft - 124; - int y = guiContainer.guiTop; - Minecraft minecraft = guiContainer.mc; - if (minecraft == null) { - return false; - } - EntityPlayerSP player = minecraft.thePlayer; - if (player == null) { - return false; - } - Collection activePotionEffects = player.getActivePotionEffects(); - if (activePotionEffects.isEmpty()) { - return false; - } - int height = 33; - if (activePotionEffects.size() > 5) { - height = 132 / (activePotionEffects.size() - 1); - } - Rectangle4i slotRect = new Rectangle4i(slotX, slotY, slotW, slotH); - for (PotionEffect potioneffect : activePotionEffects) { - Rectangle4i box = new Rectangle4i(x, y, 140, 32); - if (box.intersects(slotRect)) return true; - y += height; - } + int x = guiContainer.guiLeft - 124; + if (slotX + slotW <= x || slotX >= x + 140) { + return false; + } + + Minecraft minecraft = guiContainer.mc; + if (minecraft == null) { + return false; + } + EntityPlayerSP player = minecraft.thePlayer; + if (player == null) { + return false; + } + int potionCount = player.getActivePotionEffects().size(); + if (potionCount == 0 || NEIClientConfig.ignorePotionOverlap()) { + return false; + } + int height = 33; + if (potionCount > 5) { + height = 132 / (potionCount - 1); + } + return intersectsPotionEffects(slotY, slotH, guiContainer.guiTop, potionCount, height); + } + + static boolean intersectsPotionEffects(int slotY, int slotH, int effectY, int potionCount, int height) { + for (int i = 0; i < potionCount; i++, effectY += height) { + if (slotY + slotH > effectY && slotY < effectY + 32) return true; } return false; } diff --git a/src/main/java/codechicken/nei/NEIServerUtils.java b/src/main/java/codechicken/nei/NEIServerUtils.java index d3dfd5b5..336230fa 100644 --- a/src/main/java/codechicken/nei/NEIServerUtils.java +++ b/src/main/java/codechicken/nei/NEIServerUtils.java @@ -35,6 +35,7 @@ import net.minecraft.util.EnumChatFormatting; import net.minecraft.util.IChatComponent; import net.minecraft.world.World; import net.minecraft.world.WorldSettings.GameType; +import net.minecraftforge.fluids.FluidStack; import net.minecraftforge.oredict.OreDictionary; import org.apache.logging.log4j.Level; @@ -45,6 +46,7 @@ import codechicken.lib.inventory.InventoryRange; import codechicken.lib.inventory.InventoryUtils; import codechicken.lib.packet.PacketCustom; import codechicken.nei.PacketIDs.S2C; +import codechicken.nei.item.ItemFluidDisplay; import codechicken.nei.recipe.StackInfo; import codechicken.nei.util.NBTHelper; import cpw.mods.fml.common.FMLLog; @@ -442,13 +444,49 @@ public class NEIServerUtils { throw new RuntimeException(msg); } - @SuppressWarnings("unchecked") public static ItemStack[] extractRecipeItems(Object obj) { - if (obj instanceof ItemStack) return new ItemStack[] { (ItemStack) obj }; - if (obj instanceof ItemStack[]) return (ItemStack[]) obj; - if (obj instanceof List) return ((List) obj).toArray(new ItemStack[0]); - throw new ClassCastException(obj + " not an ItemStack, ItemStack[] or List getRange(final int start, final int end) { diff --git a/src/main/java/codechicken/nei/PositionedStack.java b/src/main/java/codechicken/nei/PositionedStack.java index a203ad42..c892b424 100644 --- a/src/main/java/codechicken/nei/PositionedStack.java +++ b/src/main/java/codechicken/nei/PositionedStack.java @@ -6,11 +6,19 @@ import java.util.Comparator; import java.util.List; import java.util.stream.Collectors; +import net.minecraft.client.Minecraft; +import net.minecraft.client.renderer.Tessellator; +import net.minecraft.client.renderer.texture.TextureMap; import net.minecraft.init.Blocks; import net.minecraft.item.Item; import net.minecraft.item.ItemStack; +import net.minecraft.util.EnumChatFormatting; +import net.minecraft.util.IIcon; +import net.minecraftforge.fluids.FluidStack; import net.minecraftforge.oredict.OreDictionary; +import org.lwjgl.opengl.GL11; + import codechicken.nei.api.ItemFilter; import codechicken.nei.api.ItemInfo; import codechicken.nei.guihook.GuiContainerManager; @@ -230,9 +238,6 @@ public class PositionedStack implements Cloneable { return "PositionedStack(output='" + item.toString() + "')"; } - /** - * A {@link PositionedStack} that keeps its items but never draws them. - */ public static class Placeholder extends PositionedStack { public Placeholder(Object object, int x, int y, boolean genPerms) { @@ -246,4 +251,124 @@ public class PositionedStack implements Cloneable { @Override public void draw(int mousex, int mousey) {} } + + public static class Fluid extends PositionedStack { + + /** The tank size the fill level is measured against, in mB. 0 means "always render full". */ + public int capacity = 0; + + private ItemStack cachedFluidItem; + private FluidStack cachedFluidStack; + + public Fluid(Object object, int x, int y, boolean genPerms) { + super(object, x, y, genPerms); + } + + public Fluid(Object object, int x, int y) { + this(object, x, y, true); + } + + public Fluid(Object object, int x, int y, int width, int height, int capacity) { + super(object, x, y, false); + this.width = width; + this.height = height; + this.capacity = capacity; + } + + protected FluidStack getFluidStack() { + + if (this.item != this.cachedFluidItem) { + this.cachedFluidItem = this.item; + this.cachedFluidStack = StackInfo.isFluidDisplayItem(this.item) ? StackInfo.getFluid(this.item) : null; + } + + return this.cachedFluidStack; + } + + @Override + public List getTooltip() { + final List tooltip = new ArrayList<>(); + final List customTooltip = super.getTooltip(); + final FluidStack fluidStack = getFluidStack(); + + if (fluidStack != null) { + tooltip.add( + EnumChatFormatting.GRAY + NEIClientUtils + .translate("recipe.fluid.tank.amount", NEIClientUtils.formatFluid(fluidStack.amount))); + } + + if (customTooltip != null) { + tooltip.addAll(customTooltip); + } + + return tooltip; + } + + @Override + public void draw(int mousex, int mousey) { + final FluidStack fluidStack = getFluidStack(); + + if (fluidStack == null) { + super.draw(mousex, mousey); + return; + } + + final int tankCapacity = this.capacity > 0 ? this.capacity : fluidStack.amount; + int fillHeight = tankCapacity > 0 + ? (int) ((long) this.height * Math.min(fluidStack.amount, tankCapacity) / tankCapacity) + : 0; + + if (fluidStack.amount > 0 && fillHeight <= 0) { + fillHeight = 1; + } + + if (fillHeight > 0) { + drawFluid(this.relx, this.rely, this.width, this.height, fillHeight, fluidStack); + } + } + + private static void drawFluid(int x, int y, int width, int height, int fillHeight, FluidStack fluidStack) { + final IIcon icon = fluidStack.getFluid().getIcon(fluidStack); + + if (icon == null) { + return; + } + + final int color = fluidStack.getFluid().getColor(fluidStack); + final float red = (color >> 16 & 0xFF) / 255F; + final float green = (color >> 8 & 0xFF) / 255F; + final float blue = (color & 0xFF) / 255F; + + Minecraft.getMinecraft().getTextureManager().bindTexture(TextureMap.locationBlocksTexture); + GL11.glColor4f(red, green, blue, 1F); + GL11.glEnable(GL11.GL_BLEND); + GL11.glBlendFunc(GL11.GL_SRC_ALPHA, GL11.GL_ONE_MINUS_SRC_ALPHA); + GL11.glDisable(GL11.GL_LIGHTING); + + final Tessellator tessellator = Tessellator.instance; + + tessellator.startDrawingQuads(); + for (int tx = 0; tx < width; tx += 16) { + final int tileWidth = Math.min(16, width - tx); + final double u2 = icon.getMinU() + (icon.getMaxU() - icon.getMinU()) * tileWidth / 16D; + + for (int ty = 0; ty < fillHeight; ty += 16) { + final int tileHeight = Math.min(16, fillHeight - ty); + final double v2 = icon.getMinV() + (icon.getMaxV() - icon.getMinV()) * tileHeight / 16D; + final int bottomY = y + height - ty; + final int topY = bottomY - tileHeight; + + tessellator.addVertexWithUV(x + tx, bottomY, 0, icon.getMinU(), v2); + tessellator.addVertexWithUV(x + tx + tileWidth, bottomY, 0, u2, v2); + tessellator.addVertexWithUV(x + tx + tileWidth, topY, 0, u2, icon.getMinV()); + tessellator.addVertexWithUV(x + tx, topY, 0, icon.getMinU(), icon.getMinV()); + } + } + tessellator.draw(); + + GL11.glDisable(GL11.GL_BLEND); + GL11.glEnable(GL11.GL_LIGHTING); + GL11.glColor4f(1F, 1F, 1F, 1F); + } + } } diff --git a/src/main/java/codechicken/nei/WorldOverlayRenderer.java b/src/main/java/codechicken/nei/WorldOverlayRenderer.java index 83d0a022..56a3af37 100644 --- a/src/main/java/codechicken/nei/WorldOverlayRenderer.java +++ b/src/main/java/codechicken/nei/WorldOverlayRenderer.java @@ -322,6 +322,12 @@ public class WorldOverlayRenderer implements IKeyStateTracker { y1 -= intOffsetY; y2 -= intOffsetY; + double centerX = (x1 + x2) / 2; + double centerZ = (z1 + z2) / 2; + + tess.setColorRGBA_F(0.9F, 0.9F, 0, (float) dist); + tess.addVertex(centerX, y1, centerZ); + tess.addVertex(centerX, y2, centerZ); tess.setColorRGBA_F(0, 0.9F, 0, 0.4F); for (double y = (int) y1; y <= y2; y++) { diff --git a/src/main/java/codechicken/nei/api/GuiInfo.java b/src/main/java/codechicken/nei/api/GuiInfo.java index 35415a02..40f9e24f 100644 --- a/src/main/java/codechicken/nei/api/GuiInfo.java +++ b/src/main/java/codechicken/nei/api/GuiInfo.java @@ -51,20 +51,29 @@ public class GuiInfo { } public static boolean hideItemPanelSlot(GuiContainer gui, Rectangle4i rect) { + return hideItemPanelSlot(gui, rect, getGuiHandlersSnapshot()); + } + + public static INEIGuiHandler[] getGuiHandlersSnapshot() { try { readLock.lock(); - if (guiHandlers.stream() - .anyMatch(handler -> handler.hideItemPanelSlot(gui, rect.x, rect.y, rect.w, rect.h))) { - return true; - } + return guiHandlers.toArray(new INEIGuiHandler[0]); } finally { readLock.unlock(); } + } + + public static boolean hideItemPanelSlot(GuiContainer gui, Rectangle4i rect, INEIGuiHandler[] handlers) { + for (INEIGuiHandler handler : handlers) { + if (handler.hideItemPanelSlot(gui, rect.x, rect.y, rect.w, rect.h)) return true; + } for (Object item : gui.buttonList) { GuiButton button = (GuiButton) item; - if ((new Rectangle4i(button.xPosition, button.yPosition, button.width, button.height)).intersects(rect)) { + if (button.xPosition + button.width > rect.x && button.xPosition < rect.x + rect.w + && button.yPosition + button.height > rect.y + && button.yPosition < rect.y + rect.h) { return true; } } diff --git a/src/main/java/codechicken/nei/api/INEIGuiAdapter.java b/src/main/java/codechicken/nei/api/INEIGuiAdapter.java index ab12e41b..986c2257 100644 --- a/src/main/java/codechicken/nei/api/INEIGuiAdapter.java +++ b/src/main/java/codechicken/nei/api/INEIGuiAdapter.java @@ -1,15 +1,9 @@ package codechicken.nei.api; -import java.util.Collections; -import java.util.List; import java.util.regex.Pattern; -import net.minecraft.client.gui.inventory.GuiContainer; -import net.minecraft.item.ItemStack; import net.minecraft.util.EnumChatFormatting; -import codechicken.nei.VisiblityData; - /** * Lets you just override those things you want to */ @@ -17,31 +11,6 @@ public class INEIGuiAdapter implements INEIGuiHandler { static final Pattern SPECIAL_REGEX_CHARS = Pattern.compile("[{}()\\[\\].+*?^$\\\\|]"); - @Override - public VisiblityData modifyVisiblity(GuiContainer gui, VisiblityData currentVisibility) { - return currentVisibility; - } - - @Override - public Iterable getItemSpawnSlots(GuiContainer gui, ItemStack item) { - return Collections.emptyList(); - } - - @Override - public List getInventoryAreas(GuiContainer gui) { - return null; - } - - @Override - public boolean handleDragNDrop(GuiContainer gui, int mousex, int mousey, ItemStack draggedStack, int button) { - return false; - } - - @Override - public boolean hideItemPanelSlot(GuiContainer gui, int x, int y, int w, int h) { - return false; - } - protected String formattingText(String displayName) { return SPECIAL_REGEX_CHARS.matcher(EnumChatFormatting.getTextWithoutFormattingCodes(displayName)) .replaceAll("\\\\$0"); diff --git a/src/main/java/codechicken/nei/api/INEIGuiHandler.java b/src/main/java/codechicken/nei/api/INEIGuiHandler.java index b6af67d8..3ffffe96 100644 --- a/src/main/java/codechicken/nei/api/INEIGuiHandler.java +++ b/src/main/java/codechicken/nei/api/INEIGuiHandler.java @@ -1,5 +1,6 @@ package codechicken.nei.api; +import java.util.Collections; import java.util.List; import net.minecraft.client.gui.inventory.GuiContainer; @@ -12,23 +13,29 @@ import codechicken.nei.VisiblityData; */ public interface INEIGuiHandler { - public VisiblityData modifyVisiblity(GuiContainer gui, VisiblityData currentVisibility); + default VisiblityData modifyVisiblity(GuiContainer gui, VisiblityData currentVisibility) { + return currentVisibility; + } /** * NEI will give the specified item to the InventoryRange returned if the player's inventory is full. Should not * return null, just an empty list */ - public Iterable getItemSpawnSlots(GuiContainer gui, ItemStack item); + default Iterable getItemSpawnSlots(GuiContainer gui, ItemStack item) { + return Collections.emptyList(); + } /** * @return A list of TaggedInventoryAreas that will be used with the savestates. */ - public List getInventoryAreas(GuiContainer gui); + default List getInventoryAreas(GuiContainer gui) { + return null; + } /** * Handles clicks while an itemstack has been dragged from the item panel. Use this to set configurable slots and * the like. Changes made to the stackSize of the dragged stack will be kept - * + * * @param gui The current gui instance * @param mousex The x position of the mouse * @param mousey The y position of the mouse @@ -37,18 +44,22 @@ public interface INEIGuiHandler { * @return True if the drag n drop was handled. False to resume processing through other routes. The held stack will * be deleted if draggedStack.stackSize == 0 */ - public boolean handleDragNDrop(GuiContainer gui, int mousex, int mousey, ItemStack draggedStack, int button); + default boolean handleDragNDrop(GuiContainer gui, int mousex, int mousey, ItemStack draggedStack, int button) { + return false; + } /** * Used to prevent the item panel from drawing on top of other gui elements. This function will also be called with * a 1x1 size rectangle on the mouse position for determining if the given coordinate should override item panel * functions such as scrolling - * + * * @param x The x coordinate of the rectangle bounding the slot * @param y The y coordinate of the rectangle bounding the slot * @param w The w coordinate of the rectangle bounding the slot * @param h The h coordinate of the rectangle bounding the slot * @return true if the item panel slot within the specified rectangle should not be rendered. */ - public boolean hideItemPanelSlot(GuiContainer gui, int x, int y, int w, int h); + default boolean hideItemPanelSlot(GuiContainer gui, int x, int y, int w, int h) { + return false; + } } diff --git a/src/main/java/codechicken/nei/api/IOverlayHandler.java b/src/main/java/codechicken/nei/api/IOverlayHandler.java index 08f1d72b..c49c218f 100644 --- a/src/main/java/codechicken/nei/api/IOverlayHandler.java +++ b/src/main/java/codechicken/nei/api/IOverlayHandler.java @@ -1,15 +1,12 @@ package codechicken.nei.api; -import java.util.ArrayList; import java.util.List; -import java.util.Optional; import java.util.stream.Collectors; import net.minecraft.client.gui.inventory.GuiContainer; -import net.minecraft.item.ItemStack; import codechicken.nei.NEIClientConfig; -import codechicken.nei.PositionedStack; +import codechicken.nei.NEIClientUtils; import codechicken.nei.recipe.GuiOverlayButton.ItemOverlayState; import codechicken.nei.recipe.IRecipeHandler; @@ -38,28 +35,14 @@ public interface IOverlayHandler { } default List presenceOverlay(GuiContainer firstGui, IRecipeHandler recipe, int recipeIndex) { - final List itemPresenceSlots = new ArrayList<>(); - final List ingredients = recipe.getIngredientStacks(recipeIndex); - final List invStacks = firstGui.inventorySlots.inventorySlots.stream() - .filter( - s -> s != null && s.getStack() != null - && s.getStack().stackSize > 0 - && s.isItemValid(s.getStack()) - && s.canTakeStack(firstGui.mc.thePlayer)) - .map(s -> s.getStack().copy()).collect(Collectors.toList()); - - for (PositionedStack stack : ingredients) { - Optional used = invStacks.stream().filter(is -> is.stackSize > 0 && stack.contains(is)) - .findAny(); - - itemPresenceSlots.add(new ItemOverlayState(stack, used.isPresent())); - - if (used.isPresent()) { - ItemStack is = used.get(); - is.stackSize -= 1; - } - } - - return itemPresenceSlots; + return NEIClientUtils.presenceOverlay( + recipe.getIngredientStacks(recipeIndex), + firstGui.inventorySlots.inventorySlots.stream() + .filter( + s -> s != null && s.getStack() != null + && s.getStack().stackSize > 0 + && s.isItemValid(s.getStack()) + && s.canTakeStack(firstGui.mc.thePlayer)) + .map(s -> s.getStack().copy()).collect(Collectors.toList())); } } diff --git a/src/main/java/codechicken/nei/api/IStackStringifyHandler.java b/src/main/java/codechicken/nei/api/IStackStringifyHandler.java index 27586f36..705b6384 100644 --- a/src/main/java/codechicken/nei/api/IStackStringifyHandler.java +++ b/src/main/java/codechicken/nei/api/IStackStringifyHandler.java @@ -24,4 +24,8 @@ public interface IStackStringifyHandler { default void pauseItemDamageSound(boolean pause) {} + default boolean isFluidDisplayItem(ItemStack stack) { + return false; + } + } diff --git a/src/main/java/codechicken/nei/api/ItemInfo.java b/src/main/java/codechicken/nei/api/ItemInfo.java index 00fc2d8a..623499c0 100644 --- a/src/main/java/codechicken/nei/api/ItemInfo.java +++ b/src/main/java/codechicken/nei/api/ItemInfo.java @@ -60,6 +60,7 @@ import codechicken.nei.config.HandlerDumper; import codechicken.nei.config.ItemPanelDumper; import codechicken.nei.config.RegistryDumper; import codechicken.nei.guihook.GuiContainerManager; +import codechicken.nei.item.ItemFluidDisplay; import codechicken.nei.recipe.BrewingRecipeHandler; import codechicken.nei.recipe.RecipeItemInputHandler; import codechicken.nei.search.IdentifierFilter; @@ -133,6 +134,7 @@ public class ItemInfo { public static void preInit() { addMobSpawnerItem(); + addFluidDisplayItem(); } public static void load() { @@ -318,6 +320,10 @@ public class ItemInfo { GameDataManipulator.replaceItem(Block.getIdFromBlock(Blocks.mob_spawner), new ItemMobSpawner()); } + private static void addFluidDisplayItem() { + GameRegistry.registerItem(new ItemFluidDisplay(), "neiFluidDisplay"); + } + private static void addInfiniteHandlers() { API.addInfiniteItemHandler(new InfiniteStackSizeHandler()); API.addInfiniteItemHandler(new InfiniteToolHandler()); @@ -402,6 +408,7 @@ public class ItemInfo { item -> item.getItem() instanceof ItemArmor armor && armor.armorType == 2); API.addSubset("Items.Armor.Boots", item -> item.getItem() instanceof ItemArmor armor && armor.armorType == 3); API.addSubset("Items.Food", item -> item.getItem() instanceof ItemFood); + API.addSubset("Items.Fluids", item -> item.getItem() instanceof ItemFluidDisplay); API.addSubset("Items.Potions.Ingredients", BrewingRecipeHandler.ingredients); for (CreativeTabs tab : CreativeTabs.creativeTabArray) { diff --git a/src/main/java/codechicken/nei/api/ShortcutInputHandler.java b/src/main/java/codechicken/nei/api/ShortcutInputHandler.java index 04c81c01..dd8e33af 100644 --- a/src/main/java/codechicken/nei/api/ShortcutInputHandler.java +++ b/src/main/java/codechicken/nei/api/ShortcutInputHandler.java @@ -32,6 +32,7 @@ import codechicken.nei.bookmark.BookmarkItem; import codechicken.nei.bookmark.BookmarkItem.BookmarkItemType; import codechicken.nei.bookmark.BookmarkPayload; import codechicken.nei.bookmark.BookmarksGridSlot; +import codechicken.nei.bookmark.tree.GuiCraftingTree; import codechicken.nei.recipe.AutoCraftingManager; import codechicken.nei.recipe.GuiCraftingRecipe; import codechicken.nei.recipe.GuiFavoriteButton; @@ -101,6 +102,12 @@ public abstract class ShortcutInputHandler { return true; } + if (ItemPanels.bookmarkPanel.getGrid().isCraftingMode(groupId) + && KeyManager.isKeyDown("bookmark.open_crafting_tree")) { + GuiCraftingTree.openCraftingTreeGui(ItemPanels.bookmarkPanel.getGrid(), groupId); + return true; + } + if (NEIClientConfig.autocraftingEnabled() && KeyManager.isKeyDown("gui.craft_items") && NEIClientUtils.shiftKey() && ItemPanels.bookmarkPanel.getGrid().isCraftingMode(groupId)) { @@ -477,6 +484,7 @@ public abstract class ShortcutInputHandler { final Map hotkeys = new HashMap<>(); if (groupId != -1) { + final boolean isCraftingMode = ItemPanels.bookmarkPanel.getGrid().isCraftingMode(groupId); hotkeys.put( KeyManager.getKeyName("bookmark.remove_recipe", NEIClientUtils.SHIFT_HASH), @@ -486,6 +494,12 @@ public abstract class ShortcutInputHandler { KeyManager.getKeyName("bookmark.chat_link", NEIClientUtils.CTRL_HASH), NEIClientUtils.translate("bookmark.group.chat_link")); + if (isCraftingMode) { + hotkeys.put( + KeyManager.getKeyName("bookmark.open_crafting_tree"), + NEIClientUtils.translate("bookmark.group.open_crafting_tree")); + } + if (BookmarkContainerInfo.getBookmarkContainerHandler(gui) != null) { hotkeys.put( KeyManager.getKeyName("bookmark.pull_items"), @@ -495,7 +509,7 @@ public abstract class ShortcutInputHandler { NEIClientUtils.translate("bookmark.group.pull_items_shift")); } - if (NEIClientConfig.autocraftingEnabled() && ItemPanels.bookmarkPanel.getGrid().isCraftingMode(groupId)) { + if (NEIClientConfig.autocraftingEnabled() && isCraftingMode) { hotkeys.put( NEIClientConfig .getKeyName("gui.craft_items", NEIClientUtils.SHIFT_HASH + NEIClientUtils.CTRL_HASH), diff --git a/src/main/java/codechicken/nei/bookmark/BookmarkGrid.java b/src/main/java/codechicken/nei/bookmark/BookmarkGrid.java index 95958a47..942fcfa8 100644 --- a/src/main/java/codechicken/nei/bookmark/BookmarkGrid.java +++ b/src/main/java/codechicken/nei/bookmark/BookmarkGrid.java @@ -24,7 +24,7 @@ import codechicken.lib.gui.GuiDraw; import codechicken.lib.vec.Rectangle4i; import codechicken.nei.BookmarkPanel.BookmarkViewMode; import codechicken.nei.ItemPanels; -import codechicken.nei.ItemStackSet; +import codechicken.nei.ItemStackAmount; import codechicken.nei.ItemsGrid; import codechicken.nei.ItemsGrid.MouseContext; import codechicken.nei.LayoutManager; @@ -179,11 +179,15 @@ public class BookmarkGrid extends ItemsGrid item.groupId).max().orElse(DEFAULT_GROUP_ID) + 1; + final int groupId = getNextGroupId(); this.groups.put(groupId, group); return groupId; } + public int getNextGroupId() { + return this.bookmarkItems.stream().mapToInt(item -> item.groupId).max().orElse(DEFAULT_GROUP_ID) + 1; + } + @Override public int getNumPages() { @@ -913,8 +917,8 @@ public class BookmarkGrid extends ItemsGrid results = new ArrayList<>(); final List ingredients = new ArrayList<>(); @@ -950,7 +954,7 @@ public class BookmarkGrid extends ItemsGrid= this.widgetX && y >= this.widgetY + && x < this.widgetX + this.widgetW + && y < this.widgetY + this.widgetH; + } + + public void startDrag(int mouseX, int mouseY) { + this.dragging = true; + this.lastDragX = mouseX; + this.lastDragY = mouseY; + } + + public void drag(int mouseX, int mouseY) { + if (!this.dragging) { + return; + } + + this.scrollX -= (mouseX - this.lastDragX) / this.zoomLevel; + this.scrollY -= (mouseY - this.lastDragY) / this.zoomLevel; + this.lastDragX = mouseX; + this.lastDragY = mouseY; + } + + public void endDrag() { + this.dragging = false; + } + + public boolean isDragging() { + return this.dragging; + } + + public void scroll(int mouseX, int mouseY, int direction, boolean shiftKey, boolean ctrlKey) { + + if (shiftKey) { + this.scrollX -= direction * this.widgetW / (SCROLL_STEP_DIVISOR * this.zoomLevel); + } else if (ctrlKey) { + final int localX = mouseX - this.widgetX; + final int localY = mouseY - this.widgetY; + final float oldZoom = this.zoomLevel; + + this.zoomLevel = clamp((float) (this.zoomLevel * Math.pow(ZOOM_STEP_BASE, direction)), ZOOM_MIN, ZOOM_MAX); + this.scrollX += localX / oldZoom - localX / this.zoomLevel; + this.scrollY += localY / oldZoom - localY / this.zoomLevel; + } else { + this.scrollY -= direction * this.widgetH / (SCROLL_STEP_DIVISOR * this.zoomLevel); + } + + } + + public void centerOn(float worldX, float worldY) { + this.scrollX = worldX - (this.widgetW / this.zoomLevel) / 2f; + this.scrollY = worldY - (this.widgetH / this.zoomLevel) / 2f; + } + + public void clampToBounds(int treeWidth, int treeHeight) { + this.scrollX = clamp(this.scrollX, -this.widgetW / this.zoomLevel + 4, treeWidth - 4); + this.scrollY = clamp(this.scrollY, -this.widgetH / this.zoomLevel + 4, treeHeight - 4); + } + + public int visibleRowMin() { + final float zScrollY = this.scrollY * this.zoomLevel; + return (int) ((zScrollY - CULL_MARGIN) / this.zoomLevel) - CULL_ROW_MARGIN; + } + + public int visibleRowMax() { + final float zScrollY = this.scrollY * this.zoomLevel; + return (int) ((zScrollY + CULL_MARGIN) / this.zoomLevel) + (int) (this.widgetH / this.zoomLevel) + + CULL_ROW_MARGIN; + } + + public Point2D.Double toWorldPoint(Point2D mouse) { + final float zScrollX = this.scrollX * this.zoomLevel; + final float zScrollY = this.scrollY * this.zoomLevel; + + return new Point2D.Double( + (mouse.getX() - this.widgetX + zScrollX) / this.zoomLevel, + (mouse.getY() - this.widgetY + zScrollY) / this.zoomLevel); + } + + static float clamp(float value, float min, float max) { + return value < min ? min : Math.min(value, max); + } + +} diff --git a/src/main/java/codechicken/nei/bookmark/tree/CraftingTreeCanvas.java b/src/main/java/codechicken/nei/bookmark/tree/CraftingTreeCanvas.java new file mode 100644 index 00000000..749662a0 --- /dev/null +++ b/src/main/java/codechicken/nei/bookmark/tree/CraftingTreeCanvas.java @@ -0,0 +1,720 @@ +package codechicken.nei.bookmark.tree; + +import java.awt.Color; +import java.awt.Point; +import java.awt.geom.Point2D; +import java.util.ArrayList; +import java.util.Collections; +import java.util.HashMap; +import java.util.List; +import java.util.Map; +import java.util.Set; +import java.util.TreeMap; +import java.util.function.BiPredicate; + +import net.minecraft.client.renderer.RenderHelper; + +import org.lwjgl.opengl.GL11; +import org.lwjgl.opengl.GL12; + +import codechicken.lib.gui.GuiDraw; +import codechicken.lib.vec.Rectangle4i; +import codechicken.nei.ColorUtils; +import codechicken.nei.NEIClientUtils; +import codechicken.nei.NEIClientUtils.Alignment; +import codechicken.nei.PositionedStack; +import codechicken.nei.bookmark.BookmarkItem; +import codechicken.nei.drawable.DrawableBuilder; +import codechicken.nei.drawable.DrawableResource; +import codechicken.nei.guihook.GuiContainerManager; +import codechicken.nei.recipe.Recipe.RecipeId; +import codechicken.nei.scroll.GuiHelper; +import codechicken.nei.util.ReadableNumberConverter; + +class CraftingTreeCanvas { + + private static final DrawableResource SCROLLBAR_H = new DrawableBuilder( + "nei:textures/gui/craftingtree.png", + 0, + 88, + 2, + 24).build(); + + private static final DrawableResource SCROLLBAR_W = new DrawableBuilder( + "nei:textures/gui/craftingtree.png", + 0, + 84, + 24, + 2).build(); + + private static final DrawableResource ICON_COLLAPSED = new DrawableBuilder( + "nei:textures/gui/craftingtree.png", + 4, + 88, + 5, + 5).build(); + + private static final DrawableResource ICON_COLLAPSED_HOVER = new DrawableBuilder( + "nei:textures/gui/craftingtree.png", + 11, + 88, + 5, + 5).build(); + + private static final DrawableResource ICON_EXPANDED = new DrawableBuilder( + "nei:textures/gui/craftingtree.png", + 4, + 95, + 5, + 5).build(); + + private static final DrawableResource ICON_EXPANDED_HOVER = new DrawableBuilder( + "nei:textures/gui/craftingtree.png", + 11, + 95, + 5, + 5).build(); + + private static final DrawableResource ICON_REMOVE = new DrawableBuilder( + "nei:textures/gui/craftingtree.png", + 85, + 48, + 16, + 16).build(); + + private static final DrawableResource ICON_CRAFTING = new DrawableBuilder( + "nei:textures/gui/craftingtree.png", + 67, + 48, + 16, + 16).build(); + + private static final DrawableResource SLOT_DEFAULT = new DrawableBuilder( + "nei:textures/gui/craftingtree.png", + 68, + 2, + 18, + 18).build(); + + private static final DrawableResource SLOT_MISSING = new DrawableBuilder( + "nei:textures/gui/craftingtree.png", + 92, + 2, + 18, + 18).build(); + + private static final DrawableResource SLOT_CRAFTING = new DrawableBuilder( + "nei:textures/gui/craftingtree.png", + 116, + 2, + 18, + 18).build(); + + private static final DrawableResource SLOT_DISABLED = new DrawableBuilder( + "nei:textures/gui/craftingtree.png", + 140, + 2, + 18, + 18).build(); + + private static final DrawableResource SLOT_HIGHLIGHTED = new DrawableBuilder( + "nei:textures/gui/craftingtree.png", + 164, + 2, + 18, + 18).build(); + + private static final Color LINE_COLOR = new Color(ColorUtils.craftingTreeLine.getColor(), true); + private static final int HOVER_COLOR = 0x66888888; + private static final float BADGE_SCALE = 0.6f; + + public static final int SLOT_SIZE = 18; + public static final int X_SPACING = 24; + public static final int Y_SPACING = 14; + public static final int ROOT_SPACING = 36; + private static final float FIT_MARGIN = 8f; + + public final CraftingTreeGraph graph = new CraftingTreeGraph(); + + public final Map pointByNode = new HashMap<>(); + public final TreeMap> rows = new TreeMap<>(); + public final Set collapsedRecipes = Collections.newSetFromMap(new HashMap<>()); + public int treeWidth = 0; + public int treeHeight = 0; + + private final Camera camera = new Camera(); + + public void setViewport(int x, int y, int w, int h) { + this.camera.setViewport(x, y, w, h); + } + + public boolean isInWidget(int x, int y) { + return this.camera.isInWidget(x, y); + } + + public void fitToView() { + final float firstResultCenterX = this.graph.roots.isEmpty() ? this.treeWidth / 2f + : this.pointByNode.get(this.graph.roots.get(0)).x + SLOT_SIZE / 2f; + + this.camera.zoomLevel = 1.0f; + this.camera.scrollX = this.treeWidth <= (this.camera.widgetW - FIT_MARGIN) + ? (this.treeWidth - this.camera.widgetW) / 2f + : firstResultCenterX - this.camera.widgetW / 2f; + this.camera.scrollY = this.treeHeight <= (this.camera.widgetH - FIT_MARGIN) + ? (this.treeHeight - this.camera.widgetH) / 2f + : -FIT_MARGIN; + } + + public void startDrag(int mouseX, int mouseY) { + this.camera.startDrag(mouseX, mouseY); + } + + public void drag(int mouseX, int mouseY) { + this.camera.drag(mouseX, mouseY); + } + + public void endDrag() { + this.camera.endDrag(); + } + + public boolean isDragging() { + return this.camera.isDragging(); + } + + public void scroll(int mouseX, int mouseY, int direction, boolean shiftKey, boolean ctrlKey) { + this.camera.scroll(mouseX, mouseY, direction, shiftKey, ctrlKey); + } + + public void scrollTo(ItemTreeSlot node) { + if (node == null || !this.pointByNode.containsKey(node)) { + return; + } + + final Point point = this.pointByNode.get(node); + final float nodeCenterX = point.x + SLOT_SIZE / 2f; + final float nodeCenterY = point.y + SLOT_SIZE / 2f; + + this.camera.centerOn(nodeCenterX, nodeCenterY); + } + + public ItemTreeSlot getNodeMouseOver(Point2D mouse) { + return findVisibleNode(mouse, (node, local) -> { + final Point point = this.pointByNode.get(node); + + return local.x >= point.x && local.x < point.x + SLOT_SIZE + && local.y >= point.y + && local.y < point.y + SLOT_SIZE; + }); + } + + public ItemTreeSlot getHandlerBadgeMouseOver(Point2D mouse) { + return findVisibleNode(mouse, (node, local) -> { + if (node.prefItem == null || !this.graph.childrenOf.containsKey(node)) { + return false; + } + + final Point point = this.pointByNode.get(node); + final float[] badge = badgeRect(point.x, point.y); + + return local.x >= badge[0] && local.x < badge[0] + badge[2] + && local.y >= badge[1] + && local.y < badge[1] + badge[3]; + }); + } + + public ItemTreeSlot getCollapseArrowMouseOver(Point2D mouse) { + return findVisibleNode(mouse, (node, local) -> { + if (!this.graph.childrenOf.containsKey(node) || node.prefItem == null + || this.collapsedRecipes.contains(node.prefItem.recipeId) && !this.graph.roots.contains(node)) { + return false; + } + + final Point point = this.pointByNode.get(node); + final float iconX = point.x + SLOT_SIZE / 2 - ICON_COLLAPSED.width - 1; + final float iconY = point.y + SLOT_SIZE + 1; + final float iconW = ICON_COLLAPSED.width; + final float iconH = ICON_COLLAPSED.height; + + return local.x >= iconX && local.x < iconX + iconW && local.y >= iconY && local.y < iconY + iconH; + }); + } + + private ItemTreeSlot findVisibleNode(Point2D mouse, BiPredicate hitTest) { + final Point2D.Double local = this.camera.toWorldPoint(mouse); + + for (List row : this.rows.subMap(camera.visibleRowMin(), camera.visibleRowMax()).values()) { + for (ItemTreeSlot node : row) { + if (hitTest.test(node, local)) { + return node; + } + } + } + + return null; + } + + public void draw(Point2D mouse, Set collapsedItems, SearchResult searchResult, + boolean useInventorySnapshot, ItemTreeSlot hoveredNode, ItemTreeSlot deleteHoverNode) { + this.camera.clampToBounds(this.treeWidth, this.treeHeight); + + final float zScrollX = this.camera.scrollX * this.camera.zoomLevel; + final float zScrollY = this.camera.scrollY * this.camera.zoomLevel; + final int cropXMin = (int) ((zScrollX - 32) / this.camera.zoomLevel); + final int cropXMax = (int) ((zScrollX + 32) / this.camera.zoomLevel) + + (int) (this.camera.widgetW / this.camera.zoomLevel); + final ItemTreeSlot collapseHoverNode = this.camera.isDragging() ? null : getCollapseArrowMouseOver(mouse); + + GuiHelper.useScissor(this.camera.widgetX, this.camera.widgetY, this.camera.widgetW, this.camera.widgetH, () -> { + GL11.glPushMatrix(); + GL11.glPushAttrib(GL11.GL_ENABLE_BIT | GL11.GL_COLOR_BUFFER_BIT | GL11.GL_LIGHTING_BIT); + GL11.glColor4f(1, 1, 1, 1); + GL11.glEnable(GL11.GL_BLEND); + GL11.glEnable(GL12.GL_RESCALE_NORMAL); + RenderHelper.enableGUIStandardItemLighting(); + GL11.glDisable(GL11.GL_LIGHTING); + GL11.glTranslatef(this.camera.widgetX - zScrollX, this.camera.widgetY - zScrollY, 0.0f); + GL11.glScalef(this.camera.zoomLevel, this.camera.zoomLevel, 1.0f); + + for (List row : this.rows.subMap(this.camera.visibleRowMin(), this.camera.visibleRowMax()) + .values()) { + for (ItemTreeSlot node : row) { + final Point point = this.pointByNode.get(node); + + drawParentLine(node); + + if (point.x >= cropXMin && point.x <= cropXMax) { + drawSlot(node, useInventorySnapshot, searchResult, collapsedItems, node == hoveredNode); + drawCollapseIcon(node, collapsedItems, node == collapseHoverNode); + + if (node == hoveredNode) { + NEIClientUtils.gl2DRenderContext( + () -> { + GuiDraw.drawRect( + point.x + 1, + point.y + 1, + SLOT_SIZE - 2, + SLOT_SIZE - 2, + HOVER_COLOR); + }); + } + + if (node.prefItem != null && this.graph.childrenOf.containsKey(node)) { + drawSlotBadge(node, point.x, point.y); + + if (node == deleteHoverNode) { + drawDeleteButton(point); + } + } + + } + } + } + + GL11.glPopAttrib(); + GL11.glPopMatrix(); + }); + + drawScrollbars(); + } + + public void drawFull(Set collapsedItems, SearchResult searchResult, boolean useInventorySnapshot) { + GL11.glPushMatrix(); + GL11.glPushAttrib(GL11.GL_ENABLE_BIT | GL11.GL_COLOR_BUFFER_BIT | GL11.GL_LIGHTING_BIT); + GL11.glColor4f(1, 1, 1, 1); + GL11.glEnable(GL11.GL_BLEND); + GL11.glEnable(GL12.GL_RESCALE_NORMAL); + RenderHelper.enableGUIStandardItemLighting(); + GL11.glDisable(GL11.GL_LIGHTING); + + for (List row : this.rows.values()) { + for (ItemTreeSlot node : row) { + final Point point = this.pointByNode.get(node); + + drawParentLine(node); + drawSlot(node, useInventorySnapshot, searchResult, collapsedItems, false); + + if (node.prefItem != null && this.graph.childrenOf.containsKey(node)) { + drawSlotBadge(node, point.x, point.y); + } + } + } + + GL11.glPopAttrib(); + GL11.glPopMatrix(); + } + + private void drawSlot(ItemTreeSlot node, boolean useInventorySnapshot, SearchResult searchResult, + Set collapsedItems, boolean hovered) { + final Point point = this.pointByNode.get(node); + + if (searchResult != null) { + + if (node == searchResult.highlightNode) { + SLOT_HIGHLIGHTED.draw(point.x, point.y); + } else if (searchResult.searchMatches.contains(node)) { + SLOT_DEFAULT.draw(point.x, point.y); + } else { + SLOT_DISABLED.draw(point.x, point.y); + } + + } else if (useInventorySnapshot) { + + if (node.leftAmount == 0) { + + if (this.graph.parentOf.get(node) != null && this.graph.parentOf.get(node).leftAmount == 0 + || node.requestedAmount == 0) { + SLOT_DISABLED.draw(point.x, point.y); + } else { + SLOT_DEFAULT.draw(point.x, point.y); + } + + } else if (!this.graph.childrenOf.containsKey(node)) { + SLOT_MISSING.draw(point.x, point.y); + } else if (collapsedItems.contains(node.ingrItem)) { + + if (this.graph.subtreeMissingCache.contains(node)) { + SLOT_MISSING.draw(point.x, point.y); + } else { + SLOT_CRAFTING.draw(point.x, point.y); + } + + } else if (!this.graph.childrenNeedCraftingCache.contains(node)) { + SLOT_CRAFTING.draw(point.x, point.y); + } else { + SLOT_DEFAULT.draw(point.x, point.y); + } + + } else { + SLOT_DEFAULT.draw(point.x, point.y); + } + + GuiContainerManager + .drawItem(point.x + (SLOT_SIZE - 16) / 2, point.y + (SLOT_SIZE - 16) / 2, node.emptyStack, true); + + if (node.requestedAmount > 0 && node.leftAmount == 0) { + drawStackSize(node, node.ingrItem.getStackSize(node.requestedAmount), point.x, point.y, true); + } else if (node.requestedAmount > 0 && node.leftAmount > 0) { + final long amount = hovered && node.prefItem != null + && this.graph.roots.contains(node) + && this.collapsedRecipes.contains(node.prefItem.recipeId) + && NEIClientUtils.controlKey() ? node.currentRequestedAmount : node.requestedAmount; + + drawStackSize(node, node.ingrItem.getStackSize(amount), point.x, point.y, false); + } + + } + + protected void drawStackSize(ItemTreeSlot node, long stackSize, int x, int y, boolean resolved) { + String amountString = stackSize < 10_000 ? String.valueOf(stackSize) + : ReadableNumberConverter.INSTANCE.toWideReadableForm(stackSize); + + if (node.isFluidDisplay) { + amountString += "L"; + } + + final boolean hasOutputChance = node.prefItem != null && node.prefItem.chance != PositionedStack.CHANCE_FULL; + int color = 0xFFFFFF; + + if (node.ingrItem.chance != PositionedStack.CHANCE_FULL || hasOutputChance || node.isContainerItem) { + amountString = "~" + amountString; + color = 0xFFAA00; + } + + if (resolved) { + color = 0x55FF55; + } + + NEIClientUtils.drawNEIOverlayText( + amountString, + new Rectangle4i( + x + (SLOT_SIZE - 16) / 2, + y + (SLOT_SIZE - 16) / 2, + SLOT_SIZE - (SLOT_SIZE - 16), + SLOT_SIZE - (SLOT_SIZE - 16)), + 1, + color, + true, + node.isFluidDisplay ? Alignment.BottomLeft : Alignment.BottomRight); + } + + protected void drawSlotBadge(ItemTreeSlot node, int x, int y) { + final float[] badge = badgeRect(x, y); + + GL11.glPushMatrix(); + GL11.glColor4f(1, 1, 1, 1); + GL11.glTranslatef(badge[0], badge[1], 4.0f); + GL11.glScalef(BADGE_SCALE, BADGE_SCALE, 1.0f); + + if (node.info.hasImageOrItem()) { + final DrawableResource image = node.info.getImage(); + + if (image != null) { + image.draw(0, 0); + } else { + GuiContainerManager.drawItem(0, 0, node.info.getItemStack(), true); + } + + } else { + ICON_CRAFTING.draw(0, 0); + } + + GL11.glPopMatrix(); + } + + private void drawCollapseIcon(ItemTreeSlot node, Set collapsedItems, boolean hover) { + + if (!this.graph.childrenOf.containsKey(node) || node.prefItem == null + || this.collapsedRecipes.contains(node.prefItem.recipeId) && !this.graph.roots.contains(node)) { + return; + } + + final DrawableResource icon; + + if (collapsedItems.contains(node.ingrItem)) { + icon = hover ? ICON_COLLAPSED_HOVER : ICON_COLLAPSED; + } else { + icon = hover ? ICON_EXPANDED_HOVER : ICON_EXPANDED; + } + + final Point point = this.pointByNode.get(node); + + GL11.glColor4f(1, 1, 1, 1); + icon.draw(point.x + SLOT_SIZE / 2 - icon.width - 1, point.y + SLOT_SIZE + 1); + } + + private void drawDeleteButton(Point point) { + final float[] badge = badgeRect(point.x, point.y); + + GL11.glPushMatrix(); + GL11.glColor4f(1, 1, 1, 1); + GL11.glTranslatef(badge[0], badge[1], 350.0f); + GL11.glScalef(BADGE_SCALE, BADGE_SCALE, 1.0f); + ICON_REMOVE.draw(0, 0); + GL11.glPopMatrix(); + } + + private static float[] badgeRect(float x, float y) { + final float w = ICON_REMOVE.width * BADGE_SCALE; + final float h = ICON_REMOVE.height * BADGE_SCALE; + + return new float[] { x - w / 2 + 1, y - h / 2 + 1, w, h }; + } + + private void drawParentLine(ItemTreeSlot node) { + + if (!this.graph.parentOf.containsKey(node)) { + return; + } + + final Point point = this.pointByNode.get(node); + final float x0 = point.x + SLOT_SIZE / 2f; + final float y0 = point.y - 1; + + final ItemTreeSlot parentNode = this.graph.parentOf.get(node); + final Point parentPoint = this.pointByNode.get(parentNode); + final float x1 = parentPoint.x + SLOT_SIZE / 2f; + final float y1 = parentPoint.y + SLOT_SIZE; + + if (x0 != x1) { + final float midY = (y0 + y1) / 2f; + + NEIClientUtils.drawRect(x0, Math.min(y0, midY), 1, Math.abs(midY - y0) + 1, LINE_COLOR); + NEIClientUtils.drawRect(Math.min(x0, x1), midY, Math.abs(x1 - x0) + 1, 1, LINE_COLOR); + NEIClientUtils.drawRect(x1, Math.min(midY, y1), 1, Math.abs(y1 - midY) + 1, LINE_COLOR); + } else { + NEIClientUtils.drawRect(x0, Math.min(y0, y1), 1, Math.abs(y1 - y0) + 1, LINE_COLOR); + } + } + + private void drawScrollbars() { + if (this.treeWidth <= 0 || this.treeHeight <= 0) { + return; + } + + final float scrollXPct = Camera.clamp(this.camera.scrollX / this.treeWidth, 0.0f, 1.0f); + final float scrollYPct = Camera.clamp(this.camera.scrollY / this.treeHeight, 0.0f, 1.0f); + + GL11.glTranslatef(0, 0, 500.0f); + + SCROLLBAR_H.draw( + this.camera.widgetX + this.camera.widgetW - 3, + (int) (this.camera.widgetY + scrollYPct * (this.camera.widgetH - SCROLLBAR_H.height))); + + SCROLLBAR_W.draw( + (int) (this.camera.widgetX + scrollXPct * (this.camera.widgetW - SCROLLBAR_W.width)), + this.camera.widgetY + this.camera.widgetH - 3); + + GL11.glTranslatef(0, 0, -500.0f); + } + + public void recalculateCoordinates(Set collapsedRecipes, Set collapsedItems, + ItemTreeSlot anchor) { + final Map offsetFromParent = new HashMap<>(); + final Point anchorOldPoint = anchor != null ? resolveAnchorPoint(anchor) : null; + + this.collapsedRecipes.clear(); + this.pointByNode.clear(); + this.rows.clear(); + this.treeWidth = 0; + this.treeHeight = 0; + + this.collapsedRecipes.addAll(collapsedRecipes); + + for (ItemTreeSlot node : this.graph.items) { + this.pointByNode.put(node, new Point(0, 0)); + } + + final List contour = new ArrayList<>(); + + for (ItemTreeSlot root : this.graph.roots) { + final List layout = computeLayout(root, collapsedItems, offsetFromParent); + final int shift = contour.isEmpty() ? 0 : requiredRootShift(contour, layout); + + mergeContour(contour, layout, shift); + assignPositions(root, shift, 0, collapsedItems, offsetFromParent); + } + + int minX = 0; + + for (Point point : this.pointByNode.values()) { + minX = Math.min(minX, point.x); + } + + if (minX < 0) { + for (Point point : this.pointByNode.values()) { + point.x -= minX; + } + } + + for (List row : this.rows.values()) { + for (ItemTreeSlot node : row) { + this.treeWidth = Math.max(this.treeWidth, this.pointByNode.get(node).x + CraftingTreeCanvas.SLOT_SIZE); + this.treeHeight = Math + .max(this.treeHeight, this.pointByNode.get(node).y + CraftingTreeCanvas.SLOT_SIZE); + } + } + + if (anchorOldPoint != null) { + final Point anchorNewPoint = resolveAnchorPoint(anchor); + + if (anchorNewPoint != null) { + this.camera.scrollX += anchorNewPoint.x - anchorOldPoint.x; + this.camera.scrollY += anchorNewPoint.y - anchorOldPoint.y; + } + } + } + + private Point resolveAnchorPoint(ItemTreeSlot anchor) { + Point result = this.pointByNode.get(anchor); + + if (result == null) { + for (Map.Entry entry : this.pointByNode.entrySet()) { + if (entry.getKey().ingrItem.equals(anchor.ingrItem)) { + return entry.getValue(); + } + } + + } + + return result; + } + + private List computeLayout(ItemTreeSlot node, Set collapsedItems, + Map offsetFromParent) { + List children = Collections.emptyList(); + + if (!collapsedItems.contains(node.ingrItem)) { + children = this.graph.childrenOf.getOrDefault(node, Collections.emptyList()); + } + + if (children.isEmpty()) { + final List rows = new ArrayList<>(); + rows.add(new int[] { 0, 0 }); + return rows; + } + + final int[] offsets = new int[children.size()]; + final List combined = new ArrayList<>(); + + for (int i = 0; i < children.size(); i++) { + final List childRows = computeLayout(children.get(i), collapsedItems, offsetFromParent); + final int shift = i == 0 ? 0 : requiredShift(combined, childRows, X_SPACING); + + offsets[i] = shift; + mergeContour(combined, childRows, shift); + } + + final int selfX = (offsets[0] + offsets[children.size() - 1]) / 2; + + for (int i = 0; i < children.size(); i++) { + offsetFromParent.put(children.get(i), offsets[i] - selfX); + } + + for (int[] row : combined) { + row[0] -= selfX; + row[1] -= selfX; + } + + final List rows = new ArrayList<>(combined.size() + 1); + rows.add(new int[] { 0, 0 }); + rows.addAll(combined); + + return rows; + } + + private static int requiredShift(List existing, List incoming, int spacing) { + int shift = 0; + final int rows = Math.min(existing.size(), incoming.size()); + + for (int r = 0; r < rows; r++) { + shift = Math.max(shift, existing.get(r)[1] + spacing - incoming.get(r)[0]); + } + + return shift; + } + + private static int requiredRootShift(List existing, List incoming) { + int existingRight = Integer.MIN_VALUE; + + for (int[] row : existing) { + existingRight = Math.max(existingRight, row[1]); + } + + int incomingLeft = Integer.MAX_VALUE; + + for (int[] row : incoming) { + incomingLeft = Math.min(incomingLeft, row[0]); + } + + return Math.max(0, existingRight + ROOT_SPACING - incomingLeft); + } + + private static void mergeContour(List target, List source, int shift) { + for (int r = 0; r < source.size(); r++) { + final int left = source.get(r)[0] + shift; + final int right = source.get(r)[1] + shift; + + if (r < target.size()) { + target.get(r)[0] = Math.min(target.get(r)[0], left); + target.get(r)[1] = Math.max(target.get(r)[1], right); + } else { + target.add(new int[] { left, right }); + } + } + } + + private void assignPositions(ItemTreeSlot node, int x, int y, Set collapsedItems, + Map offsetFromParent) { + this.rows.computeIfAbsent(y, ignored -> new ArrayList<>()).add(node); + this.pointByNode.put(node, new Point(x, y)); + + final int childY = y + CraftingTreeCanvas.SLOT_SIZE + Y_SPACING; + + if (!collapsedItems.contains(node.ingrItem)) { + for (ItemTreeSlot child : this.graph.childrenOf.getOrDefault(node, Collections.emptyList())) { + assignPositions(child, x + offsetFromParent.get(child), childY, collapsedItems, offsetFromParent); + } + } + + } +} diff --git a/src/main/java/codechicken/nei/bookmark/tree/CraftingTreeGraph.java b/src/main/java/codechicken/nei/bookmark/tree/CraftingTreeGraph.java new file mode 100644 index 00000000..ae68d893 --- /dev/null +++ b/src/main/java/codechicken/nei/bookmark/tree/CraftingTreeGraph.java @@ -0,0 +1,99 @@ +package codechicken.nei.bookmark.tree; + +import java.util.ArrayList; +import java.util.Collections; +import java.util.HashMap; +import java.util.HashSet; +import java.util.List; +import java.util.Map; +import java.util.Set; + +import codechicken.nei.recipe.Recipe.RecipeId; + +public class CraftingTreeGraph { + + public final List roots = new ArrayList<>(); + public final List items = new ArrayList<>(); + public final Map parentOf = new HashMap<>(); + public final Map> childrenOf = new HashMap<>(); + + public final Set subtreeMissingCache = new HashSet<>(); + public final Set childrenNeedCraftingCache = new HashSet<>(); + + public void rebuild(CraftingTreeMath math) { + this.subtreeMissingCache.clear(); + this.childrenNeedCraftingCache.clear(); + + math.refresh(); + + this.roots.clear(); + this.roots.addAll(math.rootSlots); + this.items.clear(); + this.items.addAll(math.items); + this.parentOf.clear(); + this.parentOf.putAll(math.parentOf); + this.childrenOf.clear(); + this.childrenOf.putAll(math.childrenOf); + + for (ItemTreeSlot root : this.roots) { + computeSubtreeMissing(root); + } + + for (Map.Entry> entry : this.childrenOf.entrySet()) { + if (entry.getValue().stream().anyMatch(child -> child.leftAmount != 0)) { + this.childrenNeedCraftingCache.add(entry.getKey()); + } + } + } + + public Set collectUnusedRecipes(ItemTreeSlot node) { + final Map> children = new HashMap<>(); + final Map> consumers = new HashMap<>(); + int rootCount = 0; + + for (ItemTreeSlot item : this.items) { + if (item.prefItem != null) { + children.computeIfAbsent(item.ingrItem.recipeId, k -> new HashSet<>()).add(item.prefItem.recipeId); + consumers.computeIfAbsent(item.prefItem.recipeId, k -> new HashSet<>()).add(item.ingrItem.recipeId); + + if (item.ingrItem.recipeId.equals(node.prefItem.recipeId)) { + rootCount++; + } + } + } + + final Set unusedRecipes = new HashSet<>(); + final RecipeId rootRecipeId = node.prefItem.recipeId; + + if (rootCount <= 1) { + unusedRecipes.add(rootRecipeId); + collectSubtree(rootRecipeId, children, consumers, unusedRecipes); + } + + return unusedRecipes; + } + + private void collectSubtree(RecipeId recipeId, Map> children, + Map> consumers, Set unusedRecipes) { + for (RecipeId child : children.getOrDefault(recipeId, Collections.emptySet())) { + if (consumers.get(child).size() == 1 && unusedRecipes.add(child)) { + collectSubtree(child, children, consumers, unusedRecipes); + } + } + } + + private boolean computeSubtreeMissing(ItemTreeSlot node) { + boolean hasMissing = !this.childrenOf.containsKey(node); + + for (ItemTreeSlot child : this.childrenOf.getOrDefault(node, Collections.emptyList())) { + hasMissing |= child.leftAmount != 0 && computeSubtreeMissing(child); + } + + if (hasMissing) { + this.subtreeMissingCache.add(node); + } + + return hasMissing; + } + +} diff --git a/src/main/java/codechicken/nei/bookmark/tree/CraftingTreeMath.java b/src/main/java/codechicken/nei/bookmark/tree/CraftingTreeMath.java new file mode 100644 index 00000000..48b09518 --- /dev/null +++ b/src/main/java/codechicken/nei/bookmark/tree/CraftingTreeMath.java @@ -0,0 +1,149 @@ +package codechicken.nei.bookmark.tree; + +import java.util.ArrayDeque; +import java.util.ArrayList; +import java.util.Collections; +import java.util.Deque; +import java.util.HashMap; +import java.util.List; +import java.util.Map; +import java.util.Set; + +import codechicken.nei.bookmark.BookmarkItem; +import codechicken.nei.bookmark.BookmarkItem.BookmarkItemType; +import codechicken.nei.recipe.Recipe.RecipeId; +import codechicken.nei.recipe.chain.RecipeChainMath; + +public class CraftingTreeMath extends RecipeChainMath { + + public final List rootSlots = new ArrayList<>(); + public final List items = new ArrayList<>(); + public final Map parentOf = new HashMap<>(); + public final Map> childrenOf = new HashMap<>(); + + private final Deque parentStack = new ArrayDeque<>(); + private ItemTreeSlot lastItem = null; + + public CraftingTreeMath(List chainItems, Set collapsedRecipes) { + super(chainItems, collapsedRecipes); + } + + @Override + public RecipeChainMath refresh() { + this.rootSlots.clear(); + this.items.clear(); + this.parentOf.clear(); + this.childrenOf.clear(); + this.parentStack.clear(); + this.lastItem = null; + + return super.refresh(); + } + + @Override + protected void calculationStepTrigger(BookmarkItem ingrItem, BookmarkItem prefItem, long requestedAmount, + long containerAmount, long inventoryAmount, long ingrAmount, long produced) { + + if (ingrItem.type == BookmarkItemType.RESULT) { + final ItemTreeSlot slot = new ItemTreeSlot( + ingrItem, + Math.max(0, this.requiredAmount.get(prefItem) - requestedAmount), + requestedAmount, + this.requiredAmount.get(prefItem), + 0, + prefItem); + + this.rootSlots.add(slot); + this.items.add(slot); + + this.lastItem = slot; + } else { + + if (prefItem != null && hasContainerItem(prefItem.itemStack)) { + + if (requestedAmount > 1) { + final long requestedSteps = getToolsContainerItems( + prefItem.itemStack.copy(), + requestedAmount).leftSteps; + requestedAmount = (long) Math + .ceil((double) requestedAmount / Math.max(1, requestedAmount - requestedSteps)); + } + + if (containerAmount > 1) { + final long containerSteps = getToolsContainerItems( + prefItem.itemStack.copy(), + containerAmount).leftSteps; + containerAmount = (long) Math + .ceil((double) containerAmount / Math.max(1, containerAmount - containerSteps)); + } + } + + final ItemTreeSlot slot = new ItemTreeSlot( + ingrItem, + 0, + requestedAmount, + produced, + containerAmount, + prefItem); + + this.items.add(slot); + this.parentOf.put(slot, this.parentStack.peek()); + this.childrenOf.computeIfAbsent(this.parentStack.peek(), k -> new ArrayList<>()).add(slot); + + this.lastItem = slot; + } + } + + @Override + protected void prepareIngredients(RecipeId recipeId, long multiplier, List visited) { + this.parentStack.push(this.lastItem); + super.prepareIngredients(recipeId, multiplier, visited); + this.lastItem = this.parentStack.pop(); + } + + @Override + protected void calculateSuitableRecipe(BookmarkItem ingrItem, long ingrMultiplier, List visited) { + final BookmarkItem prefItem = this.preferredItems.get(ingrItem); + super.calculateSuitableRecipe(ingrItem, ingrMultiplier, visited); + + if (prefItem != null && !isForeignBoxBoundary(ingrItem) + && !visited.contains(prefItem.recipeId) + && !this.childrenOf.containsKey(this.lastItem)) { + visited.add(prefItem.recipeId); + prepareIngredients(prefItem.recipeId, visited); + visited.remove(prefItem.recipeId); + } + + } + + protected void prepareIngredients(RecipeId recipeId, List visited) { + this.parentStack.push(this.lastItem); + + for (BookmarkItem item : this.ingredientsByRecipe.getOrDefault(recipeId, Collections.emptyList())) { + if (!item.emptyFactor()) { + calculateSuitableRecipe(item, visited); + } + } + + this.lastItem = this.parentStack.pop(); + } + + protected void calculateSuitableRecipe(BookmarkItem ingrItem, List visited) { + final BookmarkItem prefItem = this.preferredItems.get(ingrItem); + final ItemTreeSlot slot = new ItemTreeSlot(ingrItem, 0, 0, 0, 0, prefItem); + + this.items.add(slot); + this.parentOf.put(slot, this.parentStack.peek()); + this.childrenOf.computeIfAbsent(this.parentStack.peek(), k -> new ArrayList<>()).add(slot); + + this.lastItem = slot; + + if (prefItem != null && !isForeignBoxBoundary(ingrItem) && !visited.contains(prefItem.recipeId)) { + visited.add(prefItem.recipeId); + prepareIngredients(prefItem.recipeId, visited); + visited.remove(prefItem.recipeId); + } + + } + +} diff --git a/src/main/java/codechicken/nei/bookmark/tree/CraftingTreeState.java b/src/main/java/codechicken/nei/bookmark/tree/CraftingTreeState.java new file mode 100644 index 00000000..f54a9f53 --- /dev/null +++ b/src/main/java/codechicken/nei/bookmark/tree/CraftingTreeState.java @@ -0,0 +1,105 @@ +package codechicken.nei.bookmark.tree; + +import java.util.EnumSet; +import java.util.HashSet; +import java.util.Set; + +import codechicken.nei.NEIClientConfig; +import codechicken.nei.bookmark.BookmarkItem; + +class CraftingTreeState { + + enum CollapseMode { + EXPANDED, + SMART, + ALL + } + + enum StatsSection { + INGREDIENTS_NEEDED, + INGREDIENTS_AVAILABLE, + CRAFTING_NEEDED, + CRAFTING_AVAILABLE, + RESULTS, + REMAINDERS, + HANDLERS + } + + private static final String KEY_STATS_VISIBLE = "craftingTree.statsVisible"; + private static final String KEY_STATS_SECTIONS = "craftingTree.statsSections"; + private static final String KEY_USE_INVENTORY_SNAPSHOT = "craftingTree.useInventorySnapshot"; + private static final String KEY_COLLAPSE_MODE = "craftingTree.collapseMode"; + + public boolean statsPanelVisible = true; + public final Set visibleStatsSections = EnumSet.allOf(StatsSection.class); + public boolean useInventorySnapshot = false; + public CollapseMode collapseMode = CollapseMode.EXPANDED; + + public final Set collapsedItems = new HashSet<>(); + public ItemTreeSlot replaceRecipeNode; + + public SearchResult searchItemResult; + public SearchResult searchStatsResult; + + public void load() { + this.statsPanelVisible = !NEIClientConfig.world.nbt.hasKey(KEY_STATS_VISIBLE) + || NEIClientConfig.world.nbt.getBoolean(KEY_STATS_VISIBLE); + + final int savedSectionsMask = NEIClientConfig.world.nbt.hasKey(KEY_STATS_SECTIONS) + ? NEIClientConfig.world.nbt.getInteger(KEY_STATS_SECTIONS) + : -1; + + this.visibleStatsSections.clear(); + + for (StatsSection section : StatsSection.values()) { + if ((savedSectionsMask & (1 << section.ordinal())) != 0) { + this.visibleStatsSections.add(section); + } + } + + this.useInventorySnapshot = NEIClientConfig.world.nbt.getBoolean(KEY_USE_INVENTORY_SNAPSHOT); + + final CollapseMode[] collapseModes = CollapseMode.values(); + final int savedCollapseMode = NEIClientConfig.world.nbt.getInteger(KEY_COLLAPSE_MODE); + this.collapseMode = savedCollapseMode >= 0 && savedCollapseMode < collapseModes.length + ? collapseModes[savedCollapseMode] + : CollapseMode.EXPANDED; + this.replaceRecipeNode = null; + } + + public void toggleStatsPanelVisible() { + this.statsPanelVisible = !this.statsPanelVisible; + NEIClientConfig.world.nbt.setBoolean(KEY_STATS_VISIBLE, this.statsPanelVisible); + } + + public void toggleStatsSection(StatsSection section) { + + if (!this.visibleStatsSections.remove(section)) { + this.visibleStatsSections.add(section); + } + + int mask = 0; + + for (StatsSection visibleSection : this.visibleStatsSections) { + mask |= 1 << visibleSection.ordinal(); + } + + NEIClientConfig.world.nbt.setInteger(KEY_STATS_SECTIONS, mask); + } + + public void toggleUseInventorySnapshot() { + this.useInventorySnapshot = !this.useInventorySnapshot; + NEIClientConfig.world.nbt.setBoolean(KEY_USE_INVENTORY_SNAPSHOT, this.useInventorySnapshot); + } + + public void cycleCollapseMode() { + final CollapseMode[] collapseModes = CollapseMode.values(); + this.collapseMode = collapseModes[(this.collapseMode.ordinal() + 1) % collapseModes.length]; + NEIClientConfig.world.nbt.setInteger(KEY_COLLAPSE_MODE, this.collapseMode.ordinal()); + } + + public SearchResult activeSearchResult() { + return this.searchItemResult != null ? this.searchItemResult : this.searchStatsResult; + } + +} diff --git a/src/main/java/codechicken/nei/bookmark/tree/CraftingTreeToolbar.java b/src/main/java/codechicken/nei/bookmark/tree/CraftingTreeToolbar.java new file mode 100644 index 00000000..422e5cf9 --- /dev/null +++ b/src/main/java/codechicken/nei/bookmark/tree/CraftingTreeToolbar.java @@ -0,0 +1,241 @@ +package codechicken.nei.bookmark.tree; + +import java.util.Arrays; +import java.util.List; +import java.util.function.BooleanSupplier; +import java.util.function.Supplier; + +import net.minecraft.client.Minecraft; +import net.minecraft.client.gui.GuiButton; + +import org.lwjgl.opengl.GL11; + +import codechicken.nei.GuiNEIButton; +import codechicken.nei.NEIClientUtils; +import codechicken.nei.drawable.DrawableBuilder; +import codechicken.nei.drawable.DrawableResource; + +class CraftingTreeToolbar { + + private static class GuiStatsButton extends GuiNEIButton { + + private final Supplier icon; + private final BooleanSupplier isEnabled; + private final Supplier tooltip; + + public GuiStatsButton(int buttonId, Supplier icon, Supplier tooltip, + BooleanSupplier isEnabled) { + super(buttonId, 0, 0, 16, 16, ""); + this.tooltip = tooltip; + this.icon = icon; + this.isEnabled = isEnabled; + } + + public String getTooltip() { + return this.tooltip.get(); + } + + @Override + public int getHoverState(boolean mouseOver) { + return this.isEnabled.getAsBoolean() ? 0 : super.getHoverState(mouseOver); + } + + @Override + protected void drawContent(Minecraft minecraft, int y, int x, boolean mouseOver) { + final DrawableResource icon = this.icon.get(); + final int iconX = this.xPosition + (this.width - icon.width / 2) / 2; + final int iconY = this.yPosition + (this.height - icon.height / 2) / 2; + + GL11.glPushMatrix(); + GL11.glColor4f(1, 1, 1, 1); + GL11.glEnable(GL11.GL_BLEND); + GL11.glBlendFunc(GL11.GL_SRC_ALPHA, GL11.GL_ONE_MINUS_SRC_ALPHA); + GL11.glTranslated(iconX, iconY, 0); + GL11.glScalef(0.5f, 0.5f, 1); + + icon.bindTexture(); + GL11.glTexParameteri(GL11.GL_TEXTURE_2D, GL11.GL_TEXTURE_MIN_FILTER, GL11.GL_LINEAR); + GL11.glTexParameteri(GL11.GL_TEXTURE_2D, GL11.GL_TEXTURE_MAG_FILTER, GL11.GL_LINEAR); + icon.draw(0, 0); + GL11.glTexParameteri(GL11.GL_TEXTURE_2D, GL11.GL_TEXTURE_MIN_FILTER, GL11.GL_NEAREST); + GL11.glTexParameteri(GL11.GL_TEXTURE_2D, GL11.GL_TEXTURE_MAG_FILTER, GL11.GL_NEAREST); + + GL11.glDisable(GL11.GL_BLEND); + GL11.glPopMatrix(); + } + + } + + private static final DrawableResource STATS_TEXTURE = new DrawableBuilder( + "nei:textures/gui/craftingtree.png", + 2, + 66, + 16, + 16).build(); + + private static final DrawableResource COMPACT_STATS_TEXTURE = new DrawableBuilder( + "nei:textures/gui/craftingtree.png", + 20, + 66, + 16, + 16).build(); + + private static final DrawableResource FIT_TEXTURE = new DrawableBuilder( + "nei:textures/gui/craftingtree.png", + 38, + 66, + 16, + 16).build(); + + private static final DrawableResource INV_TEXTURE = new DrawableBuilder( + "nei:textures/gui/craftingtree.png", + 56, + 66, + 16, + 16).build(); + + private static final DrawableResource LINK_TEXTURE = new DrawableBuilder( + "nei:textures/gui/craftingtree.png", + 74, + 66, + 16, + 16).build(); + + private static final DrawableResource ICON_COLLAPSED = new DrawableBuilder( + "nei:textures/gui/craftingtree.png", + 92, + 66, + 16, + 16).build(); + + private static final DrawableResource ICON_INDETERMINATE = new DrawableBuilder( + "nei:textures/gui/craftingtree.png", + 110, + 66, + 16, + 16).build(); + + private static final DrawableResource ICON_EXPANDED = new DrawableBuilder( + "nei:textures/gui/craftingtree.png", + 128, + 66, + 16, + 16).build(); + + private static final DrawableResource ICON_SCREENSHOT = new DrawableBuilder( + "nei:textures/gui/craftingtree.png", + 146, + 66, + 16, + 16).build(); + + private static final DrawableResource ICON_SETTINGS = new DrawableBuilder( + "nei:textures/gui/craftingtree.png", + 164, + 66, + 16, + 16).build(); + + private static final int BUTTON_SPACING = 20; + + public static final int INV_BUTTON_ID = 0; + public static final int FIT_BUTTON_ID = 1; + public static final int COLLAPSE_ALL_BUTTON_ID = 2; + public static final int TOGGLE_STATS_BUTTON_ID = 3; + public static final int STATS_SECTIONS_BUTTON_ID = 4; + public static final int LINK_BUTTON_ID = 5; + public static final int SCREENSHOT_BUTTON_ID = 6; + + private final CraftingTreeState uiState; + private final GuiStatsButton[] buttons; + + public CraftingTreeToolbar(CraftingTreeState uiState) { + this.uiState = uiState; + + this.buttons = new GuiStatsButton[] { + new GuiStatsButton( + INV_BUTTON_ID, + () -> INV_TEXTURE, + () -> NEIClientUtils.translate( + this.uiState.useInventorySnapshot ? "bookmark.tree.toolbar.inventory_on" + : "bookmark.tree.toolbar.inventory_off"), + () -> this.uiState.useInventorySnapshot), + + new GuiStatsButton( + FIT_BUTTON_ID, + () -> FIT_TEXTURE, + () -> NEIClientUtils.translate("bookmark.tree.toolbar.fit_to_view"), + () -> false), + + new GuiStatsButton(COLLAPSE_ALL_BUTTON_ID, () -> switch (this.uiState.collapseMode) { + case EXPANDED -> ICON_EXPANDED; + case SMART -> ICON_INDETERMINATE; + case ALL -> ICON_COLLAPSED; + }, () -> NEIClientUtils.translate(switch (this.uiState.collapseMode) { + case EXPANDED -> "bookmark.tree.toolbar.collapse_resolved"; + case SMART -> "bookmark.tree.toolbar.collapse_all"; + case ALL -> "bookmark.tree.toolbar.expand_all"; + }), () -> this.uiState.collapseMode != CraftingTreeState.CollapseMode.EXPANDED), + + new GuiStatsButton( + TOGGLE_STATS_BUTTON_ID, + () -> this.uiState.visibleStatsSections.size() == CraftingTreeState.StatsSection.values().length + ? STATS_TEXTURE + : COMPACT_STATS_TEXTURE, + () -> NEIClientUtils.translate( + this.uiState.statsPanelVisible ? "bookmark.tree.toolbar.stats_on" + : "bookmark.tree.toolbar.stats_off"), + () -> this.uiState.statsPanelVisible), + + new GuiStatsButton( + STATS_SECTIONS_BUTTON_ID, + () -> ICON_SETTINGS, + () -> NEIClientUtils.translate("bookmark.tree.toolbar.stats_sections"), + () -> false), + new GuiStatsButton( + LINK_BUTTON_ID, + () -> LINK_TEXTURE, + () -> NEIClientUtils.translate("bookmark.tree.toolbar.link"), + () -> false), + new GuiStatsButton( + SCREENSHOT_BUTTON_ID, + () -> ICON_SCREENSHOT, + () -> NEIClientUtils.translate("bookmark.tree.toolbar.screenshot"), + () -> false) + + }; + } + + public void layout(int x, int y) { + for (int i = 0; i < this.buttons.length; i++) { + this.buttons[i].xPosition = x + BUTTON_SPACING * i; + this.buttons[i].yPosition = y; + } + } + + public void addTo(List buttonList) { + buttonList.addAll(Arrays.asList(this.buttons)); + } + + public GuiButton getButton(int buttonId) { + + for (int i = 0; i < this.buttons.length; i++) { + if (this.buttons[i].id == buttonId) { + return this.buttons[i]; + } + } + + return null; + } + + public String getTooltip(Minecraft mc, int mousex, int mousey) { + for (GuiStatsButton button : this.buttons) { + if (button.mousePressed(mc, mousex, mousey)) { + return button.getTooltip(); + } + } + + return null; + } + +} diff --git a/src/main/java/codechicken/nei/bookmark/tree/GuiCraftingTree.java b/src/main/java/codechicken/nei/bookmark/tree/GuiCraftingTree.java new file mode 100644 index 00000000..37ac8b84 --- /dev/null +++ b/src/main/java/codechicken/nei/bookmark/tree/GuiCraftingTree.java @@ -0,0 +1,1265 @@ +package codechicken.nei.bookmark.tree; + +import java.awt.geom.Point2D; +import java.awt.image.BufferedImage; +import java.io.File; +import java.nio.IntBuffer; +import java.nio.file.FileAlreadyExistsException; +import java.time.LocalDateTime; +import java.time.format.DateTimeFormatter; +import java.util.ArrayList; +import java.util.Collections; +import java.util.List; +import java.util.Locale; +import java.util.Map; +import java.util.Set; +import java.util.stream.Stream; + +import javax.imageio.ImageIO; + +import net.minecraft.client.Minecraft; +import net.minecraft.client.gui.GuiButton; +import net.minecraft.client.gui.GuiScreen; +import net.minecraft.client.gui.inventory.GuiContainer; +import net.minecraft.client.renderer.OpenGlHelper; +import net.minecraft.client.shader.Framebuffer; +import net.minecraft.event.ClickEvent; +import net.minecraft.inventory.Slot; +import net.minecraft.item.ItemStack; +import net.minecraft.util.ChatComponentText; +import net.minecraft.util.ChatComponentTranslation; +import net.minecraft.util.EnumChatFormatting; + +import org.lwjgl.BufferUtils; +import org.lwjgl.input.Keyboard; +import org.lwjgl.input.Mouse; +import org.lwjgl.opengl.GL11; +import org.lwjgl.opengl.GL12; + +import codechicken.lib.gui.GuiDraw; +import codechicken.nei.KeyManager; +import codechicken.nei.LRUCache; +import codechicken.nei.NEICPH; +import codechicken.nei.NEIClientUtils; +import codechicken.nei.PositionedStack; +import codechicken.nei.SearchField.GuiSearchField; +import codechicken.nei.VisiblityData; +import codechicken.nei.Widget; +import codechicken.nei.api.IGuiContainerOverlay; +import codechicken.nei.api.INEIGuiHandler; +import codechicken.nei.api.ItemFilter; +import codechicken.nei.bookmark.BookmarkGrid; +import codechicken.nei.bookmark.BookmarkGroup; +import codechicken.nei.bookmark.BookmarkItem; +import codechicken.nei.bookmark.BookmarkItem.BookmarkItemType; +import codechicken.nei.bookmark.BookmarkPayload; +import codechicken.nei.drawable.DrawableBuilder; +import codechicken.nei.drawable.DrawableResource; +import codechicken.nei.guihook.IContainerTooltipHandler; +import codechicken.nei.guihook.IGuiClientSide; +import codechicken.nei.guihook.IGuiHandleMouseWheel; +import codechicken.nei.recipe.AcceptsFollowingTooltipLineHandler; +import codechicken.nei.recipe.AutoCraftingManager; +import codechicken.nei.recipe.GuiCraftingRecipe; +import codechicken.nei.recipe.GuiOverlayButton; +import codechicken.nei.recipe.GuiRecipe; +import codechicken.nei.recipe.GuiRecipeButton.UpdateRecipeButtonsEvent; +import codechicken.nei.recipe.GuiRecipeTab; +import codechicken.nei.recipe.Recipe; +import codechicken.nei.recipe.Recipe.RecipeId; +import codechicken.nei.recipe.RecipeTooltipLineHandler; +import codechicken.nei.recipe.StackInfo; +import codechicken.nei.util.EmptyContainer; +import codechicken.nei.util.NEIMouseUtils; +import codechicken.nei.util.ReadableNumberConverter; +import codechicken.nei.util.SlotInaccessible; +import cpw.mods.fml.common.eventhandler.SubscribeEvent; + +public class GuiCraftingTree extends GuiContainer implements INEIGuiHandler, IGuiClientSide, IGuiHandleMouseWheel, + IContainerTooltipHandler, IGuiContainerOverlay { + + public static class EventHandler { + + @SubscribeEvent + public void updateRecipeButtons(UpdateRecipeButtonsEvent.Post event) { + GuiScreen screen = event.gui; + + while (screen instanceof GuiReciperecipeGui) { + screen = recipeGui.prevGui; + } + + if (screen instanceof GuiCraftingTree treeGui) { + for (int index = 0; index < event.buttonList.size(); index++) { + if (event.buttonList.get(index) instanceof GuiOverlayButton button) { + event.buttonList.set( + index, + new TreeOverlayButton(treeGui, button.handlerRef, button.xPosition, button.yPosition)); + } + } + } + + } + } + + private static final DrawableResource BG_TEXTURE = new DrawableBuilder( + "nei:textures/gui/craftingtree.png", + 0, + 0, + 64, + 64).build(); + + private static final DateTimeFormatter SCREENSHOT_DATE_FORMAT = DateTimeFormatter + .ofPattern("yyyy-MM-dd_HH.mm.ss", Locale.ROOT); + + private static final int MARGIN = 4; + private static final int PADDING = 9; + private static final int PADDING_TOP = 22; + + private static LRUCache handlerTitleCache = new LRUCache<>(100); + + private GuiScreen prevGui; + private boolean isFirstScreen = true; + + private final BookmarkGrid grid; + private final int groupId; + private CraftingTreeMath math; + private Set collapsedRecipes; + + private final StatsPanel statsPanel = new StatsPanel(); + private final StatsSectionsMenu statsSectionsMenu = new StatsSectionsMenu(); + private final CraftingTreeCanvas canvas = new CraftingTreeCanvas(); + private boolean statsPanelVisible; + + private GuiSearchField searchField; + + private RecipeTooltipLineHandler recipeTooltipLineHandler; + private AcceptsFollowingTooltipLineHandler acceptsFollowingTooltipLineHandler; + + private final CraftingTreeState uiState = new CraftingTreeState(); + private final CraftingTreeToolbar toolbar; + + private ItemTreeSlot hoveredNode; + private ItemTreeSlot hoveredBadgeHandler; + + protected GuiCraftingTree(GuiScreen prevGui, BookmarkGrid grid, int groupId) { + super(new EmptyContainer()); + this.prevGui = prevGui; + this.grid = grid; + this.groupId = groupId; + + this.toolbar = new CraftingTreeToolbar(this.uiState); + } + + public static void openCraftingTreeGui(BookmarkGrid grid, int groupId) { + final Minecraft mc = NEIClientUtils.mc(); + mc.displayGuiScreen(new GuiCraftingTree(mc.currentScreen, grid, groupId)); + } + + protected void addRecipe(Recipe recipe) { + final ItemTreeSlot replaceNode = this.uiState.replaceRecipeNode; + this.uiState.replaceRecipeNode = null; + + if (recipe != null) { + final RecipeId recipeId = recipe.getRecipeId(); + boolean changed = false; + + if (replaceNode != null) { + final Set unusedRecipes = this.canvas.graph.collectUnusedRecipes(replaceNode); + unusedRecipes.remove(recipeId); + + for (RecipeId unusedId : unusedRecipes) { + changed |= this.grid.removeRecipe(unusedId, this.groupId); + } + } + + if (!this.grid.existsRecipe(recipeId, this.groupId)) { + this.grid.addRecipe(recipe, 1, this.groupId); + changed = true; + } + + if (changed) { + rebuildTree(null); + } + } + + NEIClientUtils.mc().displayGuiScreen(this); + } + + @Override + public void initGui() { + this.xSize = this.width; + this.ySize = this.height; + + super.initGui(); + + this.canvas.setViewport( + MARGIN + PADDING, + MARGIN + PADDING_TOP, + this.width - MARGIN * 2 - PADDING * 2, + this.height - MARGIN * 2 - PADDING_TOP - PADDING); + + this.searchField = new GuiSearchField() { + + @Override + public void mouseClicked(int x, int y, int button) { + + if (button == 1 && x >= this.xPosition + && x < this.xPosition + this.width + && y >= this.yPosition + && y < this.yPosition + this.height) { + setText(""); + onSearchTextChanged(); + } else { + super.mouseClicked(x, y, button); + } + + } + + }; + this.searchField.width = Math.min(140, (this.width - MARGIN * 2 - PADDING * 2) / 3); + this.searchField.height = 14; + this.searchField.xPosition = this.width - MARGIN - this.searchField.width - PADDING; + this.searchField.yPosition = MARGIN + 5; + this.searchField.setMaxStringLength(256); + + this.toolbar.layout(MARGIN + PADDING, MARGIN + 4); + + this.buttonList.clear(); + this.toolbar.addTo(this.buttonList); + + this.uiState.load(); + + rebuildTree(null); + } + + @Override + public boolean doesGuiPauseGame() { + return false; + } + + @Override + public GuiContainer getFirstScreen() { + + if (this.prevGui instanceof IGuiContainerOverlay overlay) { + return overlay.getFirstScreen(); + } + + return this.prevGui instanceof GuiContainer gui ? gui : null; + } + + @Override + public GuiScreen getFirstScreenGeneral() { + return this; + } + + @Override + public void updateScreen() { + this.statsPanel.update(); + + super.updateScreen(); + } + + private void rebuildTree(ItemTreeSlot anchor) { + final BookmarkGroup group = this.grid.getGroup(this.groupId); + final List chainItems = group.crafting != null + ? new ArrayList<>(this.grid.createChainItems(this.groupId).values()) + : Collections.emptyList(); + + this.collapsedRecipes = group.collapsedRecipes; + this.math = new CraftingTreeMath(chainItems, this.collapsedRecipes); + this.math.initialItems.clear(); + + if (this.uiState.useInventorySnapshot) { + final GuiContainer firstGui = getFirstScreen(); + + if (firstGui != null) { + for (ItemStack stack : AutoCraftingManager.getInventoryItems(firstGui).values()) { + if (stack != null) { + this.math.initialItems.add(BookmarkItem.of(-1, stack)); + } + } + } + } + + this.canvas.graph.rebuild(this.math); + + if (this.isFirstScreen) { + updateCollapsedItems(); + } else { + this.canvas.recalculateCoordinates(this.collapsedRecipes, this.uiState.collapsedItems, anchor); + } + + rebuildStatsPanel(); + + if (this.isFirstScreen) { + this.isFirstScreen = false; + this.canvas.fitToView(); + } + } + + private void rebuildStatsPanel() { + this.statsPanel.rebuild( + this.math, + this.canvas.graph, + this.uiState.useInventorySnapshot, + this.uiState.visibleStatsSections, + MARGIN + PADDING, + MARGIN + PADDING_TOP, + this.width - MARGIN * 2 - PADDING * 2, + this.height - MARGIN * 2 - PADDING_TOP - PADDING); + + updateSearchItemMatches(); + updateSearchStatsMatches(); + this.statsPanel.setHighlight(this.uiState.searchStatsResult); + this.statsPanelVisible = this.uiState.statsPanelVisible && !this.statsPanel.getWidgets().isEmpty(); + + this.canvas.setViewport( + MARGIN + PADDING, + MARGIN + PADDING_TOP, + this.width - MARGIN * 2 - PADDING * 2, + this.height - MARGIN * 2 - PADDING_TOP - PADDING - (this.statsPanelVisible ? this.statsPanel.h : 0)); + } + + @Override + protected void drawGuiContainerBackgroundLayer(float partialTicks, int mouseX, int mouseY) { + final boolean canHover = !this.canvas.isDragging() && this.canvas.isInWidget(mouseX, mouseY) + && this.statsPanel.getStackMouseOver(mouseX, mouseY) == null; + this.hoveredBadgeHandler = canHover ? this.canvas.getHandlerBadgeMouseOver(getMousePosition()) : null; + this.hoveredNode = canHover && hoveredBadgeHandler == null ? this.canvas.getNodeMouseOver(getMousePosition()) + : null; + + BG_TEXTURE.draw( + MARGIN, + MARGIN, + this.width - MARGIN * 2, + this.height - MARGIN * 2, + PADDING, + PADDING, + PADDING_TOP, + PADDING); + + if (this.math.outputRecipes.isEmpty()) { + drawCenteredString( + this.fontRendererObj, + NEIClientUtils.translate("bookmark.tree.empty"), + this.width / 2, + MARGIN + PADDING_TOP + (this.height - MARGIN * 2 - PADDING_TOP) / 2, + 0xFFAAAAAA); + } else { + this.canvas.draw( + getMousePosition(), + this.uiState.collapsedItems, + this.uiState.activeSearchResult(), + this.uiState.useInventorySnapshot, + this.hoveredNode, + this.hoveredBadgeHandler); + + if (this.statsPanelVisible) { + this.statsPanel.draw(mouseX, mouseY); + } + } + + drawCenteredString( + this.fontRendererObj, + NEIClientUtils.translate("bookmark.tree.title"), + this.width / 2, + MARGIN + PADDING_TOP / 2 - this.fontRendererObj.FONT_HEIGHT / 2 + 1, + 0xFFFFFFFF); + + this.searchField.drawTextBox(); + + this.statsSectionsMenu.draw(mouseX, mouseY, this.uiState); + } + + @Override + protected void actionPerformed(GuiButton button) { + + switch (button.id) { + case CraftingTreeToolbar.INV_BUTTON_ID: + this.uiState.toggleUseInventorySnapshot(); + rebuildTree(null); + break; + case CraftingTreeToolbar.FIT_BUTTON_ID: + this.canvas.fitToView(); + break; + case CraftingTreeToolbar.TOGGLE_STATS_BUTTON_ID: + this.uiState.toggleStatsPanelVisible(); + rebuildStatsPanel(); + break; + case CraftingTreeToolbar.STATS_SECTIONS_BUTTON_ID: + + if (this.statsSectionsMenu.visible) { + this.statsSectionsMenu.close(); + } else { + this.statsSectionsMenu.open(button.xPosition, button.yPosition + button.height + 2); + } + + break; + case CraftingTreeToolbar.LINK_BUTTON_ID: + NEIClientUtils.sendChatItemLink(BookmarkPayload.of(this.groupId).toNBT()); + break; + case CraftingTreeToolbar.COLLAPSE_ALL_BUTTON_ID: + this.uiState.cycleCollapseMode(); + updateCollapsedItems(); + this.canvas.fitToView(); + break; + case CraftingTreeToolbar.SCREENSHOT_BUTTON_ID: + saveScreenshot(); + break; + default: + return; + } + + } + + private void saveScreenshot() { + + if (this.math.outputRecipes.isEmpty()) { + return; + } + + if (!OpenGlHelper.isFramebufferEnabled()) { + NEIClientUtils.printChatMessage( + new ChatComponentText(NEIClientUtils.translate("bookmark.tree.screenshot.fbo_unsupported"))); + return; + } + + final Minecraft mc = NEIClientUtils.mc(); + + try { + final int screenshotZoom = 2; + final File screenshotsDir = new File(mc.mcDataDir, "screenshots"); + screenshotsDir.mkdirs(); + + final StatsPanel screenshotStats = this.statsPanelVisible ? new StatsPanel() : null; + final int treeWidth = this.canvas.treeWidth; + final int treeHeight = this.canvas.treeHeight + 16; + int statsWidth = 0; + int statsHeight = 0; + + if (screenshotStats != null) { + screenshotStats.rebuild( + this.math, + this.canvas.graph, + this.uiState.useInventorySnapshot, + this.uiState.visibleStatsSections, + 0, + 0, + treeWidth, + Short.MAX_VALUE); + + screenshotStats.x = 0; + screenshotStats.y = treeHeight; + screenshotStats.update(); + statsWidth = screenshotStats.getActualWidth(); + statsHeight = screenshotStats.h = screenshotStats.getActualHeight() + 8; + } + + final int contentWidth = Math.max(treeWidth, statsWidth); + final float treeShiftX = (contentWidth - treeWidth) / 2f; + + if (screenshotStats != null && statsWidth > treeWidth) { + screenshotStats.w = statsWidth; + screenshotStats.x = 0; + screenshotStats.update(); + } + + final int maxGlTexSize = GL11.glGetInteger(GL11.GL_MAX_TEXTURE_SIZE) / 2; + int imgHeight = screenshotZoom * (treeHeight + statsHeight + 16); + int imgWidth = screenshotZoom * (contentWidth + 16); + + // Make sure the image can be actually allocated, worst case it'll be cropped + while ((long) imgWidth * (long) imgHeight >= (long) Integer.MAX_VALUE / 4) { + if (imgWidth > imgHeight) { + imgWidth /= 2; + } else { + imgHeight /= 2; + } + } + + final int xChunks = (imgWidth + maxGlTexSize - 1) / maxGlTexSize; + final int yChunks = (imgHeight + maxGlTexSize - 1) / maxGlTexSize; + final int fbWidth = Math.min(imgWidth, maxGlTexSize); + final int fbHeight = Math.min(imgHeight, maxGlTexSize); + + final BufferedImage outputImg = new BufferedImage(imgWidth, imgHeight, BufferedImage.TYPE_INT_ARGB); + final IntBuffer downloadBuffer = BufferUtils.createIntBuffer(fbWidth * fbHeight); + + GL11.glPushMatrix(); + GL11.glPushAttrib(GL11.GL_ALL_ATTRIB_BITS); + + final Framebuffer fb = new Framebuffer(fbWidth, fbHeight, true); + + GL11.glMatrixMode(GL11.GL_PROJECTION); + GL11.glLoadIdentity(); + GL11.glOrtho(0, fbWidth / (float) screenshotZoom, fbHeight / (float) screenshotZoom, 0, 1000, 3000); + GL11.glMatrixMode(GL11.GL_MODELVIEW); + GL11.glLoadIdentity(); + GL11.glDisable(GL11.GL_DEPTH_TEST); + + try { + fb.bindFramebuffer(true); + + for (int xChunk = 0; xChunk < xChunks; xChunk++) { + final int xStart = xChunk * maxGlTexSize; + final int xChunkSize = Math.min((xChunk + 1) * maxGlTexSize, imgWidth) - xStart; + + for (int yChunk = 0; yChunk < yChunks; yChunk++) { + final int yStart = yChunk * maxGlTexSize; + final int yChunkSize = Math.min((yChunk + 1) * maxGlTexSize, imgHeight) - yStart; + + GL11.glPushMatrix(); + GL11.glTranslatef( + 8 - xStart / (float) screenshotZoom, + 8 - yStart / (float) screenshotZoom, + -2000.0f); + GL11.glClear(GL11.GL_COLOR_BUFFER_BIT | GL11.GL_DEPTH_BUFFER_BIT); + + GL11.glPushMatrix(); + GL11.glTranslatef(treeShiftX, 0, 0); + this.canvas.drawFull( + this.uiState.collapsedItems, + this.uiState.activeSearchResult(), + this.uiState.useInventorySnapshot); + GL11.glPopMatrix(); + + if (screenshotStats != null) { + GL11.glPushMatrix(); + screenshotStats.drawFull(); + GL11.glPopMatrix(); + } + + GL11.glPopMatrix(); + + GL11.glBindTexture(GL11.GL_TEXTURE_2D, fb.framebufferTexture); + GL11.glGetTexImage( + GL11.GL_TEXTURE_2D, + 0, + GL12.GL_BGRA, + GL12.GL_UNSIGNED_INT_8_8_8_8_REV, + downloadBuffer); + + for (int y = 0; y < yChunkSize; y++) { + for (int x = 0; x < xChunkSize; x++) { + outputImg.setRGB( + x + xStart, + y + yStart, + downloadBuffer.get((fbHeight - 1 - y) * fbWidth + x)); + } + } + } + } + } finally { + fb.deleteFramebuffer(); + GL11.glViewport(0, 0, mc.displayWidth, mc.displayHeight); + } + + GL11.glPopAttrib(); + GL11.glPopMatrix(); + + final String date = SCREENSHOT_DATE_FORMAT.format(LocalDateTime.now()); + String filename = String.format("%s-nei.png", date); + File outFile = new File(screenshotsDir, filename); + for (int i = 1; outFile.exists() && i < 99; i++) { + filename = String.format("%s-nei-%d.png", date, i); + outFile = new File(screenshotsDir, filename); + } + if (outFile.exists()) { + throw new FileAlreadyExistsException(filename); + } + ImageIO.write(outputImg, "png", outFile); + + final ChatComponentText chatLink = new ChatComponentText(filename); + chatLink.getChatStyle() + .setChatClickEvent(new ClickEvent(ClickEvent.Action.OPEN_FILE, outFile.getAbsolutePath())); + chatLink.getChatStyle().setUnderlined(true); + NEIClientUtils.printChatMessage(new ChatComponentTranslation("screenshot.success", chatLink)); + } catch (Exception e) { + NEIClientUtils.printChatMessage(new ChatComponentTranslation("screenshot.failure", e.getMessage())); + } + } + + private void updateCollapsedItems() { + this.uiState.collapsedItems.clear(); + + for (ItemTreeSlot node : this.canvas.graph.childrenOf.keySet()) { + + if (this.canvas.graph.roots.contains(node)) { + continue; + } + + final boolean collapse = switch (this.uiState.collapseMode) { + case EXPANDED -> false; + case SMART -> !this.canvas.graph.childrenNeedCraftingCache.contains(node); + case ALL -> true; + }; + + if (collapse) { + this.uiState.collapsedItems.add(node.ingrItem); + } + } + + this.canvas.recalculateCoordinates(this.collapsedRecipes, this.uiState.collapsedItems, null); + } + + protected ItemStack getItemStackMouseOver(int mousex, int mousey) { + + if (this.statsPanelVisible) { + final ItemStack stack = this.statsPanel.getStackMouseOver(mousex, mousey); + + if (stack != null) { + return stack; + } + } + + if (this.hoveredNode != null) { + return this.hoveredNode.itemStack; + } + + return null; + } + + @Override + public Slot getSlotAtPosition(int mousex, int mousey) { + final ItemStack hoveredStack = getItemStackMouseOver(mousex, mousey); + final EmptyContainer slotcontainer = (EmptyContainer) this.inventorySlots; + slotcontainer.setActiveStack(hoveredStack); + + return hoveredStack != null ? new SlotInaccessible(hoveredStack, 0, 0) : null; + } + + @Override + protected void mouseClicked(int mouseX, int mouseY, int button) { + this.searchField.mouseClicked(mouseX, mouseY, button); + + if (this.statsSectionsMenu.visible) { + + if (this.statsSectionsMenu.handleClick(mouseX, mouseY, this.uiState)) { + rebuildStatsPanel(); + return; + } + + if (!isOverButton(this.toolbar.getButton(CraftingTreeToolbar.STATS_SECTIONS_BUTTON_ID), mouseX, mouseY)) { + this.statsSectionsMenu.close(); + } + } + + if (this.statsPanelVisible) { + + if (handleWidgetClick(mouseX, mouseY, button)) { + return; + } + + if (this.statsPanel.handleClick(mouseX, mouseY, button)) { + return; + } + } + + if (button == 0 && handleCanvasClick(mouseX, mouseY)) { + return; + } + + super.mouseClicked(mouseX, mouseY, button); + } + + private static boolean isOverButton(GuiButton button, int mouseX, int mouseY) { + return mouseX >= button.xPosition && mouseX < button.xPosition + button.width + && mouseY >= button.yPosition + && mouseY < button.yPosition + button.height; + } + + private boolean handleWidgetClick(int mouseX, int mouseY, int button) { + final Object widgetGUID = this.statsPanel.getWidgetGUIDUnderMouse(mouseX, mouseY); + + if (widgetGUID == null) { + return false; + } + + if (button == 1 && this.uiState.searchStatsResult != null + && this.uiState.searchStatsResult.matchesGUID(widgetGUID)) { + NEIClientUtils.playClickSound(); + + this.uiState.searchStatsResult = null; + this.statsPanel.setHighlight(null); + onSearchTextChanged(); + return true; + } + + if (button == 0) { + NEIClientUtils.playClickSound(); + + if (this.uiState.searchStatsResult == null || !this.uiState.searchStatsResult.matchesGUID(widgetGUID)) { + this.uiState.searchItemResult = null; + this.uiState.searchStatsResult = new SearchResult(widgetGUID); + updateSearchStatsMatches(); + this.statsPanel.setHighlight(this.uiState.searchStatsResult); + } + + searchGoTo(this.uiState.searchStatsResult, !NEIClientUtils.shiftKey()); + return true; + } + + return false; + } + + private boolean handleCanvasClick(int mouseX, int mouseY) { + + if (!this.canvas.isInWidget(mouseX, mouseY)) { + return false; + } + + final Point2D mouse = getMousePosition(); + final ItemTreeSlot deleteButtonTarget = this.canvas.getHandlerBadgeMouseOver(mouse); + final ItemTreeSlot hoveredNode = deleteButtonTarget != null ? null : this.canvas.getNodeMouseOver(mouse); + + if (hoveredNode != null) { + + if (NEIClientUtils.altKey() && hoveredNode.prefItem != null) { + NEIClientUtils.playClickSound(); + this.grid.toggleCollapsedRecipe(this.groupId, hoveredNode.prefItem.recipeId); + rebuildTree(hoveredNode); + return true; + } else if (this.canvas.graph.childrenOf.containsKey(hoveredNode)) { + this.uiState.replaceRecipeNode = hoveredNode; + } + + } else if (deleteButtonTarget != null) { + NEIClientUtils.playClickSound(); + final RecipeId recipeId = deleteButtonTarget.prefItem.recipeId; + final int itemIndex = this.grid + .indexOf(this.groupId, deleteButtonTarget.prefItem.itemStack, recipeId, false); + + this.grid.removeRecipe(itemIndex, false); + + if (!this.grid.existsRecipe(recipeId, this.groupId)) { + for (RecipeId unusedId : this.canvas.graph.collectUnusedRecipes(deleteButtonTarget)) { + this.grid.removeRecipe(unusedId, this.groupId); + } + } + + rebuildTree(null); + return true; + } else { + final ItemTreeSlot collapseTarget = this.canvas.getCollapseArrowMouseOver(mouse); + + if (collapseTarget != null) { + NEIClientUtils.playClickSound(); + final BookmarkItem item = collapseTarget.ingrItem; + + if (!this.uiState.collapsedItems.remove(item)) { + this.uiState.collapsedItems.add(item); + } + + this.canvas.recalculateCoordinates(this.collapsedRecipes, this.uiState.collapsedItems, collapseTarget); + + return true; + } + + this.canvas.startDrag(mouseX, mouseY); + } + + return false; + } + + @Override + protected void mouseClickMove(int mouseX, int mouseY, int button, long timeSinceLastClick) { + if (button != 0) { + return; + } + + if (this.statsPanelVisible) { + + if (this.statsPanel.isDraggingScrollbar()) { + this.statsPanel.mouseDragged(mouseX, mouseY, button, timeSinceLastClick); + return; + } + + } + + this.canvas.drag(mouseX, mouseY); + } + + @Override + protected void mouseMovedOrUp(int mouseX, int mouseY, int state) { + super.mouseMovedOrUp(mouseX, mouseY, state); + + if (this.statsPanelVisible) { + this.statsPanel.mouseUp(mouseX, mouseY, state); + } + + this.canvas.endDrag(); + } + + @Override + public void mouseScrolled(int wheel) { + final Point2D mouse = getMousePosition(); + + if (handleItemWheel(wheel, mouse)) { + return; + } + + final int direction = wheel > 0 ? 1 : -1; + + if (NEIClientUtils.shiftKey() && this.acceptsFollowingTooltipLineHandler != null) { + final BookmarkItem item = (BookmarkItem) this.acceptsFollowingTooltipLineHandler.tooltipGUID; + final int itemIndex = this.grid + .indexOf(this.groupId, item.itemStack, item.recipeId, item.type == BookmarkItemType.INGREDIENT); + + if (item.permutations.size() > 1) { + final List items = acceptsFollowingTooltipLineHandler.getItems(); + ItemStack activeStack = this.acceptsFollowingTooltipLineHandler.getActiveStack(); + int stackIndex = 0; + + for (int i = 0; i < items.size(); i++) { + if (StackInfo.equalItemAndNBT(activeStack, items.get(i), true)) { + stackIndex = i; + break; + } + } + + activeStack = items.get((items.size() - direction + stackIndex) % items.size()); + + this.acceptsFollowingTooltipLineHandler.setActiveStack(activeStack); + + if (itemIndex != -1) { + final BookmarkItem oldItem = this.grid.getBookmarkItem(itemIndex); + final BookmarkItem newItem = oldItem.copyWithPerm(activeStack); + this.grid.replaceBookmarkItem(itemIndex, newItem); + } else { + this.grid.onItemsChanged(); + } + + item.itemStack = activeStack; + rebuildTree(null); + } + + return; + } + + this.canvas.scroll( + (int) mouse.getX(), + (int) mouse.getY(), + direction, + NEIClientUtils.shiftKey(), + NEIClientUtils.controlKey()); + } + + private boolean handleItemWheel(int wheel, Point2D mouse) { + final int direction = wheel > 0 ? 1 : -1; + final int x = (int) mouse.getX(); + final int y = (int) mouse.getY(); + + if (this.statsPanelVisible && this.statsPanel.contains(x, y) && this.statsPanel.onMouseWheel(direction, x, y) + || !this.canvas.isInWidget(x, y)) { + return true; + } + + if (NEIClientUtils.controlKey()) { + final ItemTreeSlot node = this.canvas.getNodeMouseOver(mouse); + + if (this.canvas.graph.roots.contains(node)) { + final BookmarkItem item = node.ingrItem; + final RecipeId recipeId = item.recipeId; + + if (recipeId != null) { + final long multiplier = NEIClientUtils.altKey() ? NEIClientUtils.getScrollMultiplier(item.itemStack) + : 1; + + this.grid.shiftRecipeAmount(this.groupId, recipeId, multiplier * direction); + rebuildTree(null); + + return true; + } + } + + } + + return false; + } + + @Override + protected void keyTyped(char typedChar, int keyCode) { + + if (keyCode == Keyboard.KEY_ESCAPE) { + this.mc.displayGuiScreen(this.prevGui); + NEICPH.sendRequestContainer(); + return; + } + + if (this.searchField.isFocused()) { + + if (keyCode == Keyboard.KEY_RETURN) { + if (this.uiState.searchItemResult == null) { + onSearchTextChanged(); + } else { + searchGoTo(this.uiState.searchItemResult, !NEIClientUtils.shiftKey()); + } + return; + } + + if (this.searchField.textboxKeyTyped(typedChar, keyCode)) { + onSearchTextChanged(); + return; + } + } + + if (this.statsPanelVisible && KeyManager.isKeyDown("recipe.recipe")) { + final Point2D mouse = getMousePosition(); + final Widget widget = this.statsPanel.getWidgetUnderMouse((int) mouse.getX(), (int) mouse.getY()); + + if (widget != null && widget instanceof StatsPanel.ItemStatsSlot itemStatsSlot + && itemStatsSlot.recipeId != null) { + GuiCraftingRecipe.openRecipeGui("recipeId", itemStatsSlot.recipeId.getResult(), itemStatsSlot.recipeId); + return; + } + } + + super.keyTyped(typedChar, keyCode); + } + + private static String getHandlerTitle(String handlerName) { + return handlerTitleCache.computeIfAbsent( + handlerName, + hname -> Stream + .concat( + GuiCraftingRecipe.craftinghandlers.stream(), + GuiCraftingRecipe.serialCraftingHandlers.stream()) + .filter(handler -> hname.equals(GuiRecipeTab.getHandlerInfo(handler).getHandlerName())) + .findFirst().map(handler -> handler.getRecipeName().trim()).orElse(hname)); + } + + @Override + public List handleTooltip(GuiContainer gui, int mousex, int mousey, List currenttip) { + final String toolbarTooltip = this.toolbar.getTooltip(gui.mc, mousex, mousey); + + if (this.recipeTooltipLineHandler != null && getSlotAtPosition(mousex, mousey) == null) { + this.recipeTooltipLineHandler = null; + } + + if (toolbarTooltip != null) { + currenttip.add(toolbarTooltip); + } else if (this.hoveredBadgeHandler != null) { + final RecipeId recipeId = this.hoveredBadgeHandler.prefItem != null + ? this.hoveredBadgeHandler.prefItem.recipeId + : null; + final long multiplier = this.hoveredBadgeHandler.multiplier; + + addRecipeTooltipLine(recipeId, multiplier, currenttip); + } else { + + if (this.statsPanelVisible) { + final Widget widget = this.statsPanel.getWidgetUnderMouse(mousex, mousey); + + if (widget instanceof StatsPanel.HandlerStatsSlot handlerStatsSlot) { + currenttip.add(getHandlerTitle(handlerStatsSlot.handlerName) + GuiDraw.TOOLTIP_LINESPACE); + currenttip.add( + EnumChatFormatting.GRAY + NEIClientUtils.translate( + "bookmark.tree.stats.handler_recipes", + handlerStatsSlot.stats.recipeCount)); + currenttip.add( + EnumChatFormatting.GRAY + NEIClientUtils.translate( + "bookmark.tree.stats.handler_iterations", + handlerStatsSlot.stats.iterations)); + } + } + + } + + return currenttip; + } + + private void addRecipeTooltipLine(RecipeId recipeId, long multiplier, List currenttip) { + + if (recipeId == null) { + this.recipeTooltipLineHandler = null; + } else + if (this.recipeTooltipLineHandler == null || !this.recipeTooltipLineHandler.getRecipeId().equals(recipeId) + || this.recipeTooltipLineHandler.getMultiplier() != multiplier) { + this.recipeTooltipLineHandler = new RecipeTooltipLineHandler(recipeId, multiplier); + } + + if (this.recipeTooltipLineHandler != null) { + currenttip.add(GuiDraw.TOOLTIP_HANDLER + GuiDraw.getTipLineId(this.recipeTooltipLineHandler)); + } + } + + @Override + public List handleItemTooltip(GuiContainer gui, ItemStack itemstack, int mousex, int mousey, + List currenttip) { + + final ItemTreeSlot hoveredItemNode = this.hoveredNode; + + if (hoveredItemNode != null) { + final BookmarkItem item = hoveredItemNode.ingrItem; + + if (item.chance != PositionedStack.CHANCE_FULL) { + final String chanceText = NEIClientUtils + .formatChance(item.chance / (float) PositionedStack.CHANCE_FULL); + + currenttip.add( + 1, + EnumChatFormatting.GRAY + NEIClientUtils.translate( + item.type == BookmarkItemType.INGREDIENT ? "recipe.badge.chance.consume" + : "recipe.badge.chance.output", + chanceText)); + + } + + if (this.uiState.useInventorySnapshot && hoveredItemNode.requestedAmount > 0) { + + if (hoveredItemNode.leftAmount == 0) { + final ItemStack resolvedStack = (hoveredItemNode.prefItem != null ? hoveredItemNode.prefItem + : hoveredItemNode.ingrItem).itemStack; + final String resolvedName = resolvedStack.getDisplayName(); + + currenttip.add( + 1, + EnumChatFormatting.GRAY + + NEIClientUtils.translate("bookmark.tree.item.state.resolved", resolvedName)); + } else if (hoveredItemNode.leftAmount != hoveredItemNode.requestedAmount) { + final long freshStackSize = item.getStackSize(hoveredItemNode.leftAmount); + String freshAmountText = freshStackSize < 10_000 ? String.valueOf(freshStackSize) + : ReadableNumberConverter.INSTANCE.toWideReadableForm(freshStackSize); + + if (hoveredItemNode.isFluidDisplay) { + freshAmountText += "L"; + } + + currenttip.add( + 1, + EnumChatFormatting.GRAY + + NEIClientUtils.translate("bookmark.tree.item.state.partial", freshAmountText)); + } + + if (hoveredItemNode.leftAmount > 0 && this.canvas.graph.childrenOf.containsKey(hoveredItemNode) + && !this.canvas.graph.childrenNeedCraftingCache.contains(hoveredItemNode)) { + currenttip.add( + 1, + EnumChatFormatting.GRAY + NEIClientUtils.translate("bookmark.tree.item.state.craftable")); + } + + } + + if (hoveredItemNode.prefItem != null && this.canvas.graph.childrenOf.containsKey(hoveredItemNode)) { + final BookmarkItem output = hoveredItemNode.prefItem; + final long producedAmount = output.getAmount(hoveredItemNode.multiplier); + final long surplus = producedAmount - hoveredItemNode.requestedAmount; + + if (surplus > 0) { + String surplusText = surplus < 10_000 ? String.valueOf(surplus) + : ReadableNumberConverter.INSTANCE.toWideReadableForm(surplus); + + if (hoveredItemNode.isFluidDisplay) { + surplusText += "L"; + } + + currenttip.add( + 1, + EnumChatFormatting.GRAY + + NEIClientUtils.translate("bookmark.tree.item.state.surplus", surplusText)); + } + } + + if (item.recipeId == null || hoveredItemNode.prefItem != null + || hoveredItemNode.leftAmount == 0 && hoveredItemNode.requestedAmount > 0) { + this.acceptsFollowingTooltipLineHandler = null; + } else if (this.acceptsFollowingTooltipLineHandler == null + || !item.equals(this.acceptsFollowingTooltipLineHandler.tooltipGUID)) { + this.acceptsFollowingTooltipLineHandler = AcceptsFollowingTooltipLineHandler.of( + item, + new ArrayList<>(item.permutations.values()), + hoveredItemNode.ingrItem.getItemStack(), + 2); + } + + if (this.acceptsFollowingTooltipLineHandler != null) { + currenttip.add(GuiDraw.TOOLTIP_HANDLER + GuiDraw.getTipLineId(this.acceptsFollowingTooltipLineHandler)); + } + + } else { + this.acceptsFollowingTooltipLineHandler = null; + + if (this.statsPanelVisible) { + final Widget widget = this.statsPanel.getWidgetUnderMouse(mousex, mousey); + if (widget instanceof StatsPanel.ItemStatsSlot itemStatsSlot) { + addRecipeTooltipLine(itemStatsSlot.recipeId, itemStatsSlot.multiplier, currenttip); + } + } + + } + + return currenttip; + } + + @Override + public Map handleHotkeys(GuiContainer gui, int mousex, int mousey, Map hotkeys) { + + if (this.hoveredNode != null) { + if (this.hoveredNode.prefItem != null) { + hotkeys.put( + NEIClientUtils.getKeyName(NEIClientUtils.ALT_HASH, NEIMouseUtils.MOUSE_BTN_LMB), + NEIClientUtils.translate("bookmark.tree.item.toggle_recipe")); + } + + if (this.canvas.graph.roots.contains(this.hoveredNode)) { + hotkeys.put( + NEIClientUtils.getKeyName( + NEIClientUtils.CTRL_HASH, + NEIMouseUtils.MOUSE_BTN_NONE + NEIMouseUtils.MOUSE_SCROLL), + NEIClientUtils.translate("bookmark.change_quantity")); + + hotkeys.put( + NEIClientUtils.getKeyName( + NEIClientUtils.CTRL_HASH + NEIClientUtils.ALT_HASH, + NEIMouseUtils.MOUSE_BTN_NONE + NEIMouseUtils.MOUSE_SCROLL), + NEIClientUtils.translate("bookmark.change_quantity_step")); + } + } else if (this.statsPanelVisible) { + final Object widgetGUID = this.statsPanel.getWidgetGUIDUnderMouse(mousex, mousey); + + if (widgetGUID != null) { + + if (this.uiState.searchStatsResult != null && this.uiState.searchStatsResult.matchesGUID(widgetGUID)) { + hotkeys.put( + NEIMouseUtils.getKeyName(NEIMouseUtils.MOUSE_BTN_LMB), + NEIClientUtils.translate("bookmark.tree.stats.next_highlight")); + + hotkeys.put( + NEIClientUtils.getKeyName(NEIClientUtils.SHIFT_HASH, NEIMouseUtils.MOUSE_BTN_LMB), + NEIClientUtils.translate("bookmark.tree.stats.prev_highlight")); + + hotkeys.put( + NEIMouseUtils.getKeyName(NEIMouseUtils.MOUSE_BTN_RMB), + NEIClientUtils.translate("bookmark.tree.stats.clear_highlight")); + } else { + hotkeys.put( + NEIMouseUtils.getKeyName(NEIMouseUtils.MOUSE_BTN_LMB), + NEIClientUtils.translate("bookmark.tree.stats.highlight_handler")); + } + + } + + } + + if (this.acceptsFollowingTooltipLineHandler != null) { + hotkeys.put( + NEIClientUtils.getKeyName( + NEIClientUtils.SHIFT_HASH, + NEIMouseUtils.MOUSE_BTN_NONE + NEIMouseUtils.MOUSE_SCROLL), + NEIClientUtils.translate("recipe.accepts.scroll")); + } + + return hotkeys; + } + + @Override + public VisiblityData modifyVisiblity(GuiContainer gui, VisiblityData currentVisibility) { + currentVisibility.showNEI = false; + return currentVisibility; + } + + private Point2D getMousePosition() { + final float preciseMouseX = Mouse.getX() * (float) this.width / this.mc.displayWidth; + final float preciseMouseY = this.height - Mouse.getY() * (float) this.height / this.mc.displayHeight; + return new Point2D.Float(preciseMouseX, preciseMouseY); + } + + private void onSearchTextChanged() { + final String searchText = this.searchField.getText(); + + if (this.uiState.searchStatsResult != null) { + this.uiState.searchStatsResult = null; + this.statsPanel.setHighlight(null); + } + + if (!searchText.isEmpty()) { + this.uiState.searchItemResult = new SearchResult(searchText); + updateSearchItemMatches(); + searchGoTo(this.uiState.searchItemResult, true); + } else { + this.uiState.searchItemResult = null; + } + + } + + private void searchGoTo(SearchResult searchResult, boolean forward) { + + if (searchResult == null || searchResult.searchMatches.isEmpty()) { + return; + } + + final List searchList = new ArrayList<>(searchResult.searchMatches); + int searchIndex = searchList.indexOf(searchResult.highlightNode); + + if (forward) { + + if (searchIndex >= searchList.size() - 1) { + searchIndex = -1; + } + + searchIndex++; + } else { + + if (searchIndex <= 0) { + searchIndex = searchList.size(); + } + + searchIndex--; + } + + ItemTreeSlot target = searchIndex == -1 ? null : searchList.get(searchIndex); + + if (target != null) { + ItemTreeSlot current = this.canvas.graph.parentOf.get(target); + + while (current != null) { + this.uiState.collapsedItems.remove(current.ingrItem); + current = this.canvas.graph.parentOf.get(current); + } + } + + this.canvas.recalculateCoordinates(this.collapsedRecipes, this.uiState.collapsedItems, null); + + searchResult.highlightNode = target; + this.canvas.scrollTo(target); + } + + private void updateSearchItemMatches() { + + if (this.uiState.searchItemResult != null) { + final ItemFilter filter = this.searchField.getFilter((String) this.uiState.searchItemResult.searchGUID); + this.uiState.searchItemResult.searchMatches.clear(); + this.uiState.searchItemResult.highlightNode = null; + + for (ItemTreeSlot node : this.canvas.graph.items) { + if (filter.matches(node.emptyStack)) { + this.uiState.searchItemResult.searchMatches.add(node); + } + } + } + + } + + private void updateSearchStatsMatches() { + + if (this.uiState.searchStatsResult != null) { + this.uiState.searchStatsResult.searchMatches.clear(); + this.uiState.searchStatsResult.highlightNode = null; + + final boolean byHandler = this.uiState.searchStatsResult.searchGUID instanceof String; + + for (ItemTreeSlot node : this.canvas.graph.items) { + final boolean matches = byHandler + ? node.prefItem != null + && this.uiState.searchStatsResult.matchesGUID(node.prefItem.recipeId.getHandlerName()) + : this.uiState.searchStatsResult.matchesGUID(node.emptyStack); + + if (matches) { + this.uiState.searchStatsResult.searchMatches.add(node); + } + } + } + + } + +} diff --git a/src/main/java/codechicken/nei/bookmark/tree/ItemTreeSlot.java b/src/main/java/codechicken/nei/bookmark/tree/ItemTreeSlot.java new file mode 100644 index 00000000..a34f7404 --- /dev/null +++ b/src/main/java/codechicken/nei/bookmark/tree/ItemTreeSlot.java @@ -0,0 +1,90 @@ +package codechicken.nei.bookmark.tree; + +import net.minecraft.item.ItemStack; + +import codechicken.nei.bookmark.BookmarkItem; +import codechicken.nei.recipe.GuiRecipeTab; +import codechicken.nei.recipe.HandlerInfo; +import codechicken.nei.recipe.StackInfo; + +class ItemTreeSlot { + + public final BookmarkItem ingrItem; + public final BookmarkItem prefItem; + + public final long ingeritRequestedAmount; + public final long currentRequestedAmount; + public final long requestedAmount; + + public final long containerAmount; + public final long producedAmount; + public final long leftAmount; + + public final ItemStack emptyStack; + public final ItemStack itemStack; + public final boolean isFluidDisplay; + public final boolean isContainerItem; + + public final HandlerInfo info; + public final long multiplier; + + public ItemTreeSlot(BookmarkItem ingrItem, long ingeritRequestedAmount, long currentRequestedAmount, + long producedAmount, long containerAmount, BookmarkItem prefItem) { + + this.ingrItem = ingrItem; + this.ingeritRequestedAmount = ingeritRequestedAmount; + this.currentRequestedAmount = currentRequestedAmount; + this.requestedAmount = ingeritRequestedAmount + currentRequestedAmount; + + this.containerAmount = containerAmount; + this.producedAmount = producedAmount; + this.leftAmount = producedAmount + containerAmount; + this.prefItem = prefItem; + + if (prefItem != null) { + this.info = handlerInfo(prefItem.recipeId.getHandlerName()); + this.multiplier = prefItem.getMultiplierFromAmount(this.requestedAmount); + + this.itemStack = prefItem.getItemStack(this.requestedAmount); + this.emptyStack = prefItem.getItemStack(0); + } else { + this.info = null; + this.multiplier = ingrItem.getMultiplierFromAmount(this.requestedAmount); + this.itemStack = ingrItem.getItemStack(this.requestedAmount); + this.emptyStack = ingrItem.getItemStack(0); + } + + this.isFluidDisplay = StackInfo.isFluidDisplayItem(this.emptyStack); + this.isContainerItem = isContainerItem(this.emptyStack); + } + + private static HandlerInfo handlerInfo(String handlerName) { + final HandlerInfo info = GuiRecipeTab.getHandlerInfo(handlerName, null); + return info != null ? info : GuiRecipeTab.DEFAULT_HANDLER_INFO; + } + + private static boolean isContainerItem(ItemStack stack) { + boolean isContainerItem = false; + + if (stack.getItem().hasContainerItem(stack)) { + final boolean isPausedItemDamageSound = StackInfo.isPausedItemDamageSound(); + + try { + + StackInfo.pauseItemDamageSound(true); + + final ItemStack containerItem = stack.getItem().getContainerItem(stack); + + if (containerItem != null) { + isContainerItem = stack.getItem() == containerItem.getItem(); + } + + } finally { + StackInfo.pauseItemDamageSound(isPausedItemDamageSound); + } + } + + return isContainerItem; + } + +} diff --git a/src/main/java/codechicken/nei/bookmark/tree/SearchResult.java b/src/main/java/codechicken/nei/bookmark/tree/SearchResult.java new file mode 100644 index 00000000..24466d6f --- /dev/null +++ b/src/main/java/codechicken/nei/bookmark/tree/SearchResult.java @@ -0,0 +1,28 @@ +package codechicken.nei.bookmark.tree; + +import java.util.LinkedHashSet; +import java.util.Set; + +import net.minecraft.item.ItemStack; + +import codechicken.nei.NEIClientUtils; + +class SearchResult { + + public final Object searchGUID; + public ItemTreeSlot highlightNode; + public final Set searchMatches = new LinkedHashSet<>(); + + public SearchResult(Object searchGUID) { + this.searchGUID = searchGUID; + } + + public boolean matchesGUID(Object guid) { + if (guid instanceof ItemStack stack && this.searchGUID instanceof ItemStack searchStack) { + return NEIClientUtils.areStacksSameTypeCraftingWithNBT(stack, searchStack); + } + + return this.searchGUID.equals(guid); + } + +} diff --git a/src/main/java/codechicken/nei/bookmark/tree/StatsPanel.java b/src/main/java/codechicken/nei/bookmark/tree/StatsPanel.java new file mode 100644 index 00000000..14403435 --- /dev/null +++ b/src/main/java/codechicken/nei/bookmark/tree/StatsPanel.java @@ -0,0 +1,744 @@ +package codechicken.nei.bookmark.tree; + +import java.util.ArrayList; +import java.util.Comparator; +import java.util.HashMap; +import java.util.LinkedHashMap; +import java.util.List; +import java.util.Map; +import java.util.Set; + +import net.minecraft.client.renderer.RenderHelper; +import net.minecraft.item.ItemStack; +import net.minecraft.nbt.NBTTagCompound; + +import org.lwjgl.opengl.GL11; +import org.lwjgl.opengl.GL12; + +import codechicken.lib.gui.GuiDraw; +import codechicken.lib.vec.Rectangle4i; +import codechicken.nei.ItemSorter; +import codechicken.nei.ItemStackAmount; +import codechicken.nei.NEIClientUtils; +import codechicken.nei.NEIClientUtils.Alignment; +import codechicken.nei.Widget; +import codechicken.nei.bookmark.BookmarkItem; +import codechicken.nei.drawable.DrawableBuilder; +import codechicken.nei.drawable.DrawableResource; +import codechicken.nei.guihook.GuiContainerManager; +import codechicken.nei.recipe.GuiRecipeTab; +import codechicken.nei.recipe.HandlerInfo; +import codechicken.nei.recipe.Recipe.RecipeId; +import codechicken.nei.recipe.StackInfo; +import codechicken.nei.recipe.chain.RecipeChainMath; +import codechicken.nei.scroll.ScrollBar; +import codechicken.nei.scroll.ScrollContainer; +import codechicken.nei.util.ReadableNumberConverter; + +class StatsPanel extends ScrollContainer { + + public static class HandlerStats { + + public long iterations; + public long recipeCount; + } + + private static class SectionLabel extends Widget { + + public final String text; + + public SectionLabel(String text) { + this.text = text; + this.w = GuiDraw.fontRenderer.getStringWidth(text); + this.h = GuiDraw.fontRenderer.FONT_HEIGHT + 4; + } + + @Override + public void draw(int mx, int my) { + NEIClientUtils.gl2DRenderContext( + () -> GuiDraw.fontRenderer.drawStringWithShadow(this.text, this.x, this.y, 0xFFFFFFFF)); + } + } + + public static class ItemStatsSlot extends Widget { + + public final ItemStack stack; + public final long stackSize; + public final RecipeId recipeId; + public final long multiplier; + public final HandlerInfo info; + public final DrawableResource icon; + private final boolean isFluidDisplay; + public boolean highlight = false; + + public ItemStatsSlot(ItemStack stack, long stackSize, DrawableResource icon, RecipeId recipeId, + long multiplier) { + this.stack = StackInfo.withAmount(stack, 0); + this.stackSize = stackSize; + this.icon = icon; + this.recipeId = recipeId; + this.multiplier = multiplier; + this.isFluidDisplay = StackInfo.isFluidDisplayItem(stack); + this.info = this.recipeId != null ? handlerInfo(this.recipeId.getHandlerName()) : null; + this.w = SLOT_SIZE; + this.h = SLOT_SIZE; + } + + public ItemStatsSlot(ItemStack stack, long stackSize, DrawableResource icon) { + this(stack, stackSize, icon, null, 1); + } + + @Override + public void draw(int mx, int my) { + + if (this.highlight) { + SLOT_HIGHLIGHTED.draw(this.x, this.y); + } else { + this.icon.draw(this.x, this.y); + } + + GuiContainerManager + .drawItem(this.x + (SLOT_SIZE - 16) / 2, this.y + (SLOT_SIZE - 16) / 2, this.stack, true, ""); + + drawStackSize(); + + if (mx >= this.x && mx < this.x + SLOT_SIZE && my >= this.y && my < this.y + SLOT_SIZE) { + NEIClientUtils.gl2DRenderContext( + () -> GuiDraw.drawRect(this.x + 1, this.y + 1, SLOT_SIZE - 2, SLOT_SIZE - 2, HOVER_COLOR)); + } + + if (this.recipeId != null) { + drawHandlerBadge(); + } + } + + private void drawHandlerBadge() { + final float scale = 0.6f; + final float badgeX = x - 6 * scale; + + GL11.glPushMatrix(); + GL11.glColor4f(1, 1, 1, 1); + GL11.glTranslatef(badgeX, y - 6 * scale, 3.0f); + GL11.glScalef(scale, scale, 1.0f); + + if (this.info.hasImageOrItem()) { + final DrawableResource image = this.info.getImage(); + + if (image != null) { + image.draw(0, 0); + } else { + GuiContainerManager.drawItem(0, 0, this.info.getItemStack(), true); + } + + } else { + ICON_CRAFTING.draw(0, 0); + } + + GL11.glPopMatrix(); + } + + private void drawStackSize() { + String amountString = stackSize < 10_000 ? String.valueOf(stackSize) + : ReadableNumberConverter.INSTANCE.toWideReadableForm(stackSize); + + if (this.isFluidDisplay) { + amountString += "L"; + } + + NEIClientUtils.drawNEIOverlayText( + amountString, + new Rectangle4i( + x + (SLOT_SIZE - 16) / 2, + y + (SLOT_SIZE - 16) / 2, + SLOT_SIZE - (SLOT_SIZE - 16), + SLOT_SIZE - (SLOT_SIZE - 16)), + 1, + 0xFFFFFF, + true, + this.isFluidDisplay ? Alignment.BottomLeft : Alignment.BottomRight); + } + + } + + public static class HandlerStatsSlot extends Widget { + + public final String handlerName; + public final HandlerInfo info; + public final HandlerStats stats; + public boolean highlight = false; + + public HandlerStatsSlot(String handlerName, HandlerStats stats) { + this.handlerName = handlerName; + this.info = handlerInfo(handlerName); + this.stats = stats; + this.w = SLOT_SIZE; + this.h = SLOT_SIZE; + } + + @Override + public void draw(int mx, int my) { + + if (this.highlight) { + SLOT_HIGHLIGHTED.draw(this.x, this.y); + } else { + SLOT_DEFAULT.draw(this.x, this.y); + } + + if (this.info.hasImageOrItem()) { + final DrawableResource image = this.info.getImage(); + + if (image != null) { + image.draw(this.x + (SLOT_SIZE - 16) / 2, this.y + (SLOT_SIZE - 16) / 2); + } else { + GuiContainerManager.drawItem( + this.x + (SLOT_SIZE - 16) / 2, + this.y + (SLOT_SIZE - 16) / 2, + this.info.getItemStack(), + true); + } + } else { + ICON_CRAFTING.draw(this.x + (SLOT_SIZE - 16) / 2, this.y + (SLOT_SIZE - 16) / 2); + } + + NEIClientUtils.drawNEIOverlayText( + "x" + ReadableNumberConverter.INSTANCE.toWideReadableForm(this.stats.iterations), + new Rectangle4i(this.x + 1, this.y + 1, SLOT_SIZE - 2, SLOT_SIZE - 2), + 1, + 0xFFFFFF, + true, + Alignment.TopLeft); + + NEIClientUtils.drawNEIOverlayText( + ReadableNumberConverter.INSTANCE.toWideReadableForm(this.stats.recipeCount), + new Rectangle4i(this.x + 1, this.y + 1, SLOT_SIZE - 2, SLOT_SIZE - 2), + 1, + 0xFFFFFF, + true, + Alignment.BottomRight); + + if (mx >= this.x && mx < this.x + SLOT_SIZE && my >= this.y && my < this.y + SLOT_SIZE) { + NEIClientUtils.gl2DRenderContext( + () -> GuiDraw.drawRect(this.x + 1, this.y + 1, SLOT_SIZE - 2, SLOT_SIZE - 2, HOVER_COLOR)); + } + } + + } + + private static final int SLOT_SIZE = 18; + + private static final int SLOT_INLINE_GAP = 2; + private static final int SLOT_BLOCK_GAP = 2; + private static final int COLUMN_GAP = 10; + + private static final int HOVER_COLOR = 0x66999999; + + private static final DrawableResource BG_TEXTURE = new DrawableBuilder( + "nei:textures/gui/craftingtree.png", + 26, + 84, + 46, + 16).build(); + + private static final DrawableResource SLOT_DEFAULT = new DrawableBuilder( + "nei:textures/gui/craftingtree.png", + 68, + 26, + 18, + 18).build(); + + private static final DrawableResource SLOT_MISSING = new DrawableBuilder( + "nei:textures/gui/craftingtree.png", + 92, + 26, + 18, + 18).build(); + + private static final DrawableResource SLOT_CRAFTING = new DrawableBuilder( + "nei:textures/gui/craftingtree.png", + 116, + 26, + 18, + 18).build(); + + private static final DrawableResource SLOT_DISABLED = new DrawableBuilder( + "nei:textures/gui/craftingtree.png", + 140, + 26, + 18, + 18).build(); + + private static final DrawableResource SLOT_HIGHLIGHTED = new DrawableBuilder( + "nei:textures/gui/craftingtree.png", + 164, + 26, + 18, + 18).build(); + + private static final DrawableResource ICON_CRAFTING = new DrawableBuilder( + "nei:textures/gui/craftingtree.png", + 67, + 48, + 16, + 16).build(); + + private static final int Z_OFFSET = 100; + + public StatsPanel() { + final ScrollBar scrollbar = new ScrollBar().setTrackWidth(4) + .setThumbTexture(new DrawableBuilder("nei:textures/gui/craftingtree.png", 26, 100, 24, 4).build(), 0, 0) + .setTrackTexture(new DrawableBuilder("nei:textures/gui/craftingtree.png", 26, 104, 24, 4).build(), 0, 0) + .setTrackPadding(1, -5, 1, 0).setOverflowType(ScrollBar.OverflowType.AUTO); + + setHorizontalScroll(scrollbar); + setPaddingBlock(4, 4); + setPaddingInline(1, 1); + } + + public void rebuild(RecipeChainMath math, CraftingTreeGraph graph, boolean useInventorySnapshot, + Set sections, int widgetX, int widgetY, int widgetW, int widgetH) { + + clear(); + + final List labels = new ArrayList<>(); + final List> sectionGroups = new ArrayList<>(); + final List inputsAndAvailable = new ArrayList<>(); + + if (sections.contains(CraftingTreeState.StatsSection.INGREDIENTS_NEEDED)) { + inputsAndAvailable.addAll(collectInputs(math, useInventorySnapshot)); + } + + if (sections.contains(CraftingTreeState.StatsSection.INGREDIENTS_AVAILABLE)) { + inputsAndAvailable.addAll(collectAvailable(math)); + } + + if (!inputsAndAvailable.isEmpty()) { + labels.add(NEIClientUtils.translate("bookmark.tree.stats.ingredients")); + sectionGroups.add(inputsAndAvailable); + } + + final boolean showCraftingNeeded = sections.contains(CraftingTreeState.StatsSection.CRAFTING_NEEDED); + final boolean showCraftingAvailable = sections.contains(CraftingTreeState.StatsSection.CRAFTING_AVAILABLE); + + if (showCraftingNeeded || showCraftingAvailable) { + final List craftingNeededSlot = new ArrayList<>(); + final List craftingAvailableSlot = new ArrayList<>(); + final Map recipeMissing = new LinkedHashMap<>(); + final Map recipeLevel = new HashMap<>(); + + for (Map.Entry> entry : graph.childrenOf.entrySet()) { + final ItemTreeSlot node = entry.getKey(); + final boolean needsCrafting = graph.childrenNeedCraftingCache.contains(node); + + recipeMissing.merge(node.prefItem, needsCrafting, (a, b) -> a || b); + recipeLevel.merge(node.prefItem, treeLevel(node, graph.parentOf), Math::max); + } + + final List> sortedRecipeMissing = new ArrayList<>( + recipeMissing.entrySet()); + + sortedRecipeMissing.sort( + Comparator.>comparingInt(entry -> recipeLevel.get(entry.getKey())) + .thenComparing(entry -> entry.getKey().itemStack, ItemSorter.instance)); + + for (Map.Entry entry : sortedRecipeMissing) { + final BookmarkItem resultItem = entry.getKey(); + final long amount = resultItem.getAmount(); + + if (amount > 0) { + final boolean missingIngredients = entry.getValue(); + + if (missingIngredients ? !showCraftingNeeded : !showCraftingAvailable) { + continue; + } + + final List slot = missingIngredients ? craftingNeededSlot : craftingAvailableSlot; + + slot.add( + new ItemStatsSlot( + resultItem.itemStack, + resultItem.getStackSize(amount), + missingIngredients ? SLOT_DEFAULT : SLOT_CRAFTING, + resultItem.recipeId, + resultItem.getMultiplier())); + } + } + + final List craftingSlots = new ArrayList<>(craftingNeededSlot); + craftingSlots.addAll(craftingAvailableSlot); + + if (!craftingSlots.isEmpty()) { + labels.add(NEIClientUtils.translate("bookmark.tree.stats.crafting")); + sectionGroups.add(craftingSlots); + } + } + + final List outputsAndRemainders = new ArrayList<>(); + + if (sections.contains(CraftingTreeState.StatsSection.RESULTS)) { + outputsAndRemainders.addAll(collectOutputs(math)); + } + + if (sections.contains(CraftingTreeState.StatsSection.REMAINDERS)) { + outputsAndRemainders.addAll(collectRemainder(math)); + } + + if (!outputsAndRemainders.isEmpty()) { + labels.add(NEIClientUtils.translate("bookmark.tree.stats.results")); + sectionGroups.add(outputsAndRemainders); + } + + if (sections.contains(CraftingTreeState.StatsSection.HANDLERS)) { + final List handlers = collectHandlers(math); + + if (!handlers.isEmpty()) { + labels.add(NEIClientUtils.translate("bookmark.tree.stats.handlers")); + sectionGroups.add(handlers); + } + } + + layoutSections(labels, sectionGroups, widgetX, widgetY, widgetW, widgetH); + } + + private void layoutSections(List labels, List> sections, int widgetX, int widgetY, int widgetW, + int widgetH) { + final int maxRowWidth = Math.max(SLOT_SIZE, widgetW); + final int sectionCount = sections.size(); + final int[] sizes = new int[sectionCount]; + final int[] labelWidths = new int[sectionCount]; + final int[] columns = new int[sectionCount]; + final int maxRows = widgetH / ((GuiDraw.fontRenderer.FONT_HEIGHT + 4) + SLOT_SIZE * 2 + SLOT_BLOCK_GAP) > 3 ? 2 + : 1; + + for (int i = 0; i < sectionCount; i++) { + sizes[i] = sections.get(i).size(); + labelWidths[i] = GuiDraw.fontRenderer.getStringWidth(labels.get(i) + ":"); + columns[i] = sizes[i] == 0 ? 0 : (sizes[i] + maxRows - 1) / maxRows; + } + + int compactWidth = COLUMN_GAP * Math.max(0, sectionCount - 1); + + for (int i = 0; i < sectionCount; i++) { + compactWidth += sectionWidth(columns[i], labelWidths[i]); + } + + if (compactWidth <= maxRowWidth) { + int budget = (maxRowWidth - compactWidth) / (SLOT_SIZE + SLOT_INLINE_GAP); + + while (budget > 0) { + boolean grew = false; + + for (int i = 0; i < sectionCount && budget > 0; i++) { + if (columns[i] < sizes[i]) { + columns[i]++; + --budget; + grew = true; + } + } + + if (!grew) { + break; + } + } + } + + final List widgets = new ArrayList<>(); + int cursorX = 0; + int maxHeight = 0; + + for (int i = 0; i < sectionCount; i++) { + final int height = placeSection(widgets, labels.get(i), sections.get(i), columns[i], cursorX, 0); + maxHeight = Math.max(maxHeight, height); + cursorX += sectionWidth(columns[i], labelWidths[i]) + COLUMN_GAP; + } + + final int contentW = Math.max(0, cursorX - COLUMN_GAP); + final int contentH = maxHeight; + + final int maxVisibleH = maxRows * SLOT_SIZE + Math.max(0, maxRows - 1) * SLOT_BLOCK_GAP + + GuiDraw.fontRenderer.FONT_HEIGHT + + 4; + + final int visibleHeight = Math.min(contentH, maxVisibleH); + + this.w = widgetW; + this.x = widgetX; + this.h = visibleHeight + this.paddingBlockStart + this.paddingBlockEnd; + this.y = widgetY + widgetH - this.h; + + final int xShift = contentW < this.w ? (this.w - contentW) / 2 : 0; + + for (Widget widget : widgets) { + widget.x += xShift; + } + + setWidgets(widgets); + update(); + } + + private static int sectionWidth(int columns, int labelWidth) { + return Math.max(columns * SLOT_SIZE + Math.max(0, columns - 1) * SLOT_INLINE_GAP, labelWidth); + } + + private static int placeSection(List widgets, String label, List group, int columns, int x, int y) { + final SectionLabel sectionLabel = new SectionLabel(label + ":"); + sectionLabel.x = x; + sectionLabel.y = y; + widgets.add(sectionLabel); + + final int gridY = y + GuiDraw.fontRenderer.FONT_HEIGHT + 4; + final int rowWidth = columns * SLOT_SIZE + Math.max(0, columns - 1) * SLOT_INLINE_GAP; + int cursorX = 0; + int row = 0; + boolean any = false; + + for (Widget entry : group) { + + if (cursorX > 0) { + if (cursorX + SLOT_INLINE_GAP + SLOT_SIZE > rowWidth) { + cursorX = 0; + row++; + } else { + cursorX += SLOT_INLINE_GAP; + } + } else if (cursorX + SLOT_SIZE > rowWidth) { + cursorX = 0; + row++; + } + + entry.x = x + cursorX; + entry.y = gridY + row * (SLOT_SIZE + SLOT_BLOCK_GAP); + widgets.add(entry); + + cursorX += SLOT_SIZE; + any = true; + } + + final int rows = any ? row + 1 : 0; + return (gridY - y) + rows * SLOT_SIZE + Math.max(0, rows - 1) * SLOT_BLOCK_GAP; + } + + public ItemStack getStackMouseOver(int mouseX, int mouseY) { + final Widget widget = getWidgetUnderMouse(mouseX, mouseY); + return widget instanceof ItemStatsSlot slot ? slot.stack : null; + } + + public void setHighlight(SearchResult searchResult) { + for (Widget widget : getWidgets()) { + if (widget instanceof HandlerStatsSlot slot) { + slot.highlight = searchResult != null && searchResult.matchesGUID(slot.handlerName); + } else if (widget instanceof ItemStatsSlot slot) { + slot.highlight = searchResult != null && searchResult.matchesGUID(slot.stack); + } + } + } + + public Object getWidgetGUIDUnderMouse(int mouseX, int mouseY) { + final Widget widget = getWidgetUnderMouse(mouseX, mouseY); + + if (widget instanceof HandlerStatsSlot slot) { + return slot.handlerName; + } else if (widget instanceof ItemStatsSlot slot) { + return slot.stack; + } + + return null; + } + + public String getHandlerMouseOver(int mouseX, int mouseY) { + final Widget widget = getWidgetUnderMouse(mouseX, mouseY); + + if (widget instanceof HandlerStatsSlot slot) { + return slot.handlerName; + } else if (widget instanceof ItemStatsSlot slot && slot.recipeId != null) { + return slot.recipeId.getHandlerName(); + } + + return null; + } + + public RecipeId getRecipeIdMouseOver(int mouseX, int mouseY) { + final Widget widget = getWidgetUnderMouse(mouseX, mouseY); + return widget instanceof ItemStatsSlot slot ? slot.recipeId : null; + } + + public boolean isDraggingScrollbar() { + return canScrollHorizontal() && getHorizontalScroll().isMouseDragged(); + } + + @Override + public boolean onMouseWheel(int direction, int mouseX, int mouseY) { + + if (canScrollHorizontal() && boundsOutside().contains(mouseX, mouseY)) { + getHorizontalScroll().setScrollOffset(this, getHorizontalScrollOffset() - direction * MOUSE_SCROLL_SPEED); + return true; + } + + return super.onMouseWheel(direction, mouseX, mouseY); + } + + public void draw(int mouseX, int mouseY) { + GL11.glTranslatef(0, 0, Z_OFFSET); + GL11.glPushAttrib(GL11.GL_ENABLE_BIT | GL11.GL_COLOR_BUFFER_BIT | GL11.GL_LIGHTING_BIT); + GL11.glEnable(GL12.GL_RESCALE_NORMAL); + GL11.glColor4f(1, 1, 1, 1); + RenderHelper.enableGUIStandardItemLighting(); + GL11.glDisable(GL11.GL_LIGHTING); + + BG_TEXTURE.draw(this.x, this.y, this.w, this.h, 0, 0, 2, 0); + + super.draw(mouseX, mouseY); + + GL11.glPopAttrib(); + GL11.glTranslatef(0, 0, -Z_OFFSET); + } + + public void drawFull() { + GL11.glPushAttrib(GL11.GL_ENABLE_BIT | GL11.GL_COLOR_BUFFER_BIT | GL11.GL_LIGHTING_BIT); + GL11.glEnable(GL12.GL_RESCALE_NORMAL); + GL11.glColor4f(1, 1, 1, 1); + RenderHelper.enableGUIStandardItemLighting(); + GL11.glDisable(GL11.GL_LIGHTING); + + drawContent(-1, -1); + GL11.glPopAttrib(); + } + + private List collectAvailable(RecipeChainMath math) { + final ItemStackAmount items = new ItemStackAmount(); + final List widgets = new ArrayList<>(); + + for (BookmarkItem item : math.initialItems) { + final long amount = math.requiredAmount.getOrDefault(item, 0L); + + if (amount > 0) { + items.add(item.itemStack, item.getStackSize(amount)); + } + + } + + for (Map.Entry entry : items.entrySet()) { + if (entry.getValue() > 0) { + widgets.add( + new ItemStatsSlot(StackInfo.loadFromNBT(entry.getKey(), 0), entry.getValue(), SLOT_DEFAULT)); + } + } + + return widgets; + } + + private List collectInputs(RecipeChainMath math, boolean useInventorySnapshot) { + final ItemStackAmount items = new ItemStackAmount(); + final List widgets = new ArrayList<>(); + + for (BookmarkItem item : math.recipeIngredients) { + final long amount = math.requiredAmount.containsKey(math.preferredItems.get(item)) ? 0 + : math.requiredAmount.getOrDefault(item, item.getAmount()); + + if (amount > 0) { + items.add(item.itemStack, item.getStackSize(amount)); + } + } + + for (Map.Entry entry : items.entrySet()) { + if (entry.getValue() > 0) { + widgets.add( + new ItemStatsSlot( + StackInfo.loadFromNBT(entry.getKey(), 0), + entry.getValue(), + useInventorySnapshot ? SLOT_MISSING : SLOT_DEFAULT)); + } + } + + return widgets; + } + + private List collectOutputs(RecipeChainMath math) { + final ItemStackAmount items = new ItemStackAmount(); + final List widgets = new ArrayList<>(); + + for (BookmarkItem item : math.recipeResults) { + final long amount = item.getAmount() - math.requiredAmount.getOrDefault(item, 0L); + + if (amount > 0 && math.outputRecipes.containsKey(item.recipeId)) { + items.add(item.itemStack, item.getStackSize(amount)); + } + } + + for (Map.Entry entry : items.entrySet()) { + if (entry.getValue() > 0) { + widgets.add( + new ItemStatsSlot(StackInfo.loadFromNBT(entry.getKey(), 0), entry.getValue(), SLOT_DEFAULT)); + } + } + + return widgets; + } + + private List collectRemainder(RecipeChainMath math) { + final ItemStackAmount items = new ItemStackAmount(); + final List widgets = new ArrayList<>(); + + for (BookmarkItem item : math.recipeResults) { + final long amount = item.getAmount() - math.requiredAmount.getOrDefault(item, 0L); + + if (amount > 0 && !math.outputRecipes.containsKey(item.recipeId)) { + items.add(item.itemStack, item.getStackSize(amount)); + } + } + + for (ItemStack stack : math.containerItemsInventory) { + if (stack != null) { + items.add(stack); + } + } + + for (ItemStack stack : math.containerItemsCrafting) { + if (stack != null) { + items.add(stack); + } + } + + for (Map.Entry entry : items.entrySet()) { + if (entry.getValue() > 0) { + widgets.add( + new ItemStatsSlot(StackInfo.loadFromNBT(entry.getKey(), 0), entry.getValue(), SLOT_DISABLED)); + } + } + + return widgets; + } + + private List collectHandlers(RecipeChainMath math) { + final Map handlerStats = new HashMap<>(); + final List widgets = new ArrayList<>(); + + for (BookmarkItem item : math.recipeResults) { + final HandlerStats stats = handlerStats + .computeIfAbsent(item.recipeId.getHandlerName(), k -> new HandlerStats()); + stats.iterations += item.getMultiplier(); + stats.recipeCount++; + } + + for (Map.Entry entry : handlerStats.entrySet()) { + widgets.add(new HandlerStatsSlot(entry.getKey(), entry.getValue())); + } + + return widgets; + } + + private static int treeLevel(ItemTreeSlot node, Map parentOf) { + int level = 0; + + for (ItemTreeSlot current = parentOf.get(node); current != null; current = parentOf.get(current)) { + level++; + } + + return level; + } + + private static HandlerInfo handlerInfo(String handlerName) { + final HandlerInfo info = GuiRecipeTab.getHandlerInfo(handlerName, null); + return info != null ? info : GuiRecipeTab.DEFAULT_HANDLER_INFO; + } + +} diff --git a/src/main/java/codechicken/nei/bookmark/tree/StatsSectionsMenu.java b/src/main/java/codechicken/nei/bookmark/tree/StatsSectionsMenu.java new file mode 100644 index 00000000..e4a2b483 --- /dev/null +++ b/src/main/java/codechicken/nei/bookmark/tree/StatsSectionsMenu.java @@ -0,0 +1,121 @@ +package codechicken.nei.bookmark.tree; + +import static codechicken.lib.gui.GuiDraw.drawStringC; + +import org.lwjgl.opengl.GL11; + +import codechicken.lib.gui.GuiDraw; +import codechicken.nei.LayoutManager; +import codechicken.nei.NEIClientUtils; +import codechicken.nei.bookmark.tree.CraftingTreeState.StatsSection; + +class StatsSectionsMenu { + + private static final StatsSection[] SECTIONS = StatsSection.values(); + + private static final int ROW_HEIGHT = 16; + private static final int LABEL_PADDING = 10; + private static final int MIN_WIDTH = 70; + private static final int TOP_PADDING = 4; + private static final int Z_OFFSET = 500; + + private static final int COLOR_HOVER = 0xFFFFFFA0; + private static final int COLOR_ENABLED = 0xFFE0E0E0; + private static final int COLOR_DISABLED = 0xFFA0A0A0; + + public boolean visible = false; + + private int x; + private int y; + private int w; + private int h; + + public void open(int anchorX, int anchorY) { + this.visible = true; + + int maxLabelWidth = 0; + + for (StatsSection section : SECTIONS) { + maxLabelWidth = Math.max(maxLabelWidth, GuiDraw.fontRenderer.getStringWidth(label(section))); + } + + this.w = Math.max(MIN_WIDTH, maxLabelWidth + LABEL_PADDING * 2); + this.h = TOP_PADDING + SECTIONS.length * ROW_HEIGHT; + this.x = anchorX; + this.y = anchorY; + } + + public void close() { + this.visible = false; + } + + public boolean isInWidget(int mouseX, int mouseY) { + return this.visible && mouseX >= this.x + && mouseX < this.x + this.w + && mouseY >= this.y + && mouseY < this.y + this.h; + } + + public boolean handleClick(int mouseX, int mouseY, CraftingTreeState uiState) { + + if (!isInWidget(mouseX, mouseY)) { + return false; + } + + final int relativeY = mouseY - this.y - TOP_PADDING; + + if (relativeY >= 0) { + final int index = relativeY / ROW_HEIGHT; + + if (index < SECTIONS.length) { + uiState.toggleStatsSection(SECTIONS[index]); + } + } + + return true; + } + + public void draw(int mouseX, int mouseY, CraftingTreeState uiState) { + + if (!this.visible) { + return; + } + + GL11.glTranslatef(0, 0, Z_OFFSET); + + for (int i = 0; i < SECTIONS.length; i++) { + final StatsSection section = SECTIONS[i]; + final int rowY = this.y + TOP_PADDING + i * ROW_HEIGHT; + final boolean hover = mouseX >= this.x && mouseX < this.x + this.w + && mouseY >= rowY + && mouseY < rowY + ROW_HEIGHT; + final boolean checked = uiState.visibleStatsSections.contains(section); + final int color = hover ? COLOR_HOVER : checked ? COLOR_ENABLED : COLOR_DISABLED; + + if (checked) { + GL11.glColor4f(1.0F, 1.0F, 1.0F, 1.0F); + LayoutManager.drawButtonBackground(this.x, rowY, this.w, ROW_HEIGHT, false, 1); + } else { + GL11.glColor4f(0.65F, 0.65F, 0.65F, 1.0F); + LayoutManager.drawButtonBackground(this.x, rowY, this.w, ROW_HEIGHT, false, 0); + } + + drawStringC(label(section), this.x, rowY, this.w, ROW_HEIGHT, color); + } + + GL11.glColor4f(1, 1, 1, 1); + GL11.glTranslatef(0, 0, -Z_OFFSET); + } + + private static String label(StatsSection section) { + return NEIClientUtils.translate(switch (section) { + case INGREDIENTS_NEEDED -> "bookmark.tree.stats.ingredients_needed"; + case INGREDIENTS_AVAILABLE -> "bookmark.tree.stats.ingredients_available"; + case CRAFTING_NEEDED -> "bookmark.tree.stats.crafting_needed"; + case CRAFTING_AVAILABLE -> "bookmark.tree.stats.crafting_available"; + case RESULTS -> "bookmark.tree.stats.results"; + case REMAINDERS -> "bookmark.tree.stats.remainders"; + case HANDLERS -> "bookmark.tree.stats.handlers"; + }); + } +} diff --git a/src/main/java/codechicken/nei/bookmark/tree/TreeOverlayButton.java b/src/main/java/codechicken/nei/bookmark/tree/TreeOverlayButton.java new file mode 100644 index 00000000..5becebf2 --- /dev/null +++ b/src/main/java/codechicken/nei/bookmark/tree/TreeOverlayButton.java @@ -0,0 +1,75 @@ +package codechicken.nei.bookmark.tree; + +import java.util.List; +import java.util.Map; + +import net.minecraft.client.Minecraft; + +import org.lwjgl.opengl.GL11; + +import codechicken.nei.NEIClientUtils; +import codechicken.nei.drawable.DrawableBuilder; +import codechicken.nei.drawable.DrawableResource; +import codechicken.nei.recipe.GuiRecipeButton; +import codechicken.nei.recipe.Recipe; +import codechicken.nei.recipe.RecipeHandlerRef; + +public class TreeOverlayButton extends GuiRecipeButton { + + protected static final DrawableResource ICON_FILL = new DrawableBuilder( + "nei:textures/nei_sprites.png", + 28, + 76, + 9, + 10).build(); + protected static final int BUTTON_ID_SHIFT = 4; + + public final GuiCraftingTree treeGui; + + public TreeOverlayButton(GuiCraftingTree treeGui, RecipeHandlerRef handlerRef, int x, int y) { + super(handlerRef, x, y, handlerRef.recipeIndex + BUTTON_ID_SHIFT, "+"); + this.treeGui = treeGui; + } + + @Override + public List handleTooltip(List currenttip) { + currenttip.add(NEIClientUtils.translate("bookmark.tree.overlay")); + return currenttip; + } + + @Override + public Map handleHotkeys(int mousex, int mousey, Map hotkeys) { + return hotkeys; + } + + @Override + public void mouseReleased(int mouseX, int mouseY) { + if (this.treeGui != null) { + this.treeGui.addRecipe(Recipe.of(this.handlerRef)); + } + } + + @Override + protected void drawContent(Minecraft minecraft, int y, int x, boolean mouseOver) { + final int iconX = this.xPosition + (this.width - ICON_FILL.width - 1) / 2; + final int iconY = this.yPosition + (this.height - ICON_FILL.height) / 2; + + GL11.glColor4f(1, 1, 1, this.enabled ? 1 : 0.5f); + GL11.glEnable(GL11.GL_BLEND); + GL11.glBlendFunc(GL11.GL_SRC_ALPHA, GL11.GL_ONE_MINUS_SRC_ALPHA); + ICON_FILL.draw(iconX, iconY); + GL11.glDisable(GL11.GL_BLEND); + GL11.glColor4f(1, 1, 1, 1); + } + + @Override + public void drawItemOverlay() {} + + public Recipe getRecipe() { + return Recipe.of(this.handlerRef); + } + + @Override + public void lastKeyTyped(char keyChar, int keyID) {} + +} diff --git a/src/main/java/codechicken/nei/drawable/DrawableResource.java b/src/main/java/codechicken/nei/drawable/DrawableResource.java index f73b9fd1..a2d5c8f1 100644 --- a/src/main/java/codechicken/nei/drawable/DrawableResource.java +++ b/src/main/java/codechicken/nei/drawable/DrawableResource.java @@ -40,6 +40,10 @@ public class DrawableResource extends Image { return height + paddingTop + paddingBottom; } + public void bindTexture() { + Minecraft.getMinecraft().getTextureManager().bindTexture(this.resourceLocation); + } + public void draw(int xOffset, int yOffset) { draw(xOffset, yOffset, 0, 0, 0, 0); } @@ -50,7 +54,7 @@ public class DrawableResource extends Image { final int height = this.height - maskBottom - maskTop; GL11.glEnable(GL11.GL_TEXTURE_2D); - Minecraft.getMinecraft().getTextureManager().bindTexture(this.resourceLocation); + bindTexture(); drawModalRectWithCustomSizedTexture(xOffset + maskLeft, yOffset + maskTop, maskLeft, maskTop, width, height); if (!is2DTexture) GL11.glDisable(GL11.GL_TEXTURE_2D); } @@ -72,7 +76,7 @@ public class DrawableResource extends Image { final int remainderHeight = tileHeight - (tileHeightCount * middleHeight); GL11.glEnable(GL11.GL_TEXTURE_2D); - Minecraft.getMinecraft().getTextureManager().bindTexture(this.resourceLocation); + bindTexture(); // middle parts for (int tileW = 0; tileW <= tileWidthCount; tileW++) { diff --git a/src/main/java/codechicken/nei/guihook/GuiContainerManager.java b/src/main/java/codechicken/nei/guihook/GuiContainerManager.java index 1a5fb953..07432ed2 100644 --- a/src/main/java/codechicken/nei/guihook/GuiContainerManager.java +++ b/src/main/java/codechicken/nei/guihook/GuiContainerManager.java @@ -314,7 +314,7 @@ public class GuiContainerManager { } private static int modelviewDepth = -1; - private static boolean contextEnabled = false; + private static int contextDepth = 0; private static final ItemStackSet renderingErrorItems = new ItemStackSet(); public static void drawItem(int offsetX, int offsetY, ItemStack itemstack, FontRenderer fontRenderer, @@ -411,16 +411,15 @@ public class GuiContainerManager { } public static void enableMatrixStackLogging() { - if (!contextEnabled) { + if (contextDepth == 0) { GL11.glPushAttrib(GL11.GL_ENABLE_BIT | GL11.GL_COLOR_BUFFER_BIT | GL11.GL_LIGHTING_BIT); modelviewDepth = GL11.glGetInteger(GL11.GL_MODELVIEW_STACK_DEPTH); - contextEnabled = true; } + contextDepth++; } public static void disableMatrixStackLogging() { - if (contextEnabled) { - contextEnabled = false; + if (contextDepth > 0 && --contextDepth == 0) { modelviewDepth = -1; GL11.glPopAttrib(); } @@ -621,7 +620,7 @@ public class GuiContainerManager { if (!secondDisplayName.isEmpty()) { tooltip.add(1, EnumChatFormatting.DARK_GRAY + secondDisplayName + GuiDraw.TOOLTIP_LINESPACE); - } else { + } else if (!tooltip.get(0).startsWith(GuiDraw.TOOLTIP_HANDLER)) { tooltip.set(0, tooltip.get(0) + GuiDraw.TOOLTIP_LINESPACE); } diff --git a/src/main/java/codechicken/nei/item/FluidDisplayRenderer.java b/src/main/java/codechicken/nei/item/FluidDisplayRenderer.java new file mode 100644 index 00000000..1518a975 --- /dev/null +++ b/src/main/java/codechicken/nei/item/FluidDisplayRenderer.java @@ -0,0 +1,92 @@ +package codechicken.nei.item; + +import net.minecraft.client.Minecraft; +import net.minecraft.client.gui.FontRenderer; +import net.minecraft.client.renderer.Tessellator; +import net.minecraft.client.renderer.texture.TextureMap; +import net.minecraft.item.ItemStack; +import net.minecraft.util.IIcon; +import net.minecraftforge.client.IItemRenderer; +import net.minecraftforge.fluids.FluidStack; + +import org.lwjgl.opengl.GL11; + +import codechicken.nei.util.ReadableNumberConverter; + +public class FluidDisplayRenderer implements IItemRenderer { + + @Override + public boolean handleRenderType(ItemStack item, ItemRenderType type) { + return type == ItemRenderType.INVENTORY; + } + + @Override + public boolean shouldUseRenderHelper(ItemRenderType type, ItemStack item, ItemRendererHelper helper) { + return false; + } + + @Override + public void renderItem(ItemRenderType type, ItemStack item, Object... data) { + if (type != ItemRenderType.INVENTORY || !(item.getItem() instanceof ItemFluidDisplay fluidDisplay)) { + return; + } + + renderIcon(item, fluidDisplay); + renderAmountOverlay(item, fluidDisplay); + } + + private void renderIcon(ItemStack item, ItemFluidDisplay fluidDisplay) { + final IIcon icon = fluidDisplay.getIconIndex(item); + if (icon == null) { + return; + } + + final int color = fluidDisplay.getColorFromItemStack(item, 0); + final float red = (color >> 16 & 0xFF) / 255F; + final float green = (color >> 8 & 0xFF) / 255F; + final float blue = (color & 0xFF) / 255F; + + Minecraft.getMinecraft().getTextureManager().bindTexture(TextureMap.locationBlocksTexture); + GL11.glColor4f(red, green, blue, 1F); + GL11.glEnable(GL11.GL_BLEND); + GL11.glBlendFunc(GL11.GL_SRC_ALPHA, GL11.GL_ONE_MINUS_SRC_ALPHA); + + final Tessellator tessellator = Tessellator.instance; + tessellator.startDrawingQuads(); + tessellator.addVertexWithUV(0, 16, 0, icon.getMinU(), icon.getMaxV()); + tessellator.addVertexWithUV(16, 16, 0, icon.getMaxU(), icon.getMaxV()); + tessellator.addVertexWithUV(16, 0, 0, icon.getMaxU(), icon.getMinV()); + tessellator.addVertexWithUV(0, 0, 0, icon.getMinU(), icon.getMinV()); + tessellator.draw(); + + GL11.glColor4f(1F, 1F, 1F, 1F); + GL11.glDisable(GL11.GL_BLEND); + } + + private void renderAmountOverlay(ItemStack item, ItemFluidDisplay fluidDisplay) { + final FluidStack fluidStack = fluidDisplay.getFluid(item); + if (fluidStack == null || fluidStack.amount <= 0) { + return; + } + + String amountString = ""; + + if (fluidStack.amount < 10_000) { + amountString = String.valueOf(fluidStack.amount) + "L"; + } else { + amountString = ReadableNumberConverter.INSTANCE.toWideReadableForm(fluidStack.amount) + "L"; + } + + final FontRenderer fontRender = Minecraft.getMinecraft().fontRenderer; + float smallTextScale = fontRender.getUnicodeFlag() ? 3F / 4F : 1F / 2F; + GL11.glPushAttrib(GL11.GL_ENABLE_BIT); + GL11.glDisable(GL11.GL_BLEND); + GL11.glPushMatrix(); + GL11.glScalef(smallTextScale, smallTextScale, 1.0f); + + fontRender + .drawString(amountString, 0, (int) (16 / smallTextScale) - fontRender.FONT_HEIGHT + 1, 0xFFFFFF, true); + GL11.glPopMatrix(); + GL11.glPopAttrib(); + } +} diff --git a/src/main/java/codechicken/nei/item/ItemFluidDisplay.java b/src/main/java/codechicken/nei/item/ItemFluidDisplay.java new file mode 100644 index 00000000..fd5e8fc2 --- /dev/null +++ b/src/main/java/codechicken/nei/item/ItemFluidDisplay.java @@ -0,0 +1,196 @@ +package codechicken.nei.item; + +import java.util.List; + +import net.minecraft.client.renderer.texture.IIconRegister; +import net.minecraft.creativetab.CreativeTabs; +import net.minecraft.entity.player.EntityPlayer; +import net.minecraft.item.Item; +import net.minecraft.item.ItemStack; +import net.minecraft.nbt.NBTTagCompound; +import net.minecraft.util.EnumChatFormatting; +import net.minecraft.util.IIcon; +import net.minecraftforge.client.MinecraftForgeClient; +import net.minecraftforge.fluids.Fluid; +import net.minecraftforge.fluids.FluidRegistry; +import net.minecraftforge.fluids.FluidStack; +import net.minecraftforge.fluids.IFluidContainerItem; + +import codechicken.nei.NEIClientConfig; +import codechicken.nei.NEIClientUtils; +import cpw.mods.fml.relauncher.Side; +import cpw.mods.fml.relauncher.SideOnly; + +public class ItemFluidDisplay extends Item implements IFluidContainerItem { + + public static ItemFluidDisplay INSTANCE; + + public final static CreativeTabs tabFluids = new CreativeTabs("neiFluids") { + + @Override + public Item getTabIconItem() { + return INSTANCE; + } + + @Override + @SideOnly(Side.CLIENT) + public ItemStack getIconItemStack() { + return createStack(new FluidStack(FluidRegistry.WATER, 0)); + } + }; + + public ItemFluidDisplay() { + setMaxStackSize(1); + setUnlocalizedName("nei.fluidDisplay"); + INSTANCE = this; + + setCreativeTab(tabFluids); + MinecraftForgeClient.registerItemRenderer(this, new FluidDisplayRenderer()); + } + + public static ItemStack createStack(FluidStack fluidStack) { + if (fluidStack == null || fluidStack.getFluid() == null) { + return null; + } + + int fluidId; + + try { + fluidId = FluidRegistry.getFluidID(fluidStack.getFluid()); + } catch (Exception e) { + NEIClientConfig.logger.error("Failed to get fluid id for: " + fluidStack.getFluid().getName(), e); + return null; + } + + final ItemStack stack = new ItemStack(INSTANCE, 1, fluidId); + final NBTTagCompound nbtTag = new NBTTagCompound(); + + if (fluidStack.tag != null) { + nbtTag.setTag("FluidTag", fluidStack.tag.copy()); + } + + nbtTag.setInteger("neiFluidDisplayAmount", fluidStack.amount); + stack.setTagCompound(nbtTag); + return stack; + } + + @Override + public FluidStack getFluid(ItemStack stack) { + + if (stack == null || !(stack.getItem() instanceof ItemFluidDisplay) || !stack.hasTagCompound()) { + return null; + } + + final Fluid fluid = FluidRegistry.getFluid(stack.getItemDamage()); + + if (fluid == null) { + return null; + } + + final NBTTagCompound nbTag = stack.getTagCompound(); + final FluidStack fluidStack = new FluidStack(fluid, nbTag.getInteger("neiFluidDisplayAmount")); + + if (nbTag.hasKey("FluidTag")) { + fluidStack.tag = nbTag.getCompoundTag("FluidTag"); + } + + return fluidStack; + } + + @Override + public int getCapacity(ItemStack stack) { + + if (stack == null || !(stack.getItem() instanceof ItemFluidDisplay) || !stack.hasTagCompound()) { + return 0; + } + + return stack.getTagCompound().getInteger("neiFluidDisplayAmount"); + } + + @Override + public int fill(ItemStack container, FluidStack resource, boolean doFill) { + return 0; + } + + @Override + public FluidStack drain(ItemStack container, int maxDrain, boolean doDrain) { + return null; + } + + @Override + public IIcon getIconFromDamage(int metadata) { + final Fluid fluid = FluidRegistry.getFluid(metadata); + final IIcon icon = fluid != null ? fluid.getStillIcon() : null; + return icon != null ? icon : FluidRegistry.WATER.getStillIcon(); + } + + @Override + public int getSpriteNumber() { + return 0; + } + + @Override + public int getColorFromItemStack(ItemStack stack, int renderPass) { + final Fluid fluid = stack != null ? FluidRegistry.getFluid(stack.getItemDamage()) : null; + return fluid != null ? fluid.getColor() : 0xFFFFFF; + } + + @Override + public String getItemStackDisplayName(ItemStack stack) { + final Fluid fluid = stack != null ? FluidRegistry.getFluid(stack.getItemDamage()) : null; + return fluid != null ? fluid.getLocalizedName() : super.getItemStackDisplayName(stack); + } + + @Override + public String getUnlocalizedName(ItemStack stack) { + final Fluid fluid = stack != null ? FluidRegistry.getFluid(stack.getItemDamage()) : null; + return fluid != null ? fluid.getUnlocalizedName() : super.getUnlocalizedName(stack); + } + + @Override + @SideOnly(Side.CLIENT) + public void addInformation(ItemStack stack, EntityPlayer player, List tooltip, boolean advanced) { + final Fluid fluid = FluidRegistry.getFluid(stack.getItemDamage()); + + if (fluid == null) { + return; + } + + if (NEIClientConfig.getBooleanSetting("inventory.tooltip.showFluidTemperature")) { + tooltip.add( + EnumChatFormatting.RED + NEIClientUtils.translate( + "inventory.tooltip.temperature.fluid", + NEIClientUtils.formatNumber(fluid.getTemperature()))); + } + + if (NEIClientConfig.getBooleanSetting("inventory.tooltip.showFluidState")) { + tooltip.add( + EnumChatFormatting.GREEN + NEIClientUtils.translate( + "inventory.tooltip.state.fluid", + NEIClientUtils.translate( + fluid.isGaseous() ? "inventory.tooltip.state.fluid.gas" + : "inventory.tooltip.state.fluid.liquid"))); + } + + } + + @Override + public void registerIcons(IIconRegister register) {} + + @Override + @SideOnly(Side.CLIENT) + public void getSubItems(Item aItem, CreativeTabs aTab, List aList) { + for (int i = 0, j = FluidRegistry.getMaxID(); i < j; i++) { + final Fluid fluid = FluidRegistry.getFluid(i); + if (fluid == null) { + continue; + } + + final ItemStack stack = ItemFluidDisplay.createStack(new FluidStack(fluid, 0)); + if (stack != null) { + aList.add(stack); + } + } + } + +} diff --git a/src/main/java/codechicken/nei/recipe/GuiFavoriteButton.java b/src/main/java/codechicken/nei/recipe/GuiFavoriteButton.java index 9340c49a..c3be9d55 100644 --- a/src/main/java/codechicken/nei/recipe/GuiFavoriteButton.java +++ b/src/main/java/codechicken/nei/recipe/GuiFavoriteButton.java @@ -23,6 +23,7 @@ import codechicken.nei.KeyManager; import codechicken.nei.LayoutManager; import codechicken.nei.NEIClientConfig; import codechicken.nei.NEIClientUtils; +import codechicken.nei.bookmark.tree.GuiCraftingTree; import codechicken.nei.drawable.DrawableBuilder; import codechicken.nei.drawable.DrawableResource; import codechicken.nei.recipe.Recipe.RecipeId; @@ -127,6 +128,12 @@ public class GuiFavoriteButton extends GuiRecipeButton { saveRecipeInBookmark(); } + if (KeyManager.isKeyDown("bookmark.open_crafting_tree") && NEIClientUtils.shiftKey() + && saveRecipeInBookmark()) { + final int groupId = ItemPanels.bookmarkPanel.getGrid().getNextGroupId() - 1; + GuiCraftingTree.openCraftingTreeGui(ItemPanels.bookmarkPanel.getGrid(), groupId); + } + } @Override @@ -135,6 +142,10 @@ public class GuiFavoriteButton extends GuiRecipeButton { KeyManager.getKeyName("bookmark.add", NEIClientUtils.SHIFT_HASH), translate("recipe.favorite.bookmark_recipe")); + hotkeys.put( + KeyManager.getKeyName("bookmark.open_crafting_tree", NEIClientUtils.SHIFT_HASH), + NEIClientUtils.translate("bookmark.group.open_crafting_tree")); + if (this.recipe.getResults().size() > 1) { hotkeys.put( NEIMouseUtils.getKeyName(NEIMouseUtils.MOUSE_BTN_NONE + NEIMouseUtils.MOUSE_SCROLL), @@ -189,8 +200,8 @@ public class GuiFavoriteButton extends GuiRecipeButton { return true; } - public void saveRecipeInBookmark() { - ItemPanels.bookmarkPanel.addGroup(getRecipesTree(getRecipe()), BookmarkViewMode.TODO_LIST, true); + public boolean saveRecipeInBookmark() { + return ItemPanels.bookmarkPanel.addGroup(getRecipesTree(getRecipe()), BookmarkViewMode.TODO_LIST, true); } private List getRecipesTree(Recipe mainRecipe) { diff --git a/src/main/java/codechicken/nei/recipe/GuiOverlayButton.java b/src/main/java/codechicken/nei/recipe/GuiOverlayButton.java index f9564867..344235da 100644 --- a/src/main/java/codechicken/nei/recipe/GuiOverlayButton.java +++ b/src/main/java/codechicken/nei/recipe/GuiOverlayButton.java @@ -29,6 +29,15 @@ import codechicken.nei.util.NEIMouseUtils; public class GuiOverlayButton extends GuiRecipeButton { + protected static DrawableResource notPresent = new DrawableBuilder( + "nei:textures/nei_tabbed_sprites.png", + 0, + 40, + 8, + 8).build(); + protected static DrawableResource present = new DrawableBuilder("nei:textures/nei_tabbed_sprites.png", 8, 40, 8, 8) + .build(); + public enum ItemOverlayFormat { BACKGROUND, @@ -58,11 +67,23 @@ public class GuiOverlayButton extends GuiRecipeButton { } public void draw(ItemOverlayFormat format) { - LayoutManager.drawItemPresenceOverlay( - this.slot.relx, - this.slot.rely, - this.isPresent, - format == ItemOverlayFormat.BACKGROUND); + + if (format == ItemOverlayFormat.BACKGROUND) { + NEIClientUtils.gl2DRenderContext( + () -> drawRect( + this.slot.relx, + this.slot.rely, + this.slot.width, + this.slot.height, + isPresent ? 0x8000AA00 : 0x80AA0000)); + } else { + final DrawableResource icon = isPresent ? present : notPresent; + LayoutManager.drawIcon( + this.slot.relx + this.slot.width - icon.width, + this.slot.rely + this.slot.height - icon.height, + icon); + } + } } @@ -256,6 +277,11 @@ public class GuiOverlayButton extends GuiRecipeButton { return this.itemPresenceCache; } + @Override + public void onPermutationsChanged() { + this.itemPresenceCache.clear(); + } + public void setRequireShiftForOverlayRecipe(boolean require) { this.requireShiftForOverlayRecipe = require; updateEnabled(); @@ -291,30 +317,15 @@ public class GuiOverlayButton extends GuiRecipeButton { } protected List presenceOverlay(List ingredients) { - final List states = new ArrayList<>(); - final List invStacks = this.firstGui.inventorySlots.inventorySlots.stream() - .filter( - s -> s != null && s.getStack() != null - && s.getStack().stackSize > 0 - && s.isItemValid(s.getStack()) - && s.canTakeStack(this.firstGui.mc.thePlayer)) - .map(s -> s.getStack().copy()).collect(Collectors.toCollection(ArrayList::new)); - - for (PositionedStack stack : ingredients) { - boolean found = false; - - for (ItemStack is : invStacks) { - if (is.stackSize > 0 && stack.contains(is)) { - is.stackSize--; - found = true; - break; - } - } - - states.add(new ItemOverlayState(stack, found)); - } - - return states; + return NEIClientUtils.presenceOverlay( + ingredients, + this.firstGui.inventorySlots.inventorySlots.stream() + .filter( + s -> s != null && s.getStack() != null + && s.getStack().stackSize > 0 + && s.isItemValid(s.getStack()) + && s.canTakeStack(this.firstGui.mc.thePlayer)) + .map(s -> s.getStack().copy()).collect(Collectors.toList())); } public void overlayRecipe(boolean shift) { diff --git a/src/main/java/codechicken/nei/recipe/GuiRecipeButton.java b/src/main/java/codechicken/nei/recipe/GuiRecipeButton.java index 0dbc478a..f24d9f92 100644 --- a/src/main/java/codechicken/nei/recipe/GuiRecipeButton.java +++ b/src/main/java/codechicken/nei/recipe/GuiRecipeButton.java @@ -65,6 +65,10 @@ public abstract class GuiRecipeButton extends GuiNEIButton { } + public void onPermutationsChanged() { + + } + public boolean mouseScrolled(int scroll) { return false; } diff --git a/src/main/java/codechicken/nei/recipe/NEIRecipeWidget.java b/src/main/java/codechicken/nei/recipe/NEIRecipeWidget.java index a761b49a..2856e66a 100644 --- a/src/main/java/codechicken/nei/recipe/NEIRecipeWidget.java +++ b/src/main/java/codechicken/nei/recipe/NEIRecipeWidget.java @@ -175,6 +175,10 @@ public class NEIRecipeWidget extends Widget { if (!NEIClientUtils.shiftKey() && ((this.cycleticks++) / 20) != this.lastcycle || this.lastcycle == -1) { this.lastcycle = this.cycleticks / 20; updatePermutations(); + + for (GuiRecipeButton button : getRecipeButtonsIfInit()) { + button.onPermutationsChanged(); + } } for (GuiRecipeButton button : getRecipeButtons()) { diff --git a/src/main/java/codechicken/nei/recipe/RecipeTooltipLineHandler.java b/src/main/java/codechicken/nei/recipe/RecipeTooltipLineHandler.java index 8e69de7d..147d7a53 100644 --- a/src/main/java/codechicken/nei/recipe/RecipeTooltipLineHandler.java +++ b/src/main/java/codechicken/nei/recipe/RecipeTooltipLineHandler.java @@ -13,6 +13,7 @@ import codechicken.nei.drawable.DrawableResource; import codechicken.nei.guihook.GuiContainerManager; import codechicken.nei.recipe.Recipe.RecipeId; import codechicken.nei.scroll.GuiHelper; +import codechicken.nei.util.ReadableNumberConverter; public class RecipeTooltipLineHandler implements ITooltipLineHandler { @@ -32,9 +33,15 @@ public class RecipeTooltipLineHandler implements ITooltipLineHandler { protected NEIRecipeWidget widget = null; protected RecipeId recipeId = null; protected boolean createdGui = false; + protected long multiplier = 0; + + public RecipeTooltipLineHandler(RecipeId recipeId, long multiplier) { + this.recipeId = recipeId; + this.multiplier = multiplier; + } public RecipeTooltipLineHandler(RecipeId recipeId) { - this.recipeId = recipeId; + this(recipeId, 0); } public ItemStack getItemStack() { @@ -45,6 +52,10 @@ public class RecipeTooltipLineHandler implements ITooltipLineHandler { return this.recipeId; } + public long getMultiplier() { + return this.multiplier; + } + @Override public Dimension getSize() { @@ -104,6 +115,14 @@ public class RecipeTooltipLineHandler implements ITooltipLineHandler { GuiDraw.drawRect(BG_PADDING, BG_PADDING, size.width - BG_PADDING * 2, 12, 0x30000000); GuiDraw.drawStringC(this.recipeName, this.widget.w / 2, BG_PADDING + 2, 0xffffff); + if (this.multiplier > 0) { + GuiDraw.drawString( + "x" + ReadableNumberConverter.INSTANCE.toWideReadableForm(this.multiplier), + BG_PADDING + 2, + BG_PADDING + 2, + 0xffffff); + } + GuiHelper.useScissor( this.widget.x, this.widget.y, diff --git a/src/main/java/codechicken/nei/recipe/StackInfo.java b/src/main/java/codechicken/nei/recipe/StackInfo.java index eb4d0c71..02efdd83 100644 --- a/src/main/java/codechicken/nei/recipe/StackInfo.java +++ b/src/main/java/codechicken/nei/recipe/StackInfo.java @@ -21,6 +21,7 @@ import codechicken.nei.LRUCache; import codechicken.nei.api.IStackStringifyHandler; import codechicken.nei.api.ItemInfo; import codechicken.nei.recipe.stackinfo.DefaultStackStringifyHandler; +import codechicken.nei.recipe.stackinfo.FluidDisplayStackStringifyHandler; import codechicken.nei.recipe.stackinfo.GTFluidStackStringifyHandler; import codechicken.nei.util.ItemStackKey; import codechicken.nei.util.NBTHelper; @@ -40,6 +41,7 @@ public class StackInfo { static { stackStringifyHandlers.add(new DefaultStackStringifyHandler()); + stackStringifyHandlers.add(new FluidDisplayStackStringifyHandler()); stackStringifyHandlers.add(new GTFluidStackStringifyHandler()); } @@ -90,6 +92,19 @@ public class StackInfo { return result == null ? stack : result; } + public static boolean isFluidDisplayItem(ItemStack stack) { + if (stack == null) { + return false; + } + + for (int i = stackStringifyHandlers.size() - 1; i >= 0; i--) { + if (stackStringifyHandlers.get(i).isFluidDisplayItem(stack)) { + return true; + } + } + return false; + } + public static void pauseItemDamageSound(boolean pause) { if (isPausedItemDamageSound != (isPausedItemDamageSound = pause)) { for (IStackStringifyHandler handler : stackStringifyHandlers) { diff --git a/src/main/java/codechicken/nei/recipe/chain/RecipeChainMath.java b/src/main/java/codechicken/nei/recipe/chain/RecipeChainMath.java index a0dbb33b..2dda27d4 100644 --- a/src/main/java/codechicken/nei/recipe/chain/RecipeChainMath.java +++ b/src/main/java/codechicken/nei/recipe/chain/RecipeChainMath.java @@ -1,5 +1,6 @@ package codechicken.nei.recipe.chain; +import java.util.ArrayDeque; import java.util.ArrayList; import java.util.Collections; import java.util.HashMap; @@ -25,7 +26,7 @@ import codechicken.nei.recipe.StackInfo; public class RecipeChainMath { - private static class ContainerItemResult { + protected static class ContainerItemResult { public ItemStack stack; public ItemStack containerItem; @@ -48,13 +49,19 @@ public class RecipeChainMath { public final List recipeIngredients = new ArrayList<>(); public final List recipeResults = new ArrayList<>(); + protected final Map> ingredientsByRecipe = new HashMap<>(); + protected final Map> resultsByRecipe = new HashMap<>(); + public final Map preferredItems = new HashMap<>(); public final Map requiredAmount = new HashMap<>(); - public final List containerItems = new ArrayList<>(); + + public final List containerItemsCrafting = new ArrayList<>(); + public final List containerItemsInventory = new ArrayList<>(); + private final List containerItemsBlacklist = new ArrayList<>(); - private RecipeChainMath(List recipeItems, Set collapsedRecipes) { + protected RecipeChainMath(List recipeItems, Set collapsedRecipes) { final Map multipliers = new HashMap<>(); for (BookmarkItem item : recipeItems) { @@ -70,6 +77,8 @@ public class RecipeChainMath { } } + rebuildRecipeIndex(); + for (Map.Entry entry : multipliers.entrySet()) { if (entry.getValue() > 1 || collapsedRecipes.contains(entry.getKey())) { collectPreferredItems(entry.getKey(), this.preferredItems, new HashSet<>()); @@ -125,14 +134,26 @@ public class RecipeChainMath { } + private void rebuildRecipeIndex() { + this.ingredientsByRecipe.clear(); + this.resultsByRecipe.clear(); + + for (BookmarkItem item : this.recipeIngredients) { + this.ingredientsByRecipe.computeIfAbsent(item.recipeId, k -> new ArrayList<>()).add(item); + } + + for (BookmarkItem item : this.recipeResults) { + this.resultsByRecipe.computeIfAbsent(item.recipeId, k -> new ArrayList<>()).add(item); + } + } + private void collectPreferredItems(RecipeId recipeId, Map preferredItems, Set visited) { visited.add(recipeId); - for (BookmarkItem ingrItem : this.recipeIngredients) { - if (!ingrItem.emptyFactor() && recipeId.equals(ingrItem.recipeId) - && !preferredItems.containsKey(ingrItem)) { + for (BookmarkItem ingrItem : this.ingredientsByRecipe.getOrDefault(recipeId, Collections.emptyList())) { + if (!ingrItem.emptyFactor() && !preferredItems.containsKey(ingrItem)) { BookmarkItem activeItem = null; BookmarkItem prefItem = null; @@ -178,8 +199,8 @@ public class RecipeChainMath { private void removeLoop(RecipeId recipeId, Map preferredItems, Set visited) { visited.add(recipeId); - for (BookmarkItem ingrItem : this.recipeIngredients) { - if (!ingrItem.emptyFactor() && recipeId.equals(ingrItem.recipeId) && preferredItems.containsKey(ingrItem)) { + for (BookmarkItem ingrItem : this.ingredientsByRecipe.getOrDefault(recipeId, Collections.emptyList())) { + if (!ingrItem.emptyFactor() && preferredItems.containsKey(ingrItem)) { BookmarkItem prefItem = preferredItems.get(ingrItem); if (visited.contains(prefItem.recipeId)) { @@ -194,6 +215,87 @@ public class RecipeChainMath { visited.remove(recipeId); } + private List getOutputRecipeProcessingOrder() { + + if (this.outputRecipes.size() <= 1) { + return new ArrayList<>(this.outputRecipes.keySet()); + } + + final Map> dependents = new HashMap<>(); + final Map inDegree = new HashMap<>(); + + for (RecipeId recipeId : this.outputRecipes.keySet()) { + inDegree.put(recipeId, 0); + } + + for (RecipeId recipeId : this.outputRecipes.keySet()) { + final Set dependencies = new HashSet<>(); + collectBoxDependencies(recipeId, recipeId, dependencies, new HashSet<>()); + dependents.put(recipeId, dependencies); + + for (RecipeId dependency : dependencies) { + inDegree.merge(dependency, 1, Integer::sum); + } + } + + final List order = new ArrayList<>(); + final ArrayDeque queue = new ArrayDeque<>(); + + for (RecipeId recipeId : this.outputRecipes.keySet()) { + if (inDegree.get(recipeId) == 0) { + queue.add(recipeId); + } + } + + while (!queue.isEmpty()) { + final RecipeId recipeId = queue.poll(); + order.add(recipeId); + + for (RecipeId dependency : dependents.getOrDefault(recipeId, Collections.emptySet())) { + if (inDegree.merge(dependency, -1, Integer::sum) == 0) { + queue.add(dependency); + } + } + } + + if (order.size() != this.outputRecipes.size()) { + for (RecipeId recipeId : this.outputRecipes.keySet()) { + if (!order.contains(recipeId)) { + order.add(recipeId); + } + } + } + + return order; + } + + private void collectBoxDependencies(RecipeId boxId, RecipeId currentRecipeId, Set dependencies, + Set visited) { + + if (!visited.add(currentRecipeId)) { + return; + } + + for (BookmarkItem ingrItem : this.ingredientsByRecipe.getOrDefault(currentRecipeId, Collections.emptyList())) { + if (ingrItem.emptyFactor()) { + continue; + } + + final BookmarkItem prefItem = this.preferredItems.get(ingrItem); + if (prefItem == null) { + continue; + } + + if (this.outputRecipes.containsKey(prefItem.recipeId) && !prefItem.recipeId.equals(boxId)) { + dependencies.add(prefItem.recipeId); + } else { + collectBoxDependencies(boxId, prefItem.recipeId, dependencies, visited); + } + } + + visited.remove(currentRecipeId); + } + public RecipeId createMasterRoot() { final List rootIngredients = new ArrayList<>(); @@ -216,6 +318,7 @@ public class RecipeChainMath { BookmarkItem.builder(-1, ROOT_ITEM).factor(1).recipeId(ROOT_RECIPE_ID).type(BookmarkItemType.RESULT) .build()); this.recipeIngredients.addAll(rootIngredients); + rebuildRecipeIndex(); return ROOT_RECIPE_ID; } @@ -276,6 +379,12 @@ public class RecipeChainMath { return missedItems; } + protected boolean isForeignBoxBoundary(BookmarkItem ingrItem) { + final BookmarkItem prefItem = this.preferredItems.get(ingrItem); + return prefItem != null && ingrItem.type != BookmarkItemType.RESULT + && this.outputRecipes.containsKey(prefItem.recipeId); + } + private void resetCalculation() { for (BookmarkItem item : this.recipeIngredients) { @@ -288,7 +397,8 @@ public class RecipeChainMath { this.preferredItems.clear(); this.requiredAmount.clear(); - this.containerItems.clear(); + this.containerItemsCrafting.clear(); + this.containerItemsInventory.clear(); this.containerItemsBlacklist.clear(); for (RecipeId recipeId : this.outputRecipes.keySet()) { @@ -313,9 +423,13 @@ public class RecipeChainMath { } } - for (BookmarkItem prefItem : this.recipeResults) { - if (!prefItem.emptyFactor() && this.outputRecipes.containsKey(prefItem.recipeId)) { - final long prefMultiplier = this.outputRecipes.get(prefItem.recipeId); + for (RecipeId recipeId : getOutputRecipeProcessingOrder()) { + final long prefMultiplier = this.outputRecipes.get(recipeId); + + for (BookmarkItem prefItem : this.resultsByRecipe.getOrDefault(recipeId, Collections.emptyList())) { + if (prefItem.emptyFactor()) { + continue; + } if (prefItem.itemStack.getItem().hasContainerItem(prefItem.itemStack)) { this.containerItemsBlacklist.add(prefItem.itemStack); @@ -341,20 +455,40 @@ public class RecipeChainMath { return this; } - private void calculateSuitableRecipe(BookmarkItem ingrItem, long ingrMultiplier, List visited) { + protected void calculateSuitableRecipe(BookmarkItem ingrItem, long ingrMultiplier, List visited) { final BookmarkItem prefItem = this.preferredItems.get(ingrItem); long ingrAmount = ingrItem .getAmount(ingrMultiplier, prefItem != null ? prefItem.itemStack : ingrItem.itemStack); + final long requested = ingrAmount; + long containerAmount = 0; + long inventoryAmount = 0; // calculate existing containers if (ingrAmount > 0) { for (ItemStack stack : ingrItem.permutations.values()) { if (hasContainerItem(stack)) { - final long stackSize = ingrItem.getStackSize(ingrAmount); - final long shiftSize = shiftContainerItems(stack, stackSize); - if (stackSize != shiftSize && (ingrAmount = shiftSize * ingrItem.fluidCellAmount) == 0) { - break; + long stackSize = ingrItem.getStackSize(ingrAmount); + long shiftSize = shiftContainerItems(stack, stackSize, this.containerItemsCrafting); + + if (stackSize != shiftSize) { + final long newIngrAmount = shiftSize * ingrItem.fluidCellAmount; + containerAmount += ingrAmount - newIngrAmount; + if ((ingrAmount = newIngrAmount) == 0) { + break; + } } + + stackSize = shiftSize; + shiftSize = shiftContainerItems(stack, stackSize, this.containerItemsInventory); + + if (stackSize != shiftSize) { + final long newIngrAmount = shiftSize * ingrItem.fluidCellAmount; + inventoryAmount += ingrAmount - newIngrAmount; + if ((ingrAmount = newIngrAmount) == 0) { + break; + } + } + } } } @@ -362,20 +496,36 @@ public class RecipeChainMath { // calculate existing initial items if (ingrAmount > 0) { for (BookmarkItem item : this.initialItems) { - if (item.containsItems(ingrItem) - && (ingrAmount = addRequiredAmount(item, ingrAmount, item.getAmount())) == 0) { - break; + if (item.containsItems(ingrItem)) { + final long newIngrAmount = addRequiredAmount( + item, + ingrAmount, + item.getAmount(), + this.containerItemsInventory); + inventoryAmount += ingrAmount - newIngrAmount; + if ((ingrAmount = newIngrAmount) == 0) { + break; + } } } } // shift amount - if (prefItem == null) { - addRequiredAmount(ingrItem, ingrAmount, Long.MAX_VALUE); - } else if (visited.contains(prefItem.recipeId)) { - addRequiredAmount(prefItem, ingrAmount, Long.MAX_VALUE); - } else { - addRequiredAmount(prefItem, ingrAmount, Long.MAX_VALUE); + final BookmarkItem producer = prefItem != null ? prefItem : ingrItem; + final long beforeShift = this.requiredAmount.getOrDefault(producer, 0L); + + addRequiredAmount(producer, ingrAmount, Long.MAX_VALUE, this.containerItemsCrafting); + + calculationStepTrigger( + ingrItem, + prefItem, + requested, + containerAmount, + inventoryAmount, + ingrAmount, + this.requiredAmount.getOrDefault(producer, 0L) - beforeShift); + + if (prefItem != null && !isForeignBoxBoundary(ingrItem) && !visited.contains(prefItem.recipeId)) { final long multiplier = Math .max(0, prefItem.getMultiplierFromAmount(this.requiredAmount.get(prefItem)) - prefItem.multiplier); @@ -389,17 +539,21 @@ public class RecipeChainMath { } - private void prepareIngredients(RecipeId recipeId, long multiplier, List visited) { + protected void calculationStepTrigger(BookmarkItem ingrItem, BookmarkItem prefItem, long requested, + long containerAmount, long inventoryAmount, long ingrAmount, long produced) {} - for (BookmarkItem item : this.recipeIngredients) { - if (!item.emptyFactor() && recipeId.equals(item.recipeId)) { + protected void prepareIngredients(RecipeId recipeId, long multiplier, List visited) { + + for (BookmarkItem item : this.ingredientsByRecipe.getOrDefault(recipeId, Collections.emptyList())) { + if (!item.emptyFactor()) { calculateSuitableRecipe(item, multiplier, visited); } } } - private long addRequiredAmount(BookmarkItem prefItem, long ingrAmount, long maxAmount) { + protected long addRequiredAmount(BookmarkItem prefItem, long ingrAmount, long maxAmount, + List containerItems) { long shiftAmount = this.requiredAmount.getOrDefault(prefItem, 0L); if (hasContainerItem(prefItem.itemStack)) { @@ -410,7 +564,7 @@ public class RecipeChainMath { itemStack = itemStack.copy(); itemStack.stackSize = 1; - ingrAmount = shiftContainerItems(itemStack, prefItem.getStackSize(ingrAmount)) + ingrAmount = shiftContainerItems(itemStack, prefItem.getStackSize(ingrAmount), containerItems) * prefItem.fluidCellAmount; if (ingrAmount > 0) { @@ -419,7 +573,8 @@ public class RecipeChainMath { if (result.stack == null) { final long stepsPerReplacement = steps - result.leftSteps; - multiplier = Math.min(steps / stepsPerReplacement, maxAmount - shiftAmount); + multiplier = Math + .min(steps / stepsPerReplacement, (maxAmount - shiftAmount) / prefItem.fluidCellAmount); steps -= multiplier * stepsPerReplacement; } else { steps = result.leftSteps; @@ -431,16 +586,16 @@ public class RecipeChainMath { while (stackSize > Integer.MAX_VALUE) { final ItemStack copy = result.containerItem.copy(); copy.stackSize = Integer.MAX_VALUE; - this.containerItems.add(copy); + containerItems.add(copy); stackSize -= copy.stackSize; } result.containerItem.stackSize = (int) stackSize; - this.containerItems.add(result.containerItem); + containerItems.add(result.containerItem); } if (result.stack != null) { - this.containerItems.add(result.stack); + containerItems.add(result.stack); } ingrAmount = steps * prefItem.fluidCellAmount; @@ -461,11 +616,11 @@ public class RecipeChainMath { return ingrAmount; } - private long shiftContainerItems(ItemStack aStack, long steps) { - final int initialSize = this.containerItems.size(); + private long shiftContainerItems(ItemStack aStack, long steps, List containerItems) { + final int initialSize = containerItems.size(); for (int i = 0; i < initialSize && steps > 0; i++) { - ItemStack bStack = this.containerItems.get(i); + ItemStack bStack = containerItems.get(i); if (bStack != null && NEIClientUtils.areStacksSameTypeCraftingWithNBT(aStack, bStack)) { final ContainerItemResult result = getToolsContainerItems(bStack, steps); @@ -474,20 +629,20 @@ public class RecipeChainMath { steps = result.leftSteps; if (result.containerItem != null) { - this.containerItems.add(result.containerItem); + containerItems.add(result.containerItem); } - this.containerItems.set(i, bStack); + containerItems.set(i, bStack); } } - this.containerItems.removeIf(stack -> stack == null); + containerItems.removeIf(stack -> stack == null); return steps; } - private ContainerItemResult getToolsContainerItems(ItemStack aStack, long steps) { + protected ContainerItemResult getToolsContainerItems(ItemStack aStack, long steps) { final NBTTagCompound tagCompound = aStack.getTagCompound(); if (tagCompound != null && tagCompound.hasKey("GT.ToolStats")) { @@ -541,7 +696,7 @@ public class RecipeChainMath { return 0; } - private boolean hasContainerItem(ItemStack aStack) { + protected boolean hasContainerItem(ItemStack aStack) { if (aStack.getItem().hasContainerItem(aStack)) { @@ -558,16 +713,12 @@ public class RecipeChainMath { } private void addShift(RecipeId recipeId, long shift) { - for (BookmarkItem item : this.recipeIngredients) { - if (recipeId.equals(item.recipeId)) { - item.multiplier += shift; - } + for (BookmarkItem item : this.ingredientsByRecipe.getOrDefault(recipeId, Collections.emptyList())) { + item.multiplier += shift; } - for (BookmarkItem item : this.recipeResults) { - if (recipeId.equals(item.recipeId)) { - item.multiplier += shift; - } + for (BookmarkItem item : this.resultsByRecipe.getOrDefault(recipeId, Collections.emptyList())) { + item.multiplier += shift; } } diff --git a/src/main/java/codechicken/nei/recipe/chain/RecipeChainTooltipLineHandler.java b/src/main/java/codechicken/nei/recipe/chain/RecipeChainTooltipLineHandler.java index abcb9df8..584a7ecd 100644 --- a/src/main/java/codechicken/nei/recipe/chain/RecipeChainTooltipLineHandler.java +++ b/src/main/java/codechicken/nei/recipe/chain/RecipeChainTooltipLineHandler.java @@ -145,7 +145,12 @@ public class RecipeChainTooltipLineHandler implements ITooltipLineHandler { } if (this.lastShiftKey) { - for (ItemStack stack : math.containerItems) { + for (ItemStack stack : math.containerItemsInventory) { + if (stack != null) { + remainder.add(stack.copy()); + } + } + for (ItemStack stack : math.containerItemsCrafting) { if (stack != null) { remainder.add(stack.copy()); } diff --git a/src/main/java/codechicken/nei/recipe/debug/LabelWidget.java b/src/main/java/codechicken/nei/recipe/debug/LabelWidget.java index 3918de13..4031a082 100644 --- a/src/main/java/codechicken/nei/recipe/debug/LabelWidget.java +++ b/src/main/java/codechicken/nei/recipe/debug/LabelWidget.java @@ -40,7 +40,7 @@ public class LabelWidget extends Widget implements IUpdatableWidget { @Override public List handleTooltip(int mx, int my, List tooltip) { - if (contains(mx, my)) { + if (contains(mx, my) && this.value != null) { tooltip.add(this.value); } diff --git a/src/main/java/codechicken/nei/recipe/stackinfo/DefaultStackStringifyHandler.java b/src/main/java/codechicken/nei/recipe/stackinfo/DefaultStackStringifyHandler.java index 953e5c6e..250a6ced 100644 --- a/src/main/java/codechicken/nei/recipe/stackinfo/DefaultStackStringifyHandler.java +++ b/src/main/java/codechicken/nei/recipe/stackinfo/DefaultStackStringifyHandler.java @@ -1,9 +1,14 @@ package codechicken.nei.recipe.stackinfo; +import net.minecraft.block.Block; +import net.minecraft.block.BlockLiquid; +import net.minecraft.block.material.Material; import net.minecraft.item.Item; import net.minecraft.item.ItemStack; import net.minecraft.nbt.NBTTagCompound; +import net.minecraftforge.fluids.Fluid; import net.minecraftforge.fluids.FluidContainerRegistry; +import net.minecraftforge.fluids.FluidRegistry; import net.minecraftforge.fluids.FluidStack; import net.minecraftforge.fluids.IFluidContainerItem; @@ -49,8 +54,24 @@ public class DefaultStackStringifyHandler implements IStackStringifyHandler { public FluidStack getFluid(ItemStack stack) { FluidStack fluidStack = FluidContainerRegistry.getFluidForFilledItem(stack); - if (fluidStack == null && stack.getItem() instanceof IFluidContainerItem) { - fluidStack = ((IFluidContainerItem) stack.getItem()).getFluid(stack); + if (fluidStack == null && stack.getItem() instanceof IFluidContainerItem container) { + fluidStack = container.getFluid(stack); + } + + if (fluidStack == null && Block.getBlockFromItem(stack.getItem()) instanceof BlockLiquid liquidBlock) { + Fluid fluid = FluidRegistry.lookupFluidForBlock(liquidBlock); + + if (fluid == null) { + if (liquidBlock.getMaterial() == Material.water) { + fluid = FluidRegistry.WATER; + } else if (liquidBlock.getMaterial() == Material.lava) { + fluid = FluidRegistry.LAVA; + } + } + + if (fluid != null) { + fluidStack = new FluidStack(fluid, FluidContainerRegistry.BUCKET_VOLUME); + } } return fluidStack; diff --git a/src/main/java/codechicken/nei/recipe/stackinfo/FluidDisplayStackStringifyHandler.java b/src/main/java/codechicken/nei/recipe/stackinfo/FluidDisplayStackStringifyHandler.java new file mode 100644 index 00000000..cc2ec0a8 --- /dev/null +++ b/src/main/java/codechicken/nei/recipe/stackinfo/FluidDisplayStackStringifyHandler.java @@ -0,0 +1,77 @@ +package codechicken.nei.recipe.stackinfo; + +import net.minecraft.item.ItemStack; +import net.minecraft.nbt.NBTTagCompound; +import net.minecraftforge.fluids.Fluid; +import net.minecraftforge.fluids.FluidRegistry; +import net.minecraftforge.fluids.FluidStack; + +import codechicken.nei.api.IStackStringifyHandler; +import codechicken.nei.item.ItemFluidDisplay; + +public class FluidDisplayStackStringifyHandler implements IStackStringifyHandler { + + public static final String NBT_FLUID_NAME = "neiFluidName"; + + @Override + public boolean isFluidDisplayItem(ItemStack stack) { + return stack.getItem() instanceof ItemFluidDisplay; + } + + @Override + public NBTTagCompound convertItemStackToNBT(ItemStack stack, boolean saveStackSize) { + + if (!(stack.getItem() instanceof ItemFluidDisplay)) { + return null; + } + + final FluidStack fluidStack = ((ItemFluidDisplay) stack.getItem()).getFluid(stack); + + if (fluidStack == null) { + return null; + } + + final NBTTagCompound nbTag = new NBTTagCompound(); + nbTag.setString(NBT_FLUID_NAME, fluidStack.getFluid().getName()); + nbTag.setInteger("Count", saveStackSize ? fluidStack.amount : 1); + + if (fluidStack.tag != null) { + nbTag.setTag("FluidTag", fluidStack.tag.copy()); + } + + return nbTag; + } + + @Override + public ItemStack convertNBTToItemStack(NBTTagCompound nbtTag) { + + if (!nbtTag.hasKey(NBT_FLUID_NAME)) { + return null; + } + + final Fluid fluid = FluidRegistry.getFluid(nbtTag.getString(NBT_FLUID_NAME)); + + if (fluid == null) { + return null; + } + + final FluidStack fluidStack = new FluidStack(fluid, nbtTag.getInteger("Count")); + + if (nbtTag.hasKey("FluidTag")) { + fluidStack.tag = nbtTag.getCompoundTag("FluidTag"); + } + + return ItemFluidDisplay.createStack(fluidStack); + } + + @Override + public FluidStack getFluid(ItemStack stack) { + + if (stack.getItem() instanceof ItemFluidDisplay fluidDisplay) { + return fluidDisplay.getFluid(stack); + } + + return null; + } + +} diff --git a/src/main/java/codechicken/nei/recipe/stackinfo/GTFluidStackStringifyHandler.java b/src/main/java/codechicken/nei/recipe/stackinfo/GTFluidStackStringifyHandler.java index 46b9e220..f0bb93cb 100644 --- a/src/main/java/codechicken/nei/recipe/stackinfo/GTFluidStackStringifyHandler.java +++ b/src/main/java/codechicken/nei/recipe/stackinfo/GTFluidStackStringifyHandler.java @@ -11,13 +11,13 @@ import net.minecraftforge.fluids.FluidRegistry; import net.minecraftforge.fluids.FluidStack; import codechicken.nei.api.IStackStringifyHandler; +import codechicken.nei.item.ItemFluidDisplay; import cpw.mods.fml.common.registry.GameRegistry; import cpw.mods.fml.relauncher.ReflectionHelper; public class GTFluidStackStringifyHandler implements IStackStringifyHandler { protected static Class itemFluidDisplay = null; - protected static Method getFluidDisplayStack = null; protected static Method getFluidFromDisplayStack = null; protected static Class gtMetaGeneratedTool = null; protected static Field playSound = null; @@ -33,7 +33,6 @@ public class GTFluidStackStringifyHandler implements IStackStringifyHandler { "gregtech.common.items.ItemFluidDisplay", "gregtech.common.items.GT_FluidDisplayItem"); getFluidFromDisplayStack = gtUtility.getMethod("getFluidFromDisplayStack", ItemStack.class); - getFluidDisplayStack = gtUtility.getMethod("getFluidDisplayStack", FluidStack.class, boolean.class); gtMetaGeneratedTool = ReflectionHelper.getClass( loader, @@ -45,14 +44,15 @@ public class GTFluidStackStringifyHandler implements IStackStringifyHandler { } } + @Override public NBTTagCompound convertItemStackToNBT(ItemStack stack, boolean saveStackSize) { - if (stack.getItem() != GameRegistry.findItem("ae2fc", "fluid_drop")) { + if (stack != null && isFluidDisplayItem(stack)) { final FluidStack fluidStack = getFluid(stack); if (fluidStack != null) { final NBTTagCompound nbTag = new NBTTagCompound(); - nbTag.setString("gtFluidName", fluidStack.getFluid().getName()); + nbTag.setString(FluidDisplayStackStringifyHandler.NBT_FLUID_NAME, fluidStack.getFluid().getName()); nbTag.setInteger("Count", saveStackSize ? fluidStack.amount : 144); return nbTag; } @@ -61,23 +61,23 @@ public class GTFluidStackStringifyHandler implements IStackStringifyHandler { return null; } + @Override public ItemStack convertNBTToItemStack(NBTTagCompound nbtTag) { - if (getFluidDisplayStack != null && nbtTag.hasKey("gtFluidName")) { + if (nbtTag.hasKey("gtFluidName")) { final String fluidName = nbtTag.getString("gtFluidName"); final Fluid fluid = FluidRegistry.getFluid(fluidName); final int amount = nbtTag.getInteger("Count"); if (fluid != null) { - try { - return (ItemStack) getFluidDisplayStack.invoke(null, new FluidStack(fluid, amount), true); - } catch (Exception e) {} + return ItemFluidDisplay.createStack(new FluidStack(fluid, amount)); } } return null; } + @Override public FluidStack getFluid(ItemStack stack) { final Item item = stack.getItem(); @@ -110,6 +110,7 @@ public class GTFluidStackStringifyHandler implements IStackStringifyHandler { return null; } + @Override public ItemStack normalizeRecipeQueryStack(ItemStack stack) { if (stack.getItem() == GameRegistry.findItem("ae2fc", "fluid_drop") @@ -117,9 +118,7 @@ public class GTFluidStackStringifyHandler implements IStackStringifyHandler { final FluidStack fluidStack = getFluid(stack); if (fluidStack != null) { - try { - return (ItemStack) getFluidDisplayStack.invoke(null, fluidStack, true); - } catch (Exception e) {} + return ItemFluidDisplay.createStack(fluidStack); } } @@ -136,4 +135,11 @@ public class GTFluidStackStringifyHandler implements IStackStringifyHandler { } + @Override + public boolean isFluidDisplayItem(ItemStack stack) { + final Item item = stack.getItem(); + return (itemFluidDisplay != null && itemFluidDisplay.isInstance(item)) + || item == GameRegistry.findItem("ae2fc", "fluid_packet"); + } + } diff --git a/src/main/java/codechicken/nei/search/ModNameFilter.java b/src/main/java/codechicken/nei/search/ModNameFilter.java index 29a12540..cc5c9afd 100644 --- a/src/main/java/codechicken/nei/search/ModNameFilter.java +++ b/src/main/java/codechicken/nei/search/ModNameFilter.java @@ -1,13 +1,17 @@ package codechicken.nei.search; +import java.util.HashMap; +import java.util.Map; import java.util.regex.Pattern; -import net.minecraft.item.Item; import net.minecraft.item.ItemStack; +import net.minecraftforge.fluids.Fluid; +import net.minecraftforge.fluids.FluidRegistry; import codechicken.nei.NEIClientConfig; import codechicken.nei.api.ItemFilter; import codechicken.nei.api.ItemInfo; +import codechicken.nei.item.ItemFluidDisplay; import cpw.mods.fml.common.Loader; import cpw.mods.fml.common.ModContainer; import cpw.mods.fml.common.registry.GameRegistry; @@ -15,6 +19,7 @@ import cpw.mods.fml.common.registry.GameRegistry.UniqueIdentifier; public class ModNameFilter implements ItemFilter { + private static final Map fluidOwners = new HashMap<>(); private final Pattern pattern; public ModNameFilter(Pattern pattern) { @@ -23,31 +28,52 @@ public class ModNameFilter implements ItemFilter { @Override public boolean matches(ItemStack itemStack) { - return this.pattern.matcher(nameFromStack(itemStack.getItem())).find(); + return this.pattern.matcher(nameFromStack(itemStack)).find(); } - protected static String nameFromStack(Item item) { + protected static String nameFromStack(ItemStack itemStack) { try { - ModContainer mod = Loader.instance().getIndexedModList().get(getModId(item)); + ModContainer mod = Loader.instance().getIndexedModList().get(getModId(itemStack)); return mod == null ? "Minecraft" : mod.getName(); - } catch (NullPointerException e) { + } catch (Throwable e) { return ""; } } - protected static String getModId(Item item) { + protected static String getModId(ItemStack itemStack) { - if (!ItemInfo.itemOwners.containsKey(item)) { + if (itemStack.getItem() instanceof ItemFluidDisplay fluidDisplay) { + return getFluidModId(fluidDisplay, itemStack); + } + + if (!ItemInfo.itemOwners.containsKey(itemStack.getItem())) { try { - UniqueIdentifier ident = GameRegistry.findUniqueIdentifierFor(item); - ItemInfo.itemOwners.put(item, ident.modId); + final UniqueIdentifier identifier = GameRegistry.findUniqueIdentifierFor(itemStack.getItem()); + ItemInfo.itemOwners.put(itemStack.getItem(), identifier.modId); } catch (Exception ignored) { - NEIClientConfig.logger.error("Failed to find identifier for: " + item); - ItemInfo.itemOwners.put(item, "Unknown"); + NEIClientConfig.logger.error("Failed to find identifier for: " + itemStack.getItem()); + ItemInfo.itemOwners.put(itemStack.getItem(), "Unknown"); } } - return ItemInfo.itemOwners.get(item); + return ItemInfo.itemOwners.get(itemStack.getItem()); + } + + private static String getFluidModId(ItemFluidDisplay fluidDisplay, ItemStack itemStack) { + final Fluid fluid = FluidRegistry.getFluid(itemStack.getItemDamage()); + final String fluidName = FluidRegistry.getDefaultFluidName(fluid); + + if (!fluidOwners.containsKey(fluidName)) { + try { + final UniqueIdentifier identifier = new UniqueIdentifier(fluidName); + fluidOwners.put(fluidName, identifier.modId); + } catch (Exception ignored) { + NEIClientConfig.logger.error("Failed to find identifier for fluid: " + fluidName); + fluidOwners.put(fluidName, "Unknown"); + } + } + + return fluidOwners.get(fluidName); } } diff --git a/src/main/resources/assets/nei/cfg/collapsibleitems.cfg b/src/main/resources/assets/nei/cfg/collapsibleitems.cfg index f3c43cc1..3867b19b 100644 --- a/src/main/resources/assets/nei/cfg/collapsibleitems.cfg +++ b/src/main/resources/assets/nei/cfg/collapsibleitems.cfg @@ -25,4 +25,6 @@ minecraft:record_ #splash potion minecraft:potion 16000-17000 #lingering potion -minecraft:potion 8000-9000 \ No newline at end of file +minecraft:potion 8000-9000 +#fluid display +neifluiddisplay \ No newline at end of file diff --git a/src/main/resources/assets/nei/csv/handlers.csv b/src/main/resources/assets/nei/csv/handlers.csv index 4a17d169..3595981e 100644 --- a/src/main/resources/assets/nei/csv/handlers.csv +++ b/src/main/resources/assets/nei/csv/handlers.csv @@ -44,14 +44,14 @@ com.rwtema.extrautils.nei.InfoHandler,Extra Utilities,ExtraUtilities:chandelier, com.rwtema.extrautils.nei.MicroBlocksHandler,Extra Utilities,ExtraUtilities:microblocks:1,,ExtraUtilities,TRUE,,,,,,,,,,,, com.rwtema.extrautils.nei.SoulHandler,Extra Utilities,ExtraUtilities:mini-soul,,ExtraUtilities,TRUE,,,,,,,,,,,, hellfirepvp.beebetteratbees.client.gui.BBABGuiRecipeTreeHandler,Bees,Forestry:beeQueenGE,,Forestry,TRUE,,,140,,2,,,,,,, -forestry.factory.recipes.nei.NEIHandlerBottler,Forestry for Minecraft,Forestry:factory,,Forestry,TRUE,,,84,,5,,,,,,, -forestry.factory.recipes.nei.NEIHandlerCarpenter,Forestry for Minecraft,Forestry:factory:1,,Forestry,TRUE,,,81,,5,,,,,,, +forestry.factory.recipes.nei.NEIHandlerBottler,Forestry for Minecraft,Forestry:factory,,Forestry,TRUE,,,71,,5,,,,,,, +forestry.factory.recipes.nei.NEIHandlerCarpenter,Forestry for Minecraft,Forestry:factory:1,,Forestry,TRUE,,,95,,5,,,,,,, forestry.factory.recipes.nei.NEIHandlerCentrifuge,Forestry for Minecraft,Forestry:factory:2,,Forestry,TRUE,,,81,,5,,,,,,, forestry.factory.recipes.nei.NEIHandlerFabricator,Forestry for Minecraft,Forestry:factory2,,Forestry,TRUE,,,,,,,,,,,, -forestry.factory.recipes.nei.NEIHandlerFermenter,Forestry for Minecraft,Forestry:factory:3,,Forestry,TRUE,,,81,,5,,,,,,, -forestry.factory.recipes.nei.NEIHandlerMoistener,Forestry for Minecraft,Forestry:factory:4,,Forestry,TRUE,,,84,,5,,,,,,, -forestry.factory.recipes.nei.NEIHandlerSqueezer,Forestry for Minecraft,Forestry:factory:5,,Forestry,TRUE,,,84,,5,,,,,,, -forestry.factory.recipes.nei.NEIHandlerStill,Forestry for Minecraft,Forestry:factory:6,,Forestry,TRUE,,,81,,5,,,,,,, +forestry.factory.recipes.nei.NEIHandlerFermenter,Forestry for Minecraft,Forestry:factory:3,,Forestry,TRUE,,2,69,,5,,,,,,, +forestry.factory.recipes.nei.NEIHandlerMoistener,Forestry for Minecraft,Forestry:factory:4,,Forestry,TRUE,,1,70,,5,,,,,,, +forestry.factory.recipes.nei.NEIHandlerSqueezer,Forestry for Minecraft,Forestry:factory:5,,Forestry,TRUE,,,98,,5,,,,,,, +forestry.factory.recipes.nei.NEIHandlerStill,Forestry for Minecraft,Forestry:factory:6,,Forestry,TRUE,,2,69,,5,,,,,,, net.bdew.neiaddons.forestry.bees.BeeBreedingHandler,Forestry for Minecraft,Forestry:beeQueenGE,,Forestry,TRUE,,,65,,5,,,,,,, net.bdew.neiaddons.forestry.bees.BeeProduceHandler,Forestry for Minecraft,Forestry:beeQueenGE,,Forestry,TRUE,,,65,,5,,,,,,, net.bdew.neiaddons.forestry.butterflies.ButterflyBreedingHandler,Forestry for Minecraft,Forestry:butterflyGE,,Forestry,TRUE,,,,,,,,,,,, diff --git a/src/main/resources/assets/nei/lang/en_US.lang b/src/main/resources/assets/nei/lang/en_US.lang index 3fd9c011..4f53afa2 100644 --- a/src/main/resources/assets/nei/lang/en_US.lang +++ b/src/main/resources/assets/nei/lang/en_US.lang @@ -30,6 +30,7 @@ nei.bookmark.group.sorting=Move Position nei.bookmark.group.remove_recipe=Remove Group nei.bookmark.group.pull_items=Pull all Items nei.bookmark.group.pull_items_shift=Pull missing Items +nei.bookmark.group.open_crafting_tree=Open Crafting Tree nei.bookmark.group.craft_missing=Craft Missing Items nei.bookmark.group.craft_all=Craft Items nei.bookmark.group.chat_link=Send Bookmark Group to Chat @@ -52,6 +53,45 @@ nei.bookmark.crafting_chain.output=Results nei.bookmark.crafting_chain.remainder=Remainders nei.bookmark.crafting_chain.needed=Required Crafts nei.bookmark.crafting_chain.available=Available Items +nei.bookmark.tree.title=Crafting Tree +nei.bookmark.tree.empty=No crafting chain to display +nei.bookmark.tree.overlay=Use for recipe tree +nei.bookmark.tree.item.state.resolved=In inventory: %s +nei.bookmark.tree.item.state.partial=Still needed: %s +nei.bookmark.tree.item.state.craftable=Can be crafted +nei.bookmark.tree.item.state.surplus=Extra produced: %s +nei.bookmark.tree.item.toggle_recipe=Collapse/Expand Recipe + +nei.bookmark.tree.stats.handlers=Handlers +nei.bookmark.tree.stats.ingredients=Ingredients +nei.bookmark.tree.stats.ingredients_needed=Ingredients Needed +nei.bookmark.tree.stats.ingredients_available=Ingredients Available +nei.bookmark.tree.stats.results=Results +nei.bookmark.tree.stats.remainders=Remainders +nei.bookmark.tree.stats.crafting=Crafting +nei.bookmark.tree.stats.crafting_needed=Crafting Needed +nei.bookmark.tree.stats.crafting_available=Crafting Available +nei.bookmark.tree.stats.handler_iterations=Iterations: %s +nei.bookmark.tree.stats.handler_recipes=Unique Recipes: %s + +nei.bookmark.tree.stats.highlight_handler=Highlight Recipe Handler +nei.bookmark.tree.stats.next_highlight=Go to Next Highlighted Handler +nei.bookmark.tree.stats.prev_highlight=Go to Previous Highlighted Handler +nei.bookmark.tree.stats.clear_highlight=Clear Handler Highlight + +nei.bookmark.tree.toolbar.inventory_off=Recompute tree using player inventory (snapshot) +nei.bookmark.tree.toolbar.inventory_on=Using inventory snapshot - click to clear +nei.bookmark.tree.toolbar.fit_to_view=Fit tree to view +nei.bookmark.tree.toolbar.stats_off=Show stats panel +nei.bookmark.tree.toolbar.stats_on=Hide stats panel +nei.bookmark.tree.toolbar.stats_sections=Choose visible stats sections +nei.bookmark.tree.toolbar.link=Send Bookmark Group to Chat +nei.bookmark.tree.toolbar.collapse_resolved=Collapse items with nothing left to craft +nei.bookmark.tree.toolbar.collapse_all=Collapse all nested items +nei.bookmark.tree.toolbar.expand_all=Expand all nested items +nei.bookmark.tree.toolbar.screenshot=Save tree as image +nei.bookmark.tree.screenshot.fbo_unsupported=Could not save crafting tree screenshot: framebuffers are not supported + nei.inventory.search.placeholder=Search... nei.itempanel.quantity.default=One stack nei.itempanel.loading=Loading Item List... @@ -123,7 +163,14 @@ nei.inventory.current.gamemode.2=Current gamemode: creative+ nei.inventory.current.gamemode.3=Current gamemode: adventure nei.inventory.tooltip.page=Page: %s / %s [Press %s to see next page] nei.inventory.tooltip.count.item=Count: %s + +itemGroup.neiFluids=Fluids + nei.inventory.tooltip.count.fluid=Amount: %s +nei.inventory.tooltip.temperature.fluid=Temperature: %sK +nei.inventory.tooltip.state.fluid=State: %s +nei.inventory.tooltip.state.fluid.gas=Gas +nei.inventory.tooltip.state.fluid.liquid=Liquid nei.inventory.gamemode.0=Click: Set gamemode to survival nei.inventory.gamemode.1=Click: Set gamemode to creative @@ -200,6 +247,7 @@ nei.options.keys.gui.search=Focus Search Bar nei.options.keys.bookmark.add=Add Bookmark nei.options.keys.bookmark.remove_recipe=Remove Group from Bookmarks (Shift +) nei.options.keys.bookmark.pull_items=Pull all Bookmarked Items +nei.options.keys.bookmark.open_crafting_tree=Open Crafting Tree Window nei.options.keys.bookmark.hide=Toggle Bookmark Panel Visibility nei.options.keys.bookmark.chat_link=Send link to chat (Ctrl +) nei.options.keys.gui.overlay=Fill/Overlay Crafting Grid @@ -486,6 +534,14 @@ nei.options.inventory.itemUntranslator=Item Untranslator nei.options.inventory.itemUntranslator.true=Enabled nei.options.inventory.itemUntranslator.false=Disabled +nei.options.inventory.tooltip=Tooltips +nei.options.inventory.tooltip.showFluidTemperature=Show Fluid Temperature +nei.options.inventory.tooltip.showFluidTemperature.true=Yes +nei.options.inventory.tooltip.showFluidTemperature.false=No +nei.options.inventory.tooltip.showFluidState=Show Fluid State +nei.options.inventory.tooltip.showFluidState.true=Yes +nei.options.inventory.tooltip.showFluidState.false=No + nei.options.command=Commands nei.options.command.creative=Gamemode nei.options.command.creative.tip={0} = 1 for creative, 0 for survival, {1} = player @@ -576,6 +632,7 @@ nei.debug.RecipeHandler.reset=Reset nei.recipe.page=Page %s/%s nei.recipe.tooltip=Recipes +nei.recipe.fluid.tank.amount=Amount: %s nei.recipe.tab.view_all.tooltip=View all categories nei.recipe.search.tooltip.name=Filter Syntax nei.recipe.search.tooltip.shift=§7Hold §6Shift§7 for more info @@ -674,6 +731,7 @@ nei.subsets.Items.Armor.Boots=Boots nei.subsets.Items.Armor.Chestplates=Chestplates nei.subsets.Items.Armor.Helmets=Helmets nei.subsets.Items.Armor.Leggings=Leggings +nei.subsets.Items.Fluids=Fluids nei.subsets.Items.Food=Food nei.subsets.Items.Potions=Potions nei.subsets.Items.Potions.Ingredients=Ingredients @@ -691,6 +749,9 @@ nei.subsets.Items.Weapons=Weapons nei.subsets.Items.Weapons.Ranged=Ranged nei.subsets.Items.Weapons.Swords=Swords nei.subsets.Untranslated=Untranslated +nei.subsets.Favorites=Favorites +nei.subsets.Favorites.Manual=Manual +nei.subsets.Favorites.Generated=Generated nei.subsets.Mod=Mod nei.presets.new=New Preset diff --git a/src/main/resources/assets/nei/lang/ru_RU.lang b/src/main/resources/assets/nei/lang/ru_RU.lang index f852421c..6a1da14f 100644 --- a/src/main/resources/assets/nei/lang/ru_RU.lang +++ b/src/main/resources/assets/nei/lang/ru_RU.lang @@ -84,6 +84,13 @@ nei.inventory.current.gamemode.2=Текущий режим игры: творч nei.inventory.current.gamemode.3=Текущий режим игры: приключение nei.inventory.tooltip.page=Страница: %s / %s [Нажмите %s для перехода на следующую страницу] +itemGroup.neiFluids=Жидкости + +nei.inventory.tooltip.temperature.fluid=Температура: %sK +nei.inventory.tooltip.state.fluid=Состояние: %s +nei.inventory.tooltip.state.fluid.gas=Газ +nei.inventory.tooltip.state.fluid.liquid=Жидкость + nei.inventory.gamemode.0=Клик: Установить режим игры на выживание nei.inventory.gamemode.1=Клик: Установить режим игры на творческий nei.inventory.gamemode.2=Клик: Установить режим игры на творческий+ @@ -444,6 +451,7 @@ nei.subsets.Items.Armor.Boots=Ботинки nei.subsets.Items.Armor.Chestplates=Нагрудники nei.subsets.Items.Armor.Helmets=Шлемы nei.subsets.Items.Armor.Leggings=Поножи +nei.subsets.Items.Fluids=Жидкости nei.subsets.Items.Food=Еда nei.subsets.Items.Potions=Зелья nei.subsets.Items.Potions.Ingredients=Ингредиенты diff --git a/src/main/resources/assets/nei/lang/uk_UA.lang b/src/main/resources/assets/nei/lang/uk_UA.lang new file mode 100644 index 00000000..69a162bc --- /dev/null +++ b/src/main/resources/assets/nei/lang/uk_UA.lang @@ -0,0 +1,721 @@ +nei.load=Завантажити +nei.save=Зберегти + +# Клавіша керування PC/Linux +nei.key.ctrl=CTRL +nei.key.shift=SHIFT +nei.key.alt=ALT +nei.mouse.left=ЛКМ +nei.mouse.right=ПКМ +nei.mouse.middle=СКМ +nei.mouse.other=Кнопка %d +nei.mouse.scroll=Прокручування +nei.mouse.drag=Перетягування +# Клавіша Command на Mac +nei.key.ctrl.mac=CMD +nei.showHotkeys=Утримуйте %s для відображення гарячих клавіш + +nei.bookmark.toggle=Закладки +nei.bookmark.toggle.tip=Перемикнути видимість панелі закладок +nei.bookmark.pullBookmarkedItems.tip=Перемістити всі предмети із закладок зі сховища до інвентарю + +nei.bookmark.group=Група закладок +nei.bookmark.group.include_group=Створити групу/Додати до групи +nei.bookmark.group.exclude_group=Видалити групу/Виключити з групи +nei.bookmark.group.toggle_mode=Перемикнути режим груп +nei.bookmark.group.toggle_collapse=Згорнути/Розгорнути +nei.bookmark.group.toggle_crafting_chain=Перемикнути ланцюжок крафту +nei.bookmark.group.overlay_use=Заповнити сітку крафту +nei.bookmark.group.sorting=Змінити позицію +nei.bookmark.group.remove_recipe=Видалити групу +nei.bookmark.group.pull_items=Перемістити всі предмети +nei.bookmark.group.pull_items_shift=Перемістити відсутні предмети +nei.bookmark.group.craft_missing=Скрафтити відсутні предмети +nei.bookmark.group.craft_all=Скрафтити предмети +nei.bookmark.group.chat_link=Надіслати групу закладок у чат +nei.bookmark.item.sorting=Змінити позицію +nei.bookmark.item.chat_link=Надіслати предмет у чат +nei.bookmark.remove_recipe=Видалити рецепт +nei.bookmark.remove_item=Видалити предмет +nei.bookmark.add_item=Додати закладку +nei.bookmark.add_item_with_recipe=Додати закладку з рецептом +nei.bookmark.add_item_with_recipe_and_count=Додати закладку з рецептом і кількістю +nei.bookmark.add_item_with_count=Додати закладку з кількістю +nei.bookmark.change_quantity=Змінити кількість +nei.bookmark.change_quantity_step=Змінити кількість із множником +nei.bookmark.recipe.toggle_collapse=Згорнути/Розгорнути +nei.bookmark.recipe.chat_link=Надіслати рецепт у чат +nei.bookmark.crafting_chain=Ланцюжок крафту +nei.bookmark.crafting_chain.input=Інгредієнти +nei.bookmark.crafting_chain.missing=Відсутні предмети +nei.bookmark.crafting_chain.output=Результати +nei.bookmark.crafting_chain.remainder=Залишки +nei.bookmark.crafting_chain.needed=Необхідні крафти +nei.bookmark.crafting_chain.available=Доступні предмети +nei.inventory.search.placeholder=Пошук... +nei.itempanel.quantity.default=Один стек +nei.itempanel.loading=Завантаження списку предметів... +nei.itempanel.deleteItem=Знищити предмет +nei.itempanel.collapsed.button=G +nei.itempanel.collapsed.button.tip=Згорнути/Розгорнути всі згруповані предмети +nei.itempanel.collapsed.hint.expand=Розгорнути групу (%d предметів) +nei.itempanel.collapsed.hint.collapse=Згорнути групу (%d предметів) +nei.itempanel.overlay_recipe=Накласти рецепт +nei.itempanel.craft_missing=Скрафтити відсутні предмети +nei.itempanel.craft_all=Скрафтити предмети +nei.itempanel.fill_crafting_grid=Заповнити сітку крафту +nei.itempanel.fill_crafting_grid_quantity=Заповнити сітку крафту з кількістю +nei.itempanel.open_crafting=Рецепт створення цього предмета +nei.itempanel.open_usage=Рецепти з використанням цього предмета +nei.itempanel.infinite_item=Видати нескінченний предмет +nei.itempanel.copy_name=Скопіювати назву предмета +nei.itempanel.copy_oredict=Скопіювати OreDictionary предмета +nei.itempanel.copy_id=Скопіювати ID предмета + +nei.itempanel.chat_link_item=Надіслати посилання на предмет у чат + +nei.enchant=Зачарування +nei.enchant.level=Рівень +nei.enchant.locked=Заблоковано +nei.enchant.unlocked=Розблоковано + +nei.potion.favourite=Обрані зілля +nei.potion.duration=Тривалість +nei.potion.level=Рівень + +nei.inventory.options=Налаштування +nei.inventory.options.tip=Налаштування NEI +nei.inventory.options.tip.cheatmode.0=Режим рецептів +nei.inventory.options.tip.cheatmode.1=Режим утиліт +nei.inventory.options.tip.cheatmode.2=Режим читів +nei.inventory.options.tip.cheatmode.disable=%s - натисніть тут для перемикання між режимами Рецептів, Утиліт та Читів. +nei.inventory.prev=Назад +nei.inventory.next=Далі +nei.inventory.item_subsets=Підгрупи предметів +nei.inventory.delete.inv=ЗНИЩИТИ ВСІ ПРЕДМЕТИ з поточного інвентарю +nei.inventory.delete.one=Знищити %s +nei.inventory.delete.all=Знищити ВСІ %s +nei.inventory.delete.enable=Режим знищення +nei.inventory.delete.1=Увімкнути режим знищення +nei.inventory.delete.0=Вимкнути режим знищення +nei.inventory.rain.enable=Дощ +nei.inventory.rain.1=Увімкнути дощ +nei.inventory.rain.0=Вимкнути дощ +nei.inventory.magnet.enable=Режим магніту +nei.inventory.magnet.1=Увімкнути режим магніту +nei.inventory.magnet.0=Вимкнути режим магніту +nei.inventory.dawn.enable=Світанок-полудень +nei.inventory.dawn.disable=ПКМ: Вимкнути фазу світанок-полудень +nei.inventory.dawn.set=Встановити час: Світанок +nei.inventory.noon.enable=Полудень-сутінки +nei.inventory.noon.disable=ПКМ: Вимкнути фазу полудень-сутінки +nei.inventory.noon.set=Встановити час: Полудень +nei.inventory.dusk.enable=Сутінки-опівніч +nei.inventory.dusk.disable=ПКМ: Вимкнути фазу сутінки-опівніч +nei.inventory.dusk.set=Встановити час: Сутінки +nei.inventory.midnight.enable=Опівніч-світанок +nei.inventory.midnight.disable=ПКМ: Вимкнути фазу опівніч-світанок +nei.inventory.midnight.set=Встановити час: Опівніч +nei.inventory.heal=Зцілити гравця +nei.inventory.current.gamemode.0=Поточний режим гри: Виживання +nei.inventory.current.gamemode.1=Поточний режим гри: Творчий +nei.inventory.current.gamemode.2=Поточний режим гри: Творчий+ +nei.inventory.current.gamemode.3=Поточний режим гри: Пригодницький +nei.inventory.tooltip.page=Сторінка: %s / %s [Натисніть %s для наступної сторінки] +nei.inventory.tooltip.count.item=Кількість: %s +nei.inventory.tooltip.count.fluid=Об’єм: %s + +nei.inventory.gamemode.0=Встановити режим Виживання +nei.inventory.gamemode.1=Встановити Творчий режим +nei.inventory.gamemode.2=Встановити Творчий+ режим +nei.inventory.gamemode.3=Встановити Пригодницький режим + +nei.chat.gamemode.0=Тепер ви граєте в режимі Виживання +nei.chat.gamemode.1=Тепер ви граєте у Творчому режимі +nei.chat.gamemode.2=Тепер ви граєте в режимі Творчий+ +nei.chat.gamemode.3=Тепер ви граєте в Пригодницькому режимі +nei.chat.rain.on=Дощ увімкнено +nei.chat.rain.off=Дощ вимкнено +nei.chat.time=День %d. %d:00 +nei.chat.give.noitem=Такого предмета не існує. +nei.chat.recipe.error=Сталася помилка під час завантаження рецепта. Перегляньте лог для отримання деталей. +nei.chat.render.error=Сталася помилка під час відображення предмета. Перегляньте лог для отримання деталей. +nei.chat.chunkoverlay.0=Відображення чанків: Вимкнено +nei.chat.chunkoverlay.1=Відображення чанків: Кути чанків +nei.chat.chunkoverlay.2=Відображення чанків: Чанки +nei.chat.chunkoverlay.3=Відображення чанків: Рудні жили GT +nei.chat.moboverlay.0=Відображення спавну мобів: §cВимкнено +nei.chat.moboverlay.1=Відображення спавну мобів: §2Увімкнено +nei.chat.item_link.text=<%s> §6Натисніть, щоб додати закладку: %s +nei.chat.item_link.item.text=Додати предмет у закладки +nei.chat.item_link.recipe.text=Додати рецепт у закладки +nei.chat.item_link.group.text=Додати групу в закладки +nei.chat.bookmark_added.text=Закладку додано! + +nei.chat.recipeid.many_params=Забагато параметрів! Використання: %s +nei.chat.recipeid.not_found=Файл %s не знайдено! +nei.chat.recipeid.diff.start=Розпочато порівняння рецептів! +nei.chat.recipeid.diff.finish=Завершено порівняння рецептів! +nei.chat.recipeid.dump.start=Розпочато опрацювання обробників рецептів! +nei.chat.recipeid.dump.finish=Завершено опрацювання обробників рецептів! + +nei.chat.untranslator.dump.start=Розпочато створення дампу untranslator! +nei.chat.untranslator.dump.finish=Завершено створення дампу untranslator! +nei.chat.untranslator.dump.error=Дочекайтеся завантаження предметів! +nei.chat.untranslator.clear=Файл успішно видалено! +nei.chat.untranslator.clear.error=Не вдалося видалити файл! + +nei.options=Налаштування NEI +nei.options.back=Повернутися +nei.options.save=Зберегти +nei.options.world=Світ +nei.options.global=Глобально +nei.options.global.tip.0=Налаштування застосовуються до всіх світів +nei.options.global.tip.1=Натисніть W біля налаштування, щоб увімкнути перевизначення для цього світу +nei.options.wbutton.tip.0=Використовуються глобальні налаштування +nei.options.wbutton.tip.1=Перевизначення глобального налаштування + +nei.options.keys=Прив’язка клавіш +nei.options.keys.tip=Налаштувати гарячі клавіші NEI у вікні керування Minecraft +nei.options.keys.gui=Інвентар NEI +nei.options.keys.world=Світ NEI +nei.options.keys.recipe=Рецепти NEI +nei.options.keys.bookmark=Закладки NEI +nei.options.keys.copy=Копіювання NEI +nei.options.keys.itemzoom=Наближення предметів NEI +nei.options.keys.showenchant=Показати зачарування +nei.options.keys.recipe.recipe=Рецепт +nei.options.keys.recipe.usage=Використання +nei.options.keys.gui.enchant=Зачарування +nei.options.keys.gui.potion=Зілля +nei.options.keys.recipe.back=Повернутися до попереднього рецепту +nei.options.keys.gui.prev=Попередня сторінка панелі предметів +nei.options.keys.gui.next=Наступна сторінка панелі предметів +nei.options.keys.gui.hide=Перемикнути видимість +nei.options.keys.recipe.next_recipe=Наступний рецепт +nei.options.keys.recipe.prev_recipe=Попередній рецепт +nei.options.keys.recipe.next_machine=Наступна категорія +nei.options.keys.recipe.prev_machine=Попередня категорія +nei.options.keys.gui.search=Фокус на рядок пошуку +nei.options.keys.bookmark.add=Додати закладку +nei.options.keys.bookmark.remove_recipe=Видалити групу із закладок (Shift +) +nei.options.keys.bookmark.pull_items=Перемістити всі предмети із закладок +nei.options.keys.bookmark.hide=Перемикнути видимість панелі закладок +nei.options.keys.bookmark.chat_link=Надіслати посилання в чат (Ctrl +) +nei.options.keys.gui.overlay=Заповнити/Накласти сітку крафту +nei.options.keys.gui.getprevioussearch=Попередній пошуковий запит +nei.options.keys.gui.getnextsearch=Наступний пошуковий запит +nei.options.keys.gui.next_tooltip=Наступна підказка +nei.options.keys.copy.name=Скопіювати назву предмета (Ctrl +) +nei.options.keys.gui.craft_items=Скрафтити предмети (Shift +) +nei.options.keys.copy.oredict=Скопіювати OreDictionary предмета (Ctrl +) +nei.options.keys.copy.identifier=Скопіювати ID предмета (Ctrl +) +nei.options.keys.itemzoom.toggle=Перемикнути наближення предмета (Shift +) +nei.options.keys.itemzoom.hold=Утримувати для відображення наближення предмета +nei.options.keys.itemzoom.zoom_in=Збільшити масштаб предмета +nei.options.keys.itemzoom.zoom_out=Зменшити масштаб предмета +nei.options.keys.bookmark.favorite=Додати в обране (Shift +) +nei.options.keys.bookmark.favorite_item=Перемикнути обране (Shift +) +nei.options.keys.world.chunkoverlay=Відображення меж чанків +nei.options.keys.world.moboverlay=Відображення спавну мобів +nei.options.keys.world.highlight_tips=Контекстні підказки +nei.options.keys.world.dawn=Світанок +nei.options.keys.world.noon=Полудень +nei.options.keys.world.dusk=Сутінки +nei.options.keys.world.midnight=Опівніч +nei.options.keys.world.rain=Дощ +nei.options.keys.world.heal=Зцілення +nei.options.keys.world.creative=Режим гри +nei.options.keys.world.creative.tip=Перемикати режим гри + +nei.options.inventory=Інвентар +nei.options.inventory.bookmarks=Панель закладок +nei.options.inventory.bookmarks.enabled=Видимість панелі закладок +nei.options.inventory.bookmarks.enabled.true=Видима +nei.options.inventory.bookmarks.enabled.false=Прихована +nei.options.inventory.bookmarks.animation=Анімація закладок у стилі REI +nei.options.inventory.bookmarks.animation.true=Так +nei.options.inventory.bookmarks.animation.false=Ні +nei.options.inventory.bookmarks.recipeChainDir=Напрямок ланцюжка крафту +nei.options.inventory.bookmarks.recipeChainDir.0=Спочатку інгредієнти +nei.options.inventory.bookmarks.recipeChainDir.1=Спочатку результат +nei.options.inventory.bookmarks.recipeTooltipsMode=Показувати підказки рецептів у закладках +nei.options.inventory.bookmarks.recipeTooltipsMode.0=Ніколи +nei.options.inventory.bookmarks.recipeTooltipsMode.1=У горизонтальному вигляді +nei.options.inventory.bookmarks.recipeTooltipsMode.2=У вертикальному вигляді +nei.options.inventory.bookmarks.recipeTooltipsMode.3=Завжди +nei.options.inventory.bookmarks.showRecipeMarkerMode=Показувати маркер рецепта +nei.options.inventory.bookmarks.showRecipeMarkerMode.0=Не показувати +nei.options.inventory.bookmarks.showRecipeMarkerMode.1=Текст +nei.options.inventory.bookmarks.showRecipeMarkerMode.2=Тло +nei.options.inventory.bookmarks.showRecipeHandlerIcon=Показувати іконку обробника +nei.options.inventory.bookmarks.showRecipeHandlerIcon.true=Так +nei.options.inventory.bookmarks.showRecipeHandlerIcon.false=Ні + +nei.options.inventory.bookmarks.recipeMarkerColor=Колір маркера рецепта +nei.options.inventory.bookmarks.ignorePotionOverlap=Ігнорувати перекриття з HUD ефектів зілля +nei.options.inventory.bookmarks.ignorePotionOverlap.true=Так +nei.options.inventory.bookmarks.ignorePotionOverlap.false=Ні +nei.options.inventory.bookmarks.worldSpecific=Прив’язка до світу +nei.options.inventory.bookmarks.worldSpecific.true=Так +nei.options.inventory.bookmarks.worldSpecific.false=Ні +nei.options.inventory.bookmarks.bookmarkItemsWithRecipe=Додавати в закладки предмети з рецептом +nei.options.inventory.bookmarks.bookmarkItemsWithRecipe.true=Так +nei.options.inventory.bookmarks.bookmarkItemsWithRecipe.false=Ні +nei.options.inventory.bookmarks.bookmarkRecipeWithCount=Додавати в закладки рецепт з кількістю +nei.options.inventory.bookmarks.bookmarkRecipeWithCount.true=Так +nei.options.inventory.bookmarks.bookmarkRecipeWithCount.false=Ні +nei.options.inventory.favorites=Обране +nei.options.inventory.favorites.enabled=Видимість +nei.options.inventory.favorites.enabled.true=Видимо +nei.options.inventory.favorites.enabled.false=Приховано +nei.options.inventory.favorites.worldSpecific=Прив’язка до світу +nei.options.inventory.favorites.worldSpecific.true=Так +nei.options.inventory.favorites.worldSpecific.false=Ні +nei.options.inventory.favorites.showRecipeTooltipInPanel=Підказки рецептів у правій панелі +nei.options.inventory.favorites.showRecipeTooltipInPanel.true=Так +nei.options.inventory.favorites.showRecipeTooltipInPanel.false=Ні +nei.options.inventory.favorites.showRecipeTooltipInGui=Підказки рецептів у меню рецептів +nei.options.inventory.favorites.showRecipeTooltipInGui.true=Так +nei.options.inventory.favorites.showRecipeTooltipInGui.false=Ні +nei.options.inventory.favorites.depth=Глибина +nei.options.inventory.favorites.generateSingleRecipeFavorites=Додавати в обране окремі рецепти +nei.options.inventory.favorites.generateSingleRecipeFavorites.true=Так +nei.options.inventory.favorites.generateSingleRecipeFavorites.false=Ні +nei.options.inventory.hotkeysHelpText=Показувати підказки щодо гарячих клавіш +nei.options.inventory.hotkeysHelpText.true=Так +nei.options.inventory.hotkeysHelpText.false=Ні +nei.options.inventory.showHotkeys=Показувати гарячі клавіші +nei.options.inventory.showHotkeys.true=Так +nei.options.inventory.showHotkeys.false=Ні +nei.options.inventory.guirecipe=Інтерфейс рецептів +nei.options.inventory.guirecipe.jeiStyleTabs=Вкладки у стилі JEI +nei.options.inventory.guirecipe.jeiStyleTabs.true=Так +nei.options.inventory.guirecipe.jeiStyleTabs.false=Ні [Дивак] +nei.options.inventory.guirecipe.itemPresenceOverlay=Індикатор наявності предметів під час наведення на «?» +nei.options.inventory.guirecipe.itemPresenceOverlay.0=Немає +nei.options.inventory.guirecipe.itemPresenceOverlay.1=Іконка +nei.options.inventory.guirecipe.itemPresenceOverlay.2=Тло +nei.options.inventory.guirecipe.slotHighlightPresent=Підсвічувати наявні предмети +nei.options.inventory.guirecipe.slotHighlightPresent.true=Так +nei.options.inventory.guirecipe.slotHighlightPresent.false=Ні +nei.options.inventory.guirecipe.infiniteScroll=Нескінченне прокручування +nei.options.inventory.guirecipe.infiniteScroll.true=Так +nei.options.inventory.guirecipe.infiniteScroll.false=Ні +nei.options.inventory.guirecipe.jeiStyleRecipeCatalyst=Каталізатори рецептів у стилі JEI +nei.options.inventory.guirecipe.jeiStyleRecipeCatalyst.0=Немає +nei.options.inventory.guirecipe.jeiStyleRecipeCatalyst.1=Сітка +nei.options.inventory.guirecipe.jeiStyleRecipeCatalyst.2=Прокручування +nei.options.inventory.guirecipe.cycledIngredientsTooltip=Підказка щодо циклічних інгредієнтів +nei.options.inventory.guirecipe.cycledIngredientsTooltip.true=Показувати +nei.options.inventory.guirecipe.cycledIngredientsTooltip.false=Приховувати +nei.options.inventory.guirecipe.handlerInfo=Віджет інформації про обробник +nei.options.inventory.guirecipe.handlerInfo.tip=Використовуйте Shift+D в інтерфейсі рецептів +nei.options.inventory.guirecipe.handlerInfo.true=Увімкнено +nei.options.inventory.guirecipe.handlerInfo.false=Вимкнено + +nei.options.inventory.guirecipe.scrollPages=Прокручування сторінок +nei.options.inventory.guirecipe.scrollPages.true=Увімкнено +nei.options.inventory.guirecipe.scrollPages.false=Вимкнено + +nei.options.inventory.guirecipe.maxHeight=Максимальна висота +nei.options.inventory.showItemQuantityWidget=Показувати віджет кількості предметів +nei.options.inventory.showItemQuantityWidget.true=Так +nei.options.inventory.showItemQuantityWidget.false=Ні +nei.options.inventory.search=Віджет пошуку +nei.options.inventory.search.widgetPosition=Позиція віджета +nei.options.inventory.search.widgetPosition.true=По центру +nei.options.inventory.search.widgetPosition.false=Праворуч +nei.options.inventory.search.hideUntilSearching=Приховувати до початку пошуку +nei.options.inventory.search.hideUntilSearching.true=Так +nei.options.inventory.search.hideUntilSearching.false=Ні +nei.options.inventory.search.widgetAutofocus=Автофокус +nei.options.inventory.search.widgetAutofocus.0=Ні +nei.options.inventory.search.widgetAutofocus.1=Так +nei.options.inventory.search.widgetAutofocus.2=Розширений +nei.options.inventory.search.patternMode=Режим пошуку +nei.options.inventory.search.patternMode.0=Звичайний +nei.options.inventory.search.patternMode.1=Розширений +nei.options.inventory.search.patternMode.2=Регулярні вирази +nei.options.inventory.search.patternMode.3=Розширений+ +nei.options.inventory.search.spaceMode=Пробіл працює як +nei.options.inventory.search.spaceMode.0=Логічне «AND» +nei.options.inventory.search.spaceMode.0.tip=Пробіл між токенами без префіксів працює як логічний оператор «AND» +nei.options.inventory.search.spaceMode.1=Пробіл +nei.options.inventory.search.spaceMode.1.tip=Пробіл між токенами без префіксів працює як звичайний пробіл +nei.options.inventory.search.spaceMode.2=Логічне «AND» (в категорії) +nei.options.inventory.search.spaceMode.2.tip=Пробіл працює як оператор «AND», але всі токени повинні бути в межах однієї категорії +nei.options.inventory.search.quoteDropItemName=Брати в лапки назву перетягнутого предмета +nei.options.inventory.search.quoteDropItemName.true=Так +nei.options.inventory.search.quoteDropItemName.false=Ні +nei.options.inventory.search.format=Формат пошуку +nei.options.inventory.search.format.true=Старий формат +nei.options.inventory.search.format.false=Розширений +nei.options.inventory.search.modNameSearchMode=Пошук за назвою моду +nei.options.inventory.search.modNameSearchMode.0=Завжди +nei.options.inventory.search.modNameSearchMode.1=Префікс: %s +nei.options.inventory.search.modNameSearchMode.2=Ніколи +nei.options.inventory.search.tooltipSearchMode=Пошук у підказках +nei.options.inventory.search.tooltipSearchMode.0=Завжди +nei.options.inventory.search.tooltipSearchMode.1=Префікс: %s +nei.options.inventory.search.tooltipSearchMode.2=Ніколи +nei.options.inventory.search.identifierSearchMode=Пошук за ID ресурсу +nei.options.inventory.search.identifierSearchMode.0=Завжди +nei.options.inventory.search.identifierSearchMode.1=Префікс: %s +nei.options.inventory.search.identifierSearchMode.2=Ніколи +nei.options.inventory.search.oreDictSearchMode=Пошук у OreDictionary +nei.options.inventory.search.oreDictSearchMode.0=Завжди +nei.options.inventory.search.oreDictSearchMode.1=Префікс: %s +nei.options.inventory.search.oreDictSearchMode.2=Ніколи +nei.options.inventory.search.subsetsSearchMode=Пошук у підгрупах предметів +nei.options.inventory.search.subsetsSearchMode.0=Завжди +nei.options.inventory.search.subsetsSearchMode.1=Префікс: %s +nei.options.inventory.search.subsetsSearchMode.2=Ніколи +nei.options.inventory.guirecipe.creativeTabStyle=Стиль вкладок Creative чи JEI +nei.options.inventory.guirecipe.creativeTabStyle.true=Creative +nei.options.inventory.guirecipe.creativeTabStyle.false=JEI +nei.options.inventory.optimize_gui_overlap_computation=Оптимізувати обчислення перекриття інтерфейсів +nei.options.inventory.optimize_gui_overlap_computation.true=Так +nei.options.inventory.optimize_gui_overlap_computation.false=Ні +nei.options.inventory.autocrafting=Автокрафт +nei.options.inventory.autocrafting.true=Увімкнено +nei.options.inventory.autocrafting.false=Вимкнено +nei.options.inventory.guirecipe.shiftOverlayRecipe=Утримувати Shift для переміщення предметів під час накладання рецепта +nei.options.inventory.guirecipe.shiftOverlayRecipe.true=Так +nei.options.inventory.guirecipe.shiftOverlayRecipe.false=Ні +nei.options.inventory.widgetsenabled.true=NEI увімкнено +nei.options.inventory.widgetsenabled.false=NEI вимкнено +nei.options.inventory.cheatmode.0=Режим рецептів +nei.options.inventory.cheatmode.1=Режим утиліт +nei.options.inventory.cheatmode.2=Режим читів +nei.options.inventory.guirecipe.profile=Профілювання рецептів +nei.options.inventory.guirecipe.profile.true=Так +nei.options.inventory.guirecipe.profile.false=Ні +nei.options.inventory.itemsort=Сортування панелі предметів +nei.options.inventory.itemIDs=ID предметів +nei.options.inventory.itemIDs.0=Приховано +nei.options.inventory.itemIDs.1=Авто +nei.options.inventory.itemIDs.2=Відображаються +nei.options.inventory.utilities=Утиліти +nei.options.inventory.utilities.tip=Оберіть функції для режиму утиліт +nei.options.inventory.utilities.time=Час +nei.options.inventory.utilities.rain=Дощ +nei.options.inventory.utilities.heal=Зцілення +nei.options.inventory.utilities.delete=Знищення +nei.options.inventory.utilities.magnet=Магніт +nei.options.inventory.utilities.gamemode=Режим гри +nei.options.inventory.utilities.enchant=Зачарування +nei.options.inventory.utilities.potion=Зілля +nei.options.inventory.utilities.item=Предмети +nei.options.inventory.gamemodes=Режими гри +nei.options.inventory.gamemodes.tip=Оберіть режими гри для перемикання +nei.options.inventory.gamemodes.creative=Творчий +nei.options.inventory.gamemodes.creative+=Творчий+ +nei.options.inventory.gamemodes.adventure=Пригодницький +nei.options.inventory.itempanelScale=Масштаб панелі предметів (у відсотках) +nei.options.inventory.disableMouseScrollTransfer=Вимкнути переміщення колесом миші +nei.options.inventory.disableMouseScrollTransfer.true=Так +nei.options.inventory.disableMouseScrollTransfer.false=Ні +nei.options.inventory.invertMouseScrollTransfer=Інвертувати напрямок переміщення колесом миші +nei.options.inventory.invertMouseScrollTransfer.true=Так +nei.options.inventory.invertMouseScrollTransfer.false=Ні +nei.options.inventory.gridRenderingCacheMode=Режим кешування візуалізації сітки +nei.options.inventory.gridRenderingCacheMode.0=Вимкнено +nei.options.inventory.gridRenderingCacheMode.1=Низький FPS +nei.options.inventory.gridRenderingCacheMode.2=Заморожування +nei.options.inventory.gridRenderingCacheFPS=FPS кешування візуалізації сітки +nei.options.inventory.collapsibleItems=Групування предметів +nei.options.inventory.collapsibleItems.enabled=Групування предметів +nei.options.inventory.collapsibleItems.enabled.true=Увімкнено +nei.options.inventory.collapsibleItems.enabled.false=Вимкнено +nei.options.inventory.collapsibleItems.customName=Показувати власну назву групи +nei.options.inventory.collapsibleItems.customName.true=Так +nei.options.inventory.collapsibleItems.customName.false=Ні +nei.options.inventory.collapsibleItems.expandedColor=Колір розгорнутої групи +nei.options.inventory.collapsibleItems.collapsedColor=Колір згорнутої групи +nei.options.inventory.history=Панель історії +nei.options.inventory.history.enabled=Видимість панелі історії +nei.options.inventory.history.enabled.true=Увімкнено +nei.options.inventory.history.enabled.false=Вимкнено +nei.options.inventory.history.color=Колір +nei.options.inventory.history.useRows=Рядки +nei.options.inventory.history.worldSpecific=Прив’язка до світу +nei.options.inventory.history.worldSpecific.true=Так +nei.options.inventory.history.worldSpecific.false=Ні +nei.options.inventory.history.save=Збереження історії +nei.options.inventory.history.save.true=Увімкнено +nei.options.inventory.history.save.false=Вимкнено +nei.options.inventory.craftables=Панель доступних крафтів +nei.options.inventory.craftables.enabled=Видимість панелі доступних крафтів +nei.options.inventory.craftables.enabled.true=Увімкнено +nei.options.inventory.craftables.enabled.false=Вимкнено +nei.options.inventory.craftables.color=Колір +nei.options.inventory.craftables.useRows=Рядки +nei.options.inventory.craftables.favoritesOnly=Показувати лише обрані +nei.options.inventory.craftables.favoritesOnly.true=Так +nei.options.inventory.craftables.favoritesOnly.false=Ні +nei.options.inventory.subsets=Віджет підгруп +nei.options.inventory.subsets.enabled=Видимість підгруп +nei.options.inventory.subsets.enabled.true=Увімкнено +nei.options.inventory.subsets.enabled.false=Вимкнено +nei.options.inventory.subsets.widgetPosition=Позиція віджета +nei.options.inventory.subsets.widgetPosition.true=Зверху +nei.options.inventory.subsets.widgetPosition.false=Знизу +nei.options.inventory.itemzoom=Панель наближення предметів +nei.options.inventory.itemzoom.enabled=Видимість панелі наближення предметів +nei.options.inventory.itemzoom.enabled.true=Увімкнено +nei.options.inventory.itemzoom.enabled.false=Вимкнено +nei.options.inventory.itemzoom.neiOnly=Лише для оверлеїв NEI +nei.options.inventory.itemzoom.neiOnly.true=Увімкнено +nei.options.inventory.itemzoom.neiOnly.false=Вимкнено +nei.options.inventory.itemzoom.neiOnly.tip=Наближати предмети лише зі списків інгредієнтів та закладок JEI. +nei.options.inventory.itemzoom.onlySolid=Показувати лише суцільні предмети +nei.options.inventory.itemzoom.onlySolid.true=Увімкнено +nei.options.inventory.itemzoom.onlySolid.false=Вимкнено +nei.options.inventory.itemzoom.helpText=Показувати текст підказки +nei.options.inventory.itemzoom.helpText.true=Увімкнено +nei.options.inventory.itemzoom.helpText.false=Вимкнено +nei.options.inventory.itemzoom.helpText.tip=Показувати назву «Наближення предмета» та гарячу клавішу перемикання під збільшеним предметом. +nei.options.inventory.itemzoom.zoom=Рівень наближення +nei.options.inventory.itemzoom.zoom.tip=Установіть менше значення, щоб зменшити ступінь наближення предмета. +nei.options.inventory.itemzoom.showName=Показувати назву +nei.options.inventory.itemzoom.showName.true=Показувати +nei.options.inventory.itemzoom.showName.false=Приховувати +nei.options.inventory.itemzoom.nameColor=Колір назви +nei.options.inventory.itemUntranslator=Оригінальні назви предметів +nei.options.inventory.itemUntranslator.true=Увімкнено +nei.options.inventory.itemUntranslator.false=Вимкнено + +nei.options.command=Команди +nei.options.command.creative=Режим гри +nei.options.command.creative.tip={0} = 1 для творчого, 0 для виживання, {1} = гравець +nei.options.command.item=Предмет +nei.options.command.item.tip={0} = гравець, {1} = ID, {2} = кількість, {3} = міцність/метадані, {4} = NBT, {5} = назва +nei.options.command.time=Час +nei.options.command.time.tip={0} = ігровий час +nei.options.command.rain=Дощ +nei.options.command.rain.tip={0} = 1 увімкнено, 0 вимкнено +nei.options.command.heal=Зцілення +nei.options.command.heal.tip={0} = гравець + +nei.options.world.highlight_tips=Контекстні підказки +nei.options.world.highlight_tips.hide=Приховані +nei.options.world.highlight_tips.show=Відображаються +nei.options.world.highlight_tips.sample=Зразок + +nei.options.world.panels=Налаштування панелей +nei.options.world.presets=Список пресетів + +nei.options.world.overlays=Налаштування оверлеїв +nei.options.world.overlays.lock=Фіксувати оверлеї між вимірами +nei.options.world.overlays.lock.true=Увімкнено +nei.options.world.overlays.lock.false=Вимкнено + +nei.options.tools=Інструменти +nei.options.tools.handler_load_from_config=Завантажувати обробники з конфігураційного файлу +nei.options.tools.handler_load_from_config.true=Конфігурація +nei.options.tools.handler_load_from_config.false=JAR +nei.options.tools.catalyst_load_from_config=Завантажувати каталізатори з конфігураційного файлу +nei.options.tools.catalyst_load_from_config.true=Конфігурація +nei.options.tools.catalyst_load_from_config.false=JAR +nei.options.tools.dump=Дампи даних +nei.options.tools.dump.dump=Створити дамп +nei.options.tools.dump.dumped=ID %s збережено в %s +nei.options.tools.dump.mode.0=Використані +nei.options.tools.dump.mode.1=Вільні +nei.options.tools.dump.mode.2=Усі +nei.options.tools.dump.item=Предметів +nei.options.tools.dump.items=Предмети +nei.options.tools.dump.block=Блоків +nei.options.tools.dump.blocks=Блоки +nei.options.tools.dump.potion=Зіллів +nei.options.tools.dump.potions=Зілля +nei.options.tools.dump.enchantment=Зачарувань +nei.options.tools.dump.enchantments=Зачарування +nei.options.tools.dump.biome=Біомів +nei.options.tools.dump.biomes=Біоми +nei.options.tools.dump.itempanel=Панель предметів +nei.options.tools.dump.itempanel.dumped=Вміст панелі предметів збережено в %s +nei.options.tools.dump.itempanel.mode.0=CSV +nei.options.tools.dump.itempanel.mode.1=NBT +nei.options.tools.dump.itempanel.mode.2=Json +nei.options.tools.dump.itempanel.mode.3=PNG +nei.options.tools.dump.itempanel.icon.dumped=Іконки панелі предметів збережено в %s +nei.options.tools.dump.itempanel.icon.cancelled=Дамп скасовано +nei.options.tools.dump.itempanel.icon.warning.1=§cУВАГА§r: Ви збираєтеся зберегти дамп %s предметів у роздільній здатності %sx%s +nei.options.tools.dump.itempanel.icon.warning.2=Утримуйте %s під час натискання цієї кнопки, щоб продовжити +nei.options.tools.dump.handlers=Обробники NEI +nei.options.tools.dump.handlers.dumped=Обробники збережено в %s +nei.options.tools.dump.handlers.mode.0=CSV +nei.options.tools.dump.handlers.mode.1=Json + +nei.debug.RecipeHandler.title=Налагодження обробника рецептів +nei.debug.RecipeHandler.copy=Скопіювати +nei.debug.RecipeHandler.Name=Назва +nei.debug.RecipeHandler.Id=ID +nei.debug.RecipeHandler.Key=Ключ +nei.debug.RecipeHandler.HHack=H.Hack +nei.debug.RecipeHandler.ModName=Назва моду +nei.debug.RecipeHandler.ModId=ID моду +nei.debug.RecipeHandler.Order=Порядок +nei.debug.RecipeHandler.yShift=yShift +nei.debug.RecipeHandler.MultiWidgets=Мультивіджети +nei.debug.RecipeHandler.Height=Висота +nei.debug.RecipeHandler.Width=Ширина +nei.debug.RecipeHandler.ShowFavorites=Показувати обрані +nei.debug.RecipeHandler.ShowOverlay=Показувати оверлеї +nei.debug.RecipeHandler.ShowBadge=Показувати плашку +nei.debug.RecipeHandler.AllowOverflowY=Дозволити вихід за межі Y +nei.debug.RecipeHandler.AllowOverflowX=Дозволити вихід за межі X +nei.debug.RecipeHandler.Override=Перевизначити +nei.debug.RecipeHandler.checkbox.on=Увімк. +nei.debug.RecipeHandler.checkbox.off=Вимк. +nei.debug.RecipeHandler.yes=Так +nei.debug.RecipeHandler.no=Ні +nei.debug.RecipeHandler.reset=Скинути + +nei.recipe.page=Сторінка %s/%s +nei.recipe.tooltip=Рецепти +nei.recipe.tab.view_all.tooltip=Переглянути всі категорії +nei.recipe.search.tooltip.name=Синтаксис фільтрів +nei.recipe.search.tooltip.shift=§7Утримуйте §6Shift§7 для детальнішої інформації +nei.recipe.search.tooltip.input=%s§fтекст§8 - §7пошук в інгредієнтах +nei.recipe.search.tooltip.output=%s§fтекст§8 - §7пошук у результатах +nei.recipe.search.tooltip.prefix=%sтекст§8 - §7%s + +nei.recipe.search.tooltip.prefix.modName=пошук за модом +nei.recipe.search.tooltip.prefix.tooltip=пошук за підказкою +nei.recipe.search.tooltip.prefix.oreDict=пошук за OreDict +nei.recipe.search.tooltip.prefix.identifier=пошук за ID ресурсу +nei.recipe.search.tooltip.prefix.subsets=пошук за підгрупами +nei.recipe.search.tooltip.prefix.chemicalFormula=пошук за хімічною формулою + +nei.recipe.search.tooltip.exclude=%s§fтекст§8 - §7виключити предмети, що містять текст +nei.recipe.search.tooltip.exclude_recipe=%s§fтекст§8 - §7виключити рецепти, що містять текст +nei.recipe.search.tooltip.or=§fa%s§fb§8 - §7пошук «a» або «b» +nei.recipe.search.tooltip.exact=%s§fтекст%s§8 - §7збіг із точною фразою + +nei.recipe.shaped=Формований крафт +nei.recipe.shapeless=Безформний крафт +nei.recipe.furnace=Витоплення +nei.recipe.fuel=Паливо +nei.recipe.fuel.smeltCount=Витоплює: %s + +nei.recipe.badge.nc=NC +nei.recipe.badge.nc.tooltip=Не витрачається у процесі + +nei.recipe.badge.ncp=NC(P) +nei.recipe.badge.ncp.tooltip=Враховується у паралельних обчисленнях, але не витрачається + +nei.recipe.badge.chance.consume=Шанс витрачання: %s +nei.recipe.badge.chance.output=Шанс отримання: %s + +# Застаріле +nei.recipe.fuel.required=Потрібно %s +# Застаріле +nei.recipe.fuel.processed=Оброблено %s +# Застаріле +nei.recipe.fuel.produced=Вироблено %s +nei.recipe.firework=Феєрверки +nei.recipe.firework.tooltip0=Барвники надають зарядам кольору +nei.recipe.firework.tooltip1=Повторне фарбування додає заряду ефект згасання кольорів +nei.recipe.firework.tooltip2=З одного феєрверку можна випустити кілька зарядів +nei.recipe.repair=Ремонт +nei.recipe.brewing=Зіллєваріння +nei.recipe.profiler.crafting=Профілювання крафту +nei.recipe.profiler.usage=Профілювання використання +nei.recipe.concurrent.usage=Паралельне використання — Всього +nei.recipe.concurrent.crafting=Паралельний крафт — Всього +nei.recipe.accepts=Приймає наступне +nei.recipe.accepts.scroll=Змінити предмет + +nei.recipe.overlay=Накладання рецепта +nei.recipe.overlay.missing=Відсутнє наступне +nei.recipe.overlay.mismatch=Невідповідність сітці крафту +nei.recipe.overlay.overlayRecipe=Накласти рецепт +nei.recipe.overlay.fillCraftingGrid=Заповнити сітку крафту +nei.recipe.overlay.bookmarkRecipe=Зберегти з рецептом +nei.recipe.overlay.bookmarkRecipeAndCount=Зберегти з рецептом і кількістю +nei.recipe.overlay.sendRecipeToChat=Надіслати рецепт у чат + +nei.recipe.favorite=Обране +nei.recipe.favorite.bookmark_recipe=Зберегти дерево рецептів +nei.recipe.favorite.change_result_index=Змінити результат +nei.recipe.favorite.toggle=Перемикнути обране + +nei.recipe.information=Інформація + +nei.itemsort.minecraft=Minecraft +nei.itemsort.minecraft.tip=Спочатку сортує предмети з ванільного Minecraft +nei.itemsort.mod=Мод +nei.itemsort.mod.tip=Групує предмети з одного моду, сортуючи за назвою моду +nei.itemsort.id=ID предмета +nei.itemsort.default=За замовчуванням +nei.itemsort.default.tip=Залишає початковий порядок кожного предмета без змін +nei.itemsort.damage=Пошкодження предмета +nei.itemsort.name=Відображувана назва + +nei.subsets.item.cheat=Видати предмет +nei.subsets.item.search=Пошук за предметом +nei.subsets.item.show=Показати предмет +nei.subsets.item.hide=Приховати предмет +nei.subsets.tag.search=Пошук за підгрупою +nei.subsets.tag.onlythis=Показати лише цю підгрупу +nei.subsets.tag.onlythis.key=Подвійне натискання ЛКМ +nei.subsets.tag.show=Показати підгрупу +nei.subsets.tag.hide=Приховати підгрупу + +nei.subsets.Blocks=Блоки +nei.subsets.Blocks.MobSpawners=Спавнери мобів +nei.subsets.CreativeTabs=Вкладки творчості +nei.subsets.Items=Предмети +nei.subsets.Items.Armor=Обладунки +nei.subsets.Items.Armor.Boots=Чоботи +nei.subsets.Items.Armor.Chestplates=Нагрудники +nei.subsets.Items.Armor.Helmets=Шоломи +nei.subsets.Items.Armor.Leggings=Наголінники +nei.subsets.Items.Food=Їжа +nei.subsets.Items.Potions=Зілля +nei.subsets.Items.Potions.Ingredients=Інгредієнти +nei.subsets.Items.Potions.Negative=Негативні +nei.subsets.Items.Potions.Neutral=Нейтральні +nei.subsets.Items.Potions.Positive=Позитивні +nei.subsets.Items.Potions.Splash=Вибухові +nei.subsets.Items.Tools=Інструменти +nei.subsets.Items.Tools.Axes=Сокири +nei.subsets.Items.Tools.Hoes=Мотики +nei.subsets.Items.Tools.Other=Інші +nei.subsets.Items.Tools.Pickaxes=Кайла +nei.subsets.Items.Tools.Shovels=Лопати +nei.subsets.Items.Weapons=Зброя +nei.subsets.Items.Weapons.Ranged=Дальнього бою +nei.subsets.Items.Weapons.Swords=Мечі +nei.subsets.Untranslated=Оригінальні +nei.subsets.Favorites=Обрані +nei.subsets.Favorites.Manual=Додані вручну +nei.subsets.Favorites.Generated=Автоматично +nei.subsets.Mod=Мод + +nei.presets.new=Новий пресет +nei.presets.toggle=Перемикнути пресети +nei.presets.create=Створити пресет +nei.presets.update=Оновити пресет +nei.presets.enabled=Увімкнено +nei.presets.filter=F +nei.presets.filter.tip=Приховати предмети з інших активних пресетів +nei.presets.name=Назва пресета +nei.presets.mode=Режим +nei.presets.mode.hide=Приховати +nei.presets.mode.hide.char=H +nei.presets.mode.hide.tip=Приховати предмети на панелі +nei.presets.mode.subset=Підгрупа +nei.presets.mode.subset.char=S +nei.presets.mode.subset.tip=Створити власні підгрупи +nei.presets.mode.remove=Видалити +nei.presets.mode.remove.tip=Приховати предмети на панелі та їхні рецепти +nei.presets.mode.remove.char=R +nei.presets.mode.group=Група +nei.presets.mode.group.tip=Створити власну групу предметів, що згортаються +nei.presets.mode.group.char=G + +nei.itemzoom.toggle=Використовуйте %s для перемикання наближення предметів diff --git a/src/main/resources/assets/nei/textures/gui/craftingtree.png b/src/main/resources/assets/nei/textures/gui/craftingtree.png new file mode 100644 index 00000000..254c412b Binary files /dev/null and b/src/main/resources/assets/nei/textures/gui/craftingtree.png differ diff --git a/src/test/java/codechicken/nei/ItemsGridTest.java b/src/test/java/codechicken/nei/ItemsGridTest.java new file mode 100644 index 00000000..ec1153bc --- /dev/null +++ b/src/test/java/codechicken/nei/ItemsGridTest.java @@ -0,0 +1,58 @@ +package codechicken.nei; + +import static org.junit.jupiter.api.Assertions.assertEquals; +import static org.mockito.Mockito.mock; +import static org.mockito.Mockito.times; +import static org.mockito.Mockito.verify; +import static org.mockito.Mockito.when; + +import java.util.Collections; +import java.util.List; + +import net.minecraft.client.gui.inventory.GuiContainer; + +import org.junit.jupiter.api.Test; + +public class ItemsGridTest { + + @Test + void synchronizesOverlapAndCaptureRefresh() { + TestGrid grid = new TestGrid(); + ItemsGrid.ScreenCapture capture = mock(ItemsGrid.ScreenCapture.class); + grid.screenCapture = capture; + + grid.setGridSize(1, 2, 18, 18); + grid.setGridSize(1, 2, 18, 18); + verify(capture, times(1)).refreshBuffer(); + + when(capture.needRefresh(1)).thenReturn(false, true); + grid.refresh(null); + grid.refresh(null); + assertEquals(1, grid.overlapRefreshes); + } + + private static final class TestGrid extends ItemsGrid { + + private int overlapRefreshes; + + @Override + protected int getGridRenderingCacheMode() { + return 1; + } + + @Override + protected void updateGuiOverlapSlots(GuiContainer gui) { + overlapRefreshes++; + } + + @Override + public List getMask() { + return Collections.emptyList(); + } + + @Override + protected ItemsGrid.MouseContext getMouseContext(int mousex, int mousey) { + return null; + } + } +} diff --git a/src/test/java/codechicken/nei/NEIPotionGuiHandlerTest.java b/src/test/java/codechicken/nei/NEIPotionGuiHandlerTest.java new file mode 100644 index 00000000..4d3b7576 --- /dev/null +++ b/src/test/java/codechicken/nei/NEIPotionGuiHandlerTest.java @@ -0,0 +1,26 @@ +package codechicken.nei; + +import static org.junit.jupiter.api.Assertions.assertFalse; +import static org.junit.jupiter.api.Assertions.assertTrue; +import static org.mockito.Mockito.mock; + +import net.minecraft.client.renderer.InventoryEffectRenderer; + +import org.junit.jupiter.api.Test; + +public class NEIPotionGuiHandlerTest { + + @Test + void preservesGapsBetweenPotionBoxes() { + assertTrue(NEIPotionGuiHandler.intersectsPotionEffects(131, 1, 100, 2, 33)); + assertFalse(NEIPotionGuiHandler.intersectsPotionEffects(132, 1, 100, 2, 33)); + } + + @Test + void skipsConfigLookupOutsidePotionColumn() { + InventoryEffectRenderer gui = mock(InventoryEffectRenderer.class); + gui.guiLeft = 200; + + assertFalse(new NEIPotionGuiHandler().hideItemPanelSlot(gui, 216, 100, 1, 1)); + } +} diff --git a/src/test/java/codechicken/nei/api/GuiInfoTest.java b/src/test/java/codechicken/nei/api/GuiInfoTest.java new file mode 100644 index 00000000..a088ace3 --- /dev/null +++ b/src/test/java/codechicken/nei/api/GuiInfoTest.java @@ -0,0 +1,36 @@ +package codechicken.nei.api; + +import static org.junit.jupiter.api.Assertions.assertFalse; +import static org.junit.jupiter.api.Assertions.assertTrue; +import static org.mockito.Mockito.mock; +import static org.mockito.Mockito.when; + +import java.util.Collections; + +import net.minecraft.client.gui.GuiButton; +import net.minecraft.client.gui.inventory.GuiContainer; + +import org.junit.jupiter.api.Test; + +import codechicken.lib.vec.Rectangle4i; + +public class GuiInfoTest { + + @Test + void checksProvidedHandlerSnapshot() { + GuiContainer gui = mock(GuiContainer.class); + INEIGuiHandler handler = mock(INEIGuiHandler.class); + when(handler.hideItemPanelSlot(gui, 1, 2, 3, 4)).thenReturn(true); + + assertTrue(GuiInfo.hideItemPanelSlot(gui, new Rectangle4i(1, 2, 3, 4), new INEIGuiHandler[] { handler })); + } + + @Test + void buttonEdgeContactDoesNotOverlap() { + GuiContainer gui = mock(GuiContainer.class); + gui.buttonList = Collections.singletonList(new GuiButton(0, 10, 10, 10, 10, "")); + + assertTrue(GuiInfo.hideItemPanelSlot(gui, new Rectangle4i(19, 19, 1, 1), new INEIGuiHandler[0])); + assertFalse(GuiInfo.hideItemPanelSlot(gui, new Rectangle4i(20, 10, 1, 1), new INEIGuiHandler[0])); + } +} diff --git a/src/test/java/codechicken/nei/guihook/GuiContainerManagerTest.java b/src/test/java/codechicken/nei/guihook/GuiContainerManagerTest.java new file mode 100644 index 00000000..d04754cd --- /dev/null +++ b/src/test/java/codechicken/nei/guihook/GuiContainerManagerTest.java @@ -0,0 +1,26 @@ +package codechicken.nei.guihook; + +import static org.mockito.Mockito.mockStatic; +import static org.mockito.Mockito.times; + +import org.junit.jupiter.api.Test; +import org.lwjgl.opengl.GL11; +import org.mockito.MockedStatic; + +public class GuiContainerManagerTest { + + @Test + void matrixStackLoggingSupportsNestedContexts() { + try (MockedStatic gl = mockStatic(GL11.class)) { + GuiContainerManager.enableMatrixStackLogging(); + GuiContainerManager.enableMatrixStackLogging(); + GuiContainerManager.disableMatrixStackLogging(); + + gl.verify(() -> GL11.glPushAttrib(GL11.GL_ENABLE_BIT | GL11.GL_COLOR_BUFFER_BIT | GL11.GL_LIGHTING_BIT)); + gl.verify(GL11::glPopAttrib, times(0)); + + GuiContainerManager.disableMatrixStackLogging(); + gl.verify(GL11::glPopAttrib); + } + } +}