diff options
Diffstat (limited to 'patch-remap/mache-spigotflower/net/minecraft/world/item/crafting/ShapedRecipe.java.patch')
-rw-r--r-- | patch-remap/mache-spigotflower/net/minecraft/world/item/crafting/ShapedRecipe.java.patch | 235 |
1 files changed, 235 insertions, 0 deletions
diff --git a/patch-remap/mache-spigotflower/net/minecraft/world/item/crafting/ShapedRecipe.java.patch b/patch-remap/mache-spigotflower/net/minecraft/world/item/crafting/ShapedRecipe.java.patch new file mode 100644 index 0000000000..28bf8b2493 --- /dev/null +++ b/patch-remap/mache-spigotflower/net/minecraft/world/item/crafting/ShapedRecipe.java.patch @@ -0,0 +1,235 @@ +--- a/net/minecraft/world/item/crafting/ShapedRecipe.java ++++ b/net/minecraft/world/item/crafting/ShapedRecipe.java +@@ -6,11 +6,18 @@ + import net.minecraft.core.RegistryAccess; + import net.minecraft.network.FriendlyByteBuf; + import net.minecraft.util.ExtraCodecs; +-import net.minecraft.world.inventory.CraftingContainer; ++import net.minecraft.world.inventory.InventoryCrafting; + import net.minecraft.world.item.ItemStack; + import net.minecraft.world.level.Level; ++// CraftBukkit start ++import org.bukkit.NamespacedKey; ++import org.bukkit.craftbukkit.inventory.CraftItemStack; ++import org.bukkit.craftbukkit.inventory.CraftRecipe; ++import org.bukkit.craftbukkit.inventory.CraftShapedRecipe; ++import org.bukkit.inventory.RecipeChoice; ++// CraftBukkit end + +-public class ShapedRecipe implements CraftingRecipe { ++public class ShapedRecipe implements RecipeCrafting { + + final ShapedRecipePattern pattern; + final ItemStack result; +@@ -30,56 +37,109 @@ + this(s, craftingbookcategory, shapedrecipepattern, itemstack, true); + } + ++ // CraftBukkit start + @Override ++ public org.bukkit.inventory.ShapedRecipe toBukkitRecipe(NamespacedKey id) { ++ CraftItemStack result = CraftItemStack.asCraftMirror(this.result); ++ CraftShapedRecipe recipe = new CraftShapedRecipe(id, result, this); ++ recipe.setGroup(this.group); ++ recipe.setCategory(CraftRecipe.getCategory(this.category())); ++ ++ switch (this.pattern.height()) { ++ case 1: ++ switch (this.pattern.width()) { ++ case 1: ++ recipe.shape("a"); ++ break; ++ case 2: ++ recipe.shape("ab"); ++ break; ++ case 3: ++ recipe.shape("abc"); ++ break; ++ } ++ break; ++ case 2: ++ switch (this.pattern.width()) { ++ case 1: ++ recipe.shape("a","b"); ++ break; ++ case 2: ++ recipe.shape("ab","cd"); ++ break; ++ case 3: ++ recipe.shape("abc","def"); ++ break; ++ } ++ break; ++ case 3: ++ switch (this.pattern.width()) { ++ case 1: ++ recipe.shape("a","b","c"); ++ break; ++ case 2: ++ recipe.shape("ab","cd","ef"); ++ break; ++ case 3: ++ recipe.shape("abc","def","ghi"); ++ break; ++ } ++ break; ++ } ++ char c = 'a'; ++ for (Ingredient list : this.pattern.ingredients()) { ++ RecipeChoice choice = CraftRecipe.toBukkit(list); ++ if (choice != null) { ++ recipe.setIngredient(c, choice); ++ } ++ ++ c++; ++ } ++ return recipe; ++ } ++ // CraftBukkit end ++ + @Override + public RecipeSerializer<?> getSerializer() { + return RecipeSerializer.SHAPED_RECIPE; + } + + @Override +- @Override + public String getGroup() { + return this.group; + } + + @Override +- @Override + public CraftingBookCategory category() { + return this.category; + } + + @Override +- @Override +- public ItemStack getResultItem(RegistryAccess registryaccess) { ++ public ItemStack getResultItem(RegistryAccess registryAccess) { + return this.result; + } + + @Override +- @Override + public NonNullList<Ingredient> getIngredients() { + return this.pattern.ingredients(); + } + + @Override +- @Override + public boolean showNotification() { + return this.showNotification; + } + + @Override +- @Override +- public boolean canCraftInDimensions(int i, int j) { +- return i >= this.pattern.width() && j >= this.pattern.height(); ++ public boolean canCraftInDimensions(int width, int height) { ++ return width >= this.pattern.width() && height >= this.pattern.height(); + } + +- @Override +- public boolean matches(CraftingContainer craftingcontainer, Level level) { +- return this.pattern.matches(craftingcontainer); ++ public boolean matches(InventoryCrafting inv, Level level) { ++ return this.pattern.matches(inv); + } + +- @Override +- public ItemStack assemble(CraftingContainer craftingcontainer, RegistryAccess registryaccess) { +- return this.getResultItem(registryaccess).copy(); ++ public ItemStack assemble(InventoryCrafting container, RegistryAccess registryAccess) { ++ return this.getResultItem(registryAccess).copy(); + } + + public int getWidth() { +@@ -91,60 +151,56 @@ + } + + @Override +- @Override + public boolean isIncomplete() { + NonNullList<Ingredient> nonnulllist = this.getIngredients(); + +- return nonnulllist.isEmpty() || nonnulllist.stream().filter((ingredient) -> { +- return !ingredient.isEmpty(); +- }).anyMatch((ingredient) -> { +- return ingredient.getItems().length == 0; ++ return nonnulllist.isEmpty() || nonnulllist.stream().filter((recipeitemstack) -> { ++ return !recipeitemstack.isEmpty(); ++ }).anyMatch((recipeitemstack) -> { ++ return recipeitemstack.getItems().length == 0; + }); + } + + public static class Serializer implements RecipeSerializer<ShapedRecipe> { + + public static final Codec<ShapedRecipe> CODEC = RecordCodecBuilder.create((instance) -> { +- return instance.group(ExtraCodecs.strictOptionalField(Codec.STRING, "group", "").forGetter((shapedrecipe) -> { +- return shapedrecipe.group; +- }), CraftingBookCategory.CODEC.fieldOf("category").orElse(CraftingBookCategory.MISC).forGetter((shapedrecipe) -> { +- return shapedrecipe.category; +- }), ShapedRecipePattern.MAP_CODEC.forGetter((shapedrecipe) -> { +- return shapedrecipe.pattern; +- }), ItemStack.ITEM_WITH_COUNT_CODEC.fieldOf("result").forGetter((shapedrecipe) -> { +- return shapedrecipe.result; +- }), ExtraCodecs.strictOptionalField(Codec.BOOL, "show_notification", true).forGetter((shapedrecipe) -> { +- return shapedrecipe.showNotification; ++ return instance.group(ExtraCodecs.strictOptionalField(Codec.STRING, "group", "").forGetter((shapedrecipes) -> { ++ return shapedrecipes.group; ++ }), CraftingBookCategory.CODEC.fieldOf("category").orElse(CraftingBookCategory.MISC).forGetter((shapedrecipes) -> { ++ return shapedrecipes.category; ++ }), ShapedRecipePattern.MAP_CODEC.forGetter((shapedrecipes) -> { ++ return shapedrecipes.pattern; ++ }), ItemStack.ITEM_WITH_COUNT_CODEC.fieldOf("result").forGetter((shapedrecipes) -> { ++ return shapedrecipes.result; ++ }), ExtraCodecs.strictOptionalField(Codec.BOOL, "show_notification", true).forGetter((shapedrecipes) -> { ++ return shapedrecipes.showNotification; + })).apply(instance, ShapedRecipe::new); + }); + + public Serializer() {} + + @Override +- @Override + public Codec<ShapedRecipe> codec() { + return ShapedRecipe.Serializer.CODEC; + } + + @Override +- @Override +- public ShapedRecipe fromNetwork(FriendlyByteBuf friendlybytebuf) { +- String s = friendlybytebuf.readUtf(); +- CraftingBookCategory craftingbookcategory = (CraftingBookCategory) friendlybytebuf.readEnum(CraftingBookCategory.class); +- ShapedRecipePattern shapedrecipepattern = ShapedRecipePattern.fromNetwork(friendlybytebuf); +- ItemStack itemstack = friendlybytebuf.readItem(); +- boolean flag = friendlybytebuf.readBoolean(); ++ public ShapedRecipe fromNetwork(FriendlyByteBuf packetdataserializer) { ++ String s = packetdataserializer.readUtf(); ++ CraftingBookCategory craftingbookcategory = (CraftingBookCategory) packetdataserializer.readEnum(CraftingBookCategory.class); ++ ShapedRecipePattern shapedrecipepattern = ShapedRecipePattern.fromNetwork(packetdataserializer); ++ ItemStack itemstack = packetdataserializer.readItem(); ++ boolean flag = packetdataserializer.readBoolean(); + + return new ShapedRecipe(s, craftingbookcategory, shapedrecipepattern, itemstack, flag); + } + +- @Override +- public void toNetwork(FriendlyByteBuf friendlybytebuf, ShapedRecipe shapedrecipe) { +- friendlybytebuf.writeUtf(shapedrecipe.group); +- friendlybytebuf.writeEnum(shapedrecipe.category); +- shapedrecipe.pattern.toNetwork(friendlybytebuf); +- friendlybytebuf.writeItem(shapedrecipe.result); +- friendlybytebuf.writeBoolean(shapedrecipe.showNotification); ++ public void toNetwork(FriendlyByteBuf buffer, ShapedRecipe recipe) { ++ buffer.writeUtf(recipe.group); ++ buffer.writeEnum(recipe.category); ++ recipe.pattern.toNetwork(buffer); ++ buffer.writeItem(recipe.result); ++ buffer.writeBoolean(recipe.showNotification); + } + } + } |