Skip to content

Commit

Permalink
add option to not sort item list
Browse files Browse the repository at this point in the history
  • Loading branch information
deirn committed Sep 20, 2023
1 parent fd8b36e commit 531a9f8
Show file tree
Hide file tree
Showing 3 changed files with 11 additions and 4 deletions.
1 change: 1 addition & 0 deletions src/api/java/mcp/mobius/waila/api/data/ItemData.java
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;

Expand Down Expand Up @@ -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
Expand All @@ -55,7 +57,7 @@ protected void appendBody(ITooltip tooltip, ItemData data, IPluginConfig config,
lastData = data;
lastItemsComponent = null;

Map<Object, ItemStack> merged = new HashMap<>();
Map<Object, ItemStack> merged = new LinkedHashMap<>();
Map<Item, Set<CompoundTag>> unique = new HashMap<>();

for (var stack : data.items()) {
Expand Down Expand Up @@ -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) {
Expand Down
1 change: 1 addition & 0 deletions src/resources/resources/assets/waila/lang/en_us.json
Original file line number Diff line number Diff line change
Expand Up @@ -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",
Expand Down

0 comments on commit 531a9f8

Please sign in to comment.