Skip to content

Commit

Permalink
Changed the map creation and item name check to remove possibility of…
Browse files Browse the repository at this point in the history
… index out of range error and key not found error.
  • Loading branch information
MrGII committed Jul 28, 2024
1 parent 6da6e1a commit 5e62f69
Showing 1 changed file with 2 additions and 2 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -16,15 +16,15 @@ public static void ModifyPotionStackSize(List<String> itemNames, List<Integer> m
ItemsStack.LOGGER.info("Changing stack size of minecraft potions.");
for (Item item : Registries.ITEM) {
String name = item.getName().getString();
if (itemNames.contains(name)) {
if (itemToMaxStackSize.containsKey(name)) {
((ItemAccessor) item).setComponents(ComponentMap.of(item.getComponents(), ComponentMap.builder().add(DataComponentTypes.MAX_STACK_SIZE, itemToMaxStackSize.get(name)).build()));
}
}
}

private static Map<String, Integer> createItemToStackSizeMap(List<String> itemNames, List<Integer> maxStackSizes) {
Map<String, Integer> itemToMaxStackSize = new java.util.HashMap<>(Map.of());
for (int i = 0; i < itemNames.size(); i++) {
for (int i = 0; i < Math.min(itemNames.size(), maxStackSizes.size()); i++) {
itemToMaxStackSize.put(itemNames.get(i), maxStackSizes.get(i));
}
return itemToMaxStackSize;
Expand Down

0 comments on commit 5e62f69

Please sign in to comment.