diff options
| author | shedaniel <daniel@shedaniel.me> | 2021-11-14 02:36:33 +0800 |
|---|---|---|
| committer | shedaniel <daniel@shedaniel.me> | 2021-11-14 02:36:33 +0800 |
| commit | 760f20e8bdf63ee4af47bb408cdac18e6dd7a591 (patch) | |
| tree | c82c23af4b13334723345612dc65f225f81cf5c3 /api/src/main/java/me | |
| parent | 5b99b04e23728c32387183df3719b1f696e994fe (diff) | |
| parent | 57f59e7da8ae83f1ad952e410601409eecf2e1c4 (diff) | |
| download | RoughlyEnoughItems-760f20e8bdf63ee4af47bb408cdac18e6dd7a591.tar.gz RoughlyEnoughItems-760f20e8bdf63ee4af47bb408cdac18e6dd7a591.tar.bz2 RoughlyEnoughItems-760f20e8bdf63ee4af47bb408cdac18e6dd7a591.zip | |
Merge remote-tracking branch 'origin/6.x-1.17' into 7.x-1.18
# Conflicts:
# gradle.properties
Diffstat (limited to 'api/src/main/java/me')
31 files changed, 3008 insertions, 25 deletions
diff --git a/api/src/main/java/me/shedaniel/rei/api/client/REIRuntime.java b/api/src/main/java/me/shedaniel/rei/api/client/REIRuntime.java index 354c1ce19..1af65d4ad 100644 --- a/api/src/main/java/me/shedaniel/rei/api/client/REIRuntime.java +++ b/api/src/main/java/me/shedaniel/rei/api/client/REIRuntime.java @@ -24,18 +24,22 @@ package me.shedaniel.rei.api.client; import me.shedaniel.math.Rectangle; +import me.shedaniel.rei.api.client.config.ConfigObject; import me.shedaniel.rei.api.client.gui.config.SearchFieldLocation; import me.shedaniel.rei.api.client.gui.widgets.TextField; import me.shedaniel.rei.api.client.gui.widgets.Tooltip; import me.shedaniel.rei.api.client.overlay.ScreenOverlay; import me.shedaniel.rei.api.client.plugins.REIClientPlugin; +import me.shedaniel.rei.api.client.registry.screen.ScreenRegistry; import me.shedaniel.rei.api.common.plugins.PluginManager; import me.shedaniel.rei.api.common.registry.Reloadable; import net.fabricmc.api.EnvType; import net.fabricmc.api.Environment; +import net.minecraft.client.Minecraft; import net.minecraft.client.gui.screens.Screen; import net.minecraft.client.gui.screens.inventory.AbstractContainerScreen; import net.minecraft.resources.ResourceLocation; +import org.jetbrains.annotations.ApiStatus; import org.jetbrains.annotations.Nullable; import java.util.Optional; @@ -54,10 +58,14 @@ public interface REIRuntime extends Reloadable<REIClientPlugin> { void toggleOverlayVisible(); default Optional<ScreenOverlay> getOverlay() { - return getOverlay(false); + return getOverlay(false, false); } - Optional<ScreenOverlay> getOverlay(boolean reset); + default Optional<ScreenOverlay> getOverlay(boolean reset) { + return getOverlay(reset, true); + } + + Optional<ScreenOverlay> getOverlay(boolean reset, boolean init); @Nullable AbstractContainerScreen<?> getPreviousContainerScreen(); @@ -76,7 +84,13 @@ public interface REIRuntime extends Reloadable<REIClientPlugin> { SearchFieldLocation getContextualSearchFieldLocation(); - Rectangle calculateEntryListArea(); + @ApiStatus.ScheduledForRemoval + @Deprecated + default Rectangle calculateEntryListArea() { + return calculateEntryListArea(ScreenRegistry.getInstance().getOverlayBounds(ConfigObject.getInstance().getDisplayPanelLocation(), Minecraft.getInstance().screen)); + } + + Rectangle calculateEntryListArea(Rectangle bounds); Rectangle calculateFavoritesListArea(); } diff --git a/api/src/main/java/me/shedaniel/rei/api/client/config/ConfigObject.java b/api/src/main/java/me/shedaniel/rei/api/client/config/ConfigObject.java index 20165ffc1..8d35049c2 100644 --- a/api/src/main/java/me/shedaniel/rei/api/client/config/ConfigObject.java +++ b/api/src/main/java/me/shedaniel/rei/api/client/config/ConfigObject.java @@ -24,6 +24,7 @@ package me.shedaniel.rei.api.client.config; import me.shedaniel.clothconfig2.api.ModifierKeyCode; +import me.shedaniel.rei.api.client.config.entry.EntryStackProvider; import me.shedaniel.rei.api.client.favorites.FavoriteEntry; import me.shedaniel.rei.api.client.gui.config.*; import me.shedaniel.rei.api.common.entry.EntryStack; @@ -88,6 +89,8 @@ public interface ConfigObject { int getMaxRecipePerPage(); + int getMaxRecipesPageHeight(); + boolean doesDisableRecipeBook(); boolean doesFixTabCloseContainer(); @@ -142,8 +145,12 @@ public interface ConfigObject { @ApiStatus.Experimental List<FavoriteEntry> getFavoriteEntries(); + @ApiStatus.ScheduledForRemoval + @Deprecated List<EntryStack<?>> getFilteredStacks(); + List<EntryStackProvider<?>> getFilteredStackProviders(); + @ApiStatus.Experimental boolean shouldAsyncSearch(); @@ -158,10 +165,22 @@ public interface ConfigObject { boolean isInventoryHighlightingAllowed(); @ApiStatus.Experimental - double getHorizontalEntriesBoundaries(); + double getHorizontalEntriesBoundariesPercentage(); + + @ApiStatus.Experimental + double getVerticalEntriesBoundariesPercentage(); + + @ApiStatus.Experimental + double getHorizontalEntriesBoundariesColumns(); + + @ApiStatus.Experimental + double getVerticalEntriesBoundariesRows(); + + @ApiStatus.Experimental + double getFavoritesHorizontalEntriesBoundariesPercentage(); @ApiStatus.Experimental - double getVerticalEntriesBoundaries(); + double getFavoritesHorizontalEntriesBoundariesColumns(); @ApiStatus.Experimental SyntaxHighlightingMode getSyntaxHighlightingMode(); diff --git a/api/src/main/java/me/shedaniel/rei/api/client/config/entry/EntryStackProvider.java b/api/src/main/java/me/shedaniel/rei/api/client/config/entry/EntryStackProvider.java new file mode 100644 index 000000000..3f784b798 --- /dev/null +++ b/api/src/main/java/me/shedaniel/rei/api/client/config/entry/EntryStackProvider.java @@ -0,0 +1,120 @@ +/* + * This file is licensed under the MIT License, part of Roughly Enough Items. + * Copyright (c) 2018, 2019, 2020, 2021 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.api.client.config.entry; + +import me.shedaniel.rei.api.common.entry.EntryStack; +import me.shedaniel.rei.api.common.util.EntryStacks; +import net.minecraft.nbt.CompoundTag; +import org.jetbrains.annotations.ApiStatus; + +import java.util.Objects; + +@ApiStatus.Experimental +@ApiStatus.NonExtendable +public interface EntryStackProvider<T> { + EntryStack<T> provide(); + + CompoundTag save(); + + boolean isValid(); + + static <T> EntryStackProvider<T> defer(CompoundTag tag) { + return new EntryStackProvider<T>() { + private EntryStack<T> stack; + + @Override + public EntryStack<T> provide() { + if (stack == null) { + try { + stack = (EntryStack<T>) EntryStack.read(tag); + } catch (Exception e) { + e.printStackTrace(); + return (EntryStack<T>) EntryStack.empty(); + } + + stack = stack.normalize(); + } + + return stack; + } + + @Override + public CompoundTag save() { + return tag.copy(); + } + + @Override + public boolean isValid() { + return !provide().isEmpty(); + } + + @Override + public boolean equals(Object o) { + if (this == o) return true; + if (!(o instanceof EntryStackProvider)) return false; + EntryStackProvider<?> that = (EntryStackProvider<?>) o; + return Objects.equals(provide(), that.provide()); + } + + @Override + public int hashCode() { + return Long.hashCode(EntryStacks.hashExact(provide())); + } + }; + } + + static <T> EntryStackProvider<T> ofStack(EntryStack<T> stack) { + stack = stack.normalize(); + EntryStack<T> finalStack = stack; + return new EntryStackProvider<T>() { + @Override + public EntryStack<T> provide() { + return finalStack; + } + + @Override + public CompoundTag save() { + return finalStack.save(); + } + + @Override + public boolean isValid() { + return !finalStack.isEmpty(); + } + + @Override + public boolean equals(Object o) { + if (this == o) return true; + if (!(o instanceof EntryStackProvider)) return false; + EntryStackProvider<?> that = (EntryStackProvider<?>) o; + return Objects.equals(provide(), that.provide()); + } + + @Override + public int hashCode() { + return Long.hashCode(EntryStacks.hashExact(provide())); + } + }; + } +} diff --git a/api/src/main/java/me/shedaniel/rei/api/client/entry/region/RegionEntry.java b/api/src/main/java/me/shedaniel/rei/api/client/entry/region/RegionEntry.java new file mode 100644 index 000000000..c36a9444b --- /dev/null +++ b/api/src/main/java/me/shedaniel/rei/api/client/entry/region/RegionEntry.java @@ -0,0 +1,61 @@ +/* + * This file is licensed under the MIT License, part of Roughly Enough Items. + * Copyright (c) 2018, 2019, 2020, 2021 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.api.client.entry.region; + +import me.shedaniel.rei.api.client.favorites.FavoriteEntry; +import me.shedaniel.rei.api.client.favorites.FavoriteMenuEntry; +import me.shedaniel.rei.api.common.entry.EntryStack; +import org.jetbrains.annotations.ApiStatus; + +import java.util.Collection; +import java.util.Optional; +import java.util.UUID; +import java.util.function.Supplier; + +@ApiStatus.Experimental +@ApiStatus.Internal +public interface RegionEntry<T extends RegionEntry<T>> { + EntryStack<?> toStack(); + + T copy(); + + default FavoriteEntry asFavorite() { + FavoriteEntry entry = FavoriteEntry.fromEntryStack(copy().toStack().normalize()); + return entry.isInvalid() ? null : entry; + } + + default boolean isEntryInvalid() { + return false; + } + + default Optional<Supplier<Collection<FavoriteMenuEntry>>> getMenuEntries() { + return Optional.empty(); + } + + UUID getUuid(); + + default boolean doAction(int button) { + return false; + } +} diff --git a/api/src/main/java/me/shedaniel/rei/api/client/favorites/CompoundFavoriteRenderer.java b/api/src/main/java/me/shedaniel/rei/api/client/favorites/CompoundFavoriteRenderer.java index e9ce917dd..2ccba2166 100644 --- a/api/src/main/java/me/shedaniel/rei/api/client/favorites/CompoundFavoriteRenderer.java +++ b/api/src/main/java/me/shedaniel/rei/api/client/favorites/CompoundFavoriteRenderer.java @@ -29,7 +29,8 @@ import me.shedaniel.clothconfig2.api.ScissorsHandler; import me.shedaniel.math.Rectangle; import me.shedaniel.rei.api.client.gui.AbstractRenderer; import me.shedaniel.rei.api.client.gui.Renderer; -import me.shedaniel.rei.api.common.util.Animator; +import me.shedaniel.rei.api.client.gui.animator.NumberAnimator; +import me.shedaniel.rei.api.client.gui.animator.ValueAnimator; import net.fabricmc.api.EnvType; import net.fabricmc.api.Environment; import net.minecraft.Util; @@ -40,7 +41,7 @@ import java.util.function.IntSupplier; @Environment(EnvType.CLIENT) public class CompoundFavoriteRenderer extends AbstractRenderer { - protected Animator offset = new Animator(0); + protected NumberAnimator<Double> offset = ValueAnimator.ofDouble(); protected Rectangle scissorArea = new Rectangle(); protected long nextSwitch = -1; protected IntFunction<Renderer> renderers; @@ -114,7 +115,7 @@ public class CompoundFavoriteRenderer extends AbstractRenderer { } if (Util.getMillis() - nextSwitch > 1000) { nextSwitch = Util.getMillis(); - offset.setTo(((int) offset.target() + 1) % count, 500); + offset.setTo((offset.target().intValue() + 1) % count, 500); } } else { offset.setTo(supplier.getAsInt() % count, 500); diff --git a/api/src/main/java/me/shedaniel/rei/api/client/favorites/FavoriteEntry.java b/api/src/main/java/me/shedaniel/rei/api/client/favorites/FavoriteEntry.java index 856cea841..493f2ddd3 100644 --- a/api/src/main/java/me/shedaniel/rei/api/client/favorites/FavoriteEntry.java +++ b/api/src/main/java/me/shedaniel/rei/api/client/favorites/FavoriteEntry.java @@ -25,13 +25,16 @@ package me.shedaniel.rei.api.client.favorites; import com.mojang.serialization.DataResult; import com.mojang.serialization.Lifecycle; +import me.shedaniel.rei.api.client.entry.region.RegionEntry; import me.shedaniel.rei.api.client.gui.Renderer; +import me.shedaniel.rei.api.client.util.ClientEntryStacks; import me.shedaniel.rei.api.common.entry.EntryStack; import me.shedaniel.rei.impl.ClientInternals; import net.fabricmc.api.EnvType; import net.fabricmc.api.Environment; import net.minecraft.nbt.CompoundTag; import net.minecraft.resources.ResourceLocation; +import org.jetbrains.annotations.ApiStatus; import org.jetbrains.annotations.Nullable; import java.util.Collection; @@ -41,7 +44,7 @@ import java.util.UUID; import java.util.function.Supplier; @Environment(EnvType.CLIENT) -public abstract class FavoriteEntry { +public abstract class FavoriteEntry implements RegionEntry<FavoriteEntry> { public static final String TYPE_KEY = "type"; private final UUID uuid = UUID.randomUUID(); @@ -71,15 +74,23 @@ public abstract class FavoriteEntry { return delegateResult(() -> FavoriteEntryType.registry().get(FavoriteEntryType.ENTRY_STACK).fromArgsResult(stack), null); } + @ApiStatus.ScheduledForRemoval + @Deprecated public static boolean isEntryInvalid(@Nullable FavoriteEntry entry) { return entry == null || entry.isInvalid(); } + @Override + public boolean isEntryInvalid() { + return isInvalid(); + } + public CompoundTag save(CompoundTag tag) { tag.putString(TYPE_KEY, getType().toString()); return Objects.requireNonNull(Objects.requireNonNull(FavoriteEntryType.registry().get(getType())).save(this, tag)); } + @Override public UUID getUuid() { return uuid; } @@ -88,14 +99,17 @@ public abstract class FavoriteEntry { public abstract Renderer getRenderer(boolean showcase); + @Override public abstract boolean doAction(int button); + @Override public Optional<Supplier<Collection<FavoriteMenuEntry>>> getMenuEntries() { return Optional.empty(); } public abstract long hashIgnoreAmount(); + @Override public abstract FavoriteEntry copy(); public abstract ResourceLocation getType(); @@ -127,4 +141,14 @@ public abstract class FavoriteEntry { public FavoriteEntry getUnwrapped() { return this; } + + @Override + public EntryStack<?> toStack() { + return ClientEntryStacks.of(getRenderer(false)); + } + + @Override + public FavoriteEntry asFavorite() { + return copy(); + } } diff --git a/api/src/main/java/me/shedaniel/rei/api/client/favorites/FavoriteEntryType.java b/api/src/main/java/me/shedaniel/rei/api/client/favorites/FavoriteEntryType.java index 7c60253b9..a317787fc 100644 --- a/api/src/main/java/me/shedaniel/rei/api/client/favorites/FavoriteEntryType.java +++ b/api/src/main/java/me/shedaniel/rei/api/client/favorites/FavoriteEntryType.java @@ -76,7 +76,8 @@ public interface FavoriteEntryType<T extends FavoriteEntry> { interface Registry extends Reloadable<REIClientPlugin> { void register(ResourceLocation id, FavoriteEntryType<?> type); - @Nullable <A extends FavoriteEntry> FavoriteEntryType<A> get(ResourceLocation id); + @Nullable + <A extends FavoriteEntry> FavoriteEntryType<A> get(ResourceLocation id); @Nullable ResourceLocation getId(FavoriteEntryType<?> type); @@ -84,6 +85,8 @@ public interface FavoriteEntryType<T extends FavoriteEntry> { Section getOrCrateSection(Component text); Iterable<Section> sections(); + + <A extends FavoriteEntry> void registerSystemFavorites(SystemFavoriteEntryProvider<A> provider); } @ApiStatus.NonExtendable diff --git a/api/src/main/java/me/shedaniel/rei/api/client/favorites/SystemFavoriteEntryProvider.java b/api/src/main/java/me/shedaniel/rei/api/client/favorites/SystemFavoriteEntryProvider.java new file mode 100644 index 000000000..c5249d616 --- /dev/null +++ b/api/src/main/java/me/shedaniel/rei/api/client/favorites/SystemFavoriteEntryProvider.java @@ -0,0 +1,38 @@ +/* + * This file is licensed under the MIT License, part of Roughly Enough Items. + * Copyright (c) 2018, 2019, 2020, 2021 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.api.client.favorites; + +import org.jetbrains.annotations.ApiStatus; + +import java.util.List; + +@FunctionalInterface +@ApiStatus.Experimental +public interface SystemFavoriteEntryProvider<T extends FavoriteEntry> { + List<T> provide(); + + default long updateInterval() { + return 250; + } +} diff --git a/api/src/main/java/me/shedaniel/rei/api/client/gui/SimpleDisplayRenderer.java b/api/src/main/java/me/shedaniel/rei/api/client/gui/SimpleDisplayRenderer.java index 246a32979..ee8ecdbc6 100644 --- a/api/src/main/java/me/shedaniel/rei/api/client/gui/SimpleDisplayRenderer.java +++ b/api/src/main/java/me/shedaniel/rei/api/client/gui/SimpleDisplayRenderer.java @@ -45,7 +45,6 @@ import org.jetbrains.annotations.ApiStatus; import org.jetbrains.annotations.Nullable; import java.util.ArrayList; -import java.util.Comparator; import java.util.List; import java.util.stream.Collectors; import java.util.stream.Stream; diff --git a/api/src/main/java/me/shedaniel/rei/api/client/gui/animator/ConstantValueProvider.java b/api/src/main/java/me/shedaniel/rei/api/client/gui/animator/ConstantValueProvider.java new file mode 100644 index 000000000..f213702b4 --- /dev/null +++ b/api/src/main/java/me/shedaniel/rei/api/client/gui/animator/ConstantValueProvider.java @@ -0,0 +1,53 @@ +/* + * This file is licensed under the MIT License, part of Roughly Enough Items. + * Copyright (c) 2018, 2019, 2020, 2021 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.api.client.gui.animator; + +import org.jetbrains.annotations.ApiStatus; + +@ApiStatus.Internal +final class ConstantValueProvider<T> implements ValueProvider<T> { + private final T value; + + public ConstantValueProvider(T value) { + this.value = value; + } + + @Override + public T value() { + return value; + } + + @Override + public T target() { + return value; + } + + @Override + public void completeImmediately() { + } + + @Override + public void update(double delta) { + } +} diff --git a/api/src/main/java/me/shedaniel/rei/api/client/gui/animator/ConventionValueAnimator.java b/api/src/main/java/me/shedaniel/rei/api/client/gui/animator/ |
