From 76d2add0bbb0955f07034f6f0fad27d719f1c3a2 Mon Sep 17 00:00:00 2001 From: md_5 Date: Thu, 25 Jun 2020 12:41:55 +1000 Subject: [PATCH] SPIGOT-5802: Add SmithingRecipe API --- nms-patches/RecipeSmithing.patch | 34 +++++++++++++++++++ .../inventory/CraftSmithingRecipe.java | 29 ++++++++++++++++ 2 files changed, 63 insertions(+) create mode 100644 nms-patches/RecipeSmithing.patch create mode 100644 src/main/java/org/bukkit/craftbukkit/inventory/CraftSmithingRecipe.java diff --git a/nms-patches/RecipeSmithing.patch b/nms-patches/RecipeSmithing.patch new file mode 100644 index 0000000000..ee4bce0341 --- /dev/null +++ b/nms-patches/RecipeSmithing.patch @@ -0,0 +1,34 @@ +--- a/net/minecraft/server/RecipeSmithing.java ++++ b/net/minecraft/server/RecipeSmithing.java +@@ -2,6 +2,13 @@ + + import com.google.gson.JsonElement; + import com.google.gson.JsonObject; ++// CraftBukkit start ++import org.bukkit.craftbukkit.inventory.CraftItemStack; ++import org.bukkit.craftbukkit.inventory.CraftRecipe; ++import org.bukkit.craftbukkit.inventory.CraftSmithingRecipe; ++import org.bukkit.craftbukkit.util.CraftNamespacedKey; ++import org.bukkit.inventory.Recipe; ++// CraftBukkit end + + public class RecipeSmithing implements IRecipe { + +@@ -58,6 +65,17 @@ + return Recipes.SMITHING; + } + ++ // CraftBukkit start ++ @Override ++ public Recipe toBukkitRecipe() { ++ CraftItemStack result = CraftItemStack.asCraftMirror(this.c); ++ ++ CraftSmithingRecipe recipe = new CraftSmithingRecipe(CraftNamespacedKey.fromMinecraft(this.d), result, CraftRecipe.toBukkit(this.a), CraftRecipe.toBukkit(this.b)); ++ ++ return recipe; ++ } ++ // CraftBukkit end ++ + public static class a implements RecipeSerializer { + + public a() {} diff --git a/src/main/java/org/bukkit/craftbukkit/inventory/CraftSmithingRecipe.java b/src/main/java/org/bukkit/craftbukkit/inventory/CraftSmithingRecipe.java new file mode 100644 index 0000000000..7364e58f0e --- /dev/null +++ b/src/main/java/org/bukkit/craftbukkit/inventory/CraftSmithingRecipe.java @@ -0,0 +1,29 @@ +package org.bukkit.craftbukkit.inventory; + +import net.minecraft.server.MinecraftServer; +import org.bukkit.NamespacedKey; +import org.bukkit.craftbukkit.util.CraftNamespacedKey; +import org.bukkit.inventory.ItemStack; +import org.bukkit.inventory.RecipeChoice; +import org.bukkit.inventory.SmithingRecipe; + +public class CraftSmithingRecipe extends SmithingRecipe implements CraftRecipe { + public CraftSmithingRecipe(NamespacedKey key, ItemStack result, RecipeChoice base, RecipeChoice addition) { + super(key, result, base, addition); + } + + public static CraftSmithingRecipe fromBukkitRecipe(SmithingRecipe recipe) { + if (recipe instanceof CraftSmithingRecipe) { + return (CraftSmithingRecipe) recipe; + } + CraftSmithingRecipe ret = new CraftSmithingRecipe(recipe.getKey(), recipe.getResult(), recipe.getBase(), recipe.getAddition()); + return ret; + } + + @Override + public void addToCraftingManager() { + ItemStack result = this.getResult(); + + MinecraftServer.getServer().getCraftingManager().addRecipe(new net.minecraft.server.RecipeSmithing(CraftNamespacedKey.toMinecraft(this.getKey()), toNMS(this.getBase(), true), toNMS(this.getAddition(), true), CraftItemStack.asNMSCopy(result))); + } +}