From 58cbbcd51a384624bf0fbc04bbcfef36a3ad82c6 Mon Sep 17 00:00:00 2001 From: CraftBukkit/Spigot Date: Wed, 6 Dec 2023 20:23:28 +1100 Subject: [PATCH] SPIGOT-7528: Fix certain custom shaped recipes By: md_5 --- .../craftbukkit/inventory/CraftShapedRecipe.java | 13 ++++++++++--- 1 file changed, 10 insertions(+), 3 deletions(-) diff --git a/paper-server/src/main/java/org/bukkit/craftbukkit/inventory/CraftShapedRecipe.java b/paper-server/src/main/java/org/bukkit/craftbukkit/inventory/CraftShapedRecipe.java index 49e6aef9a6..f1391b926f 100644 --- a/paper-server/src/main/java/org/bukkit/craftbukkit/inventory/CraftShapedRecipe.java +++ b/paper-server/src/main/java/org/bukkit/craftbukkit/inventory/CraftShapedRecipe.java @@ -1,7 +1,7 @@ package org.bukkit.craftbukkit.inventory; -import com.google.common.collect.Maps; import java.util.Map; +import java.util.Optional; import net.minecraft.core.NonNullList; import net.minecraft.server.MinecraftServer; import net.minecraft.world.item.crafting.RecipeHolder; @@ -50,8 +50,15 @@ public class CraftShapedRecipe extends ShapedRecipe implements CraftRecipe { public void addToCraftingManager() { String[] shape = this.getShape(); Map ingred = this.getChoiceMap(); - Map data = Maps.transformValues(ingred, (bukkit) -> toNMS(bukkit, false)); + int width = shape[0].length(); + NonNullList data = NonNullList.withSize(shape.length * width, RecipeItemStack.EMPTY); - MinecraftServer.getServer().getRecipeManager().addRecipe(new RecipeHolder<>(CraftNamespacedKey.toMinecraft(this.getKey()), new ShapedRecipes(this.getGroup(), CraftRecipe.getCategory(this.getCategory()), ShapedRecipePattern.of(data, shape), CraftItemStack.asNMSCopy(this.getResult())))); + for (int i = 0; i < shape.length; i++) { + String row = shape[i]; + for (int j = 0; j < row.length(); j++) { + data.set(i * width + j, toNMS(ingred.get(row.charAt(j)), false)); + } + } + MinecraftServer.getServer().getRecipeManager().addRecipe(new RecipeHolder<>(CraftNamespacedKey.toMinecraft(this.getKey()), new ShapedRecipes(this.getGroup(), CraftRecipe.getCategory(this.getCategory()), new ShapedRecipePattern(width, shape.length, data, Optional.empty()), CraftItemStack.asNMSCopy(this.getResult())))); } }