From a8ee876077e357efcd8f151ae57aba313efa736f Mon Sep 17 00:00:00 2001 From: Paul Schifferer Date: Thu, 28 Nov 2024 08:47:07 -0800 Subject: [PATCH] #27 Sort items in craft queue and shopping list --- CHANGELOG/1.18/current.md | 1 + .../client/overlay/CraftQueueOverlay.java | 33 +++++++++++++++---- .../client/overlay/ShoppingListOverlay.java | 9 +++-- 3 files changed, 34 insertions(+), 9 deletions(-) diff --git a/CHANGELOG/1.18/current.md b/CHANGELOG/1.18/current.md index e69de29..50ba2d9 100644 --- a/CHANGELOG/1.18/current.md +++ b/CHANGELOG/1.18/current.md @@ -0,0 +1 @@ +- `[NEW]` Items in the queue and shopping list are now sorted by name diff --git a/src/main/java/com/sweetrpg/crafttracker/client/overlay/CraftQueueOverlay.java b/src/main/java/com/sweetrpg/crafttracker/client/overlay/CraftQueueOverlay.java index fca38b8..b0ae5cd 100644 --- a/src/main/java/com/sweetrpg/crafttracker/client/overlay/CraftQueueOverlay.java +++ b/src/main/java/com/sweetrpg/crafttracker/client/overlay/CraftQueueOverlay.java @@ -35,7 +35,11 @@ public class CraftQueueOverlay { CraftTracker.LOGGER.trace("CRAFT_QUEUE"); var mgr = CraftingQueueManager.INSTANCE; - var products = mgr.getEndProducts(); + var products = mgr.getEndProducts().stream().sorted((i1, i2) -> { + var item1 = ForgeRegistries.ITEMS.getValue(i1.getItemId()); + var item2 = ForgeRegistries.ITEMS.getValue(i2.getItemId()); + return item1.getDescription().getString().compareTo(item2.getDescription().getString()); + }).toList(); switch(CTRuntime.INSTANCE.queueOverlayRequestedState) { case SHOW: @@ -129,8 +133,13 @@ public class CraftQueueOverlay { CraftTracker.LOGGER.trace("yPos (after intermediates title): {}", yPos); // items - for(int i = 0; i < mgr.getIntermediates().size(); i++) { - var inter = mgr.getIntermediates().get(i); + var sortedIntermediates = mgr.getIntermediates().stream().sorted((i1, i2) -> { + var item1 = ForgeRegistries.ITEMS.getValue(i1.getItemId()); + var item2 = ForgeRegistries.ITEMS.getValue(i2.getItemId()); + return item1.getDescription().getString().compareTo(item2.getDescription().getString()); + }).toList(); + for(int i = 0; i < sortedIntermediates.size(); i++) { + var inter = sortedIntermediates.get(i); var item = ForgeRegistries.ITEMS.getValue(inter.getItemId()); var stack = item.getDefaultInstance(); @@ -179,8 +188,13 @@ public class CraftQueueOverlay { CraftTracker.LOGGER.trace("yPos (after materials title): {}", yPos); // items - for(int i = 0; i < mgr.getRawMaterials().size(); i++) { - var m = mgr.getRawMaterials().get(i); + var sortedMaterials = mgr.getRawMaterials().stream().sorted((i1, i2) -> { + var item1 = ForgeRegistries.ITEMS.getValue(i1.getItemId()); + var item2 = ForgeRegistries.ITEMS.getValue(i2.getItemId()); + return item1.getDescription().getString().compareTo(item2.getDescription().getString()); + }).toList(); + for(int i = 0; i < sortedMaterials.size(); i++) { + var m = sortedMaterials.get(i); var item = ForgeRegistries.ITEMS.getValue(m.getItemId()); var stack = item.getDefaultInstance(); @@ -229,8 +243,13 @@ public class CraftQueueOverlay { CraftTracker.LOGGER.trace("yPos: {}", yPos); // items - for(int i = 0; i < mgr.getFuel().size(); i++) { - var f = mgr.getFuel().get(i); + var sortedFuels = mgr.getFuel().stream().sorted((i1, i2) -> { + var item1 = ForgeRegistries.ITEMS.getValue(i1.getItemId()); + var item2 = ForgeRegistries.ITEMS.getValue(i2.getItemId()); + return item1.getDescription().getString().compareTo(item2.getDescription().getString()); + }).toList(); + for(int i = 0; i < sortedFuels.size(); i++) { + var f = sortedFuels.get(i); var item = ForgeRegistries.ITEMS.getValue(f.getItemId()); var stack = item.getDefaultInstance(); diff --git a/src/main/java/com/sweetrpg/crafttracker/client/overlay/ShoppingListOverlay.java b/src/main/java/com/sweetrpg/crafttracker/client/overlay/ShoppingListOverlay.java index a3afb00..1aa1f40 100644 --- a/src/main/java/com/sweetrpg/crafttracker/client/overlay/ShoppingListOverlay.java +++ b/src/main/java/com/sweetrpg/crafttracker/client/overlay/ShoppingListOverlay.java @@ -92,8 +92,13 @@ public class ShoppingListOverlay { var inventory = Minecraft.getInstance().player.getInventory(); // items - for(int i = 0; i < mgr.getItems().size(); i++) { - var m = mgr.getItems().get(i); + var sortedItems = mgr.getItems().stream().sorted((i1, i2) -> { + var item1 = ForgeRegistries.ITEMS.getValue(i1.getItemId()); + var item2 = ForgeRegistries.ITEMS.getValue(i2.getItemId()); + return item1.getDescription().getString().compareTo(item2.getDescription().getString()); + }).toList(); + for(int i = 0; i < sortedItems.size(); i++) { + var m = sortedItems.get(i); var item = ForgeRegistries.ITEMS.getValue(m.getItemId()); var stack = item.getDefaultInstance();