diff --git a/plugins/civmodcore-paper/src/main/java/vg/civcraft/mc/civmodcore/inventory/items/ItemMap.java b/plugins/civmodcore-paper/src/main/java/vg/civcraft/mc/civmodcore/inventory/items/ItemMap.java index 6009c55b7..2298311ac 100644 --- a/plugins/civmodcore-paper/src/main/java/vg/civcraft/mc/civmodcore/inventory/items/ItemMap.java +++ b/plugins/civmodcore-paper/src/main/java/vg/civcraft/mc/civmodcore/inventory/items/ItemMap.java @@ -15,7 +15,6 @@ import org.bukkit.Material; import org.bukkit.inventory.Inventory; import org.bukkit.inventory.ItemStack; import org.bukkit.inventory.PlayerInventory; -import vg.civcraft.mc.civmodcore.inventory.CustomItem; /** * Allows the storage and comparison of item stacks while ignoring their maximum possible stack sizes. This offers @@ -36,7 +35,6 @@ import vg.civcraft.mc.civmodcore.inventory.CustomItem; public class ItemMap { private final Object2IntMap items; - private final Object2IntOpenHashMap customItems; private int totalItems; /** @@ -45,8 +43,6 @@ public class ItemMap { public ItemMap() { this.items = new Object2IntOpenHashMap<>(0); this.items.defaultReturnValue(0); - this.customItems = new Object2IntOpenHashMap<>(); - this.customItems.defaultReturnValue(0); this.totalItems = 0; } @@ -58,8 +54,6 @@ public class ItemMap { public ItemMap(final ItemStack item) { this.items = new Object2IntOpenHashMap<>(1); this.items.defaultReturnValue(0); - this.customItems = new Object2IntOpenHashMap<>(); - this.customItems.defaultReturnValue(0); this.totalItems = 0; addItemStack(item); } @@ -72,8 +66,6 @@ public class ItemMap { public ItemMap(final Collection stacks) { this.items = new Object2IntOpenHashMap<>(stacks.size()); this.items.defaultReturnValue(0); - this.customItems = new Object2IntOpenHashMap<>(); - this.customItems.defaultReturnValue(0); addAll(stacks); } @@ -86,8 +78,6 @@ public class ItemMap { public ItemMap(final Inventory inventory) { this.items = new Object2IntOpenHashMap<>(inventory.getSize()); this.items.defaultReturnValue(0); - this.customItems = new Object2IntOpenHashMap<>(); - this.customItems.defaultReturnValue(0); this.totalItems = 0; update(inventory); } @@ -106,15 +96,10 @@ public class ItemMap { public void addItemStack(final ItemStack input) { if (!ItemUtils.isValidItemIgnoringAmount(input)) { return; - } + } BiFunction addFn = (key, amount) -> amount == null ? input.getAmount() : amount + input.getAmount(); - String customItemKey = CustomItem.getCustomItemKey(input); - if (customItemKey != null) { - this.customItems.computeInt(customItemKey, addFn); - } else { - this.items.computeInt(INTERNAL_createKey(input), addFn); - } + this.items.computeInt(INTERNAL_createKey(input), addFn); this.totalItems += input.getAmount(); } @@ -145,12 +130,7 @@ public class ItemMap { return; } BiFunction subFun = (_key, amount) -> (amount -= input.getAmount()) <= 0 ? null : amount; - String customItemKey = CustomItem.getCustomItemKey(input); - if (customItemKey != null) { - this.customItems.computeIntIfPresent(customItemKey, subFun); - } else { - this.items.computeIntIfPresent(key, subFun); - } + this.items.computeIntIfPresent(key, subFun); } /** @@ -167,7 +147,7 @@ public class ItemMap { @Override public int hashCode() { - return Objects.hash(this.items.hashCode(), this.customItems.hashCode()); + return Objects.hash(this.items.hashCode()); } /** @@ -192,14 +172,10 @@ public class ItemMap { for (Entry entry : im.items.object2IntEntrySet()) { addItemAmount(entry.getKey(), entry.getValue()); } - for (Entry entry : im.customItems.object2IntEntrySet()) { - addItemAmount(CustomItem.getCustomItem(entry.getKey()), entry.getValue()); - } } public void update(final Inventory inventory) { this.items.clear(); - this.customItems.clear(); this.totalItems = 0; for (int i = 0; i < inventory.getSize(); i++) { final ItemStack item = inventory.getItem(i); @@ -239,12 +215,6 @@ public class ItemMap { result.addItemAmount(is.clone(), items.get(is)); } } - for (String is : customItems.keySet()) { - ItemStack item = CustomItem.getCustomItem(is); - if (item != null && item.getType() == m) { - result.addItemAmount(item, customItems.get(is)); - } - } return result; } @@ -269,11 +239,6 @@ public class ItemMap { amount += entry.getValue(); } } - for (Entry entry : matSubMap.customItems.object2IntEntrySet()) { - if (entry.getKey().equals(CustomItem.getCustomItemKey(is))) { - amount += entry.getValue(); - } - } return amount; } @@ -288,25 +253,17 @@ public class ItemMap { * @return How many unique items are stored in this map */ public int getTotalUniqueItemAmount() { - return items.keySet().size() + customItems.keySet().size(); + return items.keySet().size(); } public Map getAllItems() { - Object2IntOpenHashMap map = new Object2IntOpenHashMap<>(this.items); - for (Object2IntMap.Entry entry : this.customItems.object2IntEntrySet()) { - map.put(CustomItem.getCustomItem(entry.getKey()), entry.getIntValue()); - } - return map; + return new Object2IntOpenHashMap<>(this.items); } public Object2IntMap getItems() { return items; } - public Object2IntOpenHashMap getCustomItems() { - return customItems; - } - /** * Checks whether an inventory contains exactly what's described in this ItemMap * @@ -387,10 +344,6 @@ public class ItemMap { items.put(entry.getKey(), (int) (entry.getValue() * multiplier)); totalItems += (int) (entry.getValue() * multiplier); } - for (Entry entry : this.customItems.object2IntEntrySet()) { - customItems.put(entry.getKey(), (int) (entry.getValue() * multiplier)); - totalItems += (int) (entry.getValue() * multiplier); - } } /** @@ -543,7 +496,7 @@ public class ItemMap { public boolean equals(Object o) { if (o instanceof ItemMap im) { if (im.getTotalItemAmount() == getTotalItemAmount()) { - return im.items.equals(items) && im.customItems.equals(customItems); + return im.items.equals(items); } } return false; diff --git a/plugins/factorymod-paper/src/main/java/com/github/igotyou/FactoryMod/recipes/InputRecipe.java b/plugins/factorymod-paper/src/main/java/com/github/igotyou/FactoryMod/recipes/InputRecipe.java index f11231821..6ddc2bf48 100644 --- a/plugins/factorymod-paper/src/main/java/com/github/igotyou/FactoryMod/recipes/InputRecipe.java +++ b/plugins/factorymod-paper/src/main/java/com/github/igotyou/FactoryMod/recipes/InputRecipe.java @@ -218,33 +218,28 @@ public abstract class InputRecipe implements IRecipe { protected List formatLore(ItemMap ingredients) { List result = new ArrayList<>(); - for (Entry entry : ingredients.getItems().entrySet()) { + for (Entry entry : ingredients.getAllItems().entrySet()) { if (entry.getValue() > 0) { - if (!entry.getKey().hasItemMeta()) { - result.add(entry.getValue() + " " + ItemUtils.getItemName(entry.getKey())); - } else { - String lore = String.format("%s %s%s", entry.getValue(), ChatColor.ITALIC, ItemUtils.getItemName(entry.getKey())); - if (entry.getKey().getItemMeta().hasDisplayName()) { - lore += String.format("%s [%s%1$s]", ChatColor.DARK_AQUA, StringUtils.abbreviate(entry.getKey().getItemMeta().getDisplayName(), 20)); + ItemStack item = entry.getKey(); + String customItemKey = CustomItem.getCustomItemKey(item); + if (customItemKey != null) { + ItemStack customItem = CustomItem.getCustomItem(customItemKey); + if (customItem != null && customItem.hasItemMeta() && customItem.getItemMeta().hasDisplayName()) { + result.add(String.format("%s %s", entry.getValue(), + StringUtils.abbreviate(customItem.getItemMeta().getDisplayName(), 35))); + } else if (customItem != null && customItem.hasItemMeta() && customItem.getItemMeta().hasItemName()) { + result.add(String.format("%s %s", entry.getValue(), + StringUtils.abbreviate(customItem.getItemMeta().getItemName(), 35))); + } else { + result.add(String.format("%s %s", entry.getValue(), customItemKey)); } - result.add(lore); - } - } - } - // Custom items should have their custom name displayed more prominently, their actual item type is irrelevant - for (Entry entry : ingredients.getCustomItems().entrySet()) { - if (entry.getValue() > 0) { - ItemStack item = CustomItem.getCustomItem(entry.getKey()); - if (!item.hasItemMeta()) { + } else if (!item.hasItemMeta()) { result.add(entry.getValue() + " " + ItemUtils.getItemName(item)); } else { - String lore; + String lore = String.format("%s %s%s", entry.getValue(), ChatColor.ITALIC, ItemUtils.getItemName(item)); if (item.getItemMeta().hasDisplayName()) { - lore = String.format("%s %s", entry.getValue(), StringUtils.abbreviate(item.getItemMeta().getDisplayName(), 35)); - } else if (item.getItemMeta().hasItemName()) { - lore = String.format("%s %s", entry.getValue(), StringUtils.abbreviate(item.getItemMeta().getItemName(), 35)); - } else { - lore = String.format("%s %s%s", entry.getValue(), ChatColor.ITALIC, ItemUtils.getItemName(item)); + lore += String.format("%s [%s%1$s]", ChatColor.DARK_AQUA, + StringUtils.abbreviate(item.getItemMeta().getDisplayName(), 20)); } result.add(lore); }