diff options
| author | Unknown <shekwancheung0528@gmail.com> | 2019-06-18 16:38:49 +0800 |
|---|---|---|
| committer | Unknown <shekwancheung0528@gmail.com> | 2019-06-18 16:38:49 +0800 |
| commit | 4d0b2d3f50bf56b83498a3b787ac08afaeb85eff (patch) | |
| tree | 77c206a271fb6f5b6ae1dbe3d24d794420cf1841 /src/main/java/me | |
| parent | 69a531030df74768d86025cd5668e0418a3c1f07 (diff) | |
| download | RoughlyEnoughItems-4d0b2d3f50bf56b83498a3b787ac08afaeb85eff.tar.gz RoughlyEnoughItems-4d0b2d3f50bf56b83498a3b787ac08afaeb85eff.tar.bz2 RoughlyEnoughItems-4d0b2d3f50bf56b83498a3b787ac08afaeb85eff.zip | |
up to 4x faster search
Diffstat (limited to 'src/main/java/me')
41 files changed, 274 insertions, 183 deletions
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<T extends RecipeDisplay> { * @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<T extends RecipeDisplay> { * @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/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/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<T extends RecipeDisplay> { * * @return the display settings */ - default DisplaySettings getDisplaySettings() { + default DisplaySettings<T> getDisplaySettings() { return new DisplaySettings<T>() { @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<T extends Recipe> { +public interface RecipeDisplay { /** * @return a list of items @@ -50,11 +50,4 @@ public interface RecipeDisplay<T extends Recipe> { return Optional.empty(); } - /** - * @return the optional recipe - * @deprecated stop - */ - @Deprecated - default Optional<? extends Recipe> 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<AutoCraftingHandler> 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); <T extends Recipe<?>> void registerRecipes(Identifier category, Class<T> recipeClass, Function<T, RecipeDisplay> 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<ItemStack> supplier) { + public static ItemStackRenderer fromItemStackSupplier(Supplier<ItemStack> 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<List<List<ItemStack>>> input, Supplier<List<ItemStack>> output) { + public static SimpleRecipeRenderer fromRecipe(Supplier<List<List<ItemStack>>> input, Supplier<List<ItemStack>> output) { return new SimpleRecipeRenderer(input, output); } - static ItemStackRenderer fromItemStacks(List<ItemStack> stacks) { + public static ItemStackRenderer fromItemStacks(List<ItemStack> 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/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<RecipeFunction> recipeFunctions = Lists.newArrayList(); + private final List<AutoCraftingHandler> autoCraftingHandlers = Lists.newArrayList(); + private final List<RecipeFunction> recipeFunctions = Lists.newArrayList(); private final AtomicInteger recipeCount = new AtomicInteger(); private final Map<Identifier, List<RecipeDisplay>> recipeCategoryListMap = Maps.newHashMap(); private final Map<Identifier, DisplaySettings> categoryDisplaySettingsMap = Maps.newHashMap(); @@ -45,7 +51,7 @@ public class RecipeHelperImpl implements RecipeHelper { private final Map<Identifier, ButtonAreaSupplier> speedCraftAreaSupplierMap = Maps.newHashMap(); private final Map<Identifier, List<List<ItemStack>>> categoryWorkingStations = Maps.newHashMap(); private final List<DisplayVisibilityHandler> displayVisibilityHandlers = Lists.newArrayList(); - private final List<LiveRecipeGenerator> liveRecipeGenerators = Lists.newArrayList(); + private final List<LiveRecipeGenerator<?>> 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,11 +280,42 @@ 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<AutoCraftingHandler> 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/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; } + pu |
