From b21e6ab56e0c72ef31dca5be8dfbba93ddb5028e Mon Sep 17 00:00:00 2001 From: Boblet Date: Wed, 1 Apr 2026 13:36:59 +0200 Subject: [PATCH] ow my leg --- .../java/api/hbm/ntl/StorageManifest.java | 15 +++++----- src/main/java/api/hbm/ntl/StorageStack.java | 28 ++++++++++++++++++- .../com/hbm/inventory/gui/GUICrucible.java | 3 +- 3 files changed, 37 insertions(+), 9 deletions(-) diff --git a/src/main/java/api/hbm/ntl/StorageManifest.java b/src/main/java/api/hbm/ntl/StorageManifest.java index a1be6d9cc..628502d52 100644 --- a/src/main/java/api/hbm/ntl/StorageManifest.java +++ b/src/main/java/api/hbm/ntl/StorageManifest.java @@ -1,7 +1,8 @@ package api.hbm.ntl; import java.util.ArrayList; -import java.util.HashMap; +import java.util.Collections; +import java.util.LinkedHashMap; import java.util.List; import java.util.Map.Entry; @@ -11,7 +12,7 @@ import net.minecraft.nbt.NBTTagCompound; public class StorageManifest { - public HashMap itemMeta = new HashMap(); + public LinkedHashMap itemMeta = new LinkedHashMap(); public void writeStack(ItemStack stack) { int id = Item.getIdFromItem(stack.getItem()); @@ -38,7 +39,7 @@ public class StorageManifest { nbt.nbtAmount.put(compound, amount); } - public List getStacks() { + public List getStacks(boolean sorted) { List stacks = new ArrayList(); for(Entry itemNode : itemMeta.entrySet()) { @@ -53,16 +54,16 @@ public class StorageManifest { } } + if(sorted) Collections.sort(stacks); + return stacks; } public class MetaNode { - - public HashMap metaNBT = new HashMap(); + public LinkedHashMap metaNBT = new LinkedHashMap(); } public class NBTNode { - - public HashMap nbtAmount = new HashMap(); + public LinkedHashMap nbtAmount = new LinkedHashMap(); } } diff --git a/src/main/java/api/hbm/ntl/StorageStack.java b/src/main/java/api/hbm/ntl/StorageStack.java index 71fdd8b66..31871f696 100644 --- a/src/main/java/api/hbm/ntl/StorageStack.java +++ b/src/main/java/api/hbm/ntl/StorageStack.java @@ -1,14 +1,17 @@ package api.hbm.ntl; +import net.minecraft.item.Item; import net.minecraft.item.ItemStack; -public class StorageStack { +public class StorageStack implements Comparable { + private int cachedItemId; private ItemStack type; private long amount; public StorageStack(ItemStack type) { this(type, type.stackSize); + this.cachedItemId = Item.getIdFromItem(type.getItem()); } public StorageStack(ItemStack type, long amount) { @@ -24,4 +27,27 @@ public class StorageStack { public long getAmount() { return this.amount; } + + @Override + public int compareTo(Object o) { + StorageStack other = (StorageStack) o; + + if(this.cachedItemId < other.cachedItemId) return -1; + if(this.cachedItemId > other.cachedItemId) return 1; + if(this.type.getItemDamage() < other.type.getItemDamage()) return -1; + if(this.type.getItemDamage() > other.type.getItemDamage()) return 1; + if(this.type.hasTagCompound() && !other.type.hasTagCompound()) return -1; + if(!this.type.hasTagCompound() && other.type.hasTagCompound()) return 1; + if(this.type.hasTagCompound() && other.type.hasTagCompound()) { + // keyset size comparison should hopefully catch most of the larger NBT cases + if(this.type.stackTagCompound.func_150296_c().size() < other.type.stackTagCompound.func_150296_c().size()) return -1; + if(this.type.stackTagCompound.func_150296_c().size() > other.type.stackTagCompound.func_150296_c().size()) return 1; + int comp = this.type.stackTagCompound.toString().compareTo(other.type.stackTagCompound.toString()); // not terribly performant but hopefully not that common + if(comp != 0) return comp; + } + if(this.type.stackSize < other.type.stackSize) return -1; + if(this.type.stackSize > other.type.stackSize) return 1; + + return 0; + } } diff --git a/src/main/java/com/hbm/inventory/gui/GUICrucible.java b/src/main/java/com/hbm/inventory/gui/GUICrucible.java index 605a268b1..1c11acefb 100644 --- a/src/main/java/com/hbm/inventory/gui/GUICrucible.java +++ b/src/main/java/com/hbm/inventory/gui/GUICrucible.java @@ -87,7 +87,8 @@ public class GUICrucible extends GuiInfoContainer { GenericRecipe recipe = CrucibleRecipes.INSTANCE.recipeNameMap.get(crucible.recipe); this.renderItem(recipe != null ? recipe.getIcon() : TEMPLATE_FOLDER, 107, 81); - + + Minecraft.getMinecraft().getTextureManager().bindTexture(texture); if(!crucible.recipeStack.isEmpty()) drawStack(crucible.recipeStack, crucible.recipeZCapacity, 62, 97); if(!crucible.wasteStack.isEmpty()) drawStack(crucible.wasteStack, crucible.wasteZCapacity, 17, 97); }