SPIGOT-7770: Fix certain shaped recipes not registering
This commit is contained in:
parent
3f8e4161fd
commit
b2b08f68cf
@ -1,8 +1,8 @@
|
|||||||
package org.bukkit.craftbukkit.inventory;
|
package org.bukkit.craftbukkit.inventory;
|
||||||
|
|
||||||
|
import com.google.common.collect.Maps;
|
||||||
import java.util.Map;
|
import java.util.Map;
|
||||||
import java.util.Optional;
|
import java.util.Objects;
|
||||||
import net.minecraft.core.NonNullList;
|
|
||||||
import net.minecraft.server.MinecraftServer;
|
import net.minecraft.server.MinecraftServer;
|
||||||
import net.minecraft.world.item.crafting.RecipeHolder;
|
import net.minecraft.world.item.crafting.RecipeHolder;
|
||||||
import net.minecraft.world.item.crafting.RecipeItemStack;
|
import net.minecraft.world.item.crafting.RecipeItemStack;
|
||||||
@ -48,17 +48,27 @@ public class CraftShapedRecipe extends ShapedRecipe implements CraftRecipe {
|
|||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void addToCraftingManager() {
|
public void addToCraftingManager() {
|
||||||
String[] shape = this.getShape();
|
|
||||||
Map<Character, org.bukkit.inventory.RecipeChoice> ingred = this.getChoiceMap();
|
Map<Character, org.bukkit.inventory.RecipeChoice> ingred = this.getChoiceMap();
|
||||||
int width = shape[0].length();
|
String[] shape = replaceUndefinedIngredientsWithEmpty(this.getShape(), ingred);
|
||||||
NonNullList<RecipeItemStack> data = NonNullList.withSize(shape.length * width, RecipeItemStack.EMPTY);
|
ingred.values().removeIf(Objects::isNull);
|
||||||
|
Map<Character, RecipeItemStack> data = Maps.transformValues(ingred, (bukkit) -> toNMS(bukkit, false));
|
||||||
|
|
||||||
|
ShapedRecipePattern pattern = ShapedRecipePattern.of(data, shape);
|
||||||
|
MinecraftServer.getServer().getRecipeManager().addRecipe(new RecipeHolder<>(CraftNamespacedKey.toMinecraft(this.getKey()), new ShapedRecipes(this.getGroup(), CraftRecipe.getCategory(this.getCategory()), pattern, CraftItemStack.asNMSCopy(this.getResult()))));
|
||||||
|
}
|
||||||
|
|
||||||
|
private static String[] replaceUndefinedIngredientsWithEmpty(String[] shape, Map<Character, org.bukkit.inventory.RecipeChoice> ingredients) {
|
||||||
for (int i = 0; i < shape.length; i++) {
|
for (int i = 0; i < shape.length; i++) {
|
||||||
String row = shape[i];
|
String row = shape[i];
|
||||||
for (int j = 0; j < row.length(); j++) {
|
StringBuilder filteredRow = new StringBuilder(row.length());
|
||||||
data.set(i * width + j, toNMS(ingred.get(row.charAt(j)), false));
|
|
||||||
}
|
for (char character : row.toCharArray()) {
|
||||||
}
|
filteredRow.append(ingredients.get(character) == null ? ' ' : character);
|
||||||
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()))));
|
}
|
||||||
|
|
||||||
|
shape[i] = filteredRow.toString();
|
||||||
|
}
|
||||||
|
|
||||||
|
return shape;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
Loading…
x
Reference in New Issue
Block a user