SPIGOT-5802: Add SmithingRecipe API

This commit is contained in:
md_5 2020-06-25 12:41:55 +10:00
parent ab3875418c
commit 76d2add0bb
No known key found for this signature in database
GPG Key ID: E8E901AC7C617C11
2 changed files with 63 additions and 0 deletions

View File

@ -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<IInventory> {
@@ -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<RecipeSmithing> {
public a() {}

View File

@ -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)));
}
}