Skip to content

Commit

Permalink
fix: InventoryOverlay Tooltip display (Add fully Styled Tooltips for …
Browse files Browse the repository at this point in the history
…InventoryPreview code)
  • Loading branch information
sakura-ryoko committed Dec 18, 2024
1 parent a99e347 commit 6aed83a
Show file tree
Hide file tree
Showing 2 changed files with 25 additions and 11 deletions.
16 changes: 15 additions & 1 deletion src/main/java/fi/dy/masa/malilib/render/InventoryOverlay.java
Original file line number Diff line number Diff line change
Expand Up @@ -1116,6 +1116,7 @@ public static void renderStackToolTip(int x, int y, ItemStack stack, MinecraftCl
List<Text> list = stack.getTooltip(Item.TooltipContext.create(mc.world), mc.player, mc.options.advancedItemTooltips ? TooltipType.ADVANCED : TooltipType.BASIC);
List<String> lines = new ArrayList<>();

//dumpTooltip(list);
for (int i = 0; i < list.size(); ++i)
{
if (i == 0)
Expand Down Expand Up @@ -1144,14 +1145,27 @@ public static void renderStackToolTipStyled(int x, int y, ItemStack stack, Minec
{
if (stack.isEmpty() == false && mc.world != null && mc.player != null)
{
List<Text> toolTips = stack.getTooltip(Item.TooltipContext.create(mc.world), mc.player, mc.options.advancedItemTooltips ? TooltipType.ADVANCED : TooltipType.BASIC);
dumpTooltip(toolTips);
drawContext.drawTooltip(mc.textRenderer,
stack.getTooltip(Item.TooltipContext.create(mc.world), mc.player, mc.options.advancedItemTooltips ? TooltipType.ADVANCED : TooltipType.BASIC),
toolTips,
stack.getTooltipData(), // Bundle/Optional Data
x, y,
stack.get(DataComponentTypes.TOOLTIP_STYLE));
}
}

private static void dumpTooltip(List<Text> list)
{
int i = 0;

for (Text entry : list)
{
System.out.printf("dumpTooltip[%d]: %s\n", i, entry.getString());
i++;
}
}

public static class InventoryProperties
{
public int totalSlots = 1;
Expand Down
20 changes: 10 additions & 10 deletions src/main/java/fi/dy/masa/malilib/util/InventoryUtils.java
Original file line number Diff line number Diff line change
Expand Up @@ -640,7 +640,7 @@ public static Inventory getNbtInventory(@Nonnull NbtCompound nbt, int slotCount,
}
for (int i = 0; i < slotCount; i++)
{
inv.setStack(i, items.get(i));
inv.setStack(i, items.get(i).copy());
}

return inv;
Expand Down Expand Up @@ -678,7 +678,7 @@ else if (nbt.contains(NbtKeys.ITEM))
// item (DecoratedPot, ItemEntity)
ItemStack entry = ItemStack.fromNbtOrEmpty(registry, nbt.getCompound(NbtKeys.ITEM));
SimpleInventory inv = new SimpleInventory(1);
inv.setStack(0, entry);
inv.setStack(0, entry.copy());

return inv;
}
Expand All @@ -687,7 +687,7 @@ else if (nbt.contains(NbtKeys.ITEM_2))
// Item (Item Frame)
ItemStack entry = ItemStack.fromNbtOrEmpty(registry, nbt.getCompound(NbtKeys.ITEM_2));
SimpleInventory inv = new SimpleInventory(1);
inv.setStack(0, entry);
inv.setStack(0, entry.copy());

return inv;
}
Expand All @@ -696,7 +696,7 @@ else if (nbt.contains(NbtKeys.BOOK))
// Book (Lectern)
ItemStack entry = ItemStack.fromNbtOrEmpty(registry, nbt.getCompound(NbtKeys.BOOK));
SimpleInventory inv = new SimpleInventory(1);
inv.setStack(0, entry);
inv.setStack(0, entry.copy());

return inv;
}
Expand All @@ -705,7 +705,7 @@ else if (nbt.contains(NbtKeys.RECORD))
// RecordItem (Jukebox)
ItemStack entry = ItemStack.fromNbtOrEmpty(registry, nbt.getCompound(NbtKeys.RECORD));
SimpleInventory inv = new SimpleInventory(1);
inv.setStack(0, entry);
inv.setStack(0, entry.copy());

return inv;
}
Expand Down Expand Up @@ -754,7 +754,7 @@ public static Inventory getNbtInventoryHorseFix(@Nonnull NbtCompound nbt, int sl
{
return null;
}
inv.setStack(0, saddle);
inv.setStack(0, saddle.copy());
for (int i = 0; i < slotCount; i++)
{
inv.setStack(i + 1, items.get(i));
Expand All @@ -766,7 +766,7 @@ public static Inventory getNbtInventoryHorseFix(@Nonnull NbtCompound nbt, int sl
else if (!saddle.isEmpty())
{
SimpleInventory inv = new SimpleInventory(1);
inv.setStack(0, saddle);
inv.setStack(0, saddle.copy());

return inv;
}
Expand All @@ -775,7 +775,7 @@ else if (nbt.contains(NbtKeys.ITEM))
// item (DecoratedPot, ItemEntity)
ItemStack entry = ItemStack.fromNbtOrEmpty(registry, nbt.getCompound(NbtKeys.ITEM));
SimpleInventory inv = new SimpleInventory(1);
inv.setStack(0, entry);
inv.setStack(0, entry.copy());
}

return null;
Expand Down Expand Up @@ -963,7 +963,7 @@ public static DefaultedList<ItemStack> getBundleItems(ItemStack stackIn)

if (slot.isEmpty() == false)
{
items.add(slot);
items.add(slot.copy());
}
}

Expand Down Expand Up @@ -1003,7 +1003,7 @@ public static DefaultedList<ItemStack> getBundleItems(ItemStack stackIn, int max

while (iter.hasNext() && limit < maxSlots)
{
items.add(iter.next());
items.add(iter.next().copy());
limit++;
}

Expand Down

0 comments on commit 6aed83a

Please sign in to comment.