diff options
| author | Unknown <shekwancheung0528@gmail.com> | 2019-05-12 18:10:15 +0800 |
|---|---|---|
| committer | Unknown <shekwancheung0528@gmail.com> | 2019-05-12 18:10:15 +0800 |
| commit | a98d9191f1a97925a8a3e2e23c0a07867540a93a (patch) | |
| tree | 8aac9df58b40052b6b19c0c3ac7da66076dc5b1c /src/main/java | |
| parent | 45ed37cc8d0088b57cd2605482f471e69e5885f4 (diff) | |
| download | RoughlyEnoughItems-a98d9191f1a97925a8a3e2e23c0a07867540a93a.tar.gz RoughlyEnoughItems-a98d9191f1a97925a8a3e2e23c0a07867540a93a.tar.bz2 RoughlyEnoughItems-a98d9191f1a97925a8a3e2e23c0a07867540a93a.zip | |
Out of beta: Build 110
Diffstat (limited to 'src/main/java')
12 files changed, 273 insertions, 38 deletions
diff --git a/src/main/java/me/shedaniel/rei/api/BaseBoundsHandler.java b/src/main/java/me/shedaniel/rei/api/BaseBoundsHandler.java index f363dccac..3aaf1f482 100644 --- a/src/main/java/me/shedaniel/rei/api/BaseBoundsHandler.java +++ b/src/main/java/me/shedaniel/rei/api/BaseBoundsHandler.java @@ -11,11 +11,30 @@ import java.awt.*; import java.util.List; public interface BaseBoundsHandler extends DisplayHelper.DisplayBoundsHandler<Screen> { + /** + * Gets the exclusion zones by the screen class + * + * @param currentScreenClass the current screen class + * @param isOnRightSide whether the user has set the overlay to the right + * @return the list of exclusion zones + */ List<Rectangle> getCurrentExclusionZones(Class<? extends Screen> currentScreenClass, boolean isOnRightSide); + /** + * Register an exclusion zone + * + * @param screenClass the screen + * @param supplier the exclusion zone supplier + */ void registerExclusionZones(Class<? extends Screen> screenClass, ExclusionZoneSupplier supplier); public static interface ExclusionZoneSupplier { + /** + * Gets the current exclusion zones + * + * @param isOnRightSide whether the user has set the overlay to the right + * @return the list of exclusion zones + */ List<Rectangle> apply(boolean isOnRightSide); } } diff --git a/src/main/java/me/shedaniel/rei/api/ClientHelper.java b/src/main/java/me/shedaniel/rei/api/ClientHelper.java index fe33ddc64..d9f6c7ae8 100644 --- a/src/main/java/me/shedaniel/rei/api/ClientHelper.java +++ b/src/main/java/me/shedaniel/rei/api/ClientHelper.java @@ -41,9 +41,9 @@ public interface ClientHelper { /** * Opens a recipe viewing screen: - * {@link me.shedaniel.rei.gui.PreRecipeViewingScreen} if not set - * {@link me.shedaniel.rei.gui.RecipeViewingScreen} if set to default - * {@link me.shedaniel.rei.gui.VillagerRecipeViewingScreen} if set to villager + * Opens {@link me.shedaniel.rei.gui.PreRecipeViewingScreen} if not set + * Opens {@link me.shedaniel.rei.gui.RecipeViewingScreen} if set to default + * Opens {@link me.shedaniel.rei.gui.VillagerRecipeViewingScreen} if set to villager * * @param map the map of recipes */ @@ -115,14 +115,29 @@ public interface ClientHelper { */ String getModFromIdentifier(Identifier identifier); + /** + * @return the recipe keybind, defaulted R + */ FabricKeyBinding getRecipeKeyBinding(); + /** + * @return the usage keybind, defaulted U + */ FabricKeyBinding getUsageKeyBinding(); + /** + * @return the hide keybind, defaulted O + */ FabricKeyBinding getHideKeyBinding(); + /** + * @return the previous page keybind, defaulted not set + */ FabricKeyBinding getPreviousPageKeyBinding(); + /** + * @return the next page keybind, defaulted not set + */ FabricKeyBinding getNextPageKeyBinding(); /** diff --git a/src/main/java/me/shedaniel/rei/api/ItemRegistry.java b/src/main/java/me/shedaniel/rei/api/ItemRegistry.java index 0a9da2c46..a29682985 100644 --- a/src/main/java/me/shedaniel/rei/api/ItemRegistry.java +++ b/src/main/java/me/shedaniel/rei/api/ItemRegistry.java @@ -27,6 +27,12 @@ public interface ItemRegistry { @Deprecated List<ItemStack> getModifiableItemList(); + /** + * Gets all possible stacks from an item + * + * @param item the item to find + * @return the array of possible stacks + */ ItemStack[] getAllStacksFromItem(Item item); /** @@ -37,12 +43,23 @@ public interface ItemRegistry { */ void registerItemStack(Item afterItem, ItemStack stack); + /** + * Registers multiple stacks to the item list + * + * @param afterItem the stack to put after + * @param stacks the stacks to register + */ default void registerItemStack(Item afterItem, ItemStack... stacks) { for(ItemStack stack : stacks) if (stack != null && !stack.isEmpty()) registerItemStack(afterItem, stack); } + /** + * Registers multiple stacks to the item list + * + * @param stacks the stacks to register + */ default void registerItemStack(ItemStack... stacks) { for(ItemStack stack : stacks) if (stack != null && !stack.isEmpty()) diff --git a/src/main/java/me/shedaniel/rei/api/PluginDisabler.java b/src/main/java/me/shedaniel/rei/api/PluginDisabler.java index cd3b61578..ed4f8638c 100644 --- a/src/main/java/me/shedaniel/rei/api/PluginDisabler.java +++ b/src/main/java/me/shedaniel/rei/api/PluginDisabler.java @@ -9,20 +9,51 @@ import net.minecraft.util.Identifier; public interface PluginDisabler { + /** + * Disables multiple functions from a plugin + * + * @param plugin the identifier of the plugin + * @param functions the array of functions to be disabled + */ default void disablePluginFunctions(Identifier plugin, PluginFunction... functions) { for(PluginFunction function : functions) disablePluginFunction(plugin, function); } + /** + * Enables multiple functions from a plugin + * + * @param plugin the identifier of the plugin + * @param functions the array of functions to be enabled + */ default void enablePluginFunctions(Identifier plugin, PluginFunction... functions) { for(PluginFunction function : functions) enablePluginFunction(plugin, function); } + /** + * Disables a function from a plugin + * + * @param plugin the identifier of the plugin + * @param function the function to be disabled + */ void disablePluginFunction(Identifier plugin, PluginFunction function); + /** + * Enables a function from a plugin + * + * @param plugin the identifier of the plugin + * @param function the function to be enabled + */ void enablePluginFunction(Identifier plugin, PluginFunction function); + /** + * Checks if a plugin function has been disabled + * + * @param plugin the identifier of the plugin + * @param function the function to check + * @return whether if it has been disabled + */ boolean isFunctionEnabled(Identifier plugin, PluginFunction function); } diff --git a/src/main/java/me/shedaniel/rei/api/RecipeDisplay.java b/src/main/java/me/shedaniel/rei/api/RecipeDisplay.java index 4fb564133..9e17159bc 100644 --- a/src/main/java/me/shedaniel/rei/api/RecipeDisplay.java +++ b/src/main/java/me/shedaniel/rei/api/RecipeDisplay.java @@ -15,16 +15,35 @@ import java.util.Optional; public interface RecipeDisplay<T extends Recipe> { + /** + * @return the optional recipe + */ Optional<T> getRecipe(); + /** + * @return a list of items + */ List<List<ItemStack>> getInput(); + /** + * @return a list of outputs + */ List<ItemStack> getOutput(); + /** + * Gets the required items used in craftable filters + * + * @return the list of required items + */ default List<List<ItemStack>> getRequiredItems() { return Lists.newArrayList(); } + /** + * Gets the recipe display category identifier + * + * @return the identifier of the category + */ Identifier getRecipeCategory(); } diff --git a/src/main/java/me/shedaniel/rei/api/RecipeHelper.java b/src/main/java/me/shedaniel/rei/api/RecipeHelper.java index 58d67e97a..acb844e2e 100644 --- a/src/main/java/me/shedaniel/rei/api/RecipeHelper.java +++ b/src/main/java/me/shedaniel/rei/api/RecipeHelper.java @@ -24,10 +24,24 @@ public interface RecipeHelper { return RoughlyEnoughItemsCore.getRecipeHelper(); } + /** + * Gets the total recipe count registered + * + * @return the recipe count + */ int getRecipeCount(); - List<Recipe> getVanillaSortedRecipes(); + /** + * @return a list of sorted recipes + */ + List<Recipe> getAllSortedRecipes(); + /** + * Gets all craftable items from materials. + * + * @param inventoryItems the materials + * @return the list of craftable items + */ List<ItemStack> findCraftableByItems(List<ItemStack> inventoryItems); /** @@ -45,6 +59,12 @@ public interface RecipeHelper { */ void registerDisplay(Identifier categoryIdentifier, RecipeDisplay display); + /** + * Gets a map of recipes for an itemstack + * + * @param stack the stack to be crafted + * @return the map of recipes + */ Map<RecipeCategory, List<RecipeDisplay>> getRecipesFor(ItemStack stack); /** @@ -56,32 +76,101 @@ public interface RecipeHelper { /** * Gets all registered categories + * * @return the list of categories */ List<RecipeCategory> getAllCategories(); + /** + * Gets a map of usages for an itemstack + * + * @param stack the stack to be used + * @return the map of recipes + */ Map<RecipeCategory, List<RecipeDisplay>> getUsagesFor(ItemStack stack); + /** + * Gets the optional of the speed crafting button area from a category + * + * @param category the category of the display + * @return the optional of speed crafting button area + */ Optional<ButtonAreaSupplier> getSpeedCraftButtonArea(RecipeCategory category); + /** + * Registers a speed crafting button area + * + * @param category the category of the button area + * @param rectangle the button area + */ void registerSpeedCraftButtonArea(Identifier category, ButtonAreaSupplier rectangle); + /** + * Registers a default speed crafting button area, which is bottom right + * + * @param category the category of the button area + */ void registerDefaultSpeedCraftButtonArea(Identifier category); + /** + * Gets the speed crafting functional from a category + * + * @param category the category of the speed crafting functional + * @return the list of speed crafting functionals + */ List<SpeedCraftFunctional> getSpeedCraftFunctional(RecipeCategory category); + /** + * Registers a speed crafting functional + * + * @param category the category of the speed crafting functional + * @param functional the functional to be registered + */ void registerSpeedCraftFunctional(Identifier category, SpeedCraftFunctional functional); + /** + * Gets the map of all recipes visible to the player + * + * @return the map of recipes + */ Map<RecipeCategory, List<RecipeDisplay>> getAllRecipes(); + /** + * Registers a recipe visibility handler + * + * @param visibilityHandler the handler to be registered + */ void registerRecipeVisibilityHandler(DisplayVisibilityHandler visibilityHandler); + /** + * Unregisters a recipe visibility handler + * + * @param visibilityHandler the handler to be unregistered + */ void unregisterRecipeVisibilityHandler(DisplayVisibilityHandler visibilityHandler); + /** + * Gets an unmodifiable list of recipe visibility handlers + * + * @return the unmodifiable list of handlers + */ List<DisplayVisibilityHandler> getDisplayVisibilityHandlers(); + /** + * Checks if the display is visible by asking recipe visibility handlers + * + * @param display the display to be checked + * @param respectConfig whether it should respect the user's config + * @return whether the display should be visible + */ boolean isDisplayVisible(RecipeDisplay display, boolean respectConfig); + /** + * Gets the cached category setting by the category identifier + * + * @param category the identifier of the category + * @return the optional of the category settings + */ Optional<DisplaySettings> getCachedCategorySettings(Identifier category); } diff --git a/src/main/java/me/shedaniel/rei/api/Renderable.java b/src/main/java/me/shedaniel/rei/api/Renderable.java index 47b8f4beb..75d9161be 100644 --- a/src/main/java/me/shedaniel/rei/api/Renderable.java +++ b/src/main/java/me/shedaniel/rei/api/Renderable.java @@ -19,6 +19,12 @@ import java.util.function.Supplier; */ public interface Renderable { + /** + * Gets an item stack renderer by an item stack supplier + * + * @param supplier the supplier for getting the item stack + * @return the item stack renderer + */ static ItemStackRenderer fromItemStackSupplier(Supplier<ItemStack> supplier) { return new ItemStackRenderer() { @Override @@ -28,19 +34,32 @@ public interface Renderable { }; } + /** + * Gets an item stack renderer by an item stack + * + * @param stack the item stack to be displayed + * @return the item stack renderer + */ static ItemStackRenderer fromItemStack(ItemStack stack) { - return new ItemStackRenderer() { - @Override - public ItemStack getItemStack() { - return stack; - } - }; + return fromItemStackSupplier(() -> stack); } + /** + * Gets an empty renderer + * + * @return an empty renderer + */ static EmptyRenderer empty() { return EmptyRenderer.INSTANCE; } + /** + * Gets a simple recipe renderer from inputs and outputs + * + * @param input the list of input items + * @param output the list of output items + * @return the recipe renderer + */ static SimpleRecipeRenderer fromRecipe(Supplier<List<List<ItemStack>>> input, Supplier<List<ItemStack>> output) { return new SimpleRecipeRenderer(input, output); } @@ -56,5 +75,14 @@ public interface Renderable { }; } + /** + * Renders of the renderable + * + * @param x the x coordinate of the renderable + * @param y the y coordinate of the renderable + * @param mouseX the x coordinate of the mouse + * @param mouseY the y coordinate of the mouse + * @param delta the delta + */ void render(int x, int y, double mouseX, double mouseY, float delta); } diff --git a/src/main/java/me/shedaniel/rei/api/Renderer.java b/src/main/java/me/shedaniel/rei/api/Renderer.java index c94fd2631..aada00b8a 100644 --- a/src/main/java/me/shedaniel/rei/api/Renderer.java +++ b/src/main/java/me/shedaniel/rei/api/Renderer.java @@ -8,10 +8,20 @@ package me.shedaniel.rei.api; import net.minecraft.client.gui.DrawableHelper; public abstract class Renderer extends DrawableHelper implements Renderable { + /** + * Gets the current blit offset + * + * @return the blit offset + */ public int getBlitOffset() { return this.blitOffset; } + /** + * Sets the current blit offset + * + * @param offset the new blit offset + */ public void setBlitOffset(int offset) { this.blitOffset = offset; } diff --git a/src/main/java/me/shedaniel/rei/api/SpeedCraftFunctional.java b/src/main/java/me/shedaniel/rei/api/SpeedCraftFunctional.java index cec75d282..6824883a3 100644 --- a/src/main/java/me/shedaniel/rei/api/SpeedCraftFunctional.java +++ b/src/main/java/me/shedaniel/rei/api/SpeedCraftFunctional.java @@ -9,10 +9,29 @@ import net.minecraft.client.gui.Screen; public interface SpeedCraftFunctional<T extends RecipeDisplay> { + /** + * Gets the classes that it is functioning for + * + * @return the array of classes + */ Class[] getFunctioningFor(); + /** + * Performs the auto crafting + * + * @param screen the current screen + * @param recipe the current recipe + * @return whether it worked + */ boolean performAutoCraft(Screen screen, T recipe); + /** + * Gets if this functional accepts the auto crafting + * + * @param screen the current screen + * @param recipe the current recipe + * @return whether it is accepted + */ boolean acceptRecipe(Screen screen, T recipe); } diff --git a/src/main/java/me/shedaniel/rei/client/RecipeHelperImpl.java b/src/main/java/me/shedaniel/rei/client/RecipeHelperImpl.java index 80db040d1..db46aa08f 100644 --- a/src/main/java/me/shedaniel/rei/client/RecipeHelperImpl.java +++ b/src/main/java/me/shedaniel/rei/client/RecipeHelperImpl.java @@ -250,7 +250,7 @@ public class RecipeHelperImpl implements RecipeHelper { } @Override - public List<Recipe> getVanillaSortedRecipes() { + public List<Recipe> getAllSortedRecipes() { return getRecipeManager().values().stream().sorted(RECIPE_COMPARATOR).collect(Collectors.toList()); } diff --git a/src/main/java/me/shedaniel/rei/gui/VillagerRecipeViewingScreen.java b/src/main/java/me/shedaniel/rei/gui/VillagerRecipeViewingScreen.java index 2cf4990a3..7b70cfb93 100644 --- a/src/main/java/me/shedaniel/rei/gui/VillagerRecipeViewingScreen.java +++ b/src/main/java/me/shedaniel/rei/gui/VillagerRecipeViewingScreen.java @@ -24,12 +24,8 @@ import net.minecraft.network.chat.TextComponent; import net.minecraft.network.chat.TranslatableComponent; import net.minecraft.sound.SoundEvents; import net.minecraft.util.math.MathHelper; -import org.lwjgl.BufferUtils; -import org.lwjgl.glfw.GLFW; -import org.lwjgl.opengl.GL11; import java.awt.*; -import java.nio.IntBuffer; import java.util.List; import java.util.Map; import java.util.Optional; @@ -212,15 +208,14 @@ public class VillagerRecipeViewingScreen extends Screen { return true; if (bounds.contains(ClientUtils.getMouseLocation())) { if (double_3 < 0 && categoryMap.get(categories.get(selectedCategoryIndex)).size() > 1) { - selectedCategoryIndex++; - if (selectedCategoryIndex >= categoryMap.get(categories.get(selectedCategoryIndex)).size()) - selectedCategoryIndex = 0; + selectedRecipeIndex++; + if (selectedRecipeIndex >= categoryMap.get(categories.get(selectedCategoryIndex)).size()) + selectedRecipeIndex = 0; init(); - return true; } else if (categoryMap.get(categories.get(selectedCategoryIndex)).size() > 1) { - selectedCategoryIndex--; - if (selectedCategoryIndex < 0) - selectedCategoryIndex = categoryMap.get(categories.get(selectedCategoryIndex)).size() - 1; + selectedRecipeIndex--; + if (selectedRecipeIndex < 0) + selectedRecipeIndex = categoryMap.get(categories.get(selectedCategoryIndex)).size() - 1; init(); return true; } @@ -238,7 +233,7 @@ public class VillagerRecipeViewingScreen extends Screen { }); GuiLighting.disable(); ScreenHelper.getLastOverlay().render(mouseX, mouseY, delta); - GL11.glPushMatrix(); + GlStateManager.pushMatrix(); Scissors.begin(); Scissors.scissor(0, scrollListBounds.y + 1, width, scrollListBounds.height - 2); for(int i = 0; i < buttonWidgets.size(); i++) { @@ -258,17 +253,10 @@ public class VillagerRecipeViewingScreen extends Screen { } } Scissors.end(); - GL11.glPopMatrix(); + GlStateManager.popMatrix(); ScreenHelper.getLastOverlay().lateRender(mouseX, mouseY, delta); } - private int getTitleBarHeight() { - IntBuffer useless = BufferUtils.createIntBuffer(3), top = BufferUtils.createIntBuffer(1); - GLFW.glfwGetWindowFrameSize(minecraft.window.getHandle(), useless, top, useless, useless); - System.out.println(top.get(0)); - return top.get(0) / 3 * 2; - } - private int getReal(int i) { return (int) (i / ((double) minecraft.window.getScaledWidth() / (double) minecraft.window.getWidth())); } @@ -288,18 +276,18 @@ public class VillagerRecipeViewingScreen extends Screen { } if (ClientHelper.getInstance().getNextPageKeyBinding().matchesKey(int_1, int_2)) { if (categoryMap.get(categories.get(selectedCategoryIndex)).size() > 1) { - selectedCategoryIndex++; - if (selectedCategoryIndex >= categoryMap.get(categories.get(selectedCategoryIndex)).size()) - selectedCategoryIndex = 0; + selectedRecipeIndex ++; + if (selectedRecipeIndex >= categoryMap.get(categories.get(selectedCategoryIndex)).size()) + selectedRecipeIndex = 0; init(); return true; } return false; } else if (ClientHelper.getInstance().getPreviousPageKeyBinding().matchesKey(int_1, int_2)) { if (categoryMap.get(categories.get(selectedCategoryIndex)).size() > 1) { - selectedCategoryIndex--; - if (selectedCategoryIndex < 0) - selectedCategoryIndex = categoryMap.get(categories.get(selectedCategoryIndex)).size() - 1; + selectedRecipeIndex--; + if (selectedRecipeIndex < 0) + selectedRecipeIndex = categoryMap.get(categories.get(selectedCategoryIndex)).size() - 1; init(); return true; } diff --git a/src/main/java/me/shedaniel/rei/plugin/DefaultPlugin.java b/src/main/java/me/shedaniel/rei/plugin/DefaultPlugin.java index 806ea8eea..e49540683 100644 --- a/src/main/java/me/shedaniel/rei/plugin/DefaultPlugin.java +++ b/src/main/java/me/shedaniel/rei/plugin/DefaultPlugin.java @@ -110,7 +110,7 @@ public class DefaultPlugin implements REIPluginEntry { @Override public void registerRecipeDisplays(RecipeHelper recipeHelper) { - for(Recipe recipe : recipeHelper.getVanillaSortedRecipes()) + for(Recipe recipe : recipeHelper.getAllSortedRecipes()) if (recipe instanceof ShapelessRecipe) recipeHelper.registerDisplay(CRAFTING, new DefaultShapelessDisplay((ShapelessRecipe) recipe)); else if (recipe instanceof ShapedRecipe) |
