diff options
Diffstat (limited to 'patch-remap/mache-vineflower/net/minecraft/world/item/crafting/ShapedRecipe.java.patch')
-rw-r--r-- | patch-remap/mache-vineflower/net/minecraft/world/item/crafting/ShapedRecipe.java.patch | 205 |
1 files changed, 205 insertions, 0 deletions
diff --git a/patch-remap/mache-vineflower/net/minecraft/world/item/crafting/ShapedRecipe.java.patch b/patch-remap/mache-vineflower/net/minecraft/world/item/crafting/ShapedRecipe.java.patch new file mode 100644 index 0000000000..bf7e64ba97 --- /dev/null +++ b/patch-remap/mache-vineflower/net/minecraft/world/item/crafting/ShapedRecipe.java.patch @@ -0,0 +1,205 @@ +--- a/net/minecraft/world/item/crafting/ShapedRecipe.java ++++ b/net/minecraft/world/item/crafting/ShapedRecipe.java +@@ -2,35 +2,104 @@ + + import com.mojang.serialization.Codec; + import com.mojang.serialization.codecs.RecordCodecBuilder; +-import com.mojang.serialization.codecs.RecordCodecBuilder.Instance; + import net.minecraft.core.NonNullList; + 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; + final String group; + final CraftingBookCategory category; + final boolean showNotification; + +- public ShapedRecipe(String string, CraftingBookCategory craftingBookCategory, ShapedRecipePattern shapedRecipePattern, ItemStack itemStack, boolean flag) { +- this.group = string; +- this.category = craftingBookCategory; +- this.pattern = shapedRecipePattern; +- this.result = itemStack; ++ public ShapedRecipe(String s, CraftingBookCategory craftingbookcategory, ShapedRecipePattern shapedrecipepattern, ItemStack itemstack, boolean flag) { ++ this.group = s; ++ this.category = craftingbookcategory; ++ this.pattern = shapedrecipepattern; ++ this.result = itemstack; + this.showNotification = flag; + } + +- public ShapedRecipe(String string, CraftingBookCategory craftingBookCategory, ShapedRecipePattern shapedRecipePattern, ItemStack itemStack) { +- this(string, craftingBookCategory, shapedRecipePattern, itemStack, true); ++ public ShapedRecipe(String s, CraftingBookCategory craftingbookcategory, ShapedRecipePattern shapedrecipepattern, ItemStack itemstack) { ++ 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; + } +@@ -65,13 +134,11 @@ + return width >= this.pattern.width() && height >= this.pattern.height(); + } + +- @Override +- public boolean matches(CraftingContainer inv, Level level) { ++ public boolean matches(InventoryCrafting inv, Level level) { + return this.pattern.matches(inv); + } + +- @Override +- public ItemStack assemble(CraftingContainer container, RegistryAccess registryAccess) { ++ public ItemStack assemble(InventoryCrafting container, RegistryAccess registryAccess) { + return this.getResultItem(registryAccess).copy(); + } + +@@ -85,39 +152,49 @@ + + @Override + public boolean isIncomplete() { +- NonNullList<Ingredient> ingredients = this.getIngredients(); +- return ingredients.isEmpty() +- || ingredients.stream().filter(ingredient -> !ingredient.isEmpty()).anyMatch(filteredIngredients -> filteredIngredients.getItems().length == 0); ++ NonNullList<Ingredient> nonnulllist = this.getIngredients(); ++ ++ 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 -> instance.group( +- ExtraCodecs.strictOptionalField(Codec.STRING, "group", "").forGetter(shapedRecipe -> shapedRecipe.group), +- CraftingBookCategory.CODEC.fieldOf("category").orElse(CraftingBookCategory.MISC).forGetter(shapedRecipe -> shapedRecipe.category), +- ShapedRecipePattern.MAP_CODEC.forGetter(shapedRecipe -> shapedRecipe.pattern), +- ItemStack.ITEM_WITH_COUNT_CODEC.fieldOf("result").forGetter(shapedRecipe -> shapedRecipe.result), +- ExtraCodecs.strictOptionalField(Codec.BOOL, "show_notification", true).forGetter(shapedRecipe -> shapedRecipe.showNotification) +- ) +- .apply(instance, ShapedRecipe::new) +- ); + ++ public static final Codec<ShapedRecipe> CODEC = RecordCodecBuilder.create((instance) -> { ++ 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 + public Codec<ShapedRecipe> codec() { +- return CODEC; ++ return ShapedRecipe.Serializer.CODEC; + } + + @Override +- public ShapedRecipe fromNetwork(FriendlyByteBuf friendlyByteBuf) { +- String utf = friendlyByteBuf.readUtf(); +- CraftingBookCategory craftingBookCategory = friendlyByteBuf.readEnum(CraftingBookCategory.class); +- ShapedRecipePattern shapedRecipePattern = ShapedRecipePattern.fromNetwork(friendlyByteBuf); +- ItemStack item = friendlyByteBuf.readItem(); +- boolean _boolean = friendlyByteBuf.readBoolean(); +- return new ShapedRecipe(utf, craftingBookCategory, shapedRecipePattern, item, _boolean); ++ 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 buffer, ShapedRecipe recipe) { + buffer.writeUtf(recipe.group); + buffer.writeEnum(recipe.category); |