From 97dafeba13f188dffc2666f0351faa007bbe3dec Mon Sep 17 00:00:00 2001 From: shedaniel Date: Mon, 20 Jun 2022 17:23:47 +0800 Subject: Migrate EntryIngredient and EntryStack save() to saveIngredient() and saveStack() --- .../client/config/entry/EntryStackProvider.java | 2 +- .../rei/api/common/entry/EntryIngredient.java | 23 ++++++++++++++++++++++ .../shedaniel/rei/api/common/entry/EntryStack.java | 5 +++-- .../rei/api/common/util/EntryIngredients.java | 2 +- .../common/displays/DefaultInformationDisplay.java | 2 +- .../displays/brewing/DefaultBrewingDisplay.java | 6 +++--- .../rei/impl/common/entry/EntryIngredientImpl.java | 4 ++-- .../client/runtime/DefaultClientRuntimePlugin.java | 2 +- 8 files changed, 35 insertions(+), 11 deletions(-) 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 index 663eb6ce7..1a72ee953 100644 --- 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 @@ -95,7 +95,7 @@ public interface EntryStackProvider { @Override public CompoundTag save() { - return finalStack.save(); + return finalStack.saveStack(); } @Override diff --git a/api/src/main/java/me/shedaniel/rei/api/common/entry/EntryIngredient.java b/api/src/main/java/me/shedaniel/rei/api/common/entry/EntryIngredient.java index 6e7862a55..cb3e68f44 100644 --- a/api/src/main/java/me/shedaniel/rei/api/common/entry/EntryIngredient.java +++ b/api/src/main/java/me/shedaniel/rei/api/common/entry/EntryIngredient.java @@ -31,6 +31,7 @@ import org.jetbrains.annotations.ApiStatus; import java.util.List; import java.util.function.Predicate; +import java.util.function.Supplier; import java.util.function.UnaryOperator; import java.util.stream.Collector; import java.util.stream.Collectors; @@ -38,6 +39,7 @@ import java.util.stream.Collectors; /** * An immutable representation of a list of {@link EntryStack}. */ +@ApiStatus.NonExtendable public interface EntryIngredient extends List> { /** * Returns an empty entry ingredient. This is the singleton instance of {@link EntryIngredient} that is @@ -121,6 +123,12 @@ public interface EntryIngredient extends List> { return Internals.getEntryIngredientProvider().of(stacks); } + /** + * Returns a {@link Collector} that accumulates the stacks into a + * new {@link EntryIngredient}. + * + * @return the collector + */ static Collector, ?, EntryIngredient> collector() { return Collectors.collectingAndThen(Collectors.toList(), EntryIngredient::of); } @@ -132,7 +140,22 @@ public interface EntryIngredient extends List> { * @throws UnsupportedOperationException if an {@link EntryDefinition} does not support saving to a tag * @see EntrySerializer#supportSaving() * @see EntryStack#saveStack() + * @since 8.3 + */ + default ListTag saveIngredient() { + return save(); + } + + /** + * Saves the entry ingredient to a {@link ListTag}. This is only supported if every entry stack has a serializer. + * + * @return the saved tag + * @throws UnsupportedOperationException if an {@link EntryDefinition} does not support saving to a tag + * @see EntrySerializer#supportSaving() + * @see EntryStack#saveStack() + * @deprecated use {@link #saveIngredient()} instead */ + @Deprecated(forRemoval = true) ListTag save(); /** diff --git a/api/src/main/java/me/shedaniel/rei/api/common/entry/EntryStack.java b/api/src/main/java/me/shedaniel/rei/api/common/entry/EntryStack.java index 7626611a2..6e3dbb673 100644 --- a/api/src/main/java/me/shedaniel/rei/api/common/entry/EntryStack.java +++ b/api/src/main/java/me/shedaniel/rei/api/common/entry/EntryStack.java @@ -144,7 +144,8 @@ public interface EntryStack extends TextRepresentable, Renderer { * @return the saved tag * @throws UnsupportedOperationException if the {@link EntryDefinition} does not support saving to a tag * @see EntrySerializer#supportSaving() - * @see EntryIngredient#save() + * @see EntryIngredient#saveIngredient() + * @since 8.3 */ @Nullable default CompoundTag saveStack() { @@ -157,7 +158,7 @@ public interface EntryStack extends TextRepresentable, Renderer { * @return the saved tag * @throws UnsupportedOperationException if the {@link EntryDefinition} does not support saving to a tag * @see EntrySerializer#supportSaving() - * @see EntryIngredient#save() + * @see EntryIngredient#saveIngredient() * @deprecated use {@link #saveStack()} instead */ @Nullable diff --git a/api/src/main/java/me/shedaniel/rei/api/common/util/EntryIngredients.java b/api/src/main/java/me/shedaniel/rei/api/common/util/EntryIngredients.java index b33a3c231..a0231a40c 100644 --- a/api/src/main/java/me/shedaniel/rei/api/common/util/EntryIngredients.java +++ b/api/src/main/java/me/shedaniel/rei/api/common/util/EntryIngredients.java @@ -146,7 +146,7 @@ public final class EntryIngredients { public static ListTag save(List ingredients) { ListTag listTag = new ListTag(); for (EntryIngredient ingredient : ingredients) { - listTag.add(ingredient.save()); + listTag.add(ingredient.saveIngredient()); } return listTag; } diff --git a/default-plugin/src/main/java/me/shedaniel/rei/plugin/common/displays/DefaultInformationDisplay.java b/default-plugin/src/main/java/me/shedaniel/rei/plugin/common/displays/DefaultInformationDisplay.java index 156792870..0d287020f 100644 --- a/default-plugin/src/main/java/me/shedaniel/rei/plugin/common/displays/DefaultInformationDisplay.java +++ b/default-plugin/src/main/java/me/shedaniel/rei/plugin/common/displays/DefaultInformationDisplay.java @@ -103,7 +103,7 @@ public class DefaultInformationDisplay implements Display { return new DisplaySerializer() { @Override public CompoundTag save(CompoundTag tag, DefaultInformationDisplay display) { - tag.put("stacks", display.getEntryStacks().save()); + tag.put("stacks", display.getEntryStacks().saveIngredient()); tag.putString("name", Component.Serializer.toJson(display.getName())); ListTag descriptions = new ListTag(); for (Component text : display.getTexts()) { diff --git a/default-plugin/src/main/java/me/shedaniel/rei/plugin/common/displays/brewing/DefaultBrewingDisplay.java b/default-plugin/src/main/java/me/shedaniel/rei/plugin/common/displays/brewing/DefaultBrewingDisplay.java index 25009039b..82539fdef 100644 --- a/default-plugin/src/main/java/me/shedaniel/rei/plugin/common/displays/brewing/DefaultBrewingDisplay.java +++ b/default-plugin/src/main/java/me/shedaniel/rei/plugin/common/displays/brewing/DefaultBrewingDisplay.java @@ -96,9 +96,9 @@ public class DefaultBrewingDisplay implements Display { return new DisplaySerializer() { @Override public CompoundTag save(CompoundTag tag, DefaultBrewingDisplay display) { - tag.put("input", display.input.save()); - tag.put("reactant", display.reactant.save()); - tag.put("output", display.output.save()); + tag.put("input", display.input.saveIngredient()); + tag.put("reactant", display.reactant.saveIngredient()); + tag.put("output", display.output.saveStack()); return tag; } diff --git a/runtime/src/main/java/me/shedaniel/rei/impl/common/entry/EntryIngredientImpl.java b/runtime/src/main/java/me/shedaniel/rei/impl/common/entry/EntryIngredientImpl.java index 1f79bbbdb..2a512718d 100644 --- a/runtime/src/main/java/me/shedaniel/rei/impl/common/entry/EntryIngredientImpl.java +++ b/runtime/src/main/java/me/shedaniel/rei/impl/common/entry/EntryIngredientImpl.java @@ -348,7 +348,7 @@ public enum EntryIngredientImpl implements Internals.EntryIngredientProvider { @Override public ListTag save() { ListTag listTag = new ListTag(); - listTag.add(stack.save()); + listTag.add(stack.saveStack()); return listTag; } @@ -454,7 +454,7 @@ public enum EntryIngredientImpl implements Internals.EntryIngredientProvider { public ListTag save() { ListTag listTag = new ListTag(); for (EntryStack stack : array) { - listTag.add(stack.save()); + listTag.add(stack.saveStack()); } return listTag; } diff --git a/runtime/src/main/java/me/shedaniel/rei/plugin/client/runtime/DefaultClientRuntimePlugin.java b/runtime/src/main/java/me/shedaniel/rei/plugin/client/runtime/DefaultClientRuntimePlugin.java index 772f659ff..b57bc6f67 100644 --- a/runtime/src/main/java/me/shedaniel/rei/plugin/client/runtime/DefaultClientRuntimePlugin.java +++ b/runtime/src/main/java/me/shedaniel/rei/plugin/client/runtime/DefaultClientRuntimePlugin.java @@ -195,7 +195,7 @@ public class DefaultClientRuntimePlugin implements REIClientPlugin { @Override public CompoundTag save(EntryStackFavoriteEntry entry, CompoundTag tag) { - tag.put(key, entry.stack.save()); + tag.put(key, entry.stack.saveStack()); return tag; } } -- cgit