diff options
Diffstat (limited to 'shared-internals/src/main/java')
14 files changed, 891 insertions, 0 deletions
diff --git a/shared-internals/src/main/java/me/shedaniel/rei/impl/client/config/ConfigManagerInternal.java b/shared-internals/src/main/java/me/shedaniel/rei/impl/client/config/ConfigManagerInternal.java new file mode 100644 index 000000000..7a60c7692 --- /dev/null +++ b/shared-internals/src/main/java/me/shedaniel/rei/impl/client/config/ConfigManagerInternal.java @@ -0,0 +1,57 @@ +/* + * This file is licensed under the MIT License, part of Roughly Enough Items. + * Copyright (c) 2018, 2019, 2020, 2021, 2022 shedaniel + * + * Permission is hereby granted, free of charge, to any person obtaining a copy + * of this software and associated documentation files (the "Software"), to deal + * in the Software without restriction, including without limitation the rights + * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell + * copies of the Software, and to permit persons to whom the Software is + * furnished to do so, subject to the following conditions: + * + * The above copyright notice and this permission notice shall be included in all + * copies or substantial portions of the Software. + * + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR + * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, + * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE + * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER + * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, + * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE + * SOFTWARE. + */ + +package me.shedaniel.rei.impl.client.config; + +import me.shedaniel.autoconfig.gui.registry.GuiRegistry; +import me.shedaniel.cloth.clothconfig.shadowed.blue.endless.jankson.Jankson; +import me.shedaniel.clothconfig2.api.AbstractConfigListEntry; +import me.shedaniel.rei.api.client.config.ConfigManager; +import org.jetbrains.annotations.ApiStatus; + +import java.util.Collection; +import java.util.Collections; + +@ApiStatus.Internal +public interface ConfigManagerInternal extends ConfigManager { + /** + * @return the instance of {@link ConfigManagerInternal} + */ + static ConfigManagerInternal getInstance() { + return (ConfigManagerInternal) ConfigManager.getInstance(); + } + + Object get(String fieldKey); + + boolean set(String fieldKey, Object value); + + interface SystemSetup { + default void setup(Jankson.Builder builder) {} + + default void setup(GuiRegistry registry) {} + + default Collection<? extends AbstractConfigListEntry<?>> collectAdvanced() { + return Collections.emptyList(); + } + } +} diff --git a/shared-internals/src/main/java/me/shedaniel/rei/impl/client/favorites/MutableFavoritesList.java b/shared-internals/src/main/java/me/shedaniel/rei/impl/client/favorites/MutableFavoritesList.java new file mode 100644 index 000000000..27ac4c940 --- /dev/null +++ b/shared-internals/src/main/java/me/shedaniel/rei/impl/client/favorites/MutableFavoritesList.java @@ -0,0 +1,32 @@ +/* + * This file is licensed under the MIT License, part of Roughly Enough Items. + * Copyright (c) 2018, 2019, 2020, 2021, 2022 shedaniel + * + * Permission is hereby granted, free of charge, to any person obtaining a copy + * of this software and associated documentation files (the "Software"), to deal + * in the Software without restriction, including without limitation the rights + * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell + * copies of the Software, and to permit persons to whom the Software is + * furnished to do so, subject to the following conditions: + * + * The above copyright notice and this permission notice shall be included in all + * copies or substantial portions of the Software. + * + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR + * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, + * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE + * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER + * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, + * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE + * SOFTWARE. + */ + +package me.shedaniel.rei.impl.client.favorites; + +import me.shedaniel.rei.api.client.favorites.FavoriteEntry; + +import java.util.List; + +public interface MutableFavoritesList extends List<FavoriteEntry> { + void setAll(List<FavoriteEntry> entries); +} diff --git a/shared-internals/src/main/java/me/shedaniel/rei/impl/client/gui/InternalCursorState.java b/shared-internals/src/main/java/me/shedaniel/rei/impl/client/gui/InternalCursorState.java new file mode 100644 index 000000000..5319924f7 --- /dev/null +++ b/shared-internals/src/main/java/me/shedaniel/rei/impl/client/gui/InternalCursorState.java @@ -0,0 +1,32 @@ +/* + * This file is licensed under the MIT License, part of Roughly Enough Items. + * Copyright (c) 2018, 2019, 2020, 2021, 2022 shedaniel + * + * Permission is hereby granted, free of charge, to any person obtaining a copy + * of this software and associated documentation files (the "Software"), to deal + * in the Software without restriction, including without limitation the rights + * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell + * copies of the Software, and to permit persons to whom the Software is + * furnished to do so, subject to the following conditions: + * + * The above copyright notice and this permission notice shall be included in all + * copies or substantial portions of the Software. + * + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR + * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, + * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE + * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER + * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, + * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE + * SOFTWARE. + */ + +package me.shedaniel.rei.impl.client.gui; + +import org.jetbrains.annotations.ApiStatus; + +@ApiStatus.Internal +public class InternalCursorState { + public static boolean isLeftMousePressed; + public static boolean isRightMousePressed; +} diff --git a/shared-internals/src/main/java/me/shedaniel/rei/impl/client/gui/InternalTextures.java b/shared-internals/src/main/java/me/shedaniel/rei/impl/client/gui/InternalTextures.java new file mode 100644 index 000000000..4ab5c6961 --- /dev/null +++ b/shared-internals/src/main/java/me/shedaniel/rei/impl/client/gui/InternalTextures.java @@ -0,0 +1,38 @@ +/* + * This file is licensed under the MIT License, part of Roughly Enough Items. + * Copyright (c) 2018, 2019, 2020, 2021, 2022 shedaniel + * + * Permission is hereby granted, free of charge, to any person obtaining a copy + * of this software and associated documentation files (the "Software"), to deal + * in the Software without restriction, including without limitation the rights + * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell + * copies of the Software, and to permit persons to whom the Software is + * furnished to do so, subject to the following conditions: + * + * The above copyright notice and this permission notice shall be included in all + * copies or substantial portions of the Software. + * + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR + * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, + * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE + * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER + * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, + * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE + * SOFTWARE. + */ + +package me.shedaniel.rei.impl.client.gui; + +import net.minecraft.resources.ResourceLocation; + +public class InternalTextures { + public static final ResourceLocation ARROW_LEFT_TEXTURE = new ResourceLocation("roughlyenoughitems", "textures/gui/arrow_left.png"); + public static final ResourceLocation ARROW_RIGHT_TEXTURE = new ResourceLocation("roughlyenoughitems", "textures/gui/arrow_right.png"); + public static final ResourceLocation ARROW_LEFT_SMALL_TEXTURE = new ResourceLocation("roughlyenoughitems", "textures/gui/arrow_left_small.png"); + public static final ResourceLocation ARROW_RIGHT_SMALL_TEXTURE = new ResourceLocation("roughlyenoughitems", "textures/gui/arrow_right_small.png"); + public static final ResourceLocation CHEST_GUI_TEXTURE = new ResourceLocation("roughlyenoughitems", "textures/gui/recipecontainer.png"); + public static final ResourceLocation CHEST_GUI_TEXTURE_DARK = new ResourceLocation("roughlyenoughitems", "textures/gui/recipecontainer_dark.png"); + public static final ResourceLocation DISPLAY_TEXTURE = new ResourceLocation("roughlyenoughitems", "textures/gui/display.png"); + public static final ResourceLocation DISPLAY_TEXTURE_DARK = new ResourceLocation("roughlyenoughitems", "textures/gui/display_dark.png"); + public static final ResourceLocation TOASTS = new ResourceLocation("roughlyenoughitems", "textures/gui/toasts.png"); +} diff --git a/shared-internals/src/main/java/me/shedaniel/rei/impl/client/gui/hints/HintProvider.java b/shared-internals/src/main/java/me/shedaniel/rei/impl/client/gui/hints/HintProvider.java new file mode 100644 index 000000000..475e48f44 --- /dev/null +++ b/shared-internals/src/main/java/me/shedaniel/rei/impl/client/gui/hints/HintProvider.java @@ -0,0 +1,59 @@ +/* + * This file is licensed under the MIT License, part of Roughly Enough Items. + * Copyright (c) 2018, 2019, 2020, 2021, 2022 shedaniel + * + * Permission is hereby granted, free of charge, to any person obtaining a copy + * of this software and associated documentation files (the "Software"), to deal + * in the Software without restriction, including without limitation the rights + * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell + * copies of the Software, and to permit persons to whom the Software is + * furnished to do so, subject to the following conditions: + * + * The above copyright notice and this permission notice shall be included in all + * copies or substantial portions of the Software. + * + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR + * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, + * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE + * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER + * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, + * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE + * SOFTWARE. + */ + +package me.shedaniel.rei.impl.client.gui.hints; + +import me.shedaniel.math.Color; +import me.shedaniel.math.Point; +import me.shedaniel.math.Rectangle; +import me.shedaniel.rei.api.client.gui.widgets.Tooltip; +import me.shedaniel.rei.impl.client.gui.menu.MenuAccess; +import me.shedaniel.rei.impl.common.Internals; +import net.fabricmc.api.EnvType; +import net.fabricmc.api.Environment; +import net.minecraft.network.chat.Component; +import org.jetbrains.annotations.Nullable; + +import java.util.List; +import java.util.function.Consumer; + +@Environment(EnvType.CLIENT) +public interface HintProvider { + List<HintProvider> PROVIDERS = Internals.resolveServices(HintProvider.class); + + List<Component> provide(); + + @Nullable + Tooltip provideTooltip(Point mouse); + + @Nullable + default Double getProgress() { + return null; + } + + Color getColor(); + + List<HintButton> getButtons(MenuAccess access); + + record HintButton(Component name, Consumer<Rectangle> action) {} +} diff --git a/shared-internals/src/main/java/me/shedaniel/rei/impl/client/gui/menu/MenuAccess.java b/shared-internals/src/main/java/me/shedaniel/rei/impl/client/gui/menu/MenuAccess.java new file mode 100644 index 000000000..79daeb3f0 --- /dev/null +++ b/shared-internals/src/main/java/me/shedaniel/rei/impl/client/gui/menu/MenuAccess.java @@ -0,0 +1,51 @@ +/* + * This file is licensed under the MIT License, part of Roughly Enough Items. + * Copyright (c) 2018, 2019, 2020, 2021, 2022 shedaniel + * + * Permission is hereby granted, free of charge, to any person obtaining a copy + * of this software and associated documentation files (the "Software"), to deal + * in the Software without restriction, including without limitation the rights + * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell + * copies of the Software, and to permit persons to whom the Software is + * furnished to do so, subject to the following conditions: + * + * The above copyright notice and this permission notice shall be included in all + * copies or substantial portions of the Software. + * + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR + * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, + * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE + * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER + * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, + * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE + * SOFTWARE. + */ + +package me.shedaniel.rei.impl.client.gui.menu; + +import me.shedaniel.math.Point; +import me.shedaniel.math.Rectangle; +import me.shedaniel.rei.api.client.favorites.FavoriteMenuEntry; + +import java.util.Collection; +import java.util.UUID; +import java.util.function.Predicate; +import java.util.function.Supplier; + +public interface MenuAccess { + boolean isOpened(UUID uuid); + + boolean isAnyOpened(); + + boolean isInBounds(UUID uuid); + + void open(UUID uuid, Rectangle selfBounds, Supplier<Collection<FavoriteMenuEntry>> menuSupplier); + + void open(UUID uuid, Rectangle selfBounds, Supplier<Collection<FavoriteMenuEntry>> menuSupplier, Predicate<Point> or, Predicate<Point> and); + + void openOrClose(UUID uuid, Rectangle selfBounds, Supplier<Collection<FavoriteMenuEntry>> menuSupplier); + + boolean isValidPoint(Point point); + + void close(); +} diff --git a/shared-internals/src/main/java/me/shedaniel/rei/impl/client/gui/screen/ConfigReloadingScreen.java b/shared-internals/src/main/java/me/shedaniel/rei/impl/client/gui/screen/ConfigReloadingScreen.java new file mode 100644 index 000000000..7d64bc935 --- /dev/null +++ b/shared-internals/src/main/java/me/shedaniel/rei/impl/client/gui/screen/ConfigReloadingScreen.java @@ -0,0 +1,77 @@ +/* + * This file is licensed under the MIT License, part of Roughly Enough Items. + * Copyright (c) 2018, 2019, 2020, 2021, 2022 shedaniel + * + * Permission is hereby granted, free of charge, to any person obtaining a copy + * of this software and associated documentation files (the "Software"), to deal + * in the Software without restriction, including without limitation the rights + * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell + * copies of the Software, and to permit persons to whom the Software is + * furnished to do so, subject to the following conditions: + * + * The above copyright notice and this permission notice shall be included in all + * copies or substantial portions of the Software. + * + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR + * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, + * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE + * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER + * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, + * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE + * SOFTWARE. + */ + +package me.shedaniel.rei.impl.client.gui.screen; + +import com.mojang.blaze3d.vertex.PoseStack; +import net.minecraft.Util; +import net.minecraft.client.gui.chat.NarratorChatListener; +import net.minecraft.client.gui.screens.Screen; +import net.minecraft.network.chat.Component; +import org.jetbrains.annotations.ApiStatus; + +import java.util.function.BooleanSupplier; + +@ApiStatus.Internal +public final class ConfigReloadingScreen extends Screen { + private final Component title; + private final BooleanSupplier predicate; + private final Runnable parent; + + public ConfigReloadingScreen(Component title, BooleanSupplier predicate, Runnable parent) { + super(NarratorChatListener.NO_TITLE); + this.title = title; + this.predicate = predicate; + this.parent = parent; + } + + @Override + public boolean shouldCloseOnEsc() { + return false; + } + + @Override + public void render(PoseStack matrices, int mouseX, int mouseY, float delta) { + this.renderDirtBackground(0); + if (!predicate.getAsBoolean()) { + parent.run(); + return; + } + drawCenteredString(matrices, this.font, title, this.width / 2, this.height / 2 - 50, 16777215); + String text; + switch ((int) (Util.getMillis() / 300L % 4L)) { + case 0: + default: + text = "O o o"; + break; + case 1: + case 3: + text = "o O o"; + break; + case 2: + text = "o o O"; + } + drawCenteredString(matrices, this.font, text, this.width / 2, this.height / 2 - 41, 8421504); + super.render(matrices, mouseX, mouseY, delta); + } +} diff --git a/shared-internals/src/main/java/me/shedaniel/rei/impl/client/search/AsyncSearchManager.java b/shared-internals/src/main/java/me/shedaniel/rei/impl/client/search/AsyncSearchManager.java new file mode 100644 index 000000000..0fb426a34 --- /dev/null +++ b/shared-internals/src/main/java/me/shedaniel/rei/impl/client/search/AsyncSearchManager.java @@ -0,0 +1,162 @@ +/* + * This file is licensed under the MIT License, part of Roughly Enough Items. + * Copyright (c) 2018, 2019, 2020, 2021, 2022 shedaniel + * + * Permission is hereby granted, free of charge, to any person obtaining a copy + * of this software and associated documentation files (the "Software"), to deal + * in the Software without restriction, including without limitation the rights + * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell + * copies of the Software, and to permit persons to whom the Software is + * furnished to do so, subject to the following conditions: + * + * The above copyright notice and this permission notice shall be included in all + * copies or substantial portions of the Software. + * + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR + * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, + * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE + * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER + * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, + * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE + * SOFTWARE. + */ + +package me.shedaniel.rei.impl.client.search; + +import com.google.common.collect.Lists; +import me.shedaniel.rei.api.client.config.ConfigObject; +import me.shedaniel.rei.api.client.search.SearchFilter; +import me.shedaniel.rei.api.client.search.SearchProvider; +import me.shedaniel.rei.api.common.entry.EntryStack; +import me.shedaniel.rei.api.common.util.CollectionUtils; +import org.jetbrains.annotations.Nullable; + +import java.util.ArrayList; +import java.util.List; +import java.util.concurrent.*; +import java.util.function.Consumer; +import java.util.function.Predicate; +import java.util.function.Supplier; +import java.util.function.UnaryOperator; + +public class AsyncSearchManager implements SearchManager { + private final Supplier<List<EntryStack<?>>> stacksProvider; + private final Supplier<Predicate<EntryStack<?>>> additionalPredicateSupplier; + private final UnaryOperator<EntryStack<?>> transformer; + private Predicate<EntryStack<?>> additionalPredicate; + private SearchFilter filter; + private boolean dirty = false; + private boolean filterDirty = false; + private CompletableFuture<List<EntryStack<?>>> future; + private List<EntryStack<?>> last; + + public AsyncSearchManager(Supplier<List<EntryStack<?>>> stacksProvider, Supplier<Predicate<EntryStack<?>>> additionalPredicateSupplier, UnaryOperator<EntryStack<?>> transformer) { + this.stacksProvider = stacksProvider; + this.additionalPredicateSupplier = additionalPredicateSupplier; + this.transformer = transformer; + } + + @Override + public void markDirty() { + this.dirty = true; + } + + @Override + public void markFilterDirty() { + this.filterDirty = true; + } + + @Override + public void updateFilter(String filter) { + if (this.filter == null || !this.filter.getFilter().equals(filter)) { + this.filter = SearchProvider.getInstance().createFilter(filter); + markDirty(); + markFilterDirty(); + } + } + + @Override + public boolean isDirty() { + return last == null || dirty; + } + + @Override + public boolean isFilterDirty() { + return filterDirty; + } + + @Override + public Future<Void> getAsync(Consumer<List<EntryStack<?>>> consumer) { + if (future == null || future.isCancelled() || future.isDone() || future.isCompletedExceptionally()) { + if (future != null) future.cancel(true); + future = CompletableFuture.supplyAsync(this) + .exceptionally(throwable -> { + throwable.printStackTrace(); + return null; + }); + } + return future.thenAccept(consumer); + } + + @Override + public List<EntryStack<?>> get() { + if (isDirty()) { + this.additionalPredicate = additionalPredicateSupplier.get(); + int searchPartitionSize = ConfigObject.getInstance().getAsyncSearchPartitionSize(); + List<EntryStack<?>> stacks = stacksProvider.get(); + last = new ArrayList<>(); + + if (!stacks.isEmpty()) { + if (filterDirty) { + filter.prepareFilter(stacks); + filterDirty = false; + } + + if (ConfigObject.getInstance().shouldAsyncSearch() && stacks.size() > searchPartitionSize * 4) { + List<CompletableFuture<List<EntryStack<?>>>> futures = Lists.newArrayList(); + for (Iterable<EntryStack<?>> partitionStacks : CollectionUtils.partition(stacks, searchPartitionSize)) { + futures.add(CompletableFuture.supplyAsync(() -> { + List<EntryStack<?>> filtered = Lists.newArrayList(); + for (EntryStack<?> stack : partitionStacks) { + if (stack != null && matches(stack) && additionalPredicate.test(stack)) { + filtered.add(transformer.apply(stack)); + } + } + return filtered; + })); + } + try { + CompletableFuture.allOf(futures.toArray(new CompletableFuture[0])).get(30, TimeUnit.SECONDS); + } catch (InterruptedException | ExecutionException | TimeoutException e) { + e.printStackTrace(); + } + for (CompletableFuture<List<EntryStack<?>>> future : futures) { + List<EntryStack<?>> now = future.getNow(null); + if (now != null) last.addAll(now); + } + } else { + for (EntryStack<?> stack : stacks) { + if (matches(stack) && additionalPredicate.test(stack)) { + last.add(transformer.apply(stack)); + } + } + } + } + + dirty = false; + } + + return last; + } + + @Override + public boolean matches(EntryStack<?> stack) { + return filter.test(stack); + } + + @Override + @Nullable + public SearchFilter getSearchFilter() { + return filter; + } +} diff --git a/shared-internals/src/main/java/me/shedaniel/rei/impl/client/search/SearchManager.java b/shared-internals/src/main/java/me/shedaniel/rei/impl/client/search/SearchManager.java new file mode 100644 index 000000000..cdbc75925 --- /dev/null +++ b/shared-internals/src/main/java/me/shedaniel/rei/impl/client/search/SearchManager.java @@ -0,0 +1,52 @@ +/* + * This file is licensed under the MIT License, part of Roughly Enough Items. + * Copyright (c) 2018, 2019, 2020, 2021, 2022 shedaniel + * + * Permission is hereby granted, free of charge, to any person obtaining a copy + * of this software and associated documentation files (the "Software"), to deal + * in the Software without restriction, including without limitation the rights + * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell + * copies of the Software, and to permit persons to whom the Software is + * furnished to do so, subject to the following conditions: + * + * The above copyright notice and this permission notice shall be included in all + * copies or substantial portions of the Software. + * + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR + * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, + * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE + * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER + * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, + * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE + * SOFTWARE. + */ + +package me.shedaniel.rei.impl.client.search; + +import me.shedaniel.rei.api.client.search.SearchFilter; +import me.shedaniel.rei.api.common.entry.EntryStack; +import org.jetbrains.annotations.Nullable; + +import java.util.List; +import java.util.concurrent.Future; +import java.util.function.Consumer; +import java.util.function.Supplier; + +public interface SearchManager extends Supplier<List<EntryStack<?>>> { + void markDirty(); + + void markFilterDirty(); + + void updateFilter(String filter); + + boolean isDirty(); + + boolean isFilterDirty(); + + Future<Void> getAsync(Consumer<List<EntryStack<?>>> consumer); + + boolean matches(EntryStack<?> stack); + + @Nullable + SearchFilter getSearchFilter(); +} diff --git a/shared-internals/src/main/java/me/shedaniel/rei/impl/client/util/CrashReportUtils.java b/shared-internals/src/main/java/me/shedaniel/rei/impl/client/util/CrashReportUtils.java new file mode 100644 index 000000000..96c4fd177 --- /dev/null +++ b/shared-internals/src/main/java/me/shedaniel/rei/impl/client/util/CrashReportUtils.java @@ -0,0 +1,74 @@ +/* + * This file is licensed under the MIT License, part of Roughly Enough Items. + * Copyright (c) 2018, 2019, 2020, 2021, 2022 shedaniel + * + * Permission is hereby granted, free of charge, to any person obtaining a copy + * of this software and associated documentation files (the "Software"), to deal + * in the Software without restriction, including without limitation the rights + * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell + * copies of the Software, and to permit persons to whom the Software is + * furnished to do so, subject to the following conditions: + * + * The above copyright notice and this permission notice shall be included in all + * copies or substantial portions of the Software. + * + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR + * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, + * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE + * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER + * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, + * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE + * SOFTWARE. + */ + +package me.shedaniel.rei.impl.client.util; + +import me.shedaniel.rei.api.client.gui.Renderer; +import me.shedaniel.rei.impl.client.ClientInternals; +import net.minecraft.CrashReport; +import net.minecraft.CrashReportCategory; +import net.minecraft.ReportedException; +import net.minecraft.client.Minecraft; +import net.minecraft.client.gui.screens.Screen; + +public class CrashReportUtils { + public static CrashReport essential(Throwable throwable, String task) { + Throwable temp = throwable; + while (temp != null) { + temp = temp.getCause(); + if (temp instanceof ReportedException) { + return essential(temp, task); + } + } + CrashReport report = CrashReport.forThrowable(throwable, task); + screen(report, Minecraft.getInstance().screen); + return report; + } + + private static void screen(CrashReport report, Screen screen) { + if (screen != null) { + CrashReportCategory category = report.addCategory("Screen details"); + String screenName = screen.getClass().getCanonicalName(); + category.setDetail("Screen name", () -> screenName); + } + } + + public static void renderer(CrashReport report, Renderer renderer) { + if (renderer != null) { + CrashReportCategory category = report.addCategory("Renderer details"); + try { + renderer.fillCrashReport(report, category); + } catch (Throwable throwable) { + category.setDetailError("Filling Report", throwable); + } + } + } + + public static ReportedException throwReport(CrashReport report) { + return new ReportedException(report); + } + + public static void catchReport(CrashReport report) { + ClientInternals.crash(new ReportedException(report), report.getTitle()); + } +} diff --git a/shared-internals/src/main/java/me/shedaniel/rei/impl/client/util/InternalEntryBounds.java b/shared-internals/src/main/java/me/shedaniel/rei/impl/client/util/InternalEntryBounds.java new file mode 100644 index 000000000..ca5d88e28 --- /dev/null +++ b/shared-internals/src/main/java/me/shedaniel/rei/impl/client/util/InternalEntryBounds.java @@ -0,0 +1,35 @@ +/* + * This file is licensed under the MIT License, part of Roughly Enough Items. + * Copyright (c) 2018, 2019, 2020, 2021, 2022 |
