mirror of
https://github.com/PaperMC/Paper.git
synced 2024-11-29 11:42:55 +01:00
77a5779e24
Upstream has released updates that appear to apply and compile correctly. This update has not been tested by PaperMC and as with ANY update, please do your own testing Bukkit Changes: 2ec53f49 PR-1050: Fix empty result check for Complex Recipes 10671012 PR-1044: Add CrafterCraftEvent 4d87ffe0 Use correct method in JavaDoc ae5e5817 SPIGOT-7850: Add API for Bogged shear state 46b6d445 SPIGOT-7837: Support data pack banner patterns d5d0cefc Fix JavaDoc error b3c2b83d PR-1036: Add API for InventoryView derivatives 1fe2c75a SPIGOT-7809: Add ShieldMeta CraftBukkit Changes: 8ee6fd1b8 SPIGOT-7857: Improve ItemMeta block data deserialization 8f26c30c6 SPIGOT-7857: Fix spurious internal NBT tag when deserializing BlockStateMeta 759061b93 SPIGOT-7855: Fire does not spread or burn blocks 00fc9fb64 SPIGOT-7853: AnvilInventory#getRepairCost() always returns 0 7501e2e04 PR-1450: Add CrafterCraftEvent 8c51673e7 SPIGOT-5731: PortalCreateEvent#getEntity returns null for nether portals ignited by flint and steel d53d0d0b1 PR-1456: Fix inverted logic in CraftCrafterView#setSlotDisabled 682a678c8 SPIGOT-7850: Add API for Bogged shear state fccf5243a SPIGOT-7837: Support data pack banner patterns 9c3bd4390 PR-1431: Add API for InventoryView derivatives 0cc6acbc4 SPIGOT-7849: Fix FoodComponent serialize with "using-converts-to" using null 2c5474952 Don't rely on tags for CraftItemMetas 20d107e46 SPIGOT-7846: Fix ItemMeta for hanging signs 76f59e315 Remove redundant clone in Dropper InventoryMoveItemEvent e61a53d25 SPIGOT-7817: Call InventoryMoveItemEvent for Crafters 894682e2d SPIGOT-7839: Remove redundant Java version checks 2c12b2187 SPIGOT-7809: Add ShieldMeta and fix setting shield base colours Spigot Changes: fb8fb722 Rebuild patches 34bd42b7 SPIGOT-7835: Fix issue with custom hopper settings
116 lines
7.3 KiB
Diff
116 lines
7.3 KiB
Diff
From 0000000000000000000000000000000000000000 Mon Sep 17 00:00:00 2001
|
|
From: Jake Potrebic <jake.m.potrebic@gmail.com>
|
|
Date: Sun, 12 May 2024 15:49:36 -0700
|
|
Subject: [PATCH] Fix issues with Recipe API
|
|
|
|
|
|
diff --git a/src/main/java/net/minecraft/world/item/crafting/ShapedRecipe.java b/src/main/java/net/minecraft/world/item/crafting/ShapedRecipe.java
|
|
index 63cf2b66f51df68aa3f6d98c69368ce454869d64..1bf54b0142fe41b29b21c8b97d3f52bb24a36a92 100644
|
|
--- a/src/main/java/net/minecraft/world/item/crafting/ShapedRecipe.java
|
|
+++ b/src/main/java/net/minecraft/world/item/crafting/ShapedRecipe.java
|
|
@@ -90,7 +90,7 @@ public class ShapedRecipe extends io.papermc.paper.inventory.recipe.RecipeBookEx
|
|
char c = 'a';
|
|
for (Ingredient list : this.pattern.ingredients()) {
|
|
RecipeChoice choice = CraftRecipe.toBukkit(list);
|
|
- if (choice != null) {
|
|
+ if (choice != RecipeChoice.empty()) { // Paper
|
|
recipe.setIngredient(c, choice);
|
|
}
|
|
|
|
diff --git a/src/main/java/org/bukkit/craftbukkit/inventory/CraftRecipe.java b/src/main/java/org/bukkit/craftbukkit/inventory/CraftRecipe.java
|
|
index 6ba29875d78ede4aa7978ff689e588f7fed11528..c76c78bb7757d407102271463e14716a1b012deb 100644
|
|
--- a/src/main/java/org/bukkit/craftbukkit/inventory/CraftRecipe.java
|
|
+++ b/src/main/java/org/bukkit/craftbukkit/inventory/CraftRecipe.java
|
|
@@ -29,6 +29,10 @@ public interface CraftRecipe extends Recipe {
|
|
} else if (bukkit instanceof RecipeChoice.ExactChoice) {
|
|
stack = new Ingredient(((RecipeChoice.ExactChoice) bukkit).getChoices().stream().map((mat) -> new net.minecraft.world.item.crafting.Ingredient.ItemValue(CraftItemStack.asNMSCopy(mat))));
|
|
stack.exact = true;
|
|
+ // Paper start - support "empty" choices
|
|
+ } else if (bukkit == RecipeChoice.empty()) {
|
|
+ stack = Ingredient.EMPTY;
|
|
+ // Paper end
|
|
} else {
|
|
throw new IllegalArgumentException("Unknown recipe stack instance " + bukkit);
|
|
}
|
|
@@ -45,7 +49,7 @@ public interface CraftRecipe extends Recipe {
|
|
list.getItems();
|
|
|
|
if (list.itemStacks.length == 0) {
|
|
- return null;
|
|
+ return RecipeChoice.empty(); // Paper - null breaks API contracts
|
|
}
|
|
|
|
if (list.exact) {
|
|
diff --git a/src/main/java/org/bukkit/craftbukkit/inventory/CraftSmithingTransformRecipe.java b/src/main/java/org/bukkit/craftbukkit/inventory/CraftSmithingTransformRecipe.java
|
|
index 38690b28b6f67624d68877c1e89ebe30b402b233..3aec771478a6b17353d57e82baac53dd24779e7b 100644
|
|
--- a/src/main/java/org/bukkit/craftbukkit/inventory/CraftSmithingTransformRecipe.java
|
|
+++ b/src/main/java/org/bukkit/craftbukkit/inventory/CraftSmithingTransformRecipe.java
|
|
@@ -30,6 +30,6 @@ public class CraftSmithingTransformRecipe extends SmithingTransformRecipe implem
|
|
public void addToCraftingManager() {
|
|
ItemStack result = this.getResult();
|
|
|
|
- MinecraftServer.getServer().getRecipeManager().addRecipe(new RecipeHolder<>(CraftNamespacedKey.toMinecraft(this.getKey()), new net.minecraft.world.item.crafting.SmithingTransformRecipe(this.toNMS(this.getTemplate(), true), this.toNMS(this.getBase(), true), this.toNMS(this.getAddition(), true), CraftItemStack.asNMSCopy(result), this.willCopyDataComponents()))); // Paper - Option to prevent data components copy
|
|
+ MinecraftServer.getServer().getRecipeManager().addRecipe(new RecipeHolder<>(CraftNamespacedKey.toMinecraft(this.getKey()), new net.minecraft.world.item.crafting.SmithingTransformRecipe(this.toNMS(this.getTemplate(), false), this.toNMS(this.getBase(), false), this.toNMS(this.getAddition(), false), CraftItemStack.asNMSCopy(result), this.willCopyDataComponents()))); // Paper - Option to prevent data components copy & support empty RecipeChoice
|
|
}
|
|
}
|
|
diff --git a/src/main/java/org/bukkit/craftbukkit/inventory/CraftSmithingTrimRecipe.java b/src/main/java/org/bukkit/craftbukkit/inventory/CraftSmithingTrimRecipe.java
|
|
index 5d7782b168138383c606a2c52fbdebe1732364ac..61af2fe3534ff67f10310c6c7dec39cff0f93ee3 100644
|
|
--- a/src/main/java/org/bukkit/craftbukkit/inventory/CraftSmithingTrimRecipe.java
|
|
+++ b/src/main/java/org/bukkit/craftbukkit/inventory/CraftSmithingTrimRecipe.java
|
|
@@ -28,6 +28,6 @@ public class CraftSmithingTrimRecipe extends SmithingTrimRecipe implements Craft
|
|
|
|
@Override
|
|
public void addToCraftingManager() {
|
|
- MinecraftServer.getServer().getRecipeManager().addRecipe(new RecipeHolder<>(CraftNamespacedKey.toMinecraft(this.getKey()), new net.minecraft.world.item.crafting.SmithingTrimRecipe(this.toNMS(this.getTemplate(), true), this.toNMS(this.getBase(), true), this.toNMS(this.getAddition(), true), this.willCopyDataComponents()))); // Paper - Option to prevent data components copy
|
|
+ MinecraftServer.getServer().getRecipeManager().addRecipe(new RecipeHolder<>(CraftNamespacedKey.toMinecraft(this.getKey()), new net.minecraft.world.item.crafting.SmithingTrimRecipe(this.toNMS(this.getTemplate(), false), this.toNMS(this.getBase(), false), this.toNMS(this.getAddition(), false), this.willCopyDataComponents()))); // Paper - Option to prevent data components copy & support empty RecipeChoice
|
|
}
|
|
}
|
|
diff --git a/src/test/java/io/papermc/paper/inventory/recipe/TestRecipeChoice.java b/src/test/java/io/papermc/paper/inventory/recipe/TestRecipeChoice.java
|
|
new file mode 100644
|
|
index 0000000000000000000000000000000000000000..b6816485a2360b936c049b398183658ee18813ec
|
|
--- /dev/null
|
|
+++ b/src/test/java/io/papermc/paper/inventory/recipe/TestRecipeChoice.java
|
|
@@ -0,0 +1,24 @@
|
|
+package io.papermc.paper.inventory.recipe;
|
|
+
|
|
+import java.util.Iterator;
|
|
+import org.bukkit.Bukkit;
|
|
+import org.bukkit.inventory.Recipe;
|
|
+import org.bukkit.support.AbstractTestingBase;
|
|
+import org.junit.jupiter.api.Test;
|
|
+
|
|
+import static org.junit.jupiter.api.Assertions.assertDoesNotThrow;
|
|
+import static org.junit.jupiter.api.Assertions.assertTrue;
|
|
+
|
|
+class TestRecipeChoice extends AbstractTestingBase {
|
|
+
|
|
+ @Test
|
|
+ void testRecipeChoices() {
|
|
+ final Iterator<Recipe> iter = Bukkit.recipeIterator();
|
|
+ boolean foundRecipes = false;
|
|
+ while (iter.hasNext()) {
|
|
+ foundRecipes = true;
|
|
+ assertDoesNotThrow(iter::next, "Failed to convert a recipe to Bukkit recipe!");
|
|
+ }
|
|
+ assertTrue(foundRecipes, "No recipes found!");
|
|
+ }
|
|
+}
|
|
diff --git a/src/test/java/org/bukkit/support/DummyServer.java b/src/test/java/org/bukkit/support/DummyServer.java
|
|
index 6e9ee1b56b4151c31c373e58172055e02fd7875a..11ba7a3db4c56ec00d9ad1ed8e46b242c033fe74 100644
|
|
--- a/src/test/java/org/bukkit/support/DummyServer.java
|
|
+++ b/src/test/java/org/bukkit/support/DummyServer.java
|
|
@@ -104,6 +104,14 @@ public final class DummyServer {
|
|
when(instance.getPluginManager()).thenReturn(pluginManager);
|
|
// paper end - testing additions
|
|
|
|
+ // Paper start - add test for recipe conversion
|
|
+ when(instance.recipeIterator()).thenAnswer(ignored -> {
|
|
+ return com.google.common.collect.Iterators.transform(
|
|
+ AbstractTestingBase.DATA_PACK.getRecipeManager().byType.entries().iterator(),
|
|
+ input -> input.getValue().toBukkitRecipe());
|
|
+ });
|
|
+ // Paper end - add test for recipe conversion
|
|
+
|
|
Bukkit.setServer(instance);
|
|
} catch (Throwable t) {
|
|
throw new Error(t);
|