diff options
Diffstat (limited to 'src/main/java/me/shedaniel')
37 files changed, 409 insertions, 136 deletions
diff --git a/src/main/java/me/shedaniel/rei/RoughlyEnoughItemsCore.java b/src/main/java/me/shedaniel/rei/RoughlyEnoughItemsCore.java index f96ccd42a..eb3bec81f 100644 --- a/src/main/java/me/shedaniel/rei/RoughlyEnoughItemsCore.java +++ b/src/main/java/me/shedaniel/rei/RoughlyEnoughItemsCore.java @@ -41,7 +41,7 @@ import java.util.Optional; import java.util.stream.Collectors; public class RoughlyEnoughItemsCore implements ClientModInitializer { - + public static final Logger LOGGER; private static final RecipeHelper RECIPE_HELPER = new RecipeHelperImpl(); private static final PluginDisabler PLUGIN_DISABLER = new PluginDisablerImpl(); @@ -49,70 +49,80 @@ public class RoughlyEnoughItemsCore implements ClientModInitializer { private static final DisplayHelper DISPLAY_HELPER = new DisplayHelperImpl(); private static final Map<Identifier, REIPluginEntry> plugins = Maps.newHashMap(); private static ConfigManagerImpl configManager; - + static { LOGGER = LogManager.getFormatterLogger("REI"); } - + public static RecipeHelper getRecipeHelper() { return RECIPE_HELPER; } - + public static me.shedaniel.rei.api.ConfigManager getConfigManager() { return configManager; } - + public static ItemRegistry getItemRegisterer() { return ITEM_REGISTRY; } - + public static PluginDisabler getPluginDisabler() { return PLUGIN_DISABLER; } - + public static DisplayHelper getDisplayHelper() { return DISPLAY_HELPER; } - + public static REIPluginEntry registerPlugin(Identifier identifier, REIPluginEntry plugin) { plugins.put(identifier, plugin); RoughlyEnoughItemsCore.LOGGER.info("[REI] Registered plugin %s from %s", identifier.toString(), plugin.getClass().getSimpleName()); plugin.onFirstLoad(getPluginDisabler()); return plugin; } - + public static List<REIPluginEntry> getPlugins() { return new LinkedList<>(plugins.values()); } - + public static Optional<Identifier> getPluginIdentifier(REIPluginEntry plugin) { for(Identifier identifier : plugins.keySet()) if (identifier != null && plugins.get(identifier).equals(plugin)) return Optional.of(identifier); return Optional.empty(); } - + public static boolean hasPermissionToUsePackets() { - return hasOperatorPermission() && canUsePackets(); + try { + MinecraftClient.getInstance().getNetworkHandler().getCommandSource().hasPermissionLevel(0); + return hasOperatorPermission() && canUsePackets(); + } catch (NullPointerException e) { + return true; + } } - + public static boolean hasOperatorPermission() { - return MinecraftClient.getInstance().getNetworkHandler().getCommandSource().hasPermissionLevel(1); + try { + return MinecraftClient.getInstance().getNetworkHandler().getCommandSource().hasPermissionLevel(1); + } catch (NullPointerException e) { + return true; + } } - + public static boolean canUsePackets() { return ClientSidePacketRegistry.INSTANCE.canServerReceive(RoughlyEnoughItemsNetwork.CREATE_ITEMS_PACKET) && ClientSidePacketRegistry.INSTANCE.canServerReceive(RoughlyEnoughItemsNetwork.DELETE_ITEMS_PACKET); } - + @Override public void onInitializeClient() { configManager = new ConfigManagerImpl(); - + registerClothEvents(); discoverOldPlugins(); discoverPluginEntries(); } - + + @SuppressWarnings("deprecation") private void discoverPluginEntries() { for(REIPluginEntry reiPlugin : FabricLoader.getInstance().getEntrypoints("rei_plugins", REIPluginEntry.class)) { try { @@ -125,7 +135,8 @@ public class RoughlyEnoughItemsCore implements ClientModInitializer { } } } - + + @SuppressWarnings("deprecation") private void discoverOldPlugins() { List<Pair<Identifier, String>> list = Lists.newArrayList(); for(ModMetadata metadata : FabricLoader.getInstance().getAllMods().stream().map(ModContainer::getMetadata).filter(metadata -> metadata.containsCustomElement("roughlyenoughitems:plugins")).collect(Collectors.toList())) { @@ -164,7 +175,7 @@ public class RoughlyEnoughItemsCore implements ClientModInitializer { } } } - + private void loadPluginFromJsonObject(List<Pair<Identifier, String>> list, ModMetadata modMetadata, JsonObject object) { String namespace = modMetadata.getId(); if (object.has("namespace")) @@ -173,7 +184,7 @@ public class RoughlyEnoughItemsCore implements ClientModInitializer { String className = object.get("class").getAsString(); list.add(new Pair<>(new Identifier(namespace, id), className)); } - + private void registerClothEvents() { ClothClientHooks.SYNC_RECIPES.register((minecraftClient, recipeManager, synchronizeRecipesS2CPacket) -> { ((RecipeHelperImpl) RoughlyEnoughItemsCore.getRecipeHelper()).recipesLoaded(recipeManager); @@ -232,7 +243,7 @@ public class RoughlyEnoughItemsCore implements ClientModInitializer { ScreenHelper.getLastOverlay().lateRender(i, i1, v); }); ClothClientHooks.SCREEN_KEY_PRESSED.register((minecraftClient, screen, i, i1, i2) -> { - if (screen.getFocused() != null && screen.getFocused() instanceof TextFieldWidget || (screen.getFocused() instanceof RecipeBookGui && ((RecipeBookGuiHooks)screen.getFocused()).rei_getSearchField() != null && ((RecipeBookGuiHooks)screen.getFocused()).rei_getSearchField().isFocused())) + if (screen.getFocused() != null && screen.getFocused() instanceof TextFieldWidget || (screen.getFocused() instanceof RecipeBookGui && ((RecipeBookGuiHooks) screen.getFocused()).rei_getSearchField() != null && ((RecipeBookGuiHooks) screen.getFocused()).rei_getSearchField().isFocused())) return ActionResult.PASS; if (screen instanceof ContainerScreen) if (ScreenHelper.getLastOverlay().keyPressed(i, i1, i2)) @@ -240,5 +251,5 @@ public class RoughlyEnoughItemsCore implements ClientModInitializer { return ActionResult.PASS; }); } - + } diff --git a/src/main/java/me/shedaniel/rei/RoughlyEnoughItemsNetwork.java b/src/main/java/me/shedaniel/rei/RoughlyEnoughItemsNetwork.java index 63b7765e2..b2c444ec1 100644 --- a/src/main/java/me/shedaniel/rei/RoughlyEnoughItemsNetwork.java +++ b/src/main/java/me/shedaniel/rei/RoughlyEnoughItemsNetwork.java @@ -8,12 +8,12 @@ package me.shedaniel.rei; import me.shedaniel.rei.gui.widget.ItemListOverlay; import net.fabricmc.api.ModInitializer; import net.fabricmc.fabric.api.network.ServerSidePacketRegistry; +import net.minecraft.ChatFormat; import net.minecraft.client.resource.language.I18n; import net.minecraft.item.ItemStack; +import net.minecraft.network.chat.TextComponent; +import net.minecraft.network.chat.TranslatableComponent; import net.minecraft.server.network.ServerPlayerEntity; -import net.minecraft.text.StringTextComponent; -import net.minecraft.text.TextFormat; -import net.minecraft.text.TranslatableTextComponent; import net.minecraft.util.Identifier; public class RoughlyEnoughItemsNetwork implements ModInitializer { @@ -26,7 +26,7 @@ public class RoughlyEnoughItemsNetwork implements ModInitializer { ServerSidePacketRegistry.INSTANCE.register(DELETE_ITEMS_PACKET, (packetContext, packetByteBuf) -> { ServerPlayerEntity player = (ServerPlayerEntity) packetContext.getPlayer(); if (player.getServer().getPermissionLevel(player.getGameProfile()) < player.getServer().getOpPermissionLevel()) { - player.addChatMessage(new TranslatableTextComponent("text.rei.no_permission_cheat").applyFormat(TextFormat.RED), false); + player.addChatMessage(new TranslatableComponent("text.rei.no_permission_cheat").applyFormat(ChatFormat.RED), false); return; } if (!player.inventory.getCursorStack().isEmpty()) @@ -35,14 +35,14 @@ public class RoughlyEnoughItemsNetwork implements ModInitializer { ServerSidePacketRegistry.INSTANCE.register(CREATE_ITEMS_PACKET, (packetContext, packetByteBuf) -> { ServerPlayerEntity player = (ServerPlayerEntity) packetContext.getPlayer(); if (player.getServer().getPermissionLevel(player.getGameProfile()) < player.getServer().getOpPermissionLevel()) { - player.addChatMessage(new TranslatableTextComponent("text.rei.no_permission_cheat").applyFormat(TextFormat.RED), false); + player.addChatMessage(new TranslatableComponent("text.rei.no_permission_cheat").applyFormat(ChatFormat.RED), false); return; } ItemStack stack = packetByteBuf.readItemStack(); if (player.inventory.insertStack(stack.copy())) - player.addChatMessage(new StringTextComponent(I18n.translate("text.rei.cheat_items").replaceAll("\\{item_name}", ItemListOverlay.tryGetItemStackName(stack.copy())).replaceAll("\\{item_count}", stack.copy().getAmount() + "").replaceAll("\\{player_name}", player.getEntityName())), false); + player.addChatMessage(new TextComponent(I18n.translate("text.rei.cheat_items").replaceAll("\\{item_name}", ItemListOverlay.tryGetItemStackName(stack.copy())).replaceAll("\\{item_count}", stack.copy().getAmount() + "").replaceAll("\\{player_name}", player.getEntityName())), false); else - player.addChatMessage(new TranslatableTextComponent("text.rei.failed_cheat_items"), false); + player.addChatMessage(new TranslatableComponent("text.rei.failed_cheat_items"), false); }); } 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/DisplayHelper.java b/src/main/java/me/shedaniel/rei/api/DisplayHelper.java index 9fea85839..5cabf4ad1 100644 --- a/src/main/java/me/shedaniel/rei/api/DisplayHelper.java +++ b/src/main/java/me/shedaniel/rei/api/DisplayHelper.java @@ -56,11 +56,6 @@ public interface DisplayHelper { public static interface DisplayBoundsHandler<T> { /** - * An empty rectangle - */ - public static final Rectangle EMPTY = new Rectangle(); - - /** * Gets the base supported class for the bounds handler * * @return the base class 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 |
