diff options
| author | shedaniel <daniel@shedaniel.me> | 2022-06-20 17:23:47 +0800 |
|---|---|---|
| committer | shedaniel <daniel@shedaniel.me> | 2022-06-20 17:28:19 +0800 |
| commit | 4213c947730e4949b7cba5ea6bb249c9be035ab0 (patch) | |
| tree | adb08b3bdf5a79bead988f06bcdf904ae1b1bdb8 | |
| parent | d5d75a0b30c881850b8a96e399e2919b0b1b7bd5 (diff) | |
| download | RoughlyEnoughItems-4213c947730e4949b7cba5ea6bb249c9be035ab0.tar.gz RoughlyEnoughItems-4213c947730e4949b7cba5ea6bb249c9be035ab0.tar.bz2 RoughlyEnoughItems-4213c947730e4949b7cba5ea6bb249c9be035ab0.zip | |
Migrate EntryIngredient and EntryStack save() to saveIngredient() and saveStack()
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<T> { @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<EntryStack<?>> { /** * Returns an empty entry ingredient. This is the singleton instance of {@link EntryIngredient} that is @@ -121,6 +123,12 @@ public interface EntryIngredient extends List<EntryStack<?>> { return Internals.getEntryIngredientProvider().of(stacks); } + /** + * Returns a {@link Collector} that accumulates the stacks into a + * new {@link EntryIngredient}. + * + * @return the collector + */ static Collector<EntryStack<?>, ?, EntryIngredient> collector() { return Collectors.collectingAndThen(Collectors.toList(), EntryIngredient::of); } @@ -132,7 +140,22 @@ public interface EntryIngredient extends List<EntryStack<?>> { * @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 bdc47362b..55864b952 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<T> 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<T> 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<EntryIngredient> 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 fbae4fb85..dfa768002 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 @@ -104,7 +104,7 @@ public class DefaultInformationDisplay implements Display { return new DisplaySerializer<DefaultInformationDisplay>() { @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 dda76169c..eb6dc3df1 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<DefaultBrewingDisplay>() { @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 b10ea8b66..0e7162c77 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 @@ -194,7 +194,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; } } |
