Internals.java 5.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161
  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.impl;
  24. import me.shedaniel.math.Point;
  25. import me.shedaniel.math.Rectangle;
  26. import me.shedaniel.rei.api.*;
  27. import me.shedaniel.rei.api.fluid.FluidSupportProvider;
  28. import me.shedaniel.rei.api.fractions.Fraction;
  29. import me.shedaniel.rei.api.subsets.SubsetsRegistry;
  30. import me.shedaniel.rei.api.widgets.*;
  31. import me.shedaniel.rei.gui.widget.Widget;
  32. import net.fabricmc.api.EnvType;
  33. import net.fabricmc.api.Environment;
  34. import net.minecraft.fluid.Fluid;
  35. import net.minecraft.item.ItemStack;
  36. import net.minecraft.text.StringRenderable;
  37. import net.minecraft.text.Text;
  38. import net.minecraft.util.Identifier;
  39. import org.jetbrains.annotations.ApiStatus;
  40. import org.jetbrains.annotations.NotNull;
  41. import org.jetbrains.annotations.Nullable;
  42. import java.util.Collection;
  43. import java.util.function.BiFunction;
  44. import java.util.function.Supplier;
  45. @ApiStatus.Internal
  46. public final class Internals {
  47. private static Supplier<ConfigManager> configManager = Internals::throwNotSetup;
  48. private static Supplier<ClientHelper> clientHelper = Internals::throwNotSetup;
  49. private static Supplier<RecipeHelper> recipeHelper = Internals::throwNotSetup;
  50. private static Supplier<REIHelper> reiHelper = Internals::throwNotSetup;
  51. private static Supplier<FluidSupportProvider> fluidSupportProvider = Internals::throwNotSetup;
  52. private static Supplier<EntryStackProvider> entryStackProvider = Internals::throwNotSetup;
  53. private static Supplier<SubsetsRegistry> subsetsRegistry = Internals::throwNotSetup;
  54. private static Supplier<EntryRegistry> entryRegistry = Internals::throwNotSetup;
  55. private static Supplier<DisplayHelper> displayHelper = Internals::throwNotSetup;
  56. private static Supplier<WidgetsProvider> widgetsProvider = Internals::throwNotSetup;
  57. private static Supplier<ClientHelper.ViewSearchBuilder> viewSearchBuilder = Internals::throwNotSetup;
  58. private static BiFunction<@Nullable Point, Collection<Text>, Tooltip> tooltipProvider = (point, texts) -> throwNotSetup();
  59. private static <T> T throwNotSetup() {
  60. throw new AssertionError("REI Internals have not been initialized!");
  61. }
  62. @NotNull
  63. public static ConfigManager getConfigManager() {
  64. return configManager.get();
  65. }
  66. @NotNull
  67. public static ClientHelper getClientHelper() {
  68. return clientHelper.get();
  69. }
  70. @NotNull
  71. public static RecipeHelper getRecipeHelper() {
  72. return recipeHelper.get();
  73. }
  74. @NotNull
  75. public static REIHelper getREIHelper() {
  76. return reiHelper.get();
  77. }
  78. @NotNull
  79. @ApiStatus.Experimental
  80. public static FluidSupportProvider getFluidSupportProvider() {
  81. return fluidSupportProvider.get();
  82. }
  83. @NotNull
  84. public static EntryStackProvider getEntryStackProvider() {
  85. return entryStackProvider.get();
  86. }
  87. @NotNull
  88. public static SubsetsRegistry getSubsetsRegistry() {
  89. return subsetsRegistry.get();
  90. }
  91. @NotNull
  92. public static EntryRegistry getEntryRegistry() {
  93. return entryRegistry.get();
  94. }
  95. @NotNull
  96. public static DisplayHelper getDisplayHelper() {
  97. return displayHelper.get();
  98. }
  99. @NotNull
  100. public static WidgetsProvider getWidgetsProvider() {
  101. return widgetsProvider.get();
  102. }
  103. @NotNull
  104. public static ClientHelper.ViewSearchBuilder createViewSearchBuilder() {
  105. return viewSearchBuilder.get();
  106. }
  107. @NotNull
  108. public static Tooltip createTooltip(@Nullable Point point, Collection<Text> texts) {
  109. return tooltipProvider.apply(point, texts);
  110. }
  111. public interface EntryStackProvider {
  112. EntryStack empty();
  113. EntryStack fluid(Fluid fluid);
  114. EntryStack fluid(Fluid fluid, Fraction amount);
  115. EntryStack item(ItemStack stack);
  116. }
  117. @Environment(EnvType.CLIENT)
  118. public interface WidgetsProvider {
  119. boolean isRenderingPanel(Panel panel);
  120. Widget createDrawableWidget(DrawableConsumer drawable);
  121. Slot createSlot(Point point);
  122. Button createButton(Rectangle bounds, Text text);
  123. Panel createPanelWidget(Rectangle bounds);
  124. Label createLabel(Point point, StringRenderable text);
  125. Arrow createArrow(Rectangle rectangle);
  126. BurningFire createBurningFire(Rectangle rectangle);
  127. DrawableConsumer createTexturedConsumer(Identifier texture, int x, int y, int width, int height, float u, float v, int uWidth, int vHeight, int textureWidth, int textureHeight);
  128. DrawableConsumer createFillRectangleConsumer(Rectangle rectangle, int color);
  129. }
  130. }