From f04d72b96e5c562d4de7f5f5e5521942de5df49a Mon Sep 17 00:00:00 2001 From: shedaniel Date: Sun, 14 Nov 2021 03:20:23 +0800 Subject: Removed deprecated APIs, 1.18-pre1 --- .../me/shedaniel/rei/api/client/REIRuntime.java | 10 -- .../rei/api/client/config/ConfigObject.java | 6 +- .../rei/api/client/favorites/FavoriteEntry.java | 9 +- .../api/client/favorites/FavoriteEntryType.java | 24 +---- .../rei/api/client/gui/drag/DraggableStack.java | 6 -- .../api/client/gui/drag/DraggableStackVisitor.java | 36 +------ .../gui/drag/DraggableStackVisitorWidget.java | 40 ++------ .../rei/api/client/gui/widgets/Tooltip.java | 4 - .../rei/api/client/view/ViewSearchBuilder.java | 16 +--- .../rei/api/common/plugins/REIPlugin.java | 19 ---- .../rei/api/common/transfer/info/MenuInfo.java | 20 +--- .../api/common/transfer/info/MenuInfoProvider.java | 41 +------- .../api/common/transfer/info/MenuInfoRegistry.java | 11 +-- .../transfer/info/MenuSerializationContext.java | 31 ++++-- .../info/MenuSerializationProviderContext.java | 43 --------- .../info/simple/RecipeBookGridMenuInfo.java | 11 +++ .../info/simple/SimpleMenuInfoProvider.java | 73 ++++++++++++++ .../me/shedaniel/rei/api/common/util/Animator.java | 106 --------------------- 18 files changed, 138 insertions(+), 368 deletions(-) delete mode 100644 api/src/main/java/me/shedaniel/rei/api/common/transfer/info/MenuSerializationProviderContext.java create mode 100644 api/src/main/java/me/shedaniel/rei/api/common/transfer/info/simple/SimpleMenuInfoProvider.java delete mode 100644 api/src/main/java/me/shedaniel/rei/api/common/util/Animator.java (limited to 'api/src/main/java/me') 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 1af65d4ad..2c3cff511 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,22 +24,18 @@ 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; @@ -84,12 +80,6 @@ public interface REIRuntime extends Reloadable { SearchFieldLocation getContextualSearchFieldLocation(); - @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 8d35049c2..13ba8edf5 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 @@ -27,7 +27,6 @@ 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; import net.fabricmc.api.EnvType; import net.fabricmc.api.Environment; import org.jetbrains.annotations.ApiStatus; @@ -145,10 +144,7 @@ public interface ConfigObject { @ApiStatus.Experimental List getFavoriteEntries(); - @ApiStatus.ScheduledForRemoval - @Deprecated - List> getFilteredStacks(); - + @ApiStatus.Experimental List> getFilteredStackProviders(); @ApiStatus.Experimental 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 493f2ddd3..82e3ca72d 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 @@ -34,7 +34,6 @@ 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; @@ -71,13 +70,7 @@ public abstract class FavoriteEntry implements RegionEntry { } public static FavoriteEntry fromEntryStack(EntryStack stack) { - 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(); + return delegateResult(() -> FavoriteEntryType.registry().get(FavoriteEntryType.ENTRY_STACK).fromArgs(stack), null); } @Override 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 a317787fc..82e7b961a 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 @@ -24,7 +24,6 @@ package me.shedaniel.rei.api.client.favorites; import com.mojang.serialization.DataResult; -import com.mojang.serialization.Lifecycle; import me.shedaniel.rei.api.client.plugins.REIClientPlugin; import me.shedaniel.rei.api.common.entry.EntryStack; import me.shedaniel.rei.api.common.plugins.PluginManager; @@ -50,25 +49,9 @@ public interface FavoriteEntryType { return PluginManager.getClientInstance().get(FavoriteEntryType.Registry.class); } - @ApiStatus.ScheduledForRemoval - @Deprecated - default T read(CompoundTag object) { - throw new UnsupportedOperationException("Implementation of FavoriteEntryType must override #read or #readResult"); - } - - default DataResult readResult(CompoundTag object) { - return DataResult.success(read(object), Lifecycle.stable()); - } + DataResult read(CompoundTag object); - @ApiStatus.ScheduledForRemoval - @Deprecated - default T fromArgs(Object... args) { - throw new UnsupportedOperationException("Implementation of FavoriteEntryType must override #fromArgs or #fromArgsResult"); - } - - default DataResult fromArgsResult(Object... args) { - return DataResult.success(fromArgs(args), Lifecycle.stable()); - } + DataResult fromArgs(Object... args); CompoundTag save(T entry, CompoundTag tag); @@ -76,8 +59,7 @@ public interface FavoriteEntryType { interface Registry extends Reloadable { void register(ResourceLocation id, FavoriteEntryType type); - @Nullable - FavoriteEntryType get(ResourceLocation id); + @Nullable FavoriteEntryType get(ResourceLocation id); @Nullable ResourceLocation getId(FavoriteEntryType type); diff --git a/api/src/main/java/me/shedaniel/rei/api/client/gui/drag/DraggableStack.java b/api/src/main/java/me/shedaniel/rei/api/client/gui/drag/DraggableStack.java index b5ccc97f2..d38919ee4 100644 --- a/api/src/main/java/me/shedaniel/rei/api/client/gui/drag/DraggableStack.java +++ b/api/src/main/java/me/shedaniel/rei/api/client/gui/drag/DraggableStack.java @@ -26,19 +26,13 @@ package me.shedaniel.rei.api.client.gui.drag; import com.mojang.blaze3d.vertex.PoseStack; import me.shedaniel.math.Rectangle; import me.shedaniel.rei.api.common.entry.EntryStack; -import org.jetbrains.annotations.ApiStatus; public interface DraggableStack { EntryStack getStack(); void drag(); - @Deprecated - @ApiStatus.ScheduledForRemoval - default void release(boolean consumed) {} - default void release(DraggedAcceptorResult result) { - release(result != DraggedAcceptorResult.PASS); } default void render(PoseStack matrices, Rectangle bounds, int mouseX, int mouseY, float delta) { diff --git a/api/src/main/java/me/shedaniel/rei/api/client/gui/drag/DraggableStackVisitor.java b/api/src/main/java/me/shedaniel/rei/api/client/gui/drag/DraggableStackVisitor.java index d893eccd4..0d0f98fd7 100644 --- a/api/src/main/java/me/shedaniel/rei/api/client/gui/drag/DraggableStackVisitor.java +++ b/api/src/main/java/me/shedaniel/rei/api/client/gui/drag/DraggableStackVisitor.java @@ -27,10 +27,8 @@ import me.shedaniel.math.Rectangle; import net.minecraft.client.gui.screens.Screen; import net.minecraft.world.phys.shapes.Shapes; import net.minecraft.world.phys.shapes.VoxelShape; -import org.jetbrains.annotations.ApiStatus; import java.util.Objects; -import java.util.Optional; import java.util.function.Supplier; import java.util.stream.Stream; import java.util.stream.StreamSupport; @@ -52,10 +50,10 @@ public interface DraggableStackVisitor extends Comparable context, DraggableStack stack) { + public DraggedAcceptorResult acceptDraggedStack(DraggingContext context, DraggableStack stack) { for (DraggableStackVisitor visitor : visitors.get()) { if (visitor.isHandingScreen(context.getScreen())) { - DraggedAcceptorResult result = Objects.requireNonNull(visitor.acceptDraggedStackWithResult(context, stack)); + DraggedAcceptorResult result = Objects.requireNonNull(visitor.acceptDraggedStack(context, stack)); if (result != DraggedAcceptorResult.PASS) return result; } } @@ -71,32 +69,6 @@ public interface DraggableStackVisitor extends Comparable visitDraggedStack(DraggingContext context, DraggableStack stack) { - return Optional.empty(); - } - - /** - * Accepts a dragged stack, implementations of this function should check if the {@code context} is within - * boundaries of the accepting boundaries. - * - * @param context the context of the current dragged stack on the overlay - * @param stack the stack being dragged - * @return whether the stack is accepted by the visitor - */ - @ApiStatus.ScheduledForRemoval - @Deprecated - default boolean acceptDraggedStack(DraggingContext context, DraggableStack stack) { - Optional acceptor = visitDraggedStack(context, stack); - if (acceptor.isPresent()) { - acceptor.get().accept(stack); - return true; - } else { - return false; - } - } - /** * Accepts a dragged stack, implementations of this function should check if the {@code context} is within * boundaries of the accepting boundaries. @@ -105,8 +77,8 @@ public interface DraggableStackVisitor extends Comparable context, DraggableStack stack) { - return acceptDraggedStack(context, stack) ? DraggedAcceptorResult.CONSUMED : DraggedAcceptorResult.PASS; + default DraggedAcceptorResult acceptDraggedStack(DraggingContext context, DraggableStack stack) { + return DraggedAcceptorResult.PASS; } /** diff --git a/api/src/main/java/me/shedaniel/rei/api/client/gui/drag/DraggableStackVisitorWidget.java b/api/src/main/java/me/shedaniel/rei/api/client/gui/drag/DraggableStackVisitorWidget.java index 4234b2b6b..cbe00cc1a 100644 --- a/api/src/main/java/me/shedaniel/rei/api/client/gui/drag/DraggableStackVisitorWidget.java +++ b/api/src/main/java/me/shedaniel/rei/api/client/gui/drag/DraggableStackVisitorWidget.java @@ -24,9 +24,7 @@ package me.shedaniel.rei.api.client.gui.drag; import net.minecraft.client.gui.screens.Screen; -import org.jetbrains.annotations.ApiStatus; -import java.util.Optional; import java.util.function.Function; import java.util.stream.Stream; import java.util.stream.StreamSupport; @@ -39,9 +37,9 @@ public interface DraggableStackVisitorWidget { static DraggableStackVisitorWidget from(Function, Iterable> providers) { return new DraggableStackVisitorWidget() { @Override - public DraggedAcceptorResult acceptDraggedStackWithResult(DraggingContext context, DraggableStack stack) { + public DraggedAcceptorResult acceptDraggedStack(DraggingContext context, DraggableStack stack) { return StreamSupport.stream(providers.apply(context).spliterator(), false) - .map(visitor -> visitor.acceptDraggedStackWithResult(context, stack)) + .map(visitor -> visitor.acceptDraggedStack(context, stack)) .filter(result -> result != DraggedAcceptorResult.PASS) .findFirst() .orElse(DraggedAcceptorResult.PASS); @@ -55,32 +53,6 @@ public interface DraggableStackVisitorWidget { }; } - @ApiStatus.ScheduledForRemoval - @Deprecated(forRemoval = true) - default Optional visitDraggedStack(DraggingContext context, DraggableStack stack) { - return Optional.empty(); - } - - /** - * Accepts a dragged stack, implementations of this function should check if the {@code context} is within - * boundaries of the widget. - * - * @param context the context of the current dragged stack on the overlay - * @param stack the stack being dragged - * @return whether the stack is accepted by the widget - */ - @ApiStatus.ScheduledForRemoval - @Deprecated - default boolean acceptDraggedStack(DraggingContext context, DraggableStack stack) { - Optional acceptor = visitDraggedStack(context, stack); - if (acceptor.isPresent()) { - acceptor.get().accept(stack); - return true; - } else { - return false; - } - } - /** * Accepts a dragged stack, implementations of this function should check if the {@code context} is within * boundaries of the widget. @@ -89,8 +61,8 @@ public interface DraggableStackVisitorWidget { * @param stack the stack being dragged * @return the result of the visitor */ - default DraggedAcceptorResult acceptDraggedStackWithResult(DraggingContext context, DraggableStack stack) { - return acceptDraggedStack(context, stack) ? DraggedAcceptorResult.CONSUMED : DraggedAcceptorResult.PASS; + default DraggedAcceptorResult acceptDraggedStack(DraggingContext context, DraggableStack stack) { + return DraggedAcceptorResult.PASS; } /** @@ -112,8 +84,8 @@ public interface DraggableStackVisitorWidget { static DraggableStackVisitor toVisitor(DraggableStackVisitorWidget widget, double priority) { return new DraggableStackVisitor<>() { @Override - public DraggedAcceptorResult acceptDraggedStackWithResult(DraggingContext context, DraggableStack stack) { - return widget.acceptDraggedStackWithResult(context, stack); + public DraggedAcceptorResult acceptDraggedStack(DraggingContext context, DraggableStack stack) { + return widget.acceptDraggedStack(context, stack); } @Override diff --git a/api/src/main/java/me/shedaniel/rei/api/client/gui/widgets/Tooltip.java b/api/src/main/java/me/shedaniel/rei/api/client/gui/widgets/Tooltip.java index 919644e09..370caa671 100644 --- a/api/src/main/java/me/shedaniel/rei/api/client/gui/widgets/Tooltip.java +++ b/api/src/main/java/me/shedaniel/rei/api/client/gui/widgets/Tooltip.java @@ -87,10 +87,6 @@ public interface Tooltip { int getY(); - @Deprecated - @ApiStatus.ScheduledForRemoval - List getText(); - List entries(); List components(); diff --git a/api/src/main/java/me/shedaniel/rei/api/client/view/ViewSearchBuilder.java b/api/src/main/java/me/shedaniel/rei/api/client/view/ViewSearchBuilder.java index 9b8a7582c..2157d54e3 100644 --- a/api/src/main/java/me/shedaniel/rei/api/client/view/ViewSearchBuilder.java +++ b/api/src/main/java/me/shedaniel/rei/api/client/view/ViewSearchBuilder.java @@ -27,7 +27,6 @@ import me.shedaniel.rei.api.client.ClientHelper; import me.shedaniel.rei.api.client.registry.category.CategoryRegistry; import me.shedaniel.rei.api.client.registry.display.DisplayCategory; import me.shedaniel.rei.api.common.category.CategoryIdentifier; -import me.shedaniel.rei.api.common.display.Display; import me.shedaniel.rei.api.common.entry.EntryStack; import me.shedaniel.rei.api.common.util.CollectionUtils; import me.shedaniel.rei.impl.ClientInternals; @@ -35,7 +34,10 @@ import me.shedaniel.rei.impl.display.DisplaySpec; import org.jetbrains.annotations.ApiStatus; import org.jetbrains.annotations.Nullable; -import java.util.*; +import java.util.Collection; +import java.util.List; +import java.util.Map; +import java.util.Set; public interface ViewSearchBuilder { static ViewSearchBuilder builder() { @@ -65,16 +67,6 @@ public interface ViewSearchBuilder { @Nullable CategoryIdentifier getPreferredOpenedCategory(); - @Deprecated - @ApiStatus.ScheduledForRemoval - default Map, List> buildMap() { - Map, List> map = new HashMap<>(); - for (Map.Entry, List> entry : buildMapInternal().entrySet()) { - map.put(entry.getKey(), CollectionUtils.map(entry.getValue(), DisplaySpec::provideInternalDisplay)); - } - return map; - } - @ApiStatus.Internal Map, List> buildMapInternal(); diff --git a/api/src/main/java/me/shedaniel/rei/api/common/plugins/REIPlugin.java b/api/src/main/java/me/shedaniel/rei/api/common/plugins/REIPlugin.java index ef4444661..108b293ac 100644 --- a/api/src/main/java/me/shedaniel/rei/api/common/plugins/REIPlugin.java +++ b/api/src/main/java/me/shedaniel/rei/api/common/plugins/REIPlugin.java @@ -35,7 +35,6 @@ import org.jetbrains.annotations.ApiStatus; import java.util.Collection; import java.util.Collections; -import java.util.Objects; /** * Base interface for a REI plugin. @@ -98,30 +97,12 @@ public interface REIPlugin

> extends Comparable manager, ReloadStage stage) { - if (stage == ReloadStage.START && Objects.equals(manager, PluginManager.getInstance())) { - preRegister(); - } - } - - @ApiStatus.OverrideOnly - @Deprecated - @ApiStatus.ScheduledForRemoval - default void postRegister() { } @ApiStatus.OverrideOnly default void postStage(PluginManager

manager, ReloadStage stage) { - if (stage == ReloadStage.END && (this instanceof REIServerPlugin ? Objects.equals(manager, PluginManager.getServerInstance()) : !Objects.equals(manager, PluginManager.getInstance()))) { - preRegister(); - } } @Override diff --git a/api/src/main/java/me/shedaniel/rei/api/common/transfer/info/MenuInfo.java b/api/src/main/java/me/shedaniel/rei/api/common/transfer/info/MenuInfo.java index b5ed1de67..cde2c2231 100644 --- a/api/src/main/java/me/shedaniel/rei/api/common/transfer/info/MenuInfo.java +++ b/api/src/main/java/me/shedaniel/rei/api/common/transfer/info/MenuInfo.java @@ -23,7 +23,6 @@ package me.shedaniel.rei.api.common.transfer.info; -import me.shedaniel.rei.api.common.category.CategoryIdentifier; import me.shedaniel.rei.api.common.display.Display; import me.shedaniel.rei.api.common.display.DisplaySerializerRegistry; import me.shedaniel.rei.api.common.entry.EntryStack; @@ -43,7 +42,6 @@ import net.minecraft.world.item.ItemStack; import java.util.Collections; import java.util.List; -import java.util.Optional; /** * Provider of information for {@link AbstractContainerMenu}, for the default REI {@link me.shedaniel.rei.api.client.registry.transfer.TransferHandler}. @@ -55,12 +53,7 @@ import java.util.Optional; * @see me.shedaniel.rei.api.common.transfer.info.simple.SimplePlayerInventoryMenuInfo * @see me.shedaniel.rei.api.common.transfer.info.simple.SimpleGridMenuInfo */ -public interface MenuInfo extends MenuInfoProvider { - @Override - default Optional> provide(CategoryIdentifier categoryId, Class menuClass) { - return Optional.of(this); - } - +public interface MenuInfo { /** * Returns a {@link RecipeFinderPopulator}, used to populate a {@link RecipeFinder} with * available ingredients. @@ -136,18 +129,13 @@ public interface MenuInfo ex * @return the {@link CompoundTag} serialized */ default CompoundTag save(MenuSerializationContext context, D display) { - // TODO Remove this, replace with getDisplay() return DisplaySerializerRegistry.getInstance().save(display, new CompoundTag()); } /** - * Deserializes the {@link Display} from {@link CompoundTag}, sent from the client for further info of the transfer. + * Returns the {@link Display} for this menu info. * - * @param context the context of the transfer - * @param tag the nbt tag to deserialize from - * @return the {@link Display} deserialized + * @return the {@link Display} */ - default D read(MenuSerializationContext context, CompoundTag tag) { - return DisplaySerializerRegistry.getInstance().read(context.getCategoryIdentifier(), tag); - } + D getDisplay(); } diff --git a/api/src/main/java/me/shedaniel/rei/api/common/transfer/info/MenuInfoProvider.java b/api/src/main/java/me/shedaniel/rei/api/common/transfer/info/MenuInfoProvider.java index 904c59dd4..2d25603fd 100644 --- a/api/src/main/java/me/shedaniel/rei/api/common/transfer/info/MenuInfoProvider.java +++ b/api/src/main/java/me/shedaniel/rei/api/common/transfer/info/MenuInfoProvider.java @@ -25,12 +25,11 @@ package me.shedaniel.rei.api.common.transfer.info; import me.shedaniel.rei.api.common.category.CategoryIdentifier; import me.shedaniel.rei.api.common.display.Display; +import me.shedaniel.rei.api.common.transfer.info.simple.SimpleMenuInfoProvider; import net.fabricmc.api.EnvType; import net.fabricmc.api.Environment; import net.minecraft.nbt.CompoundTag; -import net.minecraft.world.entity.player.Player; import net.minecraft.world.inventory.AbstractContainerMenu; -import org.jetbrains.annotations.ApiStatus; import java.util.Optional; @@ -39,43 +38,11 @@ import java.util.Optional; * * @param the type of the menu * @param the type of display + * @see SimpleMenuInfoProvider */ -@FunctionalInterface public interface MenuInfoProvider { @Environment(EnvType.CLIENT) - default Optional> provideClient(D display, T menu) { - return provide((CategoryIdentifier) display.getCategoryIdentifier(), (Class) menu.getClass()); - } + Optional> provideClient(D display, MenuSerializationContext context, T menu); - default Optional> provide(CategoryIdentifier display, T menu, MenuSerializationProviderContext context, CompoundTag networkTag) { - Optional> menuInfo = provide(display, (Class) menu.getClass()); - if (menuInfo.isPresent()) { - menuInfo.get().read(new MenuSerializationContext() { - @Override - public MenuInfo getContainerInfo() { - return menuInfo.get(); - } - - @Override - public T getMenu() { - return context.getMenu(); - } - - @Override - public Player getPlayerEntity() { - return context.getPlayerEntity(); - } - - @Override - public CategoryIdentifier getCategoryIdentifier() { - return context.getCategoryIdentifier(); - } - }, networkTag); - } - return menuInfo; - } - - @Deprecated - @ApiStatus.ScheduledForRemoval - Optional> provide(CategoryIdentifier categoryId, Class menuClass); + Optional> provide(CategoryIdentifier category, T menu, MenuSerializationContext context, CompoundTag networkTag); } diff --git a/api/src/main/java/me/shedaniel/rei/api/common/transfer/info/MenuInfoRegistry.java b/api/src/main/java/me/shedaniel/rei/api/common/transfer/info/MenuInfoRegistry.java index fdb83fb30..31b79e8c2 100644 --- a/api/src/main/java/me/shedaniel/rei/api/common/transfer/info/MenuInfoRegistry.java +++ b/api/src/main/java/me/shedaniel/rei/api/common/transfer/info/MenuInfoRegistry.java @@ -32,7 +32,6 @@ import net.fabricmc.api.EnvType; import net.fabricmc.api.Environment; import net.minecraft.nbt.CompoundTag; import net.minecraft.world.inventory.AbstractContainerMenu; -import org.jetbrains.annotations.ApiStatus; import org.jetbrains.annotations.Nullable; import java.util.function.Predicate; @@ -49,17 +48,11 @@ public interface MenuInfoRegistry extends Reloadable { void registerGeneric(Predicate> categoryPredicate, MenuInfoProvider menuInfo); - @Nullable - @ApiStatus.ScheduledForRemoval - @Deprecated - MenuInfo get(CategoryIdentifier category, Class menuClass); - @Nullable @Environment(EnvType.CLIENT) - MenuInfo getClient(D display, C menu); + MenuInfo getClient(D display, MenuSerializationContext context, C menu); - @Nullable - MenuInfo get(CategoryIdentifier category, C menu, MenuSerializationProviderContext context, CompoundTag tag); + @Nullable MenuInfo get(CategoryIdentifier category, C menu, MenuSerializationContext context, CompoundTag tag); int infoSize(); } diff --git a/api/src/main/java/me/shedaniel/rei/api/common/transfer/info/MenuSerializationContext.java b/api/src/main/java/me/shedaniel/rei/api/common/transfer/info/MenuSerializationContext.java index b3ed73d5f..ba7b77edf 100644 --- a/api/src/main/java/me/shedaniel/rei/api/common/transfer/info/MenuSerializationContext.java +++ b/api/src/main/java/me/shedaniel/rei/api/common/transfer/info/MenuSerializationContext.java @@ -34,15 +34,34 @@ import net.minecraft.world.inventory.AbstractContainerMenu; * @param the type of {@link AbstractContainerMenu} * @param

the type of {@link Player}, server sided contexts may pass {@link net.minecraft.server.level.ServerPlayer} instead */ -public interface MenuSerializationContext extends MenuSerializationProviderContext { - @Override +public interface MenuSerializationContext { T getMenu(); - @Override P getPlayerEntity(); - MenuInfo getContainerInfo(); - - @Override CategoryIdentifier getCategoryIdentifier(); + + default MenuInfoContext withDisplay(D display) { + return new MenuInfoContext() { + @Override + public D getDisplay() { + return display; + } + + @Override + public T getMenu() { + return MenuSerializationContext.this.getMenu(); + } + + @Override + public P getPlayerEntity() { + return MenuSerializationContext.this.getPlayerEntity(); + } + + @Override + public CategoryIdentifier getCategoryIdentifier() { + return MenuSerializationContext.this.getCategoryIdentifier(); + } + }; + } } diff --git a/api/src/main/java/me/shedaniel/rei/api/common/transfer/info/MenuSerializationProviderContext.java b/api/src/main/java/me/shedaniel/rei/api/common/transfer/info/MenuSerializationProviderContext.java deleted file mode 100644 index 19a8cb78a..000000000 --- a/api/src/main/java/me/shedaniel/rei/api/common/transfer/info/MenuSerializationProviderContext.java +++ /dev/null @@ -1,43 +0,0 @@ -/* - * 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.common.transfer.info; - -import me.shedaniel.rei.api.common.category.CategoryIdentifier; -import me.shedaniel.rei.api.common.display.Display; -import net.minecraft.world.entity.player.Player; -import net.minecraft.world.inventory.AbstractContainerMenu; - -/** - * Context for menu display serialization. - * - * @param the type of {@link AbstractContainerMenu} - * @param

the type of {@link Player}, server sided contexts may pass {@link net.minecraft.server.level.ServerPlayer} instead - */ -public interface MenuSerializationProviderContext { - T getMenu(); - - P getPlayerEntity(); - - CategoryIdentifier getCategoryIdentifier(); -} diff --git a/api/src/main/java/me/shedaniel/rei/api/common/transfer/info/simple/RecipeBookGridMenuInfo.java b/api/src/main/java/me/shedaniel/rei/api/common/transfer/info/simple/RecipeBookGridMenuInfo.java index 63eb177c7..c1f3014f7 100644 --- a/api/src/main/java/me/shedaniel/rei/api/common/transfer/info/simple/RecipeBookGridMenuInfo.java +++ b/api/src/main/java/me/shedaniel/rei/api/common/transfer/info/simple/RecipeBookGridMenuInfo.java @@ -29,6 +29,12 @@ import net.minecraft.world.inventory.RecipeBookMenu; import net.minecraft.world.item.ItemStack; public class RecipeBookGridMenuInfo, D extends SimpleGridMenuDisplay> implements SimpleGridMenuInfo { + private final D display; + + public RecipeBookGridMenuInfo(D display) { + this.display = display; + } + @Override public int getCraftingResultSlotIndex(T menu) { return menu.getResultSlotIndex(); @@ -58,4 +64,9 @@ public class RecipeBookGridMenuInfo, D extends Simpl } }); } + + @Override + public D getDisplay() { + return display; + } } diff --git a/api/src/main/java/me/shedaniel/rei/api/common/transfer/info/simple/SimpleMenuInfoProvider.java b/api/src/main/java/me/shedaniel/rei/api/common/transfer/info/simple/SimpleMenuInfoProvider.java new file mode 100644 index 000000000..8cb051957 --- /dev/null +++ b/api/src/main/java/me/shedaniel/rei/api/common/transfer/info/simple/SimpleMenuInfoProvider.java @@ -0,0 +1,73 @@ +/* + * 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.common.transfer.info.simple; + +import me.shedaniel.rei.api.common.category.CategoryIdentifier; +import me.shedaniel.rei.api.common.display.Display; +import me.shedaniel.rei.api.common.display.DisplaySerializerRegistry; +import me.shedaniel.rei.api.common.transfer.info.MenuInfo; +import me.shedaniel.rei.api.common.transfer.info.MenuInfoProvider; +import me.shedaniel.rei.api.common.transfer.info.MenuSerializationContext; +import net.minecraft.nbt.CompoundTag; +import net.minecraft.world.inventory.AbstractContainerMenu; +import org.jetbrains.annotations.Nullable; + +import java.util.Optional; +import java.util.function.Function; + +/** + * A simple implementation of {@link MenuInfoProvider} that provides a {@link Display} for a {@link AbstractContainerMenu}. + * + * @param the type of the menu + * @param the type of display + */ +public interface SimpleMenuInfoProvider extends MenuInfoProvider { + static SimpleMenuInfoProvider of(Function> provider) { + return provider::apply; + } + + @Override + default Optional> provideClient(D display, MenuSerializationContext context, T menu) { + return Optional.ofNullable(cloneWithDisplay(display)); + } + + @Override + default Optional> provide(CategoryIdentifier category, T menu, MenuSerializationContext context, CompoundTag networkTag) { + D display = read(category, menu, context, networkTag); + if (display == null) return Optional.empty(); + return Optional.ofNullable(cloneWithDisplay(display)); + } + + @Nullable + MenuInfo cloneWithDisplay(D display); + + @Nullable + default D read(CategoryIdentifier category, T menu, MenuSerializationContext context, CompoundTag networkTag) { + if (DisplaySerializerRegistry.getInstance().hasSerializer(category)) { + return DisplaySerializerRegistry.getInstance().read(category, networkTag); + } else { + return null; + } + } +} diff --git a/api/src/main/java/me/shedaniel/rei/api/common/util/Animator.java b/api/src/main/java/me/shedaniel/rei/api/common/util/Animator.java deleted file mode 100644 index 25955d97f..000000000 --- a/api/src/main/java/me/shedaniel/rei/api/common/util/Animator.java +++ /dev/null @@ -1,106 +0,0 @@ -/* - * 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.common.util; - -import me.shedaniel.clothconfig2.impl.EasingMethod; -import net.minecraft.Util; -import org.jetbrains.annotations.ApiStatus; - -/** - * @see me.shedaniel.rei.api.client.gui.animator.ValueAnimator - */ -@Deprecated -@ApiStatus.ScheduledForRemoval -public final class Animator extends Number { - private double amount; - private double target; - private long start; - private long duration; - - public Animator() { - } - - public Animator(double amount) { - setAs(amount); - } - - public void setAs(double value) { - this.set(value, false, 0); - } - - public void setTo(double value, long duration) { - if (target != value) - this.set(value, true, duration); - } - - private void set(double value, boolean animated, long duration) { - this.target = value; - this.start = Util.getMillis(); - - if (animated) { - this.duration = duration; - } else { - this.duration = 0; - this.amount = this.target; - } - } - - public void update(double delta) { - if (duration != 0) { - if (amount < target) { - this.amount = Math.min(ease(amount, target + (target - amount), Math.min(((double) Util.getMillis() - start) / duration * delta * 3.0D, 1.0D), EasingMethod.EasingMethodImpl.LINEAR), target); - } else if (amount > target) { - this.amount = Math.max(ease(amount, target - (amount - target), Math.min(((double) Util.getMillis() - start) / duration * delta * 3.0D, 1.0D), EasingMethod.EasingMethodImpl.LINEAR), target); - } - } - } - - private static double ease(double start, double end, double amount, EasingMethod easingMethod) { - return start + (end - start) * easingMethod.apply(amount); - } - - @Override - public int intValue() { - return (int) amount; - } - - @Override - public long longValue() { - return (long) amount; - } - - @Override - public float floatValue() { - return (float) amount; - } - - @Override - public double doubleValue() { - return amount; - } - - public double target() { - return target; - } -} -- cgit