From 4d0b2d3f50bf56b83498a3b787ac08afaeb85eff Mon Sep 17 00:00:00 2001 From: Unknown Date: Tue, 18 Jun 2019 16:38:49 +0800 Subject: up to 4x faster search --- .../me/shedaniel/rei/api/AutoCraftingHandler.java | 16 ++++++ .../java/me/shedaniel/rei/api/DisplayHelper.java | 2 +- .../java/me/shedaniel/rei/api/DisplaySettings.java | 8 +-- .../me/shedaniel/rei/api/DisplayVisibility.java | 13 ----- .../rei/api/DisplayVisibilityHandler.java | 4 +- .../me/shedaniel/rei/api/ItemCheatingMode.java | 11 ---- .../java/me/shedaniel/rei/api/RecipeCategory.java | 8 +-- .../java/me/shedaniel/rei/api/RecipeDisplay.java | 9 +--- .../java/me/shedaniel/rei/api/RecipeHelper.java | 6 ++- .../java/me/shedaniel/rei/api/RelativePoint.java | 33 ------------ src/main/java/me/shedaniel/rei/api/Renderable.java | 23 +++----- src/main/java/me/shedaniel/rei/api/Renderer.java | 13 ++++- .../me/shedaniel/rei/client/ClientHelperImpl.java | 1 + .../java/me/shedaniel/rei/client/ConfigObject.java | 32 ++++++++++- .../me/shedaniel/rei/client/ItemListOrdering.java | 24 --------- .../me/shedaniel/rei/client/RecipeHelperImpl.java | 48 ++++++++++++++--- .../me/shedaniel/rei/client/RecipeScreenType.java | 19 ------- .../java/me/shedaniel/rei/client/ScreenHelper.java | 14 +++-- .../me/shedaniel/rei/client/SearchArgument.java | 32 ++++++++--- .../shedaniel/rei/gui/ContainerScreenOverlay.java | 12 +++-- .../shedaniel/rei/gui/PreRecipeViewingScreen.java | 2 +- .../rei/gui/config/DisplayVisibility.java | 13 +++++ .../shedaniel/rei/gui/config/ItemCheatingMode.java | 11 ++++ .../shedaniel/rei/gui/config/ItemListOrdering.java | 24 +++++++++ .../rei/gui/config/ItemListOrderingConfig.java | 1 - .../shedaniel/rei/gui/config/RecipeScreenType.java | 21 ++++++++ .../rei/gui/renderables/EmptyRenderer.java | 1 + .../rei/gui/widget/AutoCraftingButtonWidget.java | 9 ++-- .../shedaniel/rei/gui/widget/ItemListOverlay.java | 62 +++++++++++----------- .../shedaniel/rei/gui/widget/RecipeBaseWidget.java | 2 +- .../rei/gui/widget/RecipeChoosePageWidget.java | 6 +-- .../me/shedaniel/rei/gui/widget/SlotWidget.java | 10 ++-- .../CreativePlayerInventoryScreenHooks.java | 16 ------ .../rei/plugin/DefaultAutoCraftingPlugin.java | 3 +- .../me/shedaniel/rei/plugin/DefaultPlugin.java | 3 +- .../autocrafting/AutoCraftingTableHandler.java | 26 +++++++++ .../plugin/blasting/DefaultBlastingDisplay.java | 2 +- .../plugin/campfire/DefaultCampfireDisplay.java | 2 +- .../composting/DefaultCompostingCategory.java | 15 +++--- .../plugin/crafting/DefaultCraftingDisplay.java | 3 +- .../plugin/smelting/DefaultSmeltingDisplay.java | 2 +- .../rei/plugin/smoking/DefaultSmokingDisplay.java | 2 +- .../stonecutting/DefaultStoneCuttingCategory.java | 8 +-- .../stonecutting/DefaultStoneCuttingDisplay.java | 2 +- .../shedaniel/rei/utils/ClothScreenRegistry.java | 7 +-- 45 files changed, 336 insertions(+), 245 deletions(-) create mode 100644 src/main/java/me/shedaniel/rei/api/AutoCraftingHandler.java delete mode 100644 src/main/java/me/shedaniel/rei/api/DisplayVisibility.java delete mode 100644 src/main/java/me/shedaniel/rei/api/ItemCheatingMode.java delete mode 100644 src/main/java/me/shedaniel/rei/api/RelativePoint.java delete mode 100644 src/main/java/me/shedaniel/rei/client/ItemListOrdering.java delete mode 100644 src/main/java/me/shedaniel/rei/client/RecipeScreenType.java create mode 100644 src/main/java/me/shedaniel/rei/gui/config/DisplayVisibility.java create mode 100644 src/main/java/me/shedaniel/rei/gui/config/ItemCheatingMode.java create mode 100644 src/main/java/me/shedaniel/rei/gui/config/ItemListOrdering.java create mode 100644 src/main/java/me/shedaniel/rei/gui/config/RecipeScreenType.java delete mode 100644 src/main/java/me/shedaniel/rei/listeners/CreativePlayerInventoryScreenHooks.java create mode 100644 src/main/java/me/shedaniel/rei/plugin/autocrafting/AutoCraftingTableHandler.java (limited to 'src/main/java') diff --git a/src/main/java/me/shedaniel/rei/api/AutoCraftingHandler.java b/src/main/java/me/shedaniel/rei/api/AutoCraftingHandler.java new file mode 100644 index 000000000..ec378ac89 --- /dev/null +++ b/src/main/java/me/shedaniel/rei/api/AutoCraftingHandler.java @@ -0,0 +1,16 @@ +package me.shedaniel.rei.api; + +import me.shedaniel.rei.gui.ContainerScreenOverlay; +import net.minecraft.client.MinecraftClient; +import net.minecraft.client.gui.screen.Screen; +import net.minecraft.client.gui.screen.ingame.AbstractContainerScreen; + +public interface AutoCraftingHandler { + + default double getPriority() { + return 0d; + } + + boolean handle(MinecraftClient minecraft, Screen recipeViewingScreen, AbstractContainerScreen parentScreen, ContainerScreenOverlay overlay); + +} diff --git a/src/main/java/me/shedaniel/rei/api/DisplayHelper.java b/src/main/java/me/shedaniel/rei/api/DisplayHelper.java index 5cabf4ad1..755ca84b3 100644 --- a/src/main/java/me/shedaniel/rei/api/DisplayHelper.java +++ b/src/main/java/me/shedaniel/rei/api/DisplayHelper.java @@ -60,7 +60,7 @@ public interface DisplayHelper { * * @return the base class */ - Class getBaseSupportedClass(); + Class getBaseSupportedClass(); /** * Gets the left bounds of the overlay diff --git a/src/main/java/me/shedaniel/rei/api/DisplaySettings.java b/src/main/java/me/shedaniel/rei/api/DisplaySettings.java index ddf1f3a75..36fa1634b 100644 --- a/src/main/java/me/shedaniel/rei/api/DisplaySettings.java +++ b/src/main/java/me/shedaniel/rei/api/DisplaySettings.java @@ -13,7 +13,7 @@ public interface DisplaySettings { * @param category the category of the display * @return the height */ - int getDisplayHeight(RecipeCategory category); + int getDisplayHeight(RecipeCategory category); /** * Gets the recipe display width @@ -22,17 +22,19 @@ public interface DisplaySettings { * @param display the display of the recipe * @return the width */ - int getDisplayWidth(RecipeCategory category, T display); + int getDisplayWidth(RecipeCategory category, T display); /** * Gets the maximum amount of recipe displays of the category displayed at the same time. + * * @param category the category of the displays * @return the maximum amount */ - int getMaximumRecipePerPage(RecipeCategory category); + int getMaximumRecipePerPage(RecipeCategory category); /** * Gets the fixed amount of recipes per page. + * * @return the amount of recipes, returns -1 if not fixed */ default int getFixedRecipesPerPage() { diff --git a/src/main/java/me/shedaniel/rei/api/DisplayVisibility.java b/src/main/java/me/shedaniel/rei/api/DisplayVisibility.java deleted file mode 100644 index 0bfdb024c..000000000 --- a/src/main/java/me/shedaniel/rei/api/DisplayVisibility.java +++ /dev/null @@ -1,13 +0,0 @@ -/* - * Roughly Enough Items by Danielshe. - * Licensed under the MIT License. - */ - -package me.shedaniel.rei.api; - -public enum DisplayVisibility { - ALWAYS_VISIBLE, - @Deprecated CONFIG_OPTIONAL, - NEVER_VISIBLE, - PASS -} diff --git a/src/main/java/me/shedaniel/rei/api/DisplayVisibilityHandler.java b/src/main/java/me/shedaniel/rei/api/DisplayVisibilityHandler.java index 429306ff2..f29ca9129 100644 --- a/src/main/java/me/shedaniel/rei/api/DisplayVisibilityHandler.java +++ b/src/main/java/me/shedaniel/rei/api/DisplayVisibilityHandler.java @@ -5,6 +5,8 @@ package me.shedaniel.rei.api; +import me.shedaniel.rei.gui.config.DisplayVisibility; + public interface DisplayVisibilityHandler { /** @@ -26,6 +28,6 @@ public interface DisplayVisibilityHandler { * @param display the display of the recipe * @return the visibility */ - DisplayVisibility handleDisplay(RecipeCategory category, RecipeDisplay display); + DisplayVisibility handleDisplay(RecipeCategory category, RecipeDisplay display); } diff --git a/src/main/java/me/shedaniel/rei/api/ItemCheatingMode.java b/src/main/java/me/shedaniel/rei/api/ItemCheatingMode.java deleted file mode 100644 index 56c97027e..000000000 --- a/src/main/java/me/shedaniel/rei/api/ItemCheatingMode.java +++ /dev/null @@ -1,11 +0,0 @@ -/* - * Roughly Enough Items by Danielshe. - * Licensed under the MIT License. - */ - -package me.shedaniel.rei.api; - -public enum ItemCheatingMode { - REI_LIKE, - JEI_LIKE; -} diff --git a/src/main/java/me/shedaniel/rei/api/RecipeCategory.java b/src/main/java/me/shedaniel/rei/api/RecipeCategory.java index 0f39b7205..64c53c300 100644 --- a/src/main/java/me/shedaniel/rei/api/RecipeCategory.java +++ b/src/main/java/me/shedaniel/rei/api/RecipeCategory.java @@ -104,20 +104,20 @@ public interface RecipeCategory { * * @return the display settings */ - default DisplaySettings getDisplaySettings() { + default DisplaySettings getDisplaySettings() { return new DisplaySettings() { @Override - public int getDisplayHeight(RecipeCategory category) { + public int getDisplayHeight(RecipeCategory category) { return 66; } @Override - public int getDisplayWidth(RecipeCategory category, T display) { + public int getDisplayWidth(RecipeCategory category, T display) { return 150; } @Override - public int getMaximumRecipePerPage(RecipeCategory category) { + public int getMaximumRecipePerPage(RecipeCategory category) { return 99; } }; diff --git a/src/main/java/me/shedaniel/rei/api/RecipeDisplay.java b/src/main/java/me/shedaniel/rei/api/RecipeDisplay.java index 302667efd..a2dac34f4 100644 --- a/src/main/java/me/shedaniel/rei/api/RecipeDisplay.java +++ b/src/main/java/me/shedaniel/rei/api/RecipeDisplay.java @@ -13,7 +13,7 @@ import net.minecraft.util.Identifier; import java.util.List; import java.util.Optional; -public interface RecipeDisplay { +public interface RecipeDisplay { /** * @return a list of items @@ -50,11 +50,4 @@ public interface RecipeDisplay { return Optional.empty(); } - /** - * @return the optional recipe - * @deprecated stop - */ - @Deprecated - default Optional getRecipe() {return null;} - } diff --git a/src/main/java/me/shedaniel/rei/api/RecipeHelper.java b/src/main/java/me/shedaniel/rei/api/RecipeHelper.java index 19d411cfd..18c074121 100644 --- a/src/main/java/me/shedaniel/rei/api/RecipeHelper.java +++ b/src/main/java/me/shedaniel/rei/api/RecipeHelper.java @@ -26,6 +26,10 @@ public interface RecipeHelper { return RoughlyEnoughItemsCore.getRecipeHelper(); } + AutoCraftingHandler registerAutoCraftingHandler(AutoCraftingHandler handler); + + List getSortedAutoCraftingHandler(); + /** * Gets the total recipe count registered * @@ -204,7 +208,7 @@ public interface RecipeHelper { * @param liveRecipeGenerator the generator to register * @apiNote Still work in progress */ - void registerLiveRecipeGenerator(LiveRecipeGenerator liveRecipeGenerator); + void registerLiveRecipeGenerator(LiveRecipeGenerator liveRecipeGenerator); > void registerRecipes(Identifier category, Class recipeClass, Function mappingFunction); diff --git a/src/main/java/me/shedaniel/rei/api/RelativePoint.java b/src/main/java/me/shedaniel/rei/api/RelativePoint.java deleted file mode 100644 index 0d54e866e..000000000 --- a/src/main/java/me/shedaniel/rei/api/RelativePoint.java +++ /dev/null @@ -1,33 +0,0 @@ -/* - * Roughly Enough Items by Danielshe. - * Licensed under the MIT License. - */ - -package me.shedaniel.rei.api; - -public class RelativePoint { - - private double relativeX, relativeY; - - public RelativePoint(double relativeX, double relativeY) { - this.relativeX = relativeX; - this.relativeY = relativeY; - } - - public double getRelativeX() { - return relativeX; - } - - public double getRelativeY() { - return relativeY; - } - - public double getX(double width) { - return width * relativeX; - } - - public double getY(double height) { - return height * relativeY; - } - -} diff --git a/src/main/java/me/shedaniel/rei/api/Renderable.java b/src/main/java/me/shedaniel/rei/api/Renderable.java index 75d9161be..2d4c258ca 100644 --- a/src/main/java/me/shedaniel/rei/api/Renderable.java +++ b/src/main/java/me/shedaniel/rei/api/Renderable.java @@ -17,7 +17,7 @@ import java.util.function.Supplier; /** * The base class for renderables */ -public interface Renderable { +public class Renderable { /** * Gets an item stack renderer by an item stack supplier @@ -25,7 +25,7 @@ public interface Renderable { * @param supplier the supplier for getting the item stack * @return the item stack renderer */ - static ItemStackRenderer fromItemStackSupplier(Supplier supplier) { + public static ItemStackRenderer fromItemStackSupplier(Supplier supplier) { return new ItemStackRenderer() { @Override public ItemStack getItemStack() { @@ -40,7 +40,7 @@ public interface Renderable { * @param stack the item stack to be displayed * @return the item stack renderer */ - static ItemStackRenderer fromItemStack(ItemStack stack) { + public static ItemStackRenderer fromItemStack(ItemStack stack) { return fromItemStackSupplier(() -> stack); } @@ -49,7 +49,7 @@ public interface Renderable { * * @return an empty renderer */ - static EmptyRenderer empty() { + public static EmptyRenderer empty() { return EmptyRenderer.INSTANCE; } @@ -60,11 +60,11 @@ public interface Renderable { * @param output the list of output items * @return the recipe renderer */ - static SimpleRecipeRenderer fromRecipe(Supplier>> input, Supplier> output) { + public static SimpleRecipeRenderer fromRecipe(Supplier>> input, Supplier> output) { return new SimpleRecipeRenderer(input, output); } - static ItemStackRenderer fromItemStacks(List stacks) { + public static ItemStackRenderer fromItemStacks(List stacks) { return new ItemStackRenderer() { @Override public ItemStack getItemStack() { @@ -74,15 +74,4 @@ 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 aada00b8a..d3ddab934 100644 --- a/src/main/java/me/shedaniel/rei/api/Renderer.java +++ b/src/main/java/me/shedaniel/rei/api/Renderer.java @@ -7,7 +7,7 @@ package me.shedaniel.rei.api; import net.minecraft.client.gui.DrawableHelper; -public abstract class Renderer extends DrawableHelper implements Renderable { +public abstract class Renderer extends DrawableHelper { /** * Gets the current blit offset * @@ -25,4 +25,15 @@ public abstract class Renderer extends DrawableHelper implements Renderable { public void setBlitOffset(int offset) { this.blitOffset = offset; } + + /** + * 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 + */ + public abstract void render(int x, int y, double mouseX, double mouseY, float delta); } diff --git a/src/main/java/me/shedaniel/rei/client/ClientHelperImpl.java b/src/main/java/me/shedaniel/rei/client/ClientHelperImpl.java index 245ba3a72..56e9cf65b 100644 --- a/src/main/java/me/shedaniel/rei/client/ClientHelperImpl.java +++ b/src/main/java/me/shedaniel/rei/client/ClientHelperImpl.java @@ -17,6 +17,7 @@ import me.shedaniel.rei.api.RecipeHelper; import me.shedaniel.rei.gui.PreRecipeViewingScreen; import me.shedaniel.rei.gui.RecipeViewingScreen; import me.shedaniel.rei.gui.VillagerRecipeViewingScreen; +import me.shedaniel.rei.gui.config.RecipeScreenType; import net.fabricmc.api.ClientModInitializer; import net.fabricmc.fabric.api.client.keybinding.FabricKeyBinding; import net.fabricmc.fabric.api.network.ClientSidePacketRegistry; diff --git a/src/main/java/me/shedaniel/rei/client/ConfigObject.java b/src/main/java/me/shedaniel/rei/client/ConfigObject.java index 252d630f6..24f697471 100644 --- a/src/main/java/me/shedaniel/rei/client/ConfigObject.java +++ b/src/main/java/me/shedaniel/rei/client/ConfigObject.java @@ -6,8 +6,9 @@ package me.shedaniel.rei.client; import blue.endless.jankson.Comment; -import me.shedaniel.rei.api.ItemCheatingMode; -import me.shedaniel.rei.api.RelativePoint; +import me.shedaniel.rei.gui.config.ItemCheatingMode; +import me.shedaniel.rei.gui.config.ItemListOrdering; +import me.shedaniel.rei.gui.config.RecipeScreenType; public class ConfigObject { @@ -58,4 +59,31 @@ public class ConfigObject { "The location of choose page dialog, will automatically be set to your last location so there is no need to change this.") public RelativePoint choosePageDialogPoint = new RelativePoint(.5, .5); + public static class RelativePoint { + + private double relativeX, relativeY; + + public RelativePoint(double relativeX, double relativeY) { + this.relativeX = relativeX; + this.relativeY = relativeY; + } + + public double getRelativeX() { + return relativeX; + } + + public double getRelativeY() { + return relativeY; + } + + public double getX(double width) { + return width * relativeX; + } + + public double getY(double height) { + return height * relativeY; + } + + } + } diff --git a/src/main/java/me/shedaniel/rei/client/ItemListOrdering.java b/src/main/java/me/shedaniel/rei/client/ItemListOrdering.java deleted file mode 100644 index b1817cc33..000000000 --- a/src/main/java/me/shedaniel/rei/client/ItemListOrdering.java +++ /dev/null @@ -1,24 +0,0 @@ -/* - * Roughly Enough Items by Danielshe. - * Licensed under the MIT License. - */ - -package me.shedaniel.rei.client; - -public enum ItemListOrdering { - - registry("ordering.rei.registry"), - name("ordering.rei.name"), - item_groups("ordering.rei.item_groups"); - - private String nameTranslationKey; - - ItemListOrdering(String nameTranslationKey) { - this.nameTranslationKey = nameTranslationKey; - } - - public String getNameTranslationKey() { - return nameTranslationKey; - } - -} diff --git a/src/main/java/me/shedaniel/rei/client/RecipeHelperImpl.java b/src/main/java/me/shedaniel/rei/client/RecipeHelperImpl.java index 64450da02..25f29d7da 100644 --- a/src/main/java/me/shedaniel/rei/client/RecipeHelperImpl.java +++ b/src/main/java/me/shedaniel/rei/client/RecipeHelperImpl.java @@ -9,6 +9,11 @@ import com.google.common.collect.Lists; import com.google.common.collect.Maps; import me.shedaniel.rei.RoughlyEnoughItemsCore; import me.shedaniel.rei.api.*; +import me.shedaniel.rei.gui.ContainerScreenOverlay; +import me.shedaniel.rei.gui.config.DisplayVisibility; +import net.minecraft.client.MinecraftClient; +import net.minecraft.client.gui.screen.Screen; +import net.minecraft.client.gui.screen.ingame.AbstractContainerScreen; import net.minecraft.item.ItemStack; import net.minecraft.recipe.Recipe; import net.minecraft.recipe.RecipeManager; @@ -37,7 +42,8 @@ public class RecipeHelperImpl implements RecipeHelper { VISIBILITY_HANDLER_COMPARATOR = comparator.reversed(); } - public final List recipeFunctions = Lists.newArrayList(); + private final List autoCraftingHandlers = Lists.newArrayList(); + private final List recipeFunctions = Lists.newArrayList(); private final AtomicInteger recipeCount = new AtomicInteger(); private final Map> recipeCategoryListMap = Maps.newHashMap(); private final Map categoryDisplaySettingsMap = Maps.newHashMap(); @@ -45,7 +51,7 @@ public class RecipeHelperImpl implements RecipeHelper { private final Map speedCraftAreaSupplierMap = Maps.newHashMap(); private final Map>> categoryWorkingStations = Maps.newHashMap(); private final List displayVisibilityHandlers = Lists.newArrayList(); - private final List liveRecipeGenerators = Lists.newArrayList(); + private final List> liveRecipeGenerators = Lists.newArrayList(); private RecipeManager recipeManager; @Override @@ -81,7 +87,6 @@ public class RecipeHelperImpl implements RecipeHelper { @Override public void registerCategory(RecipeCategory category) { categories.add(category); - categoryDisplaySettingsMap.put(category.getIdentifier(), category.getDisplaySettings()); recipeCategoryListMap.put(category.getIdentifier(), Lists.newLinkedList()); categoryWorkingStations.put(category.getIdentifier(), Lists.newLinkedList()); } @@ -218,10 +223,10 @@ public class RecipeHelperImpl implements RecipeHelper { this.categories.clear(); this.speedCraftAreaSupplierMap.clear(); this.categoryWorkingStations.clear(); - this.categoryDisplaySettingsMap.clear(); this.recipeFunctions.clear(); this.displayVisibilityHandlers.clear(); this.liveRecipeGenerators.clear(); + this.autoCraftingHandlers.clear(); ((DisplayHelperImpl) RoughlyEnoughItemsCore.getDisplayHelper()).resetCache(); BaseBoundsHandler baseBoundsHandler = new BaseBoundsHandlerImpl(); RoughlyEnoughItemsCore.getDisplayHelper().registerBoundsHandler(baseBoundsHandler); @@ -266,7 +271,7 @@ public class RecipeHelperImpl implements RecipeHelper { if (getDisplayVisibilityHandlers().isEmpty()) registerRecipeVisibilityHandler(new DisplayVisibilityHandler() { @Override - public DisplayVisibility handleDisplay(RecipeCategory category, RecipeDisplay display) { + public DisplayVisibility handleDisplay(RecipeCategory category, RecipeDisplay display) { return DisplayVisibility.ALWAYS_VISIBLE; } @@ -275,10 +280,41 @@ public class RecipeHelperImpl implements RecipeHelper { return -1f; } }); + registerAutoCraftingHandler(new AutoCraftingHandler() { + @Override + public double getPriority() { + return -Double.MAX_VALUE; + } + + @Override + public boolean handle(MinecraftClient minecraft, Screen recipeViewingScreen, AbstractContainerScreen parentScreen, ContainerScreenOverlay overlay) { + minecraft.openScreen(parentScreen); + ScreenHelper.getLastOverlay().init(); + return true; + } + }); + + // Clear Cache + ((DisplayHelperImpl) RoughlyEnoughItemsCore.getDisplayHelper()).resetCache(); + this.categoryDisplaySettingsMap.clear(); + getAllCategories().forEach(category -> categoryDisplaySettingsMap.put(category.getIdentifier(), category.getDisplaySettings())); + ScreenHelper.getOptionalOverlay().ifPresent(overlay -> overlay.shouldReInit = true); + long usedTime = System.currentTimeMillis() - startTime; RoughlyEnoughItemsCore.LOGGER.info("[REI] Registered %d recipes displays, %d bounds handler, %d visibility " + "handlers and %d categories (%s) in %d ms.", recipeCount.get(), RoughlyEnoughItemsCore.getDisplayHelper().getAllBoundsHandlers().size(), getDisplayVisibilityHandlers().size(), categories.size(), String.join(", ", categories.stream().map(RecipeCategory::getCategoryName).collect(Collectors.toList())), usedTime); } + @Override + public AutoCraftingHandler registerAutoCraftingHandler(AutoCraftingHandler handler) { + autoCraftingHandlers.add(handler); + return handler; + } + + @Override + public List getSortedAutoCraftingHandler() { + return autoCraftingHandlers.stream().sorted(Comparator.comparingDouble(AutoCraftingHandler::getPriority).reversed()).collect(Collectors.toList()); + } + @Override public int getRecipeCount() { return recipeCount.get(); @@ -361,7 +397,7 @@ public class RecipeHelperImpl implements RecipeHelper { } @Override - public void registerLiveRecipeGenerator(LiveRecipeGenerator liveRecipeGenerator) { + public void registerLiveRecipeGenerator(LiveRecipeGenerator liveRecipeGenerator) { liveRecipeGenerators.add(liveRecipeGenerator); } diff --git a/src/main/java/me/shedaniel/rei/client/RecipeScreenType.java b/src/main/java/me/shedaniel/rei/client/RecipeScreenType.java deleted file mode 100644 index 78158419f..000000000 --- a/src/main/java/me/shedaniel/rei/client/RecipeScreenType.java +++ /dev/null @@ -1,19 +0,0 @@ -/* - * Roughly Enough Items by Danielshe. - * Licensed under the MIT License. - */ - -package me.shedaniel.rei.client; - -import net.minecraft.client.resource.language.I18n; - -public enum RecipeScreenType { - UNSET, - ORIGINAL, - VILLAGER; - - @Override - public String toString() { - return I18n.translate("text.rei.config.recipe_screen_type." + name().toLowerCase()); - } -} diff --git a/src/main/java/me/shedaniel/rei/client/ScreenHelper.java b/src/main/java/me/shedaniel/rei/client/ScreenHelper.java index 7c8085c1b..15ba7f335 100644 --- a/src/main/java/me/shedaniel/rei/client/ScreenHelper.java +++ b/src/main/java/me/shedaniel/rei/client/ScreenHelper.java @@ -18,8 +18,8 @@ import net.minecraft.client.util.Window; import net.minecraft.item.ItemStack; import org.apache.logging.log4j.util.TriConsumer; -import java.awt.*; import java.util.List; +import java.util.Optional; public class ScreenHelper implements ClientModInitializer { @@ -37,6 +37,10 @@ public class ScreenHelper implements ClientModInitializer { overlayVisible = !overlayVisible; } + public static Optional getOptionalOverlay() { + return Optional.ofNullable(overlay); + } + public static ContainerScreenOverlay getLastOverlay(boolean reset, boolean setPage) { if (overlay == null || reset) { overlay = new ContainerScreenOverlay(); @@ -63,13 +67,13 @@ public class ScreenHelper implements ClientModInitializer { public static void drawHoveringWidget(int x, int y, TriConsumer consumer, int width, int height, float delta) { Window window = MinecraftClient.getInstance().window; - drawHoveringWidget(new Dimension(window.getScaledWidth(), window.getScaledHeight()), x, y, consumer, width, height, delta); + drawHoveringWidget(window.getScaledWidth(), window.getScaledHeight(), x, y, consumer, width, height, delta); } - public static void drawHoveringWidget(Dimension dimension, int x, int y, TriConsumer consumer, int width, int height, float delta) { + public static void drawHoveringWidget(int screenWidth, int screenHeight, int x, int y, TriConsumer consumer, int width, int height, float delta) { int actualX = Math.max(x + 12, 6); - int actualY = Math.min(y - height / 2, dimension.height - height - 6); - if (actualX + width > dimension.width) + int actualY = Math.min(y - height / 2, screenHeight - height - 6); + if (actualX + width > screenWidth) actualX -= 24 + width; if (actualY < 6) actualY += 24; diff --git a/src/main/java/me/shedaniel/rei/client/SearchArgument.java b/src/main/java/me/shedaniel/rei/client/SearchArgument.java index 4c834ff1b..59ba0e0be 100644 --- a/src/main/java/me/shedaniel/rei/client/SearchArgument.java +++ b/src/main/java/me/shedaniel/rei/client/SearchArgument.java @@ -5,18 +5,19 @@ package me.shedaniel.rei.client; +import java.util.Locale; import java.util.function.Function; import java.util.regex.Pattern; public class SearchArgument { - public static final Function INCLUDE = integer -> integer > -1; - public static final Function NOT_INCLUDE = integer -> integer <= -1; + public static final SearchArgument ALWAYS = new SearchArgument(ArgumentType.ALWAYS, "", true); private ArgumentType argumentType; private String text; + public final Function INCLUDE = s -> boyerMooreHorspoolSearch(text, s) > -1; + public final Function NOT_INCLUDE = s -> boyerMooreHorspoolSearch(text, s) <= -1; private boolean include; private Pattern pattern; - public static final SearchArgument ALWAYS = new SearchArgument(ArgumentType.ALWAYS, "", true); public SearchArgument(ArgumentType argumentType, String text, boolean include) { this(argumentType, text, include, true); @@ -24,12 +25,31 @@ public class SearchArgument { public SearchArgument(ArgumentType argumentType, String text, boolean include, boolean autoLowerCase) { this.argumentType = argumentType; - this.text = autoLowerCase ? text.toLowerCase() : text; + this.text = autoLowerCase ? text.toLowerCase(Locale.ROOT) : text; this.include = include; } - public static Function getFunction(boolean include) { - return include ? SearchArgument.INCLUDE : SearchArgument.NOT_INCLUDE; + public static int boyerMooreHorspoolSearch(CharSequence pattern, CharSequence text) { + int shift[] = new int[256]; + for(int k = 0; k < 256; k++) + shift[k] = pattern.length(); + for(int k = 0; k < pattern.length() - 1; k++) + shift[pattern.charAt(k)] = pattern.length() - 1 - k; + int i = 0, j = 0; + while ((i + pattern.length()) <= text.length()) { + j = pattern.length() - 1; + while (text.charAt(i + j) == pattern.charAt(j)) { + j -= 1; + if (j < 0) + return i; + } + i = i + shift[text.charAt(i + pattern.length() - 1)]; + } + return -1; + } + + public Function getFunction(boolean include) { + return include ? INCLUDE : NOT_INCLUDE; } public ArgumentType getArgumentType() { diff --git a/src/main/java/me/shedaniel/rei/gui/ContainerScreenOverlay.java b/src/main/java/me/shedaniel/rei/gui/ContainerScreenOverlay.java index 727a5307a..e9de741f3 100644 --- a/src/main/java/me/shedaniel/rei/gui/ContainerScreenOverlay.java +++ b/src/main/java/me/shedaniel/rei/gui/ContainerScreenOverlay.java @@ -37,10 +37,8 @@ import net.minecraft.util.math.MathHelper; import net.minecraft.world.GameMode; import java.awt.*; -import java.util.LinkedList; import java.util.List; -import java.util.Objects; -import java.util.Optional; +import java.util.*; import java.util.stream.Collectors; public class ContainerScreenOverlay extends AbstractParentElement implements Drawable { @@ -51,6 +49,7 @@ public class ContainerScreenOverlay extends AbstractParentElement implements Dra private static int page = 0; private static ItemListOverlay itemListOverlay; private final List widgets = Lists.newLinkedList(); + public boolean shouldReInit = false; private Rectangle rectangle; private Window window; private CraftableToggleButtonWidget toggleButtonWidget; @@ -65,6 +64,7 @@ public class ContainerScreenOverlay extends AbstractParentElement implements Dra } public void init(boolean setPage) { + this.shouldReInit = false; //Update Variables this.children().clear(); this.window = MinecraftClient.getInstance().window; @@ -183,12 +183,12 @@ public class ContainerScreenOverlay extends AbstractParentElement implements Dra return false; } }); - int xxx = RoughlyEnoughItemsCore.getConfigManager().getConfig().mirrorItemPanel ? window.getScaledWidth() -30 : 10; + int xxx = RoughlyEnoughItemsCore.getConfigManager().getConfig().mirrorItemPanel ? window.getScaledWidth() - 30 : 10; for(Weather weather : Weather.values()) { widgets.add(new ButtonWidget(xxx, 35, 20, 20, "") { @Override public void onPressed() { - MinecraftClient.getInstance().player.sendChatMessage(RoughlyEnoughItemsCore.getConfigManager().getConfig().weatherCommand.replaceAll("\\{weather}", weather.name().toLowerCase())); + MinecraftClient.getInstance().player.sendChatMessage(RoughlyEnoughItemsCore.getConfigManager().getConfig().weatherCommand.replaceAll("\\{weather}", weather.name().toLowerCase(Locale.ROOT))); } @Override @@ -346,6 +346,8 @@ public class ContainerScreenOverlay extends AbstractParentElement implements Dra public void render(int mouseX, int mouseY, float delta) { List currentStacks = ClientHelper.getInstance().getInventoryItemsTypes(); if (RoughlyEnoughItemsCore.getDisplayHelper().getBaseBoundsHandler() != null && RoughlyEnoughItemsCore.getDisplayHelper().getBaseBoundsHandler().shouldRecalculateArea(!RoughlyEnoughItemsCore.getConfigManager().getConfig().mirrorItemPanel, rectangle)) + shouldReInit = true; + if (shouldReInit) init(true); else if (RoughlyEnoughItemsCore.getConfigManager().isCraftableOnlyEnabled() && (!hasSameListContent(new LinkedList<>(ScreenHelper.inventoryStacks), currentStacks) || (currentStacks.size() != ScreenHelper.inventoryStacks.size()))) { ScreenHelper.inventoryStacks = ClientHelper.getInstance().getInventoryItemsTypes(); diff --git a/src/main/java/me/shedaniel/rei/gui/PreRecipeViewingScreen.java b/src/main/java/me/shedaniel/rei/gui/PreRecipeViewingScreen.java index 8aeeb7c59..c3ade4191 100644 --- a/src/main/java/me/shedaniel/rei/gui/PreRecipeViewingScreen.java +++ b/src/main/java/me/shedaniel/rei/gui/PreRecipeViewingScreen.java @@ -10,7 +10,7 @@ import me.shedaniel.rei.RoughlyEnoughItemsCore; import me.shedaniel.rei.api.ClientHelper; import me.shedaniel.rei.api.RecipeCategory; import me.shedaniel.rei.api.RecipeDisplay; -import me.shedaniel.rei.client.RecipeScreenType; +import me.shedaniel.rei.gui.config.RecipeScreenType; import me.shedaniel.rei.client.ScreenHelper; import me.shedaniel.rei.gui.widget.ButtonWidget; import me.shedaniel.rei.gui.widget.HighlightableWidget; diff --git a/src/main/java/me/shedaniel/rei/gui/config/DisplayVisibility.java b/src/main/java/me/shedaniel/rei/gui/config/DisplayVisibility.java new file mode 100644 index 000000000..72c837c33 --- /dev/null +++ b/src/main/java/me/shedaniel/rei/gui/config/DisplayVisibility.java @@ -0,0 +1,13 @@ +/* + * Roughly Enough Items by Danielshe. + * Licensed under the MIT License. + */ + +package me.shedaniel.rei.gui.config; + +public enum DisplayVisibility { + ALWAYS_VISIBLE, + @Deprecated CONFIG_OPTIONAL, + NEVER_VISIBLE, + PASS +} diff --git a/src/main/java/me/shedaniel/rei/gui/config/ItemCheatingMode.java b/src/main/java/me/shedaniel/rei/gui/config/ItemCheatingMode.java new file mode 100644 index 000000000..e1348e615 --- /dev/null +++ b/src/main/java/me/shedaniel/rei/gui/config/ItemCheatingMode.java @@ -0,0 +1,11 @@ +/* + * Roughly Enough Items by Danielshe. + * Licensed under the MIT License. + */ + +package me.shedaniel.rei.gui.config; + +public enum ItemCheatingMode { + REI_LIKE, + JEI_LIKE; +} diff --git a/src/main/java/me/shedaniel/rei/gui/config/ItemListOrdering.java b/src/main/java/me/shedaniel/rei/gui/config/ItemListOrdering.java new file mode 100644 index 000000000..dd584bc69 --- /dev/null +++ b/src/main/java/me/shedaniel/rei/gui/config/ItemListOrdering.java @@ -0,0 +1,24 @@ +/* + * Roughly Enough Items by Danielshe. + * Licensed under the MIT License. + */ + +package me.shedaniel.rei.gui.config; + +public enum ItemListOrdering { + + registry("ordering.rei.registry"), + name("ordering.rei.name"), + item_groups("ordering.rei.item_groups"); + + private String nameTranslationKey; + + ItemListOrdering(String nameTranslationKey) { + this.nameTranslationKey = nameTranslationKey; + } + + public String getNameTranslationKey() { + return nameTranslationKey; + } + +} diff --git a/src/main/java/me/shedaniel/rei/gui/config/ItemListOrderingConfig.java b/src/main/java/me/shedaniel/rei/gui/config/ItemListOrderingConfig.java index 2742354bb..b190ff90f 100644 --- a/src/main/java/me/shedaniel/rei/gui/config/ItemListOrderingConfig.java +++ b/src/main/java/me/shedaniel/rei/gui/config/ItemListOrderingConfig.java @@ -5,7 +5,6 @@ package me.shedaniel.rei.gui.config; -import me.shedaniel.rei.client.ItemListOrdering; import net.minecraft.client.resource.language.I18n; public enum ItemListOrderingConfig { diff --git a/src/main/java/me/shedaniel/rei/gui/config/RecipeScreenType.java b/src/main/java/me/shedaniel/rei/gui/config/RecipeScreenType.java new file mode 100644 index 000000000..790a405ff --- /dev/null +++ b/src/main/java/me/shedaniel/rei/gui/config/RecipeScreenType.java @@ -0,0 +1,21 @@ +/* + * Roughly Enough Items by Danielshe. + * Licensed under the MIT License. + */ + +package me.shedaniel.rei.gui.config; + +import net.minecraft.client.resource.language.I18n; + +import java.util.Locale; + +public enum RecipeScreenType { + UNSET, + ORIGINAL, + VILLAGER; + + @Override + public String toString() { + return I18n.translate("text.rei.config.recipe_screen_type." + name().toLowerCase(Locale.ROOT)); + } +} diff --git a/src/main/java/me/shedaniel/rei/gui/renderables/EmptyRenderer.java b/src/main/java/me/shedaniel/rei/gui/renderables/EmptyRenderer.java index 3826377f0..06becf832 100644 --- a/src/main/java/me/shedaniel/rei/gui/renderables/EmptyRenderer.java +++ b/src/main/java/me/shedaniel/rei/gui/renderables/EmptyRenderer.java @@ -15,4 +15,5 @@ public class EmptyRenderer extends Renderer { public void render(int x, int y, double mouseX, double mouseY, float delta) { } + } diff --git a/src/main/java/me/shedaniel/rei/gui/widget/AutoCraftingButtonWidget.java b/src/main/java/me/shedaniel/rei/gui/widget/AutoCraftingButtonWidget.java index 2af5b1ea7..d0c8d0745 100644 --- a/src/main/java/me/shedaniel/rei/gui/widget/AutoCraftingButtonWidget.java +++ b/src/main/java/me/shedaniel/rei/gui/widget/AutoCraftingButtonWidget.java @@ -5,7 +5,9 @@ package me.shedaniel.rei.gui.widget; +import me.shedaniel.rei.api.AutoCraftingHandler; import me.shedaniel.rei.api.RecipeDisplay; +import me.shedaniel.rei.api.RecipeHelper; import me.shedaniel.rei.client.ScreenHelper; import net.minecraft.ChatFormat; import net.minecraft.client.gui.screen.ingame.AbstractContainerScreen; @@ -18,7 +20,7 @@ import java.util.function.Supplier; public class AutoCraftingButtonWidget extends ButtonWidget { - private final Supplier> displaySupplier; + private final Supplier displaySupplier; private String extraTooltip; private AbstractContainerScreen containerScreen; @@ -32,8 +34,9 @@ public class AutoCraftingButtonWidget extends ButtonWidget { @Override public void onPressed() { - minecraft.openScreen(containerScreen); - ScreenHelper.getLastOverlay().init(); + for(AutoCraftingHandler autoCraftingHandler : RecipeHelper.getInstance().getSortedAutoCraftingHandler()) + if (autoCraftingHandler.handle(minecraft,minecraft.currentScreen, containerScreen, ScreenHelper.getLastOverlay())) + break; } @Override diff --git a/src/main/java/me/shedaniel/rei/gui/widget/ItemListOverlay.java b/src/main/java/me/shedaniel/rei/gui/widget/ItemListOverlay.java index ff903278a..dd99afc7d 100644 --- a/src/main/java/me/shedaniel/rei/gui/widget/ItemListOverlay.java +++ b/src/main/java/me/shedaniel/rei/gui/widget/ItemListOverlay.java @@ -10,11 +10,11 @@ import me.shedaniel.cloth.api.ClientUtils; import me.shedaniel.rei.RoughlyEnoughItemsCore; import me.shedaniel.rei.api.ClientHelper; import me.shedaniel.rei.api.DisplayHelper; -import me.shedaniel.rei.api.ItemCheatingMode; import me.shedaniel.rei.api.RecipeHelper; -import me.shedaniel.rei.client.ItemListOrdering; import me.shedaniel.rei.client.ScreenHelper; import me.shedaniel.rei.client.SearchArgument; +import me.shedaniel.rei.gui.config.ItemCheatingMode; +import me.shedaniel.rei.gui.config.ItemListOrdering; import net.minecraft.client.MinecraftClient; import net.minecraft.client.item.TooltipContext; import net.minecraft.client.network.ClientPlayerEntity; @@ -30,10 +30,9 @@ import net.minecraft.util.registry.Registry; import org.apache.commons.lang3.StringUtils; import java.awt.*; -import java.util.Arrays; -import java.util.Collections; -import java.util.Comparator; import java.util.List; +import java.util.*; +import java.util.concurrent.atomic.AtomicReference; import java.util.stream.Collectors; public class ItemListOverlay extends Widget { @@ -100,26 +99,24 @@ public class ItemListOverlay extends Widget { public static boolean filterItem(ItemStack itemStack, List arguments) { if (arguments.isEmpty()) return true; - String mod = ClientHelper.getInstance().getModFromItem(itemStack.getItem()).toLowerCase(); - String tooltips = tryGetItemStackToolTip(itemStack, true).stream().skip(1).collect(Collectors.joining("")).replace(SPACE, EMPTY).toLowerCase(); - String name = tryGetItemStackName(itemStack).replace(SPACE, EMPTY).toLowerCase(); + AtomicReference mod = null, tooltips = null, name = null; for(SearchArgument[] arguments1 : arguments) { boolean b = true; for(SearchArgument argument : arguments1) { if (argument.getArgumentType().equals(SearchArgument.ArgumentType.ALWAYS)) return true; if (argument.getArgumentType().equals(SearchArgument.ArgumentType.MOD)) - if (SearchArgument.getFunction(!argument.isInclude()).apply(mod.indexOf(argument.getText()))) { + if (argument.getFunction(!argument.isInclude()).apply(fillMod(itemStack, mod))) { b = false; break; } if (argument.getArgumentType().equals(SearchArgument.ArgumentType.TOOLTIP)) - if (SearchArgument.getFunction(!argument.isInclude()).apply(tooltips.indexOf(argument.getText()))) { + if (argument.getFunction(!argument.isInclude()).apply(fillTooltip(itemStack, tooltips))) { b = false; break; } if (argument.getArgumentType().equals(SearchArgument.ArgumentType.TEXT)) - if (SearchArgument.getFunction(!argument.isInclude()).apply(name.indexOf(argument.getText()))) { + if (argument.getFunction(!argument.isInclude()).apply(fillName(itemStack, name))) { b = false; break; } @@ -130,6 +127,24 @@ public class ItemListOverlay extends Widget { return false; } + private static String fillMod(ItemStack itemStack, AtomicReference mod) { + if (mod == null) + mod = new AtomicReference<>(ClientHelper.getInstance().getModFromItem(itemStack.getItem()).toLowerCase(Locale.ROOT)); + return mod.get(); + } + + private static String fillTooltip(ItemStack itemStack, AtomicReference mod) { + if (mod == null) + mod = new AtomicReference<>(tryGetItemStackToolTip(itemStack, false).stream().collect(Collectors.joining("")).replace(SPACE, EMPTY).toLowerCase(Locale.ROOT)); + return mod.get(); + } + + private static String fillName(ItemStack itemStack, AtomicReference mod) { + if (mod == null) + mod = new AtomicReference<>(tryGetItemStackName(itemStack).replace(SPACE, EMPTY).toLowerCase(Locale.ROOT)); + return mod.get(); + } + public int getFullTotalSlotsPerPage() { return width * height; } @@ -274,7 +289,10 @@ public class ItemListOverlay extends Widget { else lastSearchArgument.add(new SearchArgument[]{SearchArgument.ALWAYS}); }); - os.stream().filter(itemStack -> filterItem(itemStack, lastSearchArgument)).forEachOrdered(stacks::add); + if (lastSearchArgument.isEmpty()) + os.forEach(stacks::add); + else + os.stream().filter(itemStack -> filterItem(itemStack, lastSearchArgument)).forEachOrdered(stacks::add); if (!RoughlyEnoughItemsCore.getConfigManager().isCraftableOnlyEnabled() || stacks.isEmpty() || inventoryItems.isEmpty()) return stacks; List workingItems = Lists.newArrayList(RecipeHelper.getInstance().findCraftableByItems(inventoryItems)); @@ -285,26 +303,6 @@ public class ItemListOverlay extends Widget { return lastSearchArgument; } - private boolean filterItem(ItemStack itemStack, SearchArgument... arguments) { - if (arguments.length == 0) - return true; - String mod = ClientHelper.getInstance().getModFromItem(itemStack.getItem()).toLowerCase(); - String tooltips = tryGetItemStackToolTip(itemStack, false).stream().skip(1).collect(Collectors.joining("")).replace(SPACE, EMPTY).toLowerCase(); - String name = tryGetItemStackName(itemStack).replace(SPACE, EMPTY).toLowerCase(); - for(SearchArgument argument : arguments) { - if (argument.getArgumentType().equals(SearchArgument.ArgumentType.MOD)) - if (SearchArgument.getFunction(!argument.isInclude()).apply(mod.indexOf(argument.getText()))) - return false; - if (argument.getArgumentType().equals(SearchArgument.ArgumentType.TOOLTIP)) - if (SearchArgument.getFunction(!argument.isInclude()).apply(tooltips.indexOf(argument.getText()))) - return false; - if (argument.getArgumentType().equals(SearchArgument.ArgumentType.TEXT)) - if (SearchArgument.getFunction(!argument.isInclude()).apply(name.indexOf(argument.getText()))) - return false; - } - return true; - } - public void calculateListSize(Rectangle rect) { int xOffset = 0, yOffset = 0; width = 0; diff --git a/src/main/java/me/shedaniel/rei/gui/widget/RecipeBaseWidget.java b/src/main/java/me/shedaniel/rei/gui/widget/RecipeBaseWidget.java index af452579d..d79ac9b40 100644 --- a/src/main/java/me/shedaniel/rei/gui/widget/RecipeBaseWidget.java +++ b/src/main/java/me/shedaniel/rei/gui/widget/RecipeBaseWidget.java @@ -7,7 +7,7 @@ package me.shedaniel.rei.gui.widget; import com.mojang.blaze3d.platform.GlStateManager; import me.shedaniel.rei.RoughlyEnoughItemsCore; -import me.shedaniel.rei.client.RecipeScreenType; +import me.shedaniel.rei.gui.config.RecipeScreenType; import me.shedaniel.rei.client.ScreenHelper; import net.minecraft.client.render.GuiLighting; import net.minecraft.util.Identifier; diff --git a/src/main/java/me/shedaniel/rei/gui/widget/RecipeChoosePageWidget.java b/src/main/java/me/shedaniel/rei/gui/widget/RecipeChoosePageWidget.java index 3b71c7f12..911655aea 100644 --- a/src/main/java/me/shedaniel/rei/gui/widget/RecipeChoosePageWidget.java +++ b/src/main/java/me/shedaniel/rei/gui/widget/RecipeChoosePageWidget.java @@ -9,7 +9,7 @@ import com.google.common.collect.Lists; import com.mojang.blaze3d.platform.GlStateManager; import me.shedaniel.rei.RoughlyEnoughItemsCore; import me.shedaniel.rei.api.ConfigManager; -import me.shedaniel.rei.api.RelativePoint; +import me.shedaniel.rei.client.ConfigObject; import me.shedaniel.rei.gui.RecipeViewingScreen; import net.minecraft.client.MinecraftClient; import net.minecraft.client.render.GuiLighting; @@ -44,7 +44,7 @@ public class RecipeChoosePageWidget extends DraggableWidget { private static Point getPointFromConfig() { Window window = MinecraftClient.getInstance().window; - RelativePoint point = RoughlyEnoughItemsCore.getConfigManager().getConfig().choosePageDialogPoint; + ConfigObject.RelativePoint point = RoughlyEnoughItemsCore.getConfigManager().getConfig().choosePageDialogPoint; return new Point((int) point.getX(window.getScaledWidth()), (int) point.getY(window.getScaledHeight())); } @@ -184,7 +184,7 @@ public class RecipeChoosePageWidget extends DraggableWidget { public void onMouseReleaseMidPoint(Point midPoint) { ConfigManager configManager = RoughlyEnoughItemsCore.getConfigManager(); Window window = minecraft.window; - configManager.getConfig().choosePageDialogPoint = new RelativePoint(midPoint.getX() / window.getScaledWidth(), midPoint.getY() / window.getScaledHeight()); + configManager.getConfig().choosePageDialogPoint = new ConfigObject.RelativePoint(midPoint.getX() / window.getScaledWidth(), midPoint.getY() / window.getScaledHeight()); try { configManager.saveConfig(); } catch (IOException e) { diff --git a/src/main/java/me/shedaniel/rei/gui/widget/SlotWidget.java b/src/main/java/me/shedaniel/rei/gui/widget/SlotWidget.java index 796bfcd1b..819c6ec79 100644 --- a/src/main/java/me/shedaniel/rei/gui/widget/SlotWidget.java +++ b/src/main/java/me/shedaniel/rei/gui/widget/SlotWidget.java @@ -20,19 +20,17 @@ import net.minecraft.util.Identifier; import net.minecraft.util.math.MathHelper; import java.awt.*; -import java.util.Collection; -import java.util.Collections; -import java.util.LinkedList; import java.util.List; +import java.util.*; import java.util.stream.Collectors; public class SlotWidget extends HighlightableWidget { public static final Identifier RECIPE_GUI = new Identifier("roughlyenoughitems", "textures/gui/recipecontainer.png"); public static final Identifier RECIPE_GUI_DARK = new Identifier("roughlyenoughitems", "textures/gui/recipecontainer_dark.png"); + protected int x, y; private List renderers = new LinkedList<>(); private boolean drawBackground, showToolTips, clickToMoreRecipes, drawHighlightedBackground; - protected int x, y; public SlotWidget(int x, int y, ItemStack itemStack, boolean drawBackground, boolean showToolTips) { this(x, y, Collections.singletonList(itemStack), drawBackground, showToolTips); @@ -155,10 +153,10 @@ public class SlotWidget extends HighlightableWidget { protected List getTooltip(ItemStack itemStack) { final String modString = ClientHelper.getInstance().getFormattedModFromItem(itemStack.getItem()); List toolTip = Lists.newArrayList(ItemListOverlay.tryGetItemStackToolTip(itemStack, true)); - String s1 = ClientHelperImpl.instance.getFormattedModNoItalicFromItem(itemStack.getItem()).toLowerCase(); + String s1 = ClientHelperImpl.instance.getFormattedModNoItalicFromItem(itemStack.getItem()).toLowerCase(Locale.ROOT); toolTip.addAll(getExtraToolTips(itemStack)); if (!modString.isEmpty()) { - toolTip.removeIf(s -> s.toLowerCase().contains(s1)); + toolTip.removeIf(s -> s.toLowerCase(Locale.ROOT).contains(s1)); toolTip.add(modString); } return toolTip; diff --git a/src/main/java/me/shedaniel/rei/listeners/CreativePlayerInventoryScreenHooks.java b/src/main/java/me/shedaniel/rei/listeners/CreativePlayerInventoryScreenHooks.java deleted file mode 100644 index e01f01bf0..000000000 --- a/src/main/java/me/shedaniel/rei/listeners/CreativePlayerInventoryScreenHooks.java +++ /dev/null @@ -1,16 +0,0 @@ -/* - * Roughly Enough Items by Danielshe. - * Licensed under the MIT License. - */ - -package me.shedaniel.rei.listeners; - -import net.minecraft.client.gui.screen.ingame.CreativeInventoryScreen; -import org.spongepowered.asm.mixin.Mixin; -import org.spongepowered.asm.mixin.gen.Accessor; - -@Mixin(CreativeInventoryScreen.class) -public interface CreativePlayerInventoryScreenHooks { - @Accessor("selectedTab") - int rei_getSelectedTab(); -} diff --git a/src/main/java/me/shedaniel/rei/plugin/DefaultAutoCraftingPlugin.java b/src/main/java/me/shedaniel/rei/plugin/DefaultAutoCraftingPlugin.java index 34c088c52..ff1711832 100644 --- a/src/main/java/me/shedaniel/rei/plugin/DefaultAutoCraftingPlugin.java +++ b/src/main/java/me/shedaniel/rei/plugin/DefaultAutoCraftingPlugin.java @@ -5,6 +5,7 @@ import me.shedaniel.rei.api.PluginDisabler; import me.shedaniel.rei.api.PluginFunction; import me.shedaniel.rei.api.REIPluginEntry; import me.shedaniel.rei.api.RecipeHelper; +import me.shedaniel.rei.plugin.autocrafting.AutoCraftingTableHandler; import net.minecraft.util.Identifier; public class DefaultAutoCraftingPlugin implements REIPluginEntry { @@ -28,7 +29,7 @@ public class DefaultAutoCraftingPlugin implements REIPluginEntry { @Override public void registerOthers(RecipeHelper recipeHelper) { - + recipeHelper.registerAutoCraftingHandler(new AutoCraftingTableHandler()); } } diff --git a/src/main/java/me/shedaniel/rei/plugin/DefaultPlugin.java b/src/main/java/me/shedaniel/rei/plugin/DefaultPlugin.java index 8b095e88d..3d8d3e64f 100644 --- a/src/main/java/me/shedaniel/rei/plugin/DefaultPlugin.java +++ b/src/main/java/me/shedaniel/rei/plugin/DefaultPlugin.java @@ -12,6 +12,7 @@ import me.shedaniel.rei.api.*; import me.shedaniel.rei.client.ScreenHelper; import me.shedaniel.rei.gui.RecipeViewingScreen; import me.shedaniel.rei.gui.VillagerRecipeViewingScreen; +import me.shedaniel.rei.gui.config.DisplayVisibility; import me.shedaniel.rei.plugin.blasting.DefaultBlastingCategory; import me.shedaniel.rei.plugin.blasting.DefaultBlastingDisplay; import me.shedaniel.rei.plugin.brewing.DefaultBrewingCategory; @@ -279,7 +280,7 @@ public class DefaultPlugin implements REIPluginEntry { recipeHelper.registerSpeedCraftButtonArea(DefaultPlugin.CAMPFIRE, bounds -> new Rectangle((int) bounds.getMaxX() - 16, bounds.y + 6, 10, 10)); recipeHelper.registerRecipeVisibilityHandler(new DisplayVisibilityHandler() { @Override - public DisplayVisibility handleDisplay(RecipeCategory category, RecipeDisplay display) { + public DisplayVisibility handleDisplay(RecipeCategory category, RecipeDisplay display) { return DisplayVisibility.ALWAYS_VISIBLE; } diff --git a/src/main/java/me/shedaniel/rei/plugin/autocrafting/AutoCraftingTableHandler.java b/src/main/java/me/shedaniel/rei/plugin/autocrafting/AutoCraftingTableHandler.java new file mode 100644 index 000000000..f33ee24fa --- /dev/null +++ b/src/main/java/me/shedaniel/rei/plugin/autocrafting/AutoCraftingTableHandler.java @@ -0,0 +1,26 @@ +package me.shedaniel.rei.plugin.autocrafting; + +import me.shedaniel.rei.api.AutoCraftingHandler; +import me.shedaniel.rei.client.ScreenHelper; +import me.shedaniel.rei.gui.ContainerScreenOverlay; +import me.shedaniel.rei.listeners.RecipeBookGuiHooks; +import net.minecraft.client.MinecraftClient; +import net.minecraft.client.gui.screen.Screen; +import net.minecraft.client.gui.screen.ingame.AbstractContainerScreen; +import net.minecraft.client.gui.screen.ingame.CraftingTableScreen; +import net.minecraft.container.CraftingTableContainer; + +public class AutoCraftingTableHandler implements AutoCraftingHandler { + @Override + public boolean handle(MinecraftClient minecraft, Screen recipeViewingScreen, AbstractContainerScreen parentScreen, ContainerScreenOverlay overlay) { + if (parentScreen instanceof CraftingTableScreen) { + CraftingTableScreen craftingTableScreen = (CraftingTableScreen) parentScreen; + minecraft.openScreen(craftingTableScreen); + ((RecipeBookGuiHooks) craftingTableScreen.getRecipeBookGui()).rei_getGhostSlots().reset(); + CraftingTableContainer container = craftingTableScreen.getContainer(); + ScreenHelper.getLastOverlay().init(); + return true; + } + return false; + } +} diff --git a/src/main/java/me/shedaniel/rei/plugin/blasting/DefaultBlastingDisplay.java b/src/main/java/me/shedaniel/rei/plugin/blasting/DefaultBlastingDisplay.java index d64e1315d..1cc64f818 100644 --- a/src/main/java/me/shedaniel/rei/plugin/blasting/DefaultBlastingDisplay.java +++ b/src/main/java/me/shedaniel/rei/plugin/blasting/DefaultBlastingDisplay.java @@ -20,7 +20,7 @@ import java.util.List; import java.util.Optional; import java.util.stream.Collectors; -public class DefaultBlastingDisplay implements RecipeDisplay { +public class DefaultBlastingDisplay implements RecipeDisplay { private BlastingRecipe display; private List> input; diff --git a/src/main/java/me/shedaniel/rei/plugin/campfire/DefaultCampfireDisplay.java b/src/main/java/me/shedaniel/rei/plugin/campfire/DefaultCampfireDisplay.java index 95ea5b1fd..213b3c034 100644 --- a/src/main/java/me/shedaniel/rei/plugin/campfire/DefaultCampfireDisplay.java +++ b/src/main/java/me/shedaniel/rei/plugin/campfire/DefaultCampfireDisplay.java @@ -20,7 +20,7 @@ import java.util.List; import java.util.Optional; import java.util.stream.Collectors; -public class DefaultCampfireDisplay implements RecipeDisplay { +public class DefaultCampfireDisplay implements RecipeDisplay { private List> inputs; private List output; diff --git a/src/main/java/me/shedaniel/rei/plugin/composting/DefaultCompostingCategory.java b/src/main/java/me/shedaniel/rei/plugin/composting/DefaultCompostingCategory.java index 957fa619b..79f85dd66 100644 --- a/src/main/java/me/shedaniel/rei/plugin/composting/DefaultCompostingCategory.java +++ b/src/main/java/me/shedaniel/rei/plugin/composting/DefaultCompostingCategory.java @@ -7,7 +7,10 @@ package me.shedaniel.rei.plugin.composting; import com.google.common.collect.Lists; import com.mojang.blaze3d.platform.GlStateManager; -import me.shedaniel.rei.api.*; +import me.shedaniel.rei.api.DisplaySettings; +import me.shedaniel.rei.api.RecipeCategory; +import me.shedaniel.rei.api.Renderable; +import me.shedaniel.rei.api.Renderer; import me.shedaniel.rei.gui.renderables.RecipeRenderer; import me.shedaniel.rei.gui.widget.RecipeBaseWidget; import me.shedaniel.rei.gui.widget.SlotWidget; @@ -97,20 +100,20 @@ public class DefaultCompostingCategory implements RecipeCategory getDisplaySettings() { + return new DisplaySettings() { @Override - public int getDisplayHeight(RecipeCategory iRecipeCategory) { + public int getDisplayHeight(RecipeCategory recipeCategory) { return 140; } @Override - public int getDisplayWidth(RecipeCategory iRecipeCategory, RecipeDisplay display) { + public int getDisplayWidth(RecipeCategory recipeCategory, DefaultCompostingDisplay display) { return 150; } @Override - public int getMaximumRecipePerPage(RecipeCategory iRecipeCategory) { + public int getMaximumRecipePerPage(RecipeCategory recipeCategory) { return -1; } diff --git a/src/main/java/me/shedaniel/rei/plugin/crafting/DefaultCraftingDisplay.java b/src/main/java/me/shedaniel/rei/plugin/crafting/DefaultCraftingDisplay.java index a74a3a291..b63fdc97c 100644 --- a/src/main/java/me/shedaniel/rei/plugin/crafting/DefaultCraftingDisplay.java +++ b/src/main/java/me/shedaniel/rei/plugin/crafting/DefaultCraftingDisplay.java @@ -7,10 +7,9 @@ package me.shedaniel.rei.plugin.crafting; import me.shedaniel.rei.api.RecipeDisplay; import me.shedaniel.rei.plugin.DefaultPlugin; -import net.minecraft.recipe.Recipe; import net.minecraft.util.Identifier; -public interface DefaultCraftingDisplay extends RecipeDisplay { +public interface DefaultCraftingDisplay extends RecipeDisplay { @Override default Identifier getRecipeCategory() { diff --git a/src/main/java/me/shedaniel/rei/plugin/smelting/DefaultSmeltingDisplay.java b/src/main/java/me/shedaniel/rei/plugin/smelting/DefaultSmeltingDisplay.java index e0e297c0c..b41bc1b3e 100644 --- a/src/main/java/me/shedaniel/rei/plugin/smelting/DefaultSmeltingDisplay.java +++ b/src/main/java/me/shedaniel/rei/plugin/smelting/DefaultSmeltingDisplay.java @@ -20,7 +20,7 @@ import java.util.List; import java.util.Optional; import java.util.stream.Collectors; -public class DefaultSmeltingDisplay implements RecipeDisplay { +public class DefaultSmeltingDisplay implements RecipeDisplay { private SmeltingRecipe display; private List> input; diff --git a/src/main/java/me/shedaniel/rei/plugin/smoking/DefaultSmokingDisplay.java b/src/main/java/me/shedaniel/rei/plugin/smoking/DefaultSmokingDisplay.java index 3bc95b6f4..2703549f7 100644 --- a/src/main/java/me/shedaniel/rei/plugin/smoking/DefaultSmokingDisplay.java +++ b/src/main/java/me/shedaniel/rei/plugin/smoking/DefaultSmokingDisplay.java @@ -20,7 +20,7 @@ import java.util.List; import java.util.Optional; import java.util.stream.Collectors; -public class DefaultSmokingDisplay implements RecipeDisplay { +public class DefaultSmokingDisplay implements RecipeDisplay { private SmokingRecipe display; private List> input; diff --git a/src/main/java/me/shedaniel/rei/plugin/stonecutting/DefaultStoneCuttingCategory.java b/src/main/java/me/shedaniel/rei/plugin/stonecutting/DefaultStoneCuttingCategory.java index d011cb917..c38ceb3b8 100644 --- a/src/main/java/me/shedaniel/rei/plugin/stonecutting/DefaultStoneCuttingCategory.java +++ b/src/main/java/me/shedaniel/rei/plugin/stonecutting/DefaultStoneCuttingCategory.java @@ -63,20 +63,20 @@ public class DefaultStoneCuttingCategory implements RecipeCategory getDisplaySettings() { return new DisplaySettings() { @Override - public int getDisplayHeight(RecipeCategory category) { + public int getDisplayHeight(RecipeCategory category) { return 36; } @Override - public int getDisplayWidth(RecipeCategory category, DefaultStoneCuttingDisplay display) { + public int getDisplayWidth(RecipeCategory category, DefaultStoneCuttingDisplay display) { return 150; } @Override - public int getMaximumRecipePerPage(RecipeCategory category) { + public int getMaximumRecip