M Xplat/src/main/java/vazkii/patchouli/common/recipe/BookRecipeSerializer.java => Xplat/src/main/java/vazkii/patchouli/common/recipe/BookRecipeSerializer.java +2 -1
@@ 13,10 13,11 @@ import vazkii.patchouli.common.book.BookRegistry;
import vazkii.patchouli.common.item.PatchouliItems;
import org.jetbrains.annotations.NotNull;
+import org.jetbrains.annotations.Nullable;
import java.util.function.BiFunction;
-public record BookRecipeSerializer<T extends Recipe<?>, U extends T> (RecipeSerializer<T> compose, BiFunction<T, ResourceLocation, U> converter) implements RecipeSerializer<U> {
+public record BookRecipeSerializer<T extends Recipe<?>, U extends T> (RecipeSerializer<T> compose, BiFunction<T, @Nullable ResourceLocation, U> converter) implements RecipeSerializer<U> {
@Override
@NotNull
public U fromJson(@NotNull ResourceLocation id, @NotNull JsonObject json) {
M Xplat/src/main/java/vazkii/patchouli/common/recipe/ShapedBookRecipe.java => Xplat/src/main/java/vazkii/patchouli/common/recipe/ShapedBookRecipe.java +17 -4
@@ 1,12 1,18 @@
package vazkii.patchouli.common.recipe;
+import com.google.common.base.Preconditions;
+
+import net.minecraft.core.RegistryAccess;
import net.minecraft.resources.ResourceLocation;
+import net.minecraft.world.item.ItemStack;
import net.minecraft.world.item.crafting.CraftingBookCategory;
import net.minecraft.world.item.crafting.RecipeSerializer;
import net.minecraft.world.item.crafting.ShapedRecipe;
import vazkii.patchouli.api.PatchouliAPI;
+import org.jetbrains.annotations.Nullable;
+
/**
* Recipe type for shaped book recipes.
* The format is the same as vanilla shaped recipes, but the
@@ 15,10 21,17 @@ import vazkii.patchouli.api.PatchouliAPI;
public class ShapedBookRecipe extends ShapedRecipe {
public static final RecipeSerializer<ShapedBookRecipe> SERIALIZER = new BookRecipeSerializer<>(RecipeSerializer.SHAPED_RECIPE, ShapedBookRecipe::new);
- public ShapedBookRecipe(ShapedRecipe compose, ResourceLocation outputBook) {
- super(compose.getId(), compose.getGroup(), CraftingBookCategory.MISC,
- compose.getWidth(), compose.getHeight(), compose.getIngredients(),
- PatchouliAPI.get().getBookStack(outputBook));
+ public ShapedBookRecipe(ShapedRecipe compose, @Nullable ResourceLocation outputBook) {
+ super(compose.getId(), compose.getGroup(), CraftingBookCategory.MISC, compose.getWidth(), compose.getHeight(), compose.getIngredients(), getOutputBook(compose, outputBook));
+ }
+
+ private static ItemStack getOutputBook(ShapedRecipe compose, @Nullable ResourceLocation outputBook) {
+ Preconditions.checkArgument(compose.getClass() == ShapedRecipe.class, "Must be exactly ShapedRecipe");
+ if (outputBook != null) {
+ return PatchouliAPI.get().getBookStack(outputBook);
+ }
+ // The vanilla ShapedRecipe implementation never uses the passed RegistryAccess, so this is ok.
+ return compose.getResultItem(RegistryAccess.EMPTY);
}
@Override
M Xplat/src/main/java/vazkii/patchouli/common/recipe/ShapelessBookRecipe.java => Xplat/src/main/java/vazkii/patchouli/common/recipe/ShapelessBookRecipe.java +17 -4
@@ 1,12 1,18 @@
package vazkii.patchouli.common.recipe;
+import com.google.common.base.Preconditions;
+
+import net.minecraft.core.RegistryAccess;
import net.minecraft.resources.ResourceLocation;
+import net.minecraft.world.item.ItemStack;
import net.minecraft.world.item.crafting.CraftingBookCategory;
import net.minecraft.world.item.crafting.RecipeSerializer;
import net.minecraft.world.item.crafting.ShapelessRecipe;
import vazkii.patchouli.api.PatchouliAPI;
+import org.jetbrains.annotations.Nullable;
+
/**
* Recipe type for shapeless book recipes.
* The format is the same as vanilla shapeless recipes, but the
@@ 15,10 21,17 @@ import vazkii.patchouli.api.PatchouliAPI;
public class ShapelessBookRecipe extends ShapelessRecipe {
public static final RecipeSerializer<ShapelessBookRecipe> SERIALIZER = new BookRecipeSerializer<>(RecipeSerializer.SHAPELESS_RECIPE, ShapelessBookRecipe::new);
- public ShapelessBookRecipe(ShapelessRecipe compose, ResourceLocation outputBook) {
- super(compose.getId(), compose.getGroup(), CraftingBookCategory.MISC,
- PatchouliAPI.get().getBookStack(outputBook),
- compose.getIngredients());
+ public ShapelessBookRecipe(ShapelessRecipe compose, @Nullable ResourceLocation outputBook) {
+ super(compose.getId(), compose.getGroup(), CraftingBookCategory.MISC, getOutputBook(compose, outputBook), compose.getIngredients());
+ }
+
+ private static ItemStack getOutputBook(ShapelessRecipe compose, @Nullable ResourceLocation outputBook) {
+ Preconditions.checkArgument(compose.getClass() == ShapelessRecipe.class, "Must be exactly ShapelessRecipe");
+ if (outputBook != null) {
+ return PatchouliAPI.get().getBookStack(outputBook);
+ }
+ // The vanilla ShapelessRecipe implementation never uses the passed RegistryAccess, so this is ok.
+ return compose.getResultItem(RegistryAccess.EMPTY);
}
@Override