SPIGOT-7528: Fix certain custom shaped recipes

By: md_5 <git@md-5.net>
This commit is contained in:
CraftBukkit/Spigot 2023-12-06 20:23:28 +11:00
parent dd8ca5c2dc
commit 58cbbcd51a

View file

@ -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<Character, org.bukkit.inventory.RecipeChoice> ingred = this.getChoiceMap();
Map<Character, RecipeItemStack> data = Maps.transformValues(ingred, (bukkit) -> toNMS(bukkit, false));
int width = shape[0].length();
NonNullList<RecipeItemStack> 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()))));
}
}