ClientHelper.java 4.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154
  1. /*
  2. * Copyright (c) 2018, 2019, 2020 shedaniel
  3. * Licensed under the MIT License (the "License").
  4. */
  5. package me.shedaniel.rei.api;
  6. import me.shedaniel.rei.impl.ClientHelperImpl;
  7. import net.minecraft.item.Item;
  8. import net.minecraft.item.ItemStack;
  9. import net.minecraft.util.Identifier;
  10. import org.jetbrains.annotations.ApiStatus;
  11. import java.util.List;
  12. import java.util.Map;
  13. public interface ClientHelper {
  14. /**
  15. * @return the api instance of {@link ClientHelperImpl}
  16. */
  17. @SuppressWarnings("deprecation")
  18. static ClientHelper getInstance() {
  19. return ClientHelperImpl.instance;
  20. }
  21. /**
  22. * Checks if cheating is enabled
  23. *
  24. * @return whether cheating is enabled
  25. */
  26. boolean isCheating();
  27. /**
  28. * Sets current cheating mode
  29. * Should save the config in {@link ConfigManager}.
  30. *
  31. * @param cheating the new cheating mode
  32. */
  33. void setCheating(boolean cheating);
  34. List<ItemStack> getInventoryItemsTypes();
  35. /**
  36. * Opens a recipe viewing screen:
  37. * Opens {@link me.shedaniel.rei.gui.PreRecipeViewingScreen} if not set
  38. * Opens {@link me.shedaniel.rei.gui.RecipeViewingScreen} if set to default
  39. * Opens {@link me.shedaniel.rei.gui.VillagerRecipeViewingScreen} if set to villager
  40. *
  41. * @param map the map of recipes
  42. */
  43. void openRecipeViewingScreen(Map<RecipeCategory<?>, List<RecipeDisplay>> map);
  44. /**
  45. * Registers REI's keybinds using Fabric API.
  46. */
  47. @ApiStatus.Internal
  48. void registerFabricKeyBinds();
  49. /**
  50. * Tries to cheat stack using either packets or commands.
  51. *
  52. * @param stack the stack to cheat in
  53. * @return whether it failed
  54. */
  55. boolean tryCheatingEntry(EntryStack stack);
  56. default boolean tryCheatingStack(ItemStack stack) {
  57. return tryCheatingEntry(EntryStack.create(stack));
  58. }
  59. /**
  60. * Finds recipe for the stack and opens the recipe screen.
  61. *
  62. * @param stack the stack to find recipe for
  63. * @return whether the stack has any recipes to show
  64. */
  65. boolean executeRecipeKeyBind(EntryStack stack);
  66. default boolean executeRecipeKeyBind(ItemStack stack) {
  67. return executeRecipeKeyBind(EntryStack.create(stack));
  68. }
  69. /**
  70. * Finds usage for the stack and opens the recipe screen.
  71. *
  72. * @param stack the stack to find usage for
  73. * @return whether the stack has any usages to show
  74. */
  75. boolean executeUsageKeyBind(EntryStack stack);
  76. default boolean executeUsageKeyBind(ItemStack stack) {
  77. return executeUsageKeyBind(EntryStack.create(stack));
  78. }
  79. /**
  80. * Gets the mod from an item
  81. *
  82. * @param item the item to find
  83. * @return the mod name
  84. */
  85. String getModFromItem(Item item);
  86. /**
  87. * Tries to delete the player's cursor item
  88. */
  89. void sendDeletePacket();
  90. /**
  91. * Gets the formatted mod from an item
  92. *
  93. * @param item the item to find
  94. * @return the mod name with blue and italic formatting
  95. */
  96. String getFormattedModFromItem(Item item);
  97. /**
  98. * Gets the formatted mod from an identifier
  99. *
  100. * @param identifier the identifier to find
  101. * @return the mod name with blue and italic formatting
  102. */
  103. String getFormattedModFromIdentifier(Identifier identifier);
  104. /**
  105. * Gets the mod from an identifier
  106. *
  107. * @param identifier the identifier to find
  108. * @return the mod name
  109. */
  110. default String getModFromIdentifier(Identifier identifier) {
  111. if (identifier == null)
  112. return "";
  113. return getModFromModId(identifier.getNamespace());
  114. }
  115. /**
  116. * Gets the mod from a modid
  117. *
  118. * @param modid the modid of the mod
  119. * @return the mod name
  120. */
  121. String getModFromModId(String modid);
  122. /**
  123. * Finds all recipes and open them in a recipe screen.
  124. *
  125. * @return whether there are any recipes to show
  126. */
  127. boolean executeViewAllRecipesKeyBind();
  128. boolean executeViewAllRecipesFromCategory(Identifier category);
  129. boolean executeViewAllRecipesFromCategories(List<Identifier> categories);
  130. }