EntryRegistry.java 4.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127
  1. /*
  2. * This file is licensed under the MIT License, part of Roughly Enough Items.
  3. * Copyright (c) 2018, 2019, 2020 shedaniel
  4. *
  5. * Permission is hereby granted, free of charge, to any person obtaining a copy
  6. * of this software and associated documentation files (the "Software"), to deal
  7. * in the Software without restriction, including without limitation the rights
  8. * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
  9. * copies of the Software, and to permit persons to whom the Software is
  10. * furnished to do so, subject to the following conditions:
  11. *
  12. * The above copyright notice and this permission notice shall be included in all
  13. * copies or substantial portions of the Software.
  14. *
  15. * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
  16. * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
  17. * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
  18. * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
  19. * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
  20. * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
  21. * SOFTWARE.
  22. */
  23. package me.shedaniel.rei.api;
  24. import me.shedaniel.rei.RoughlyEnoughItemsCore;
  25. import me.shedaniel.rei.utils.CollectionUtils;
  26. import net.minecraft.item.Item;
  27. import net.minecraft.item.ItemStack;
  28. import org.jetbrains.annotations.ApiStatus;
  29. import java.util.Arrays;
  30. import java.util.Collection;
  31. import java.util.List;
  32. public interface EntryRegistry {
  33. static EntryRegistry getInstance() {
  34. return RoughlyEnoughItemsCore.getEntryRegistry();
  35. }
  36. /**
  37. * Gets the current modifiable stacks list
  38. *
  39. * @return a stacks list
  40. */
  41. List<EntryStack> getStacksList();
  42. List<EntryStack> getPreFilteredList();
  43. List<ItemStack> appendStacksForItem(Item item);
  44. /**
  45. * Gets all possible stacks from an item
  46. *
  47. * @param item the item to find
  48. * @return the array of possible stacks
  49. */
  50. ItemStack[] getAllStacksFromItem(Item item);
  51. default void registerEntry(EntryStack stack) {
  52. registerEntryAfter(null, stack);
  53. }
  54. /**
  55. * Registers an new stack to the entry list
  56. *
  57. * @param afterEntry the stack to put after
  58. * @param stack the stack to register
  59. */
  60. default void registerEntryAfter(EntryStack afterEntry, EntryStack stack) {
  61. registerEntryAfter(afterEntry, stack, true);
  62. }
  63. /**
  64. * Registers an new stack to the entry list
  65. *
  66. * @param afterEntry the stack to put after
  67. * @param stack the stack to register
  68. * @param checkAlreadyContains whether the list should check if it is already on the list
  69. * @see #queueRegisterEntryAfter(EntryStack, Collection) for a faster method
  70. */
  71. @Deprecated
  72. @ApiStatus.Internal
  73. void registerEntryAfter(EntryStack afterEntry, EntryStack stack, boolean checkAlreadyContains);
  74. void queueRegisterEntryAfter(EntryStack afterEntry, Collection<? extends EntryStack> stacks);
  75. /**
  76. * Registers multiple stacks to the item list
  77. *
  78. * @param afterStack the stack to put after
  79. * @param stacks the stacks to register
  80. */
  81. default void registerEntriesAfter(EntryStack afterStack, EntryStack... stacks) {
  82. registerEntriesAfter(afterStack, Arrays.asList(stacks));
  83. }
  84. /**
  85. * Registers multiple stacks to the item list
  86. *
  87. * @param afterStack the stack to put after
  88. * @param stacks the stacks to register
  89. */
  90. void registerEntriesAfter(EntryStack afterStack, Collection<? extends EntryStack> stacks);
  91. /**
  92. * Registers multiple stacks to the item list
  93. *
  94. * @param stacks the stacks to register
  95. */
  96. default void registerEntries(EntryStack... stacks) {
  97. registerEntriesAfter(null, stacks);
  98. }
  99. /**
  100. * Checks if a stack is already registered
  101. *
  102. * @param stack the stack to check
  103. * @return whether the stack has been registered
  104. */
  105. default boolean alreadyContain(EntryStack stack) {
  106. return CollectionUtils.anyMatchEqualsAll(getStacksList(), stack);
  107. }
  108. }