ClientHelper.java 5.2 KB

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