Fix displaying amounts for an item type that is in more than one drive
This commit is contained in:
parent
277974edae
commit
226d28cd3b
|
@ -120,9 +120,7 @@ public class ESTerminalGUI implements InventoryHolder, Listener {
|
|||
break;
|
||||
case AMOUNT:
|
||||
Map<ItemStack, Integer> 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));
|
||||
|
|
|
@ -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<String> 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.
|
||||
|
|
|
@ -168,13 +168,15 @@ public class ESSystem implements Cloneable, ConfigurationSerializable {
|
|||
|
||||
for (ESDrive drive : esDrives) {
|
||||
for (Map.Entry<ItemStack, Integer> 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());
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
|
Loading…
Reference in New Issue