#712: Add API to get full result of crafting items

By: James Peters <email@jamesdpeters.com>
This commit is contained in:
Bukkit/Spigot
2023-11-06 20:37:32 +11:00
parent 3475839dd7
commit f2b2fd52d4
3 changed files with 183 additions and 0 deletions

View File

@@ -35,6 +35,7 @@ import org.bukkit.generator.ChunkGenerator;
import org.bukkit.help.HelpMap;
import org.bukkit.inventory.Inventory;
import org.bukkit.inventory.InventoryHolder;
import org.bukkit.inventory.ItemCraftResult;
import org.bukkit.inventory.ItemFactory;
import org.bukkit.inventory.ItemStack;
import org.bukkit.inventory.Merchant;
@@ -835,6 +836,74 @@ public interface Server extends PluginMessageRecipient {
@NotNull
public ItemStack craftItem(@NotNull ItemStack[] craftingMatrix, @NotNull World world, @NotNull Player player);
/**
* Get the crafted item using the list of {@link ItemStack} provided.
*
* <p>The list is formatted as a crafting matrix where the index follow
* the pattern below:</p>
*
* <pre>
* [ 0 1 2 ]
* [ 3 4 5 ]
* [ 6 7 8 ]
* </pre>
*
* @param craftingMatrix list of items to be crafted from.
* Must not contain more than 9 items.
* @param world The world the crafting takes place in.
* @return the {@link ItemStack} resulting from the given crafting matrix, if no recipe is found
* an ItemStack of {@link Material#AIR} is returned.
*/
@NotNull
public ItemStack craftItem(@NotNull ItemStack[] craftingMatrix, @NotNull World world);
/**
* Get the crafted item using the list of {@link ItemStack} provided.
*
* <p>The list is formatted as a crafting matrix where the index follow
* the pattern below:</p>
*
* <pre>
* [ 0 1 2 ]
* [ 3 4 5 ]
* [ 6 7 8 ]
* </pre>
*
* <p>The {@link World} and {@link Player} arguments are required to fulfill the Bukkit Crafting
* events.</p>
*
* <p>Calls {@link org.bukkit.event.inventory.PrepareItemCraftEvent} to imitate the {@link Player}
* initiating the crafting event.</p>
*
* @param craftingMatrix list of items to be crafted from.
* Must not contain more than 9 items.
* @param world The world the crafting takes place in.
* @param player The player to imitate the crafting event on.
* @return resulting {@link ItemCraftResult} containing the resulting item, matrix and any overflow items.
*/
@NotNull
public ItemCraftResult craftItemResult(@NotNull ItemStack[] craftingMatrix, @NotNull World world, @NotNull Player player);
/**
* Get the crafted item using the list of {@link ItemStack} provided.
*
* <p>The list is formatted as a crafting matrix where the index follow
* the pattern below:</p>
*
* <pre>
* [ 0 1 2 ]
* [ 3 4 5 ]
* [ 6 7 8 ]
* </pre>
*
* @param craftingMatrix list of items to be crafted from.
* Must not contain more than 9 items.
* @param world The world the crafting takes place in.
* @return resulting {@link ItemCraftResult} containing the resulting item, matrix and any overflow items.
*/
@NotNull
public ItemCraftResult craftItemResult(@NotNull ItemStack[] craftingMatrix, @NotNull World world);
/**
* Get an iterator through the list of crafting recipes.
*