diff --git a/src/api/java/mcp/mobius/waila/api/data/ItemData.java b/src/api/java/mcp/mobius/waila/api/data/ItemData.java index b585ea110..f1ee399df 100644 --- a/src/api/java/mcp/mobius/waila/api/data/ItemData.java +++ b/src/api/java/mcp/mobius/waila/api/data/ItemData.java @@ -22,6 +22,7 @@ public final class ItemData implements IData { public static final ResourceLocation ID = BuiltinDataUtil.rl("item"); public static final ResourceLocation CONFIG_SYNC_NBT = BuiltinDataUtil.rl("item.nbt"); public static final ResourceLocation CONFIG_MAX_HEIGHT = BuiltinDataUtil.rl("item.max_height"); + public static final ResourceLocation CONFIG_SORT_BY_COUNT = BuiltinDataUtil.rl("item.sort_by_count"); /** * Creates an item data based from plugin config. diff --git a/src/pluginExtra/java/mcp/mobius/waila/plugin/extra/provider/ItemProvider.java b/src/pluginExtra/java/mcp/mobius/waila/plugin/extra/provider/ItemProvider.java index 33c9ded05..ce04e971f 100644 --- a/src/pluginExtra/java/mcp/mobius/waila/plugin/extra/provider/ItemProvider.java +++ b/src/pluginExtra/java/mcp/mobius/waila/plugin/extra/provider/ItemProvider.java @@ -3,6 +3,7 @@ import java.util.Comparator; import java.util.HashMap; import java.util.HashSet; +import java.util.LinkedHashMap; import java.util.Map; import java.util.Set; @@ -35,6 +36,7 @@ protected ItemProvider() { protected void registerAdditions(IRegistrar registrar, int priority) { registrar.addSyncedConfig(ItemData.CONFIG_SYNC_NBT, true, false); registrar.addConfig(ItemData.CONFIG_MAX_HEIGHT, 3); + registrar.addConfig(ItemData.CONFIG_SORT_BY_COUNT, true); } @Override @@ -55,7 +57,7 @@ protected void appendBody(ITooltip tooltip, ItemData data, IPluginConfig config, lastData = data; lastItemsComponent = null; - Map merged = new HashMap<>(); + Map merged = new LinkedHashMap<>(); Map> unique = new HashMap<>(); for (var stack : data.items()) { @@ -84,9 +86,12 @@ protected void appendBody(ITooltip tooltip, ItemData data, IPluginConfig config, if (merged.isEmpty()) return; - tooltip.setLine(ItemData.ID, lastItemsComponent = new ItemListComponent(merged.values().stream() - .sorted(Comparator.comparingInt(ItemStack::getCount).reversed()) - .toList(), config.getInt(ItemData.CONFIG_MAX_HEIGHT))); + var stream = merged.values().stream(); + if (config.getBoolean(ItemData.CONFIG_SORT_BY_COUNT)) { + stream = stream.sorted(Comparator.comparingInt(ItemStack::getCount).reversed()); + } + + tooltip.setLine(ItemData.ID, lastItemsComponent = new ItemListComponent(stream.toList(), config.getInt(ItemData.CONFIG_MAX_HEIGHT))); } private record ItemWithNbt(Item item, CompoundTag tag) { diff --git a/src/resources/resources/assets/waila/lang/en_us.json b/src/resources/resources/assets/waila/lang/en_us.json index 69a3afad0..a08544740 100644 --- a/src/resources/resources/assets/waila/lang/en_us.json +++ b/src/resources/resources/assets/waila/lang/en_us.json @@ -284,6 +284,7 @@ "config.waila.plugin_wailax.item.enabled_entity" : "Show Entity Item Contents", "config.waila.plugin_wailax.item.nbt" : "Sync NBT Data", "config.waila.plugin_wailax.item.max_height" : "Max Height", + "config.waila.plugin_wailax.item.sort_by_count" : "Sort by Count", "config.waila.plugin_wailax.item.blacklist" : "Item Contents Blacklist", "config.waila.plugin_wailax.fluid" : "Fluid", "config.waila.plugin_wailax.fluid.enabled_block" : "Show Block Fluid Contents",