From ff1091d25241e6be5f89bbaa9be21a64f99343cf Mon Sep 17 00:00:00 2001 From: PrototypeTrousers Date: Mon, 6 Feb 2023 13:26:59 -0300 Subject: [PATCH] add toolitps to cells --- .../java/appeng/core/api/ApiClientHelper.java | 79 ++++++++++++++++++- 1 file changed, 75 insertions(+), 4 deletions(-) diff --git a/src/main/java/appeng/core/api/ApiClientHelper.java b/src/main/java/appeng/core/api/ApiClientHelper.java index 557fa62c3..e8340955e 100644 --- a/src/main/java/appeng/core/api/ApiClientHelper.java +++ b/src/main/java/appeng/core/api/ApiClientHelper.java @@ -4,10 +4,25 @@ package appeng.core.api; import appeng.api.config.IncludeExclude; import appeng.api.storage.ICellInventory; import appeng.api.storage.ICellInventoryHandler; +import appeng.api.storage.channels.IFluidStorageChannel; +import appeng.api.storage.channels.IItemStorageChannel; +import appeng.api.storage.data.IAEFluidStack; +import appeng.api.storage.data.IAEItemStack; import appeng.api.storage.data.IAEStack; +import appeng.api.storage.data.IItemList; import appeng.api.util.IClientHelper; import appeng.core.localization.GuiText; +import appeng.fluids.items.FluidDummyItem; +import appeng.fluids.util.AEFluidStack; +import appeng.util.item.AEItemStack; +import net.minecraft.client.Minecraft; +import net.minecraft.item.ItemStack; +import net.minecraftforge.fluids.FluidUtil; +import net.minecraftforge.items.IItemHandler; +import net.minecraftforge.oredict.OreDictionary; +import org.lwjgl.input.Keyboard; +import java.util.Collection; import java.util.List; @@ -27,16 +42,72 @@ public class ApiClientHelper implements IClientHelper { .getLocal()); } + IItemList itemList = cellInventory.getChannel().createList(); + if (handler.isPreformatted()) { final String list = (handler.getIncludeExcludeMode() == IncludeExclude.WHITELIST ? GuiText.Included : GuiText.Excluded).getLocal(); if (handler.isFuzzy()) { - lines.add(GuiText.Partitioned.getLocal() + " - " + list + ' ' + GuiText.Fuzzy.getLocal()); + lines.add("[" + GuiText.Partitioned.getLocal() + "]" + " - " + list + ' ' + GuiText.Fuzzy.getLocal()); } else { - lines.add(GuiText.Partitioned.getLocal() + " - " + list + ' ' + GuiText.Precise.getLocal()); + lines.add("[" + GuiText.Partitioned.getLocal() + "]" + " - " + list + ' ' + GuiText.Precise.getLocal()); + } + + if (Minecraft.getMinecraft().gameSettings.advancedItemTooltips || Keyboard.isKeyDown(Keyboard.KEY_LSHIFT) || Keyboard.isKeyDown(Keyboard.KEY_RSHIFT)) { + IItemHandler inv = cellInventory.getConfigInventory(); + cellInventory.getAvailableItems((IItemList) itemList); + for (int i = 0; i < inv.getSlots(); i++) { + final ItemStack is = inv.getStackInSlot(i); + if (!is.isEmpty()) { + if (cellInventory.getChannel() instanceof IItemStorageChannel) { + if (!handler.isFuzzy()) { + final IAEItemStack ais = AEItemStack.fromItemStack(is); + IAEItemStack stocked = ((IItemList) itemList).findPrecise(ais); + lines.add("[" + is.getDisplayName() + "]" + ": " + (stocked == null ? "0" : String.valueOf(stocked.getStackSize()))); + } else { + final IAEItemStack ais = AEItemStack.fromItemStack(is); + Collection stocked = ((IItemList) itemList).findFuzzy(ais, handler.getCellInv().getFuzzyMode()); + + int[] ids = OreDictionary.getOreIDs(is); + long size = 0; + for (IAEItemStack ist : stocked) { + size += ist.getStackSize(); + } + + if (is.getItem().isDamageable()) { + lines.add("[" + is.getDisplayName() + "]" + ": " + size); + } else if (ids.length > 0) { + StringBuilder sb = new StringBuilder(); + for (int j : ids) { + sb.append(OreDictionary.getOreName(j)).append(", "); + } + lines.add("[{" + sb.substring(0, sb.length() - 2) + "}]" + ": " + size); + } + } + } else if (cellInventory.getChannel() instanceof IFluidStorageChannel) { + final AEFluidStack ais; + if (is.getItem() instanceof FluidDummyItem) { + ais = AEFluidStack.fromFluidStack(((FluidDummyItem) is.getItem()).getFluidStack(is)); + } else { + ais = AEFluidStack.fromFluidStack(FluidUtil.getFluidContained(is)); + } + IAEFluidStack stocked = ((IItemList) itemList).findPrecise(ais); + lines.add("[" + is.getDisplayName() + "]" + ": " + (stocked == null ? "0" : String.valueOf(stocked.getStackSize()))); + } + } + } + } + } else { + if (Minecraft.getMinecraft().gameSettings.advancedItemTooltips || Keyboard.isKeyDown(Keyboard.KEY_LSHIFT) || Keyboard.isKeyDown(Keyboard.KEY_RSHIFT)) { + cellInventory.getAvailableItems((IItemList) itemList); + for (IAEStack s : itemList) { + if (s instanceof IAEItemStack) { + lines.add(((IAEItemStack) s).getDefinition().getDisplayName() + ": " + s.getStackSize()); + } else if (s instanceof IAEFluidStack) { + lines.add(((IAEFluidStack) s).getFluidStack().getLocalizedName() + ": " + s.getStackSize() + "mB"); + } + } } } - } - }