mirror of
https://github.com/PaperMC/Paper.git
synced 2024-11-25 20:16:19 +01:00
SPIGOT-4438: Add choice API to furnace recipes
This commit is contained in:
parent
96c461b3a5
commit
f0398e444e
@ -1,17 +1,23 @@
|
|||||||
--- a/net/minecraft/server/FurnaceRecipe.java
|
--- a/net/minecraft/server/FurnaceRecipe.java
|
||||||
+++ b/net/minecraft/server/FurnaceRecipe.java
|
+++ b/net/minecraft/server/FurnaceRecipe.java
|
||||||
@@ -2,6 +2,10 @@
|
@@ -2,6 +2,16 @@
|
||||||
|
|
||||||
import com.google.gson.JsonElement;
|
import com.google.gson.JsonElement;
|
||||||
import com.google.gson.JsonObject;
|
import com.google.gson.JsonObject;
|
||||||
|
+// CraftBukkit start
|
||||||
|
+import java.util.ArrayList;
|
||||||
|
+import java.util.List;
|
||||||
+import org.bukkit.craftbukkit.inventory.CraftFurnaceRecipe;
|
+import org.bukkit.craftbukkit.inventory.CraftFurnaceRecipe;
|
||||||
+import org.bukkit.craftbukkit.inventory.CraftItemStack;
|
+import org.bukkit.craftbukkit.inventory.CraftItemStack;
|
||||||
|
+import org.bukkit.craftbukkit.util.CraftMagicNumbers;
|
||||||
+import org.bukkit.craftbukkit.util.CraftNamespacedKey;
|
+import org.bukkit.craftbukkit.util.CraftNamespacedKey;
|
||||||
+import org.bukkit.inventory.Recipe;
|
+import org.bukkit.inventory.Recipe;
|
||||||
|
+import org.bukkit.inventory.RecipeChoice;
|
||||||
|
+// CraftBukkit end
|
||||||
|
|
||||||
public class FurnaceRecipe implements IRecipe {
|
public class FurnaceRecipe implements IRecipe {
|
||||||
|
|
||||||
@@ -56,6 +60,19 @@
|
@@ -56,6 +66,23 @@
|
||||||
return this.key;
|
return this.key;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -20,9 +26,13 @@
|
|||||||
+ CraftItemStack result = CraftItemStack.asCraftMirror(this.result);
|
+ CraftItemStack result = CraftItemStack.asCraftMirror(this.result);
|
||||||
+ RecipeItemStack list = this.ingredient;
|
+ RecipeItemStack list = this.ingredient;
|
||||||
+ list.buildChoices();
|
+ list.buildChoices();
|
||||||
+ net.minecraft.server.ItemStack stack = list.choices[0];
|
|
||||||
+
|
+
|
||||||
+ CraftFurnaceRecipe recipe = new CraftFurnaceRecipe(CraftNamespacedKey.fromMinecraft(this.key), result, CraftItemStack.asCraftMirror(stack), this.experience, this.cookingTime);
|
+ List<org.bukkit.Material> choices = new ArrayList<>(list.choices.length);
|
||||||
|
+ for (ItemStack i : list.choices) {
|
||||||
|
+ choices.add(CraftMagicNumbers.getMaterial(i.getItem()));
|
||||||
|
+ }
|
||||||
|
+
|
||||||
|
+ CraftFurnaceRecipe recipe = new CraftFurnaceRecipe(CraftNamespacedKey.fromMinecraft(this.key), result, new RecipeChoice.MaterialChoice(choices), this.experience, this.cookingTime);
|
||||||
+ recipe.setGroup(this.group);
|
+ recipe.setGroup(this.group);
|
||||||
+
|
+
|
||||||
+ return recipe;
|
+ return recipe;
|
||||||
@ -31,7 +41,7 @@
|
|||||||
public static class a implements RecipeSerializer<FurnaceRecipe> {
|
public static class a implements RecipeSerializer<FurnaceRecipe> {
|
||||||
|
|
||||||
public a() {}
|
public a() {}
|
||||||
@@ -106,11 +123,11 @@
|
@@ -106,11 +133,11 @@
|
||||||
return "smelting";
|
return "smelting";
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -1,24 +1,22 @@
|
|||||||
package org.bukkit.craftbukkit.inventory;
|
package org.bukkit.craftbukkit.inventory;
|
||||||
|
|
||||||
import java.util.stream.Stream;
|
|
||||||
import net.minecraft.server.MinecraftServer;
|
import net.minecraft.server.MinecraftServer;
|
||||||
import net.minecraft.server.RecipeItemStack;
|
|
||||||
|
|
||||||
import org.bukkit.NamespacedKey;
|
import org.bukkit.NamespacedKey;
|
||||||
import org.bukkit.craftbukkit.util.CraftNamespacedKey;
|
import org.bukkit.craftbukkit.util.CraftNamespacedKey;
|
||||||
import org.bukkit.inventory.FurnaceRecipe;
|
import org.bukkit.inventory.FurnaceRecipe;
|
||||||
import org.bukkit.inventory.ItemStack;
|
import org.bukkit.inventory.ItemStack;
|
||||||
|
import org.bukkit.inventory.RecipeChoice;
|
||||||
|
|
||||||
public class CraftFurnaceRecipe extends FurnaceRecipe implements CraftRecipe {
|
public class CraftFurnaceRecipe extends FurnaceRecipe implements CraftRecipe {
|
||||||
public CraftFurnaceRecipe(NamespacedKey key, ItemStack result, ItemStack source, float experience, int cookingTime) {
|
public CraftFurnaceRecipe(NamespacedKey key, ItemStack result, RecipeChoice source, float experience, int cookingTime) {
|
||||||
super(key, result, source.getType(), source.getDurability(), experience, cookingTime);
|
super(key, result, source, experience, cookingTime);
|
||||||
}
|
}
|
||||||
|
|
||||||
public static CraftFurnaceRecipe fromBukkitRecipe(FurnaceRecipe recipe) {
|
public static CraftFurnaceRecipe fromBukkitRecipe(FurnaceRecipe recipe) {
|
||||||
if (recipe instanceof CraftFurnaceRecipe) {
|
if (recipe instanceof CraftFurnaceRecipe) {
|
||||||
return (CraftFurnaceRecipe) recipe;
|
return (CraftFurnaceRecipe) recipe;
|
||||||
}
|
}
|
||||||
CraftFurnaceRecipe ret = new CraftFurnaceRecipe(recipe.getKey(), recipe.getResult(), recipe.getInput(), recipe.getExperience(), recipe.getCookingTime());
|
CraftFurnaceRecipe ret = new CraftFurnaceRecipe(recipe.getKey(), recipe.getResult(), recipe.getInputChoice(), recipe.getExperience(), recipe.getCookingTime());
|
||||||
ret.setGroup(recipe.getGroup());
|
ret.setGroup(recipe.getGroup());
|
||||||
return ret;
|
return ret;
|
||||||
}
|
}
|
||||||
@ -26,8 +24,7 @@ public class CraftFurnaceRecipe extends FurnaceRecipe implements CraftRecipe {
|
|||||||
@Override
|
@Override
|
||||||
public void addToCraftingManager() {
|
public void addToCraftingManager() {
|
||||||
ItemStack result = this.getResult();
|
ItemStack result = this.getResult();
|
||||||
RecipeItemStack input = new RecipeItemStack(Stream.of(new RecipeItemStack.StackProvider(CraftItemStack.asNMSCopy(this.getInput()))));
|
|
||||||
|
|
||||||
MinecraftServer.getServer().getCraftingManager().a(new net.minecraft.server.FurnaceRecipe(CraftNamespacedKey.toMinecraft(this.getKey()), this.getGroup(), input, CraftItemStack.asNMSCopy(result), getExperience(), getCookingTime()));
|
MinecraftServer.getServer().getCraftingManager().a(new net.minecraft.server.FurnaceRecipe(CraftNamespacedKey.toMinecraft(this.getKey()), this.getGroup(), toNMS(this.getInputChoice()), CraftItemStack.asNMSCopy(result), getExperience(), getCookingTime()));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user