Search in sources :

Example 1 with Recipe

use of org.bukkit.inventory.Recipe in project Denizen-For-Bukkit by DenizenScript.

the class ItemRecipeFormedScriptEvent method onRecipeFormed.

@EventHandler
public void onRecipeFormed(PrepareItemCraftEvent event) {
    HumanEntity humanEntity = event.getView().getPlayer();
    if (dEntity.isNPC(humanEntity)) {
        return;
    }
    Recipe eRecipe = event.getRecipe();
    if (eRecipe == null || eRecipe.getResult() == null) {
        return;
    }
    inventory = event.getInventory();
    result = new dItem(eRecipe.getResult());
    recipe = new dList();
    for (ItemStack itemStack : inventory.getMatrix()) {
        if (itemStack != null) {
            recipe.add(new dItem(itemStack).identify());
        } else {
            recipe.add(new dItem(Material.AIR).identify());
        }
    }
    player = dEntity.getPlayerFrom(humanEntity);
    resultChanged = false;
    cancelled = false;
    fire();
    if (cancelled) {
        inventory.setResult(null);
    } else if (resultChanged) {
        inventory.setResult(result.getItemStack());
    }
}
Also used : net.aufdemrand.denizen.objects.dItem(net.aufdemrand.denizen.objects.dItem) Recipe(org.bukkit.inventory.Recipe) net.aufdemrand.denizencore.objects.dList(net.aufdemrand.denizencore.objects.dList) HumanEntity(org.bukkit.entity.HumanEntity) ItemStack(org.bukkit.inventory.ItemStack) EventHandler(org.bukkit.event.EventHandler)

Example 2 with Recipe

use of org.bukkit.inventory.Recipe in project Glowstone by GlowstoneMC.

the class BasicCraftingTest method can_craft_wood_from_logs.

@Test
public void can_craft_wood_from_logs() {
    /*
         * Used to "prove" the CraftingManager's recipe system loads and properly finds a simple matching recipe for some inputs.
         * Sometimes needed to rule out other issues.
         */
    ItemStack[] items = new ItemStack[4];
    items[0] = new ItemStack(Material.LOG, 1, (short) 0);
    Recipe recipe = cm.getCraftingRecipe(items);
    assertThat("Crafting manager did not get recipe", recipe, IsNull.notNullValue());
    assertThat("Crafting manager got wrong material", Material.WOOD, is(recipe.getResult().getType()));
    assertThat("Crafting manager got wrong amount", 4, is(recipe.getResult().getAmount()));
}
Also used : Recipe(org.bukkit.inventory.Recipe) ItemStack(org.bukkit.inventory.ItemStack) Test(org.junit.Test)

Example 3 with Recipe

use of org.bukkit.inventory.Recipe in project MagicPlugin by elBukkit.

the class CraftingController method onPrepareCraftItem.

@EventHandler
public void onPrepareCraftItem(PrepareItemCraftEvent event) {
    CraftingInventory inventory = event.getInventory();
    ItemStack[] contents = inventory.getMatrix();
    // Check for wands glitched into the crafting inventory
    for (int i = 0; i < 9 && i < contents.length; i++) {
        ItemStack item = contents[i];
        if (Wand.isSpecial(item)) {
            inventory.setResult(new ItemStack(Material.AIR));
            return;
        }
    }
    if (!craftingEnabled)
        return;
    Recipe recipe = event.getRecipe();
    if (recipe == null)
        return;
    ItemStack result = recipe.getResult();
    if (result == null)
        return;
    Material resultType = result.getType();
    List<MagicRecipe> candidates = recipes.get(resultType);
    if (candidates == null || candidates.size() == 0)
        return;
    for (MagicRecipe candidate : candidates) {
        MagicRecipe.MatchType matchType = candidate.getMatchType(contents);
        Material substitute = candidate.getSubstitute();
        if (matchType != MagicRecipe.MatchType.NONE) {
            for (HumanEntity human : event.getViewers()) {
                if (human instanceof Player && (matchType == MagicRecipe.MatchType.PARTIAL || !hasCraftPermission((Player) human, candidate))) {
                    inventory.setResult(new ItemStack(Material.AIR));
                    return;
                }
            }
            if (matchType == MagicRecipe.MatchType.MATCH) {
                ItemStack crafted = candidate.craft();
                inventory.setResult(crafted);
            }
            break;
        } else if (substitute != null) {
            inventory.setResult(new ItemStack(substitute, 1));
        }
    }
}
Also used : CraftingInventory(org.bukkit.inventory.CraftingInventory) Player(org.bukkit.entity.Player) Recipe(org.bukkit.inventory.Recipe) MagicRecipe(com.elmakers.mine.bukkit.magic.MagicRecipe) HumanEntity(org.bukkit.entity.HumanEntity) Material(org.bukkit.Material) ItemStack(org.bukkit.inventory.ItemStack) MagicRecipe(com.elmakers.mine.bukkit.magic.MagicRecipe) EventHandler(org.bukkit.event.EventHandler)

Example 4 with Recipe

use of org.bukkit.inventory.Recipe in project CommandHelper by EngineHub.

the class BukkitMCServer method allRecipes.

@Override
public List<MCRecipe> allRecipes() {
    List<MCRecipe> ret = new ArrayList<>();
    for (Iterator recipes = s.recipeIterator(); recipes.hasNext(); ) {
        Recipe recipe = (Recipe) recipes.next();
        ret.add(BukkitConvertor.BukkitGetRecipe(recipe));
    }
    return ret;
}
Also used : MCRecipe(com.laytonsmith.abstraction.MCRecipe) Recipe(org.bukkit.inventory.Recipe) MCRecipe(com.laytonsmith.abstraction.MCRecipe) ArrayList(java.util.ArrayList) Iterator(java.util.Iterator)

Example 5 with Recipe

use of org.bukkit.inventory.Recipe in project MagicPlugin by elBukkit.

the class MagicRecipe method register.

public void register(Plugin plugin) {
    // I think we can only do this once..
    if (FIRST_REGISTER) {
        if (disableDefaultRecipe) {
            Iterator<Recipe> it = plugin.getServer().recipeIterator();
            while (it.hasNext()) {
                Recipe defaultRecipe = it.next();
                if (defaultRecipe != null && defaultRecipe.getResult().getType() == outputType && defaultRecipe.getResult().getDurability() == 0) {
                    plugin.getLogger().info("Disabled default crafting recipe for " + outputType);
                    it.remove();
                }
            }
        }
    }
    // Add our custom recipe if crafting is enabled
    if (recipe != null) {
        if (!FIRST_REGISTER) {
            List<Recipe> existing = plugin.getServer().getRecipesFor(craft());
            if (existing.size() > 0) {
                return;
            }
        }
        plugin.getLogger().info("Adding crafting recipe for " + outputKey);
        try {
            plugin.getServer().addRecipe(recipe);
        } catch (Exception ex) {
            plugin.getLogger().log(Level.WARNING, "Failed to add recipe", ex);
        }
    }
}
Also used : ShapedRecipe(org.bukkit.inventory.ShapedRecipe) Recipe(org.bukkit.inventory.Recipe)

Aggregations

Recipe (org.bukkit.inventory.Recipe)20 ItemStack (org.bukkit.inventory.ItemStack)15 ShapedRecipe (org.bukkit.inventory.ShapedRecipe)7 ShapelessRecipe (org.bukkit.inventory.ShapelessRecipe)5 EventHandler (org.bukkit.event.EventHandler)4 GlowServer (net.glowstone.GlowServer)3 RecipeManager (net.glowstone.datapack.RecipeManager)3 HumanEntity (org.bukkit.entity.HumanEntity)3 Player (org.bukkit.entity.Player)3 CraftingInventory (org.bukkit.inventory.CraftingInventory)3 Trade (com.earth2me.essentials.Trade)2 MCRecipe (com.laytonsmith.abstraction.MCRecipe)2 ArrayList (java.util.ArrayList)2 net.aufdemrand.denizen.objects.dItem (net.aufdemrand.denizen.objects.dItem)2 net.aufdemrand.denizencore.objects.dList (net.aufdemrand.denizencore.objects.dList)2 FuelManager (net.glowstone.datapack.FuelManager)2 GlowFurnaceInventory (net.glowstone.inventory.GlowFurnaceInventory)2 CraftItemEvent (org.bukkit.event.inventory.CraftItemEvent)2 MagicRecipe (com.elmakers.mine.bukkit.magic.MagicRecipe)1 ItemActionInfo (com.gamingmesh.jobs.actions.ItemActionInfo)1