ItemRegistry.java 2.0 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879
  1. /*
  2. * Roughly Enough Items by Danielshe.
  3. * Licensed under the MIT License.
  4. */
  5. package me.shedaniel.rei.api;
  6. import net.minecraft.item.Item;
  7. import net.minecraft.item.ItemStack;
  8. import java.util.List;
  9. public interface ItemRegistry {
  10. /**
  11. * Gets the current unmodifiable item list
  12. *
  13. * @return an unmodifiable item list
  14. */
  15. List<ItemStack> getItemList();
  16. /**
  17. * Gets the current modifiable item list
  18. *
  19. * @return an modifiable item list
  20. */
  21. @Deprecated
  22. List<ItemStack> getModifiableItemList();
  23. /**
  24. * Gets all possible stacks from an item
  25. *
  26. * @param item the item to find
  27. * @return the array of possible stacks
  28. */
  29. ItemStack[] getAllStacksFromItem(Item item);
  30. /**
  31. * Registers an new stack to the item list
  32. *
  33. * @param afterItem the stack to put after
  34. * @param stack the stack to register
  35. */
  36. void registerItemStack(Item afterItem, ItemStack stack);
  37. /**
  38. * Registers multiple stacks to the item list
  39. *
  40. * @param afterItem the stack to put after
  41. * @param stacks the stacks to register
  42. */
  43. default void registerItemStack(Item afterItem, ItemStack... stacks) {
  44. for(ItemStack stack : stacks)
  45. if (stack != null && !stack.isEmpty())
  46. registerItemStack(afterItem, stack);
  47. }
  48. /**
  49. * Registers multiple stacks to the item list
  50. *
  51. * @param stacks the stacks to register
  52. */
  53. default void registerItemStack(ItemStack... stacks) {
  54. for(ItemStack stack : stacks)
  55. if (stack != null && !stack.isEmpty())
  56. registerItemStack(null, stack);
  57. }
  58. /**
  59. * Checks if a stack is already registered
  60. *
  61. * @param stack the stack to check
  62. * @return whether the stack has been registered
  63. */
  64. default boolean alreadyContain(ItemStack stack) {
  65. return getItemList().stream().anyMatch(stack1 -> ItemStack.areEqual(stack, stack1));
  66. }
  67. }