diff --git a/src/main/java/net/seanomik/energeticstorage/gui/ESTerminalGUI.java b/src/main/java/net/seanomik/energeticstorage/gui/ESTerminalGUI.java index e0442f7..99ba550 100644 --- a/src/main/java/net/seanomik/energeticstorage/gui/ESTerminalGUI.java +++ b/src/main/java/net/seanomik/energeticstorage/gui/ESTerminalGUI.java @@ -120,9 +120,7 @@ public class ESTerminalGUI implements InventoryHolder, Listener { break; case AMOUNT: Map finalItems = items; - sortedKeys.sort((i1, i2) -> { - return finalItems.get(i2).compareTo(finalItems.get(i1)); - }); + sortedKeys.sort((i1, i2) -> finalItems.get(i2).compareTo(finalItems.get(i1))); break; case ID: sortedKeys.sort(Comparator.comparing(ItemStack::getType)); diff --git a/src/main/java/net/seanomik/energeticstorage/objects/ESDrive.java b/src/main/java/net/seanomik/energeticstorage/objects/ESDrive.java index 915d938..401ac22 100644 --- a/src/main/java/net/seanomik/energeticstorage/objects/ESDrive.java +++ b/src/main/java/net/seanomik/energeticstorage/objects/ESDrive.java @@ -68,6 +68,20 @@ public class ESDrive implements Cloneable, ConfigurationSerializable { uuid = (driveNBT.hasKey("ES_DriveUUID")) ? UUID.fromString(driveNBT.getString("ES_DriveUUID")) : UUID.randomUUID(); } + public static ItemStack sterilizedItem(ItemStack item) { + ItemMeta meta = item.getItemMeta(); + + if (meta.hasLore()) { + List itemLore = meta.getLore(); + itemLore.removeIf(lore -> lore.startsWith("Amount:")); + + meta.setLore(itemLore); + item.setItemMeta(meta); + } + + return item; + } + public UUID getUUID() { return uuid; } @@ -142,7 +156,8 @@ public class ESDrive implements Cloneable, ConfigurationSerializable { } public boolean addItem(ItemStack item) { - item = item.clone(); + // Sterilize items of the "Amount: " lore + item = sterilizedItem(item.clone()); if (canAddItem(item)) { // The item is contained, then update the amount. diff --git a/src/main/java/net/seanomik/energeticstorage/objects/ESSystem.java b/src/main/java/net/seanomik/energeticstorage/objects/ESSystem.java index 65f5f55..67e03e3 100644 --- a/src/main/java/net/seanomik/energeticstorage/objects/ESSystem.java +++ b/src/main/java/net/seanomik/energeticstorage/objects/ESSystem.java @@ -168,13 +168,15 @@ public class ESSystem implements Cloneable, ConfigurationSerializable { for (ESDrive drive : esDrives) { for (Map.Entry entry : drive.getItems().entrySet()) { - if (items.containsKey(entry.getKey())) { - // Set the ItemStack amount to the already existing item's amount + this amount - entry.getKey().setAmount(Math.min(entry.getValue(), 64)); - items.remove(entry.getKey()); - } + ItemStack sterilizedItem = ESDrive.sterilizedItem(entry.getKey()); - items.put(entry.getKey(), entry.getValue()); + if (items.containsKey(entry.getKey())) { + int amount = items.get(entry.getKey()); + + items.put(sterilizedItem, amount + entry.getValue()); + } else { + items.put(sterilizedItem, entry.getValue()); + } } }