From 609c2238e12ad9835c449cd9f9da842ca747d5dc Mon Sep 17 00:00:00 2001 From: Unknown Date: Tue, 18 Jun 2019 20:07:38 +0800 Subject: nah let's break everyone's plugins --- .../me/shedaniel/rei/api/BaseBoundsHandler.java | 14 +--- .../java/me/shedaniel/rei/api/DisplayHelper.java | 8 +-- .../java/me/shedaniel/rei/api/DisplaySettings.java | 44 ------------- .../rei/api/DisplayVisibilityHandler.java | 10 +-- .../java/me/shedaniel/rei/api/RecipeCategory.java | 61 ++++------------- .../java/me/shedaniel/rei/api/RecipeHelper.java | 8 --- src/main/java/me/shedaniel/rei/api/Renderable.java | 77 ---------------------- src/main/java/me/shedaniel/rei/api/Renderer.java | 65 ++++++++++++++++++ .../rei/client/BaseBoundsHandlerImpl.java | 10 +-- .../me/shedaniel/rei/client/DisplayHelperImpl.java | 20 +++--- .../me/shedaniel/rei/client/RecipeHelperImpl.java | 20 ++---- .../me/shedaniel/rei/gui/RecipeViewingScreen.java | 4 +- .../rei/gui/config/DisplayVisibility.java | 13 ---- .../rei/gui/renderables/SimpleRecipeRenderer.java | 6 +- .../me/shedaniel/rei/gui/widget/SlotWidget.java | 7 +- .../me/shedaniel/rei/plugin/DefaultPlugin.java | 26 ++------ .../plugin/DefaultPotionEffectExclusionZones.java | 6 +- .../plugin/DefaultRecipeBookExclusionZones.java | 7 +- .../plugin/blasting/DefaultBlastingCategory.java | 5 +- .../rei/plugin/brewing/DefaultBrewingCategory.java | 3 +- .../plugin/campfire/DefaultCampfireCategory.java | 3 +- .../composting/DefaultCompostingCategory.java | 32 ++------- .../plugin/crafting/DefaultCraftingCategory.java | 3 +- .../plugin/smelting/DefaultSmeltingCategory.java | 5 +- .../rei/plugin/smoking/DefaultSmokingCategory.java | 5 +- .../stonecutting/DefaultStoneCuttingCategory.java | 23 +------ 26 files changed, 153 insertions(+), 332 deletions(-) delete mode 100644 src/main/java/me/shedaniel/rei/api/DisplaySettings.java delete mode 100644 src/main/java/me/shedaniel/rei/api/Renderable.java delete mode 100644 src/main/java/me/shedaniel/rei/gui/config/DisplayVisibility.java (limited to 'src/main/java') diff --git a/src/main/java/me/shedaniel/rei/api/BaseBoundsHandler.java b/src/main/java/me/shedaniel/rei/api/BaseBoundsHandler.java index 7d311609f..cfdb29282 100644 --- a/src/main/java/me/shedaniel/rei/api/BaseBoundsHandler.java +++ b/src/main/java/me/shedaniel/rei/api/BaseBoundsHandler.java @@ -9,6 +9,7 @@ import net.minecraft.client.gui.screen.Screen; import java.awt.*; import java.util.List; +import java.util.function.Function; public interface BaseBoundsHandler extends DisplayHelper.DisplayBoundsHandler { /** @@ -24,17 +25,8 @@ public interface BaseBoundsHandler extends DisplayHelper.DisplayBoundsHandler the list of exclusion zones */ - void registerExclusionZones(Class screenClass, ExclusionZoneSupplier supplier); + void registerExclusionZones(Class screenClass, Function> 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 apply(boolean isOnRightSide); - } } diff --git a/src/main/java/me/shedaniel/rei/api/DisplayHelper.java b/src/main/java/me/shedaniel/rei/api/DisplayHelper.java index 755ca84b3..53d35a3dd 100644 --- a/src/main/java/me/shedaniel/rei/api/DisplayHelper.java +++ b/src/main/java/me/shedaniel/rei/api/DisplayHelper.java @@ -22,14 +22,14 @@ public interface DisplayHelper { * @return the sorted list of responsible bounds handlers * @see DisplayHelper#getResponsibleBoundsHandler(Class) for the unsorted version */ - List getSortedBoundsHandlers(Class screenClass); + List> getSortedBoundsHandlers(Class screenClass); /** * Gets all registered bounds handlers * * @return the list of registered bounds handlers */ - List getAllBoundsHandlers(); + List> getAllBoundsHandlers(); /** * Gets all responsible bounds handlers @@ -38,14 +38,14 @@ public interface DisplayHelper { * @return the the list of responsible bounds handlers * @see DisplayHelper#getSortedBoundsHandlers(Class) for the sorted version */ - DisplayBoundsHandler getResponsibleBoundsHandler(Class screenClass); + DisplayBoundsHandler getResponsibleBoundsHandler(Class screenClass); /** * Registers a bounds handler * * @param handler the handler to register */ - void registerBoundsHandler(DisplayBoundsHandler handler); + void registerBoundsHandler(DisplayBoundsHandler handler); /** * Gets the base bounds handler api for exclusion zones diff --git a/src/main/java/me/shedaniel/rei/api/DisplaySettings.java b/src/main/java/me/shedaniel/rei/api/DisplaySettings.java deleted file mode 100644 index 36fa1634b..000000000 --- a/src/main/java/me/shedaniel/rei/api/DisplaySettings.java +++ /dev/null @@ -1,44 +0,0 @@ -/* - * Roughly Enough Items by Danielshe. - * Licensed under the MIT License. - */ - -package me.shedaniel.rei.api; - -public interface DisplaySettings { - - /** - * Gets the recipe display height - * - * @param category the category of the display - * @return the height - */ - int getDisplayHeight(RecipeCategory category); - - /** - * Gets the recipe display width - * - * @param category the category of the display - * @param display the display of the recipe - * @return the width - */ - 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); - - /** - * Gets the fixed amount of recipes per page. - * - * @return the amount of recipes, returns -1 if not fixed - */ - default int getFixedRecipesPerPage() { - return -1; - } - -} diff --git a/src/main/java/me/shedaniel/rei/api/DisplayVisibilityHandler.java b/src/main/java/me/shedaniel/rei/api/DisplayVisibilityHandler.java index f29ca9129..5e6cde696 100644 --- a/src/main/java/me/shedaniel/rei/api/DisplayVisibilityHandler.java +++ b/src/main/java/me/shedaniel/rei/api/DisplayVisibilityHandler.java @@ -5,7 +5,7 @@ package me.shedaniel.rei.api; -import me.shedaniel.rei.gui.config.DisplayVisibility; +import net.minecraft.util.ActionResult; public interface DisplayVisibilityHandler { @@ -20,14 +20,14 @@ public interface DisplayVisibilityHandler { /** * Handles the visibility of the display. - * {@link DisplayVisibility#PASS} to pass the handling to another handler - * {@link DisplayVisibility#ALWAYS_VISIBLE} to always display it - * {@link DisplayVisibility#NEVER_VISIBLE} to never display it + * {@link ActionResult#PASS} to pass the handling to another handler + * {@link ActionResult#SUCCESS} to always display it + * {@link ActionResult#FAIL} to never display it * * @param category the category of the display * @param display the display of the recipe * @return the visibility */ - DisplayVisibility handleDisplay(RecipeCategory category, RecipeDisplay display); + ActionResult handleDisplay(RecipeCategory category, RecipeDisplay display); } diff --git a/src/main/java/me/shedaniel/rei/api/RecipeCategory.java b/src/main/java/me/shedaniel/rei/api/RecipeCategory.java index 64c53c300..73d1367c1 100644 --- a/src/main/java/me/shedaniel/rei/api/RecipeCategory.java +++ b/src/main/java/me/shedaniel/rei/api/RecipeCategory.java @@ -12,7 +12,6 @@ import me.shedaniel.rei.gui.widget.CategoryBaseWidget; import me.shedaniel.rei.gui.widget.RecipeBaseWidget; import me.shedaniel.rei.gui.widget.Widget; import net.minecraft.client.gui.DrawableHelper; -import net.minecraft.item.ItemStack; import net.minecraft.util.Identifier; import java.awt.*; @@ -30,26 +29,12 @@ public interface RecipeCategory { */ Identifier getIdentifier(); - /** - * Gets the stack to render for the icon - * - * @return the stack to render - * @deprecated use {@link RecipeCategory#getIcon()} instead - */ - @Deprecated - default ItemStack getCategoryIcon() { - return ItemStack.EMPTY; - } - /** * Gets the renderer of the icon, allowing developers to render things other than items * * @return the renderer of the icon */ - @SuppressWarnings("deprecation") - default Renderer getIcon() { - return Renderable.fromItemStackSupplier(this::getCategoryIcon); - } + Renderer getIcon(); /** * Gets the category name @@ -66,7 +51,7 @@ public interface RecipeCategory { */ @SuppressWarnings("unchecked") default RecipeRenderer getSimpleRenderer(T recipe) { - return Renderable.fromRecipe(recipe::getInput, recipe::getOutput); + return Renderer.fromRecipe(recipe::getInput, recipe::getOutput); } /** @@ -99,59 +84,41 @@ public interface RecipeCategory { } } - /** - * Gets the display settings for the category, used for getting the bounds for the display - * - * @return the display settings - */ - default DisplaySettings getDisplaySettings() { - return new DisplaySettings() { - @Override - public int getDisplayHeight(RecipeCategory category) { - return 66; - } - - @Override - public int getDisplayWidth(RecipeCategory category, T display) { - return 150; - } - - @Override - public int getMaximumRecipePerPage(RecipeCategory category) { - return 99; - } - }; - } - /** * Gets the recipe display height - * Please do not override this, use {@link RecipeCategory#getDisplaySettings()} instead * * @return the recipe display height */ default int getDisplayHeight() { - return RecipeHelper.getInstance().getCachedCategorySettings(getIdentifier()).map(settings -> settings.getDisplayHeight(this)).orElse(0); + return 66; } /** * Gets the recipe display width - * Please do not override this, use {@link RecipeCategory#getDisplaySettings()} instead * * @param display the recipe display * @return the recipe display width */ default int getDisplayWidth(T display) { - return RecipeHelper.getInstance().getCachedCategorySettings(getIdentifier()).map(settings -> settings.getDisplayWidth(this, display)).orElse(0); + return 150; } /** * Gets the maximum recipe per page. - * Please do not override this, use {@link RecipeCategory#getDisplaySettings()} instead * * @return the maximum amount of recipes for page */ default int getMaximumRecipePerPage() { - return RecipeHelper.getInstance().getCachedCategorySettings(getIdentifier()).map(settings -> settings.getMaximumRecipePerPage(this)).orElse(0); + return 99; + } + + /** + * Gets the fixed amount of recipes per page. + * + * @return the amount of recipes, returns -1 if not fixed + */ + default int getFixedRecipesPerPage() { + return -1; } /** diff --git a/src/main/java/me/shedaniel/rei/api/RecipeHelper.java b/src/main/java/me/shedaniel/rei/api/RecipeHelper.java index 80bb18238..70373ca51 100644 --- a/src/main/java/me/shedaniel/rei/api/RecipeHelper.java +++ b/src/main/java/me/shedaniel/rei/api/RecipeHelper.java @@ -196,14 +196,6 @@ public interface RecipeHelper { > void registerRecipes(Identifier category, Predicate recipeFilter, Function mappingFunction); - /** - * Gets the cached category setting by the category identifier - * - * @param category the identifier of the category - * @return the optional of the category settings - */ - Optional getCachedCategorySettings(Identifier category); - /** * Registers a live recipe generator. * diff --git a/src/main/java/me/shedaniel/rei/api/Renderable.java b/src/main/java/me/shedaniel/rei/api/Renderable.java deleted file mode 100644 index 2d4c258ca..000000000 --- a/src/main/java/me/shedaniel/rei/api/Renderable.java +++ /dev/null @@ -1,77 +0,0 @@ -/* - * Roughly Enough Items by Danielshe. - * Licensed under the MIT License. - */ - -package me.shedaniel.rei.api; - -import me.shedaniel.rei.gui.renderables.EmptyRenderer; -import me.shedaniel.rei.gui.renderables.ItemStackRenderer; -import me.shedaniel.rei.gui.renderables.SimpleRecipeRenderer; -import net.minecraft.item.ItemStack; -import net.minecraft.util.math.MathHelper; - -import java.util.List; -import java.util.function.Supplier; - -/** - * The base class for renderables - */ -public class 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 - */ - public static ItemStackRenderer fromItemStackSupplier(Supplier supplier) { - return new ItemStackRenderer() { - @Override - public ItemStack getItemStack() { - return supplier.get(); - } - }; - } - - /** - * Gets an item stack renderer by an item stack - * - * @param stack the item stack to be displayed - * @return the item stack renderer - */ - public static ItemStackRenderer fromItemStack(ItemStack stack) { - return fromItemStackSupplier(() -> stack); - } - - /** - * Gets an empty renderer - * - * @return an empty renderer - */ - public 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 - */ - public static SimpleRecipeRenderer fromRecipe(Supplier>> input, Supplier> output) { - return new SimpleRecipeRenderer(input, output); - } - - public static ItemStackRenderer fromItemStacks(List stacks) { - return new ItemStackRenderer() { - @Override - public ItemStack getItemStack() { - if (stacks.isEmpty()) - return ItemStack.EMPTY; - return stacks.get(MathHelper.floor((System.currentTimeMillis() / 500 % (double) stacks.size()) / 1f)); - } - }; - } -} diff --git a/src/main/java/me/shedaniel/rei/api/Renderer.java b/src/main/java/me/shedaniel/rei/api/Renderer.java index d3ddab934..43d4c55b3 100644 --- a/src/main/java/me/shedaniel/rei/api/Renderer.java +++ b/src/main/java/me/shedaniel/rei/api/Renderer.java @@ -5,9 +5,73 @@ package me.shedaniel.rei.api; +import me.shedaniel.rei.gui.renderables.EmptyRenderer; +import me.shedaniel.rei.gui.renderables.ItemStackRenderer; +import me.shedaniel.rei.gui.renderables.SimpleRecipeRenderer; import net.minecraft.client.gui.DrawableHelper; +import net.minecraft.item.ItemStack; +import net.minecraft.util.math.MathHelper; + +import java.util.List; +import java.util.function.Supplier; public abstract class Renderer extends DrawableHelper { + /** + * Gets an item stack renderer by an item stack supplier + * + * @param supplier the supplier for getting the item stack + * @return the item stack renderer + */ + public static ItemStackRenderer fromItemStackSupplier(Supplier supplier) { + return new ItemStackRenderer() { + @Override + public ItemStack getItemStack() { + return supplier.get(); + } + }; + } + + /** + * Gets an item stack renderer by an item stack + * + * @param stack the item stack to be displayed + * @return the item stack renderer + */ + public static ItemStackRenderer fromItemStack(ItemStack stack) { + return fromItemStackSupplier(() -> stack); + } + + /** + * Gets an empty renderer + * + * @return an empty renderer + */ + public 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 + */ + public static SimpleRecipeRenderer fromRecipe(Supplier>> input, Supplier> output) { + return new SimpleRecipeRenderer(input, output); + } + + public static ItemStackRenderer fromItemStacks(List stacks) { + return new ItemStackRenderer() { + @Override + public ItemStack getItemStack() { + if (stacks.isEmpty()) + return ItemStack.EMPTY; + return stacks.get(MathHelper.floor((System.currentTimeMillis() / 500 % (double) stacks.size()) / 1f)); + } + }; + } + /** * Gets the current blit offset * @@ -36,4 +100,5 @@ public abstract class Renderer extends DrawableHelper { * @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/BaseBoundsHandlerImpl.java b/src/main/java/me/shedaniel/rei/client/BaseBoundsHandlerImpl.java index 426ccd926..1ae0bf958 100644 --- a/src/main/java/me/shedaniel/rei/client/BaseBoundsHandlerImpl.java +++ b/src/main/java/me/shedaniel/rei/client/BaseBoundsHandlerImpl.java @@ -24,15 +24,15 @@ public class BaseBoundsHandlerImpl implements BaseBoundsHandler { private static final Function RECTANGLE_STRING_FUNCTION = rectangle -> rectangle.x + "," + rectangle.y + "," + rectangle.width + "," + rectangle.height; private static final Comparator RECTANGLE_COMPARATOR = BaseBoundsHandlerImpl::compare; - private static final Comparator, Float>, ExclusionZoneSupplier>> LIST_PAIR_COMPARATOR; + private static final Comparator, Float>, Function>>> LIST_PAIR_COMPARATOR; static { - Comparator, Float>, ExclusionZoneSupplier>> comparator = Comparator.comparingDouble(value -> value.getLeft().getRight()); + Comparator, Float>, Function>>> comparator = Comparator.comparingDouble(value -> value.getLeft().getRight()); LIST_PAIR_COMPARATOR = comparator.reversed(); } private String lastArea = null; - private List, Float>, ExclusionZoneSupplier>> list = Lists.newArrayList(); + private List, Float>, Function>>> list = Lists.newArrayList(); private static int compare(Rectangle o1, Rectangle o2) {return RECTANGLE_STRING_FUNCTION.apply(o1).compareTo(RECTANGLE_STRING_FUNCTION.apply(o2));} @@ -94,7 +94,7 @@ public class BaseBoundsHandlerImpl implements BaseBoundsHandler { } public List getCurrentExclusionZones(Class currentScreenClass, boolean isOnRightSide) { - List, Float>, ExclusionZoneSupplier>> only = list.stream().filter(pair -> pair.getLeft().getLeft().isAssignableFrom(currentScreenClass)).collect(Collectors.toList()); + List, Float>, Function>>> only = list.stream().filter(pair -> pair.getLeft().getLeft().isAssignableFrom(currentScreenClass)).collect(Collectors.toList()); only.sort(LIST_PAIR_COMPARATOR); List rectangles = Lists.newArrayList(); only.forEach(pair -> rectangles.addAll(pair.getRight().apply(isOnRightSide))); @@ -102,7 +102,7 @@ public class BaseBoundsHandlerImpl implements BaseBoundsHandler { } @Override - public void registerExclusionZones(Class screenClass, ExclusionZoneSupplier supplier) { + public void registerExclusionZones(Class screenClass, Function> supplier) { list.add(new Pair<>(new Pair<>(screenClass, 0f), supplier)); } diff --git a/src/main/java/me/shedaniel/rei/client/DisplayHelperImpl.java b/src/main/java/me/shedaniel/rei/client/DisplayHelperImpl.java index 4cac6a11f..ac6d581bf 100644 --- a/src/main/java/me/shedaniel/rei/client/DisplayHelperImpl.java +++ b/src/main/java/me/shedaniel/rei/client/DisplayHelperImpl.java @@ -19,8 +19,8 @@ import java.util.stream.Collectors; public class DisplayHelperImpl implements DisplayHelper { - private static final Comparator BOUNDS_HANDLER_COMPARATOR; - private static final DisplayBoundsHandler EMPTY = new DisplayBoundsHandler() { + private static final Comparator> BOUNDS_HANDLER_COMPARATOR; + private static final DisplayBoundsHandler EMPTY = new DisplayBoundsHandler() { @Override public Class getBaseSupportedClass() { return null; @@ -43,27 +43,27 @@ public class DisplayHelperImpl implements DisplayHelper { }; static { - Comparator comparator = Comparator.comparingDouble(DisplayBoundsHandler::getPriority); + Comparator> comparator = Comparator.comparingDouble(DisplayBoundsHandler::getPriority); BOUNDS_HANDLER_COMPARATOR = comparator.reversed(); } - private List screenDisplayBoundsHandlers = Lists.newArrayList(); - private Map handlerCache = Maps.newHashMap(); + private List> screenDisplayBoundsHandlers = Lists.newArrayList(); + private Map, DisplayBoundsHandler> handlerCache = Maps.newHashMap(); private BaseBoundsHandler baseBoundsHandler; @Override - public List getSortedBoundsHandlers(Class screenClass) { + public List> getSortedBoundsHandlers(Class screenClass) { return screenDisplayBoundsHandlers.stream().filter(handler -> handler.getBaseSupportedClass().isAssignableFrom(screenClass)).sorted(BOUNDS_HANDLER_COMPARATOR).collect(Collectors.toList()); } @Override - public List getAllBoundsHandlers() { + public List> getAllBoundsHandlers() { return screenDisplayBoundsHandlers; } @Override - public DisplayBoundsHandler getResponsibleBoundsHandler(Class screenClass) { - Optional any = handlerCache.entrySet().stream().filter(entry -> entry.getKey().equals(screenClass)).map(Map.Entry::getValue).findAny(); + public DisplayBoundsHandler getResponsibleBoundsHandler(Class screenClass) { + Optional> any = handlerCache.entrySet().stream().filter(entry -> entry.getKey().equals(screenClass)).map(Map.Entry::getValue).findAny(); if (any.isPresent()) return any.get(); handlerCache.put(screenClass, screenDisplayBoundsHandlers.stream().filter(handler -> handler.getBaseSupportedClass().isAssignableFrom(screenClass)).sorted(BOUNDS_HANDLER_COMPARATOR).findAny().orElse(EMPTY)); @@ -71,7 +71,7 @@ public class DisplayHelperImpl implements DisplayHelper { } @Override - public void registerBoundsHandler(DisplayBoundsHandler handler) { + public void registerBoundsHandler(DisplayBoundsHandler handler) { screenDisplayBoundsHandlers.add(handler); } diff --git a/src/main/java/me/shedaniel/rei/client/RecipeHelperImpl.java b/src/main/java/me/shedaniel/rei/client/RecipeHelperImpl.java index 5db09d727..679d327e8 100644 --- a/src/main/java/me/shedaniel/rei/client/RecipeHelperImpl.java +++ b/src/main/java/me/shedaniel/rei/client/RecipeHelperImpl.java @@ -9,10 +9,10 @@ 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.config.DisplayVisibility; import net.minecraft.item.ItemStack; import net.minecraft.recipe.Recipe; import net.minecraft.recipe.RecipeManager; +import net.minecraft.util.ActionResult; import net.minecraft.util.Identifier; import java.awt.*; @@ -42,7 +42,6 @@ public class RecipeHelperImpl implements RecipeHelper { private final List recipeFunctions = Lists.newArrayList(); private final AtomicInteger recipeCount = new AtomicInteger(); private final Map> recipeCategoryListMap = Maps.newHashMap(); - private final Map categoryDisplaySettingsMap = Maps.newHashMap(); private final List categories = Lists.newArrayList(); private final Map speedCraftAreaSupplierMap = Maps.newHashMap(); private final Map>> categoryWorkingStations = Maps.newHashMap(); @@ -267,8 +266,8 @@ public class RecipeHelperImpl implements RecipeHelper { if (getDisplayVisibilityHandlers().isEmpty()) registerRecipeVisibilityHandler(new DisplayVisibilityHandler() { @Override - public DisplayVisibility handleDisplay(RecipeCategory category, RecipeDisplay display) { - return DisplayVisibility.ALWAYS_VISIBLE; + public ActionResult handleDisplay(RecipeCategory category, RecipeDisplay display) { + return ActionResult.SUCCESS; } @Override @@ -278,8 +277,6 @@ public class RecipeHelperImpl implements RecipeHelper { }); // 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; @@ -353,9 +350,9 @@ public class RecipeHelperImpl implements RecipeHelper { List list = getDisplayVisibilityHandlers().stream().sorted(VISIBILITY_HANDLER_COMPARATOR).collect(Collectors.toList()); for(DisplayVisibilityHandler displayVisibilityHandler : list) { try { - DisplayVisibility visibility = displayVisibilityHandler.handleDisplay(category, display); - if (visibility != DisplayVisibility.PASS) - return visibility == DisplayVisibility.ALWAYS_VISIBLE || visibility == DisplayVisibility.CONFIG_OPTIONAL; + ActionResult visibility = displayVisibilityHandler.handleDisplay(category, display); + if (visibility != ActionResult.PASS) + return visibility == ActionResult.SUCCESS; } catch (Throwable throwable) { RoughlyEnoughItemsCore.LOGGER.error("[REI] Failed to check if the recipe is visible!", throwable); } @@ -378,11 +375,6 @@ public class RecipeHelperImpl implements RecipeHelper { recipeFunctions.add(new RecipeFunction(category, recipeFilter, mappingFunction)); } - @Override - public Optional getCachedCategorySettings(Identifier category) { - return categoryDisplaySettingsMap.entrySet().stream().filter(entry -> entry.getKey().equals(category)).map(Map.Entry::getValue).findAny(); - } - @Override public void registerLiveRecipeGenerator(LiveRecipeGenerator liveRecipeGenerator) { liveRecipeGenerators.add(liveRecipeGenerator); diff --git a/src/main/java/me/shedaniel/rei/gui/RecipeViewingScreen.java b/src/main/java/me/shedaniel/rei/gui/RecipeViewingScreen.java index d28f2c9f1..c782982ac 100644 --- a/src/main/java/me/shedaniel/rei/gui/RecipeViewingScreen.java +++ b/src/main/java/me/shedaniel/rei/gui/RecipeViewingScreen.java @@ -347,8 +347,8 @@ public class RecipeViewingScreen extends Screen { } private int getRecipesPerPage() { - if (selectedCategory.getDisplaySettings().getFixedRecipesPerPage() > 0) - return selectedCategory.getDisplaySettings().getFixedRecipesPerPage() - 1; + if (selectedCategory.getFixedRecipesPerPage() > 0) + return selectedCategory.getFixedRecipesPerPage() - 1; int height = selectedCategory.getDisplayHeight(); return MathHelper.clamp(MathHelper.floor(((double) largestHeight - 40d) / ((double) height + 7d)) - 1, 0, Math.min(RoughlyEnoughItemsCore.getConfigManager().getConfig().maxRecipePerPage - 1, selectedCategory.getMaximumRecipePerPage() - 1)); } diff --git a/src/main/java/me/shedaniel/rei/gui/config/DisplayVisibility.java b/src/main/java/me/shedaniel/rei/gui/config/DisplayVisibility.java deleted file mode 100644 index 72c837c33..000000000 --- a/src/main/java/me/shedaniel/rei/gui/config/DisplayVisibility.java +++ /dev/null @@ -1,13 +0,0 @@ -/* - * 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/renderables/SimpleRecipeRenderer.java b/src/main/java/me/shedaniel/rei/gui/renderables/SimpleRecipeRenderer.java index 71fd9a4a4..7d40f4b8f 100644 --- a/src/main/java/me/shedaniel/rei/gui/renderables/SimpleRecipeRenderer.java +++ b/src/main/java/me/shedaniel/rei/gui/renderables/SimpleRecipeRenderer.java @@ -6,7 +6,7 @@ package me.shedaniel.rei.gui.renderables; import com.google.common.collect.Lists; -import me.shedaniel.rei.api.Renderable; +import me.shedaniel.rei.api.Renderer; import me.shedaniel.rei.gui.VillagerRecipeViewingScreen; import net.minecraft.client.MinecraftClient; import net.minecraft.client.render.GuiLighting; @@ -58,8 +58,8 @@ public class SimpleRecipeRenderer extends RecipeRenderer { s.setAmount(pair.getRight().get()); return s; }).collect(Collectors.toList())); - this.inputRenderer = b.stream().filter(stacks -> !stacks.isEmpty()).map(stacks -> Renderable.fromItemStacks(stacks)).collect(Collectors.toList()); - this.outputRenderer = Renderable.fromItemStacks(output.get().stream().filter(stack -> !stack.isEmpty()).collect(Collectors.toList())); + this.inputRenderer = b.stream().filter(stacks -> !stacks.isEmpty()).map(stacks -> Renderer.fromItemStacks(stacks)).collect(Collectors.toList()); + this.outputRenderer = Renderer.fromItemStacks(output.get().stream().filter(stack -> !stack.isEmpty()).collect(Collectors.toList())); } public static boolean equalsList(List list_1, List list_2) { 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 819c6ec79..e1708478f 100644 --- a/src/main/java/me/shedaniel/rei/gui/widget/SlotWidget.java +++ b/src/main/java/me/shedaniel/rei/gui/widget/SlotWidget.java @@ -9,7 +9,6 @@ import com.google.common.collect.Lists; import com.mojang.blaze3d.platform.GlStateManager; import me.shedaniel.cloth.api.ClientUtils; import me.shedaniel.rei.api.ClientHelper; -import me.shedaniel.rei.api.Renderable; import me.shedaniel.rei.api.Renderer; import me.shedaniel.rei.client.ClientHelperImpl; import me.shedaniel.rei.client.ScreenHelper; @@ -37,7 +36,7 @@ public class SlotWidget extends HighlightableWidget { } public SlotWidget(int x, int y, Collection itemList, boolean drawBackground, boolean showToolTips) { - this(x, y, itemList.stream().map(Renderable::fromItemStack).collect(Collectors.toList()), drawBackground, showToolTips); + this(x, y, itemList.stream().map(Renderer::fromItemStack).collect(Collectors.toList()), drawBackground, showToolTips); } public SlotWidget(int x, int y, List renderers, boolean drawBackground, boolean showToolTips) { @@ -178,12 +177,12 @@ public class SlotWidget extends HighlightableWidget { public Renderer getCurrentRenderer() { if (renderers.size() == 0) - return Renderable.empty(); + return Renderer.empty(); return renderers.get(MathHelper.floor((System.currentTimeMillis() / 500 % (double) renderers.size()) / 1f)); } public void setItemList(List itemList) { - this.setRenderers(itemList.stream().map(Renderable::fromItemStack).collect(Collectors.toList())); + this.setRenderers(itemList.stream().map(Renderer::fromItemStack).collect(Collectors.toList())); } public void setRenderers(List renderers) { diff --git a/src/main/java/me/shedaniel/rei/plugin/DefaultPlugin.java b/src/main/java/me/shedaniel/rei/plugin/DefaultPlugin.java index 3d8d3e64f..bf22ed09b 100644 --- a/src/main/java/me/shedaniel/rei/plugin/DefaultPlugin.java +++ b/src/main/java/me/shedaniel/rei/plugin/DefaultPlugin.java @@ -12,7 +12,6 @@ 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; @@ -171,19 +170,19 @@ public class DefaultPlugin implements REIPluginEntry { public void registerBounds(DisplayHelper displayHelper) { displayHelper.getBaseBoundsHandler().registerExclusionZones(AbstractInventoryScreen.class, new DefaultPotionEffectExclusionZones()); displayHelper.getBaseBoundsHandler().registerExclusionZones(RecipeBookProvider.class, new DefaultRecipeBookExclusionZones()); - displayHelper.registerBoundsHandler(new DisplayHelper.DisplayBoundsHandler() { + displayHelper.registerBoundsHandler(new DisplayHelper.DisplayBoundsHandler>() { @Override - public Class getBaseSupportedClass() { + public Class getBaseSupportedClass() { return AbstractContainerScreen.class; } @Override - public Rectangle getLeftBounds(AbstractContainerScreen screen) { + public Rectangle getLeftBounds(AbstractContainerScreen screen) { return new Rectangle(2, 0, ScreenHelper.getLastContainerScreenHooks().rei_getContainerLeft() - 4, MinecraftClient.getInstance().window.getScaledHeight()); } @Override - public Rectangle getRightBounds(AbstractContainerScreen screen) { + public Rectangle getRightBounds(AbstractContainerScreen screen) { int startX = ScreenHelper.getLastContainerScreenHooks().rei_getContainerLeft() + ScreenHelper.getLastContainerScreenHooks().rei_getContainerWidth() + 2; return new Rectangle(startX, 0, MinecraftClient.getInstance().window.getScaledWidth() - startX - 2, MinecraftClient.getInstance().window.getScaledHeight()); } @@ -195,7 +194,7 @@ public class DefaultPlugin implements REIPluginEntry { }); displayHelper.registerBoundsHandler(new DisplayHelper.DisplayBoundsHandler() { @Override - public Class getBaseSupportedClass() { + public Class getBaseSupportedClass() { return RecipeViewingScreen.class; } @@ -217,7 +216,7 @@ public class DefaultPlugin implements REIPluginEntry { }); displayHelper.registerBoundsHandler(new DisplayHelper.DisplayBoundsHandler() { @Override - public Class getBaseSupportedClass() { + public Class getBaseSupportedClass() { return VillagerRecipeViewingScreen.class; } @@ -239,7 +238,7 @@ public class DefaultPlugin implements REIPluginEntry { }); displayHelper.registerBoundsHandler(new DisplayHelper.DisplayBoundsHandler() { @Override - public Class getBaseSupportedClass() { + public Class getBaseSupportedClass() { return CreativeInventoryScreen.class; } @@ -278,17 +277,6 @@ public class DefaultPlugin implements REIPluginEntry { recipeHelper.registerWorkingStations(COMPOSTING, new ItemStack(Items.COMPOSTER)); recipeHelper.registerSpeedCraftButtonArea(COMPOSTING, bounds -> null); 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) { - return DisplayVisibility.ALWAYS_VISIBLE; - } - - @Override - public float getPriority() { - return -1f; - } - }); } @Override diff --git a/src/main/java/me/shedaniel/rei/plugin/DefaultPotionEffectExclusionZones.java b/src/main/java/me/shedaniel/rei/plugin/DefaultPotionEffectExclusionZones.java index 29b150e72..3ef514ea3 100644 --- a/src/main/java/me/shedaniel/rei/plugin/DefaultPotionEffectExclusionZones.java +++ b/src/main/java/me/shedaniel/rei/plugin/DefaultPotionEffectExclusionZones.java @@ -6,7 +6,6 @@ package me.shedaniel.rei.plugin; import com.google.common.collect.Ordering; -import me.shedaniel.rei.api.BaseBoundsHandler; import me.shedaniel.rei.client.ScreenHelper; import me.shedaniel.rei.listeners.AbstractInventoryScreenHooks; import me.shedaniel.rei.listeners.ContainerScreenHooks; @@ -19,10 +18,11 @@ import java.util.ArrayList; import java.util.Collection; import java.util.Collections; import java.util.List; +import java.util.function.Function; -public class DefaultPotionEffectExclusionZones implements BaseBoundsHandler.ExclusionZoneSupplier { +public class DefaultPotionEffectExclusionZones implements Function> { @Override - public List apply(boolean isOnRightSide) { + public List apply(Boolean isOnRightSide) { if (isOnRightSide || !(ScreenHelper.getLastContainerScreen() instanceof AbstractInventoryScreen) || !((AbstractInventoryScreenHooks) ScreenHelper.getLastContainerScreen()).rei_doesOffsetGuiForEffects()) return Collections.emptyList(); Collection activePotionEffects = MinecraftClient.getInstance().player.getStatusEffects(); diff --git a/src/main/java/me/shedaniel/rei/plugin/DefaultRecipeBookExclusionZones.java b/src/main/java/me/shedaniel/rei/plugin/DefaultRecipeBookExclusionZones.java index 35da5ef24..2e1a8e72d 100644 --- a/src/main/java/me/shedaniel/rei/plugin/DefaultRecipeBookExclusionZones.java +++ b/src/main/java/me/shedaniel/rei/plugin/DefaultRecipeBookExclusionZones.java @@ -17,16 +17,17 @@ import net.minecraft.container.CraftingContainer; import java.awt.*; import java.util.Collections; import java.util.List; +import java.util.function.Function; -public class DefaultRecipeBookExclusionZones implements BaseBoundsHandler.ExclusionZoneSupplier { +public class DefaultRecipeBookExclusionZones implements Function> { @Override - public List apply(boolean isOnRightSide) { + public List apply(Boolean isOnRightSide) { if (isOnRightSide || !MinecraftClient.getInstance().player.getRecipeBook().isGuiOpen() || !(MinecraftClient.getInstance().currentScreen instanceof RecipeBookProvider) || !(ScreenHelper.getLastContainerScreen().getContainer() instanceof CraftingContainer)) return Collections.emptyList(); ContainerScreenHooks screenHooks = ScreenHelper.getLastContainerScreenHooks(); List l = Lists.newArrayList(new Rectangle(screenHooks.rei_getContainerLeft() - 4 - 145, screenHooks.rei_getContainerTop(), 4 + 145 + 30, screenHooks.rei_getContainerHeight())); - int size = ClientRecipeBook.getGroupsForContainer((CraftingContainer) ScreenHelper.getLastContainerScreen().getContainer()).size(); + int size = ClientRecipeBook.getGroupsForContainer((CraftingContainer) ScreenHelper.getLastContainerScreen().getContainer()).size(); if (size > 0) l.add(new Rectangle(screenHooks.rei_getContainerLeft() - 4 - 145 - 30, screenHooks.rei_getContainerTop(), 30, size * 27)); return l; diff --git a/src/main/java/me/shedaniel/rei/plugin/blasting/DefaultBlastingCategory.java b/src/main/java/me/shedaniel/rei/plugin/blasting/DefaultBlastingCategory.java index 6afa52724..0a975151f 100644 --- a/src/main/java/me/shedaniel/rei/plugin/blasting/DefaultBlastingCategory.java +++ b/src/main/java/me/shedaniel/rei/plugin/blasting/DefaultBlastingCategory.java @@ -7,7 +7,6 @@ package me.shedaniel.rei.plugin.blasting; import com.mojang.blaze3d.platform.GlStateManager; 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; @@ -39,7 +38,7 @@ public class DefaultBlastingCategory implements RecipeCategory Arrays.asList(recipe.getInput().get(0)), recipe::getOutput); + return Renderer.fromRecipe(() -> Arrays.asList(recipe.getInput().get(0)), recipe::getOutput); } @Override diff --git a/src/main/java/me/shedaniel/rei/plugin/brewing/DefaultBrewingCategory.java b/src/main/java/me/shedaniel/rei/plugin/brewing/DefaultBrewingCategory.java index 3d863b706..9d77ff2b0 100644 --- a/src/main/java/me/shedaniel/rei/plugin/brewing/DefaultBrewingCategory.java +++ b/src/main/java/me/shedaniel/rei/plugin/brewing/DefaultBrewingCategory.java @@ -7,7 +7,6 @@ package me.shedaniel.rei.plugin.brewing; import com.mojang.blaze3d.platform.GlStateManager; import me.shedaniel.rei.api.RecipeCategory; -import me.shedaniel.rei.api.Renderable; import me.shedaniel.rei.api.Renderer; import me.shedaniel.rei.gui.widget.RecipeBaseWidget; import me.shedaniel.rei.gui.widget.SlotWidget; @@ -39,7 +38,7 @@ public class DefaultBrewingCategory implements RecipeCategory getDisplaySettings() { - return new DisplaySettings() { - @Override - public int getDisplayHeight(RecipeCategory recipeCategory) { - return 140; - } - - @Override - public int getDisplayWidth(RecipeCategory recipeCategory, DefaultCompostingDisplay display) { - return 150; - } - - @Override - public int getMaximumRecipePerPage(RecipeCategory recipeCategory) { - return -1; - } - - @Override - public int getFixedRecipesPerPage() { - return 1; - } - }; + public int getDisplayHeight() { + return 140; } + @Override + public int getFixedRecipesPerPage() { + return 1; + } } \ No newline at end of file diff --git a/src/main/java/me/shedaniel/rei/plugin/crafting/DefaultCraftingCategory.java b/src/main/java/me/shedaniel/rei/plugin/crafting/DefaultCraftingCategory.java index 1b608436a..f63faf35e 100644 --- a/src/main/java/me/shedaniel/rei/plugin/crafting/DefaultCraftingCategory.java +++ b/src/main/java/me/shedaniel/rei/plugin/crafting/DefaultCraftingCategory.java @@ -8,7 +8,6 @@ package me.shedaniel.rei.plugin.crafting; import com.google.common.collect.Lists; import com.mojang.blaze3d.platform.GlStateManager; import me.shedaniel.rei.api.RecipeCategory; -import me.shedaniel.rei.api.Renderable; import me.shedaniel.rei.api.Renderer; import me.shedaniel.rei.gui.widget.RecipeBaseWidget; import me.shedaniel.rei.gui.widget.SlotWidget; @@ -37,7 +36,7 @@ public class DefaultCraftingCategory implements RecipeCategory Arrays.asList(recipe.getInput().get(0)), recipe::getOutput); + return Renderer.fromRecipe(() -> Arrays.asList(recipe.getInput().get(0)), recipe::getOutput); } @Override diff --git a/src/main/java/me/shedaniel/rei/plugin/smoking/DefaultSmokingCategory.java b/src/main/java/me/shedaniel/rei/plugin/smoking/DefaultSmokingCategory.java index 3d654e3c8..9edba769d 100644 --- a/src/main/java/me/shedaniel/rei/plugin/smoking/DefaultSmokingCategory.java +++ b/src/main/java/me/shedaniel/rei/plugin/smoking/DefaultSmokingCategory.java @@ -7,7 +7,6 @@ package me.shedaniel.rei.plugin.smoking; import com.mojang.blaze3d.platform.GlStateManager; 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; @@ -39,7 +38,7 @@ public class DefaultSmokingCategory implements RecipeCategory Arrays.asList(recipe.getInput().get(0)), recipe::getOutput); + return Renderer.fromRecipe(() -> Arrays.asList(recipe.getInput().get(0)), recipe::getOutput); } @Override 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 c38ceb3b8..d148e420e 100644 --- a/src/main/java/me/shedaniel/rei/plugin/stonecutting/DefaultStoneCuttingCategory.java +++ b/src/main/java/me/shedaniel/rei/plugin/stonecutting/DefaultStoneCuttingCategory.java @@ -6,9 +6,7 @@ package me.shedaniel.rei.plugin.stonecutting; import com.mojang.blaze3d.platform.GlStateManager; -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.widget.RecipeBaseWidget; import me.shedaniel.rei.gui.widget.SlotWidget; @@ -36,7 +34,7 @@ public class DefaultStoneCuttingCategory implements RecipeCategory getDisplaySettings() { - return new DisplaySettings() { - @Override - public int getDisplayHeight(RecipeCategory category) { - return 36; - } - - @Override - public int getDisplayWidth(RecipeCategory category, DefaultStoneCuttingDisplay display) { - return 150; - } - - @Override - public int getMaximumRecipePerPage(RecipeCategory category) { - return 99; - } - }; + public int getDisplayHeight() { + return 36; } } -- cgit