Search in sources :

Example 1 with MachineRecipe

use of me.mrCookieSlime.Slimefun.Objects.SlimefunItem.abstractItems.MachineRecipe in project FluffyMachines by NCBPFluffyBear.

the class ElectricDustRecycler method getDisplayRecipes.

@Nonnull
@Override
public List<ItemStack> getDisplayRecipes() {
    List<ItemStack> displayRecipes = new ArrayList<>(recipes.size() * 2);
    for (MachineRecipe recipe : recipes) {
        displayRecipes.add(recipe.getInput()[0]);
        displayRecipes.add(recipe.getOutput()[recipe.getOutput().length - 1]);
    }
    return displayRecipes;
}
Also used : MachineRecipe(me.mrCookieSlime.Slimefun.Objects.SlimefunItem.abstractItems.MachineRecipe) ArrayList(java.util.ArrayList) CustomItemStack(io.github.thebusybiscuit.slimefun4.libraries.dough.items.CustomItemStack) ItemStack(org.bukkit.inventory.ItemStack) SlimefunItemStack(io.github.thebusybiscuit.slimefun4.api.items.SlimefunItemStack) Nonnull(javax.annotation.Nonnull)

Example 2 with MachineRecipe

use of me.mrCookieSlime.Slimefun.Objects.SlimefunItem.abstractItems.MachineRecipe in project Slimefun4 by Slimefun.

the class OilPump method findNextRecipe.

@Override
protected MachineRecipe findNextRecipe(BlockMenu inv) {
    if (inv.fits(SlimefunItems.OIL_BUCKET, getOutputSlots())) {
        Block b = inv.getBlock();
        for (int slot : getInputSlots()) {
            if (SlimefunUtils.isItemSimilar(inv.getItemInSlot(slot), emptyBucket, true, false)) {
                OptionalInt supplies = Slimefun.getGPSNetwork().getResourceManager().getSupplies(oil, b.getWorld(), b.getX() >> 4, b.getZ() >> 4);
                if (supplies.isPresent() && supplies.getAsInt() > 0) {
                    MachineRecipe recipe = new MachineRecipe(26, new ItemStack[] { emptyBucket }, new ItemStack[] { SlimefunItems.OIL_BUCKET });
                    inv.consumeItem(slot);
                    Slimefun.getGPSNetwork().getResourceManager().setSupplies(oil, b.getWorld(), b.getX() >> 4, b.getZ() >> 4, supplies.getAsInt() - 1);
                    return recipe;
                } else {
                    /*
                         * Move the empty bucket to the output slot to prevent this
                         * from immediately starting all over again (to prevent lag)
                         */
                    ItemStack item = inv.getItemInSlot(slot).clone();
                    inv.replaceExistingItem(slot, null);
                    inv.pushItem(item, getOutputSlots());
                    return null;
                }
            }
        }
    }
    return null;
}
Also used : MachineRecipe(me.mrCookieSlime.Slimefun.Objects.SlimefunItem.abstractItems.MachineRecipe) Block(org.bukkit.block.Block) OptionalInt(java.util.OptionalInt) ItemStack(org.bukkit.inventory.ItemStack) SlimefunItemStack(io.github.thebusybiscuit.slimefun4.api.items.SlimefunItemStack)

Example 3 with MachineRecipe

use of me.mrCookieSlime.Slimefun.Objects.SlimefunItem.abstractItems.MachineRecipe in project Slimefun4 by Slimefun.

the class AutoEnchanter method enchant.

@Nullable
@ParametersAreNonnullByDefault
protected MachineRecipe enchant(BlockMenu menu, ItemStack target, ItemStack enchantedBook) {
    // Call an event so other Plugins can modify it.
    AsyncAutoEnchanterProcessEvent event = new AsyncAutoEnchanterProcessEvent(target, enchantedBook, menu);
    Bukkit.getPluginManager().callEvent(event);
    if (event.isCancelled()) {
        return null;
    }
    EnchantmentStorageMeta meta = (EnchantmentStorageMeta) enchantedBook.getItemMeta();
    Map<Enchantment, Integer> enchantments = new HashMap<>();
    // Find applicable enchantments
    for (Map.Entry<Enchantment, Integer> entry : meta.getStoredEnchants().entrySet()) {
        if (entry.getKey().canEnchantItem(target)) {
            if (isEnchantmentLevelAllowed(entry.getValue())) {
                enchantments.put(entry.getKey(), entry.getValue());
            } else if (!menu.toInventory().getViewers().isEmpty()) {
                showEnchantmentLevelWarning(menu);
                return null;
            }
        }
    }
    /*
         * If override is false, remove those with lower level so we don't override existing enchants
         * This also removes those with the same level so they aren't accounted for enchanting time
         */
    if (!overrideExistingEnchantsLvl.getValue()) {
        enchantments.entrySet().removeIf(e -> target.getEnchantmentLevel(e.getKey()) >= e.getValue());
    }
    // Check if we found any valid enchantments
    if (!enchantments.isEmpty()) {
        ItemStack enchantedItem = target.clone();
        enchantedItem.setAmount(1);
        enchantedItem.addUnsafeEnchantments(enchantments);
        MachineRecipe recipe = new MachineRecipe(75 * enchantments.size() / getSpeed(), new ItemStack[] { target, enchantedBook }, new ItemStack[] { enchantedItem, new ItemStack(Material.BOOK) });
        if (!InvUtils.fitAll(menu.toInventory(), recipe.getOutput(), getOutputSlots())) {
            return null;
        }
        for (int inputSlot : getInputSlots()) {
            menu.consumeItem(inputSlot);
        }
        return recipe;
    } else {
        return null;
    }
}
Also used : EnchantmentStorageMeta(org.bukkit.inventory.meta.EnchantmentStorageMeta) HashMap(java.util.HashMap) MachineRecipe(me.mrCookieSlime.Slimefun.Objects.SlimefunItem.abstractItems.MachineRecipe) AsyncAutoEnchanterProcessEvent(io.github.thebusybiscuit.slimefun4.api.events.AsyncAutoEnchanterProcessEvent) Enchantment(org.bukkit.enchantments.Enchantment) ItemStack(org.bukkit.inventory.ItemStack) SlimefunItemStack(io.github.thebusybiscuit.slimefun4.api.items.SlimefunItemStack) HashMap(java.util.HashMap) Map(java.util.Map) ParametersAreNonnullByDefault(javax.annotation.ParametersAreNonnullByDefault) Nullable(javax.annotation.Nullable)

Example 4 with MachineRecipe

use of me.mrCookieSlime.Slimefun.Objects.SlimefunItem.abstractItems.MachineRecipe in project Slimefun4 by Slimefun.

the class AutoBrewer method findNextRecipe.

@Override
@Nullable
protected MachineRecipe findNextRecipe(BlockMenu menu) {
    ItemStack input1 = menu.getItemInSlot(getInputSlots()[0]);
    ItemStack input2 = menu.getItemInSlot(getInputSlots()[1]);
    if (input1 == null || input2 == null) {
        return null;
    }
    if (isPotion(input1.getType()) || isPotion(input2.getType())) {
        boolean isPotionInFirstSlot = isPotion(input1.getType());
        ItemStack ingredient = isPotionInFirstSlot ? input2 : input1;
        // Reject any named items
        if (ingredient.hasItemMeta()) {
            return null;
        }
        ItemStack potionItem = isPotionInFirstSlot ? input1 : input2;
        PotionMeta potion = (PotionMeta) potionItem.getItemMeta();
        ItemStack output = brew(ingredient.getType(), potionItem.getType(), potion);
        if (output == null) {
            return null;
        }
        output.setItemMeta(potion);
        if (!InvUtils.fits(menu.toInventory(), output, getOutputSlots())) {
            return null;
        }
        for (int slot : getInputSlots()) {
            menu.consumeItem(slot);
        }
        return new MachineRecipe(30, new ItemStack[] { input1, input2 }, new ItemStack[] { output });
    } else {
        return null;
    }
}
Also used : MachineRecipe(me.mrCookieSlime.Slimefun.Objects.SlimefunItem.abstractItems.MachineRecipe) PotionMeta(org.bukkit.inventory.meta.PotionMeta) ItemStack(org.bukkit.inventory.ItemStack) SlimefunItemStack(io.github.thebusybiscuit.slimefun4.api.items.SlimefunItemStack) Nullable(javax.annotation.Nullable)

Example 5 with MachineRecipe

use of me.mrCookieSlime.Slimefun.Objects.SlimefunItem.abstractItems.MachineRecipe in project Slimefun4 by Slimefun.

the class Freezer method getDisplayRecipes.

@Override
public List<ItemStack> getDisplayRecipes() {
    List<ItemStack> displayRecipes = new ArrayList<>(recipes.size() * 2);
    for (MachineRecipe recipe : recipes) {
        displayRecipes.add(recipe.getInput()[0]);
        displayRecipes.add(recipe.getOutput()[recipe.getOutput().length - 1]);
    }
    return displayRecipes;
}
Also used : MachineRecipe(me.mrCookieSlime.Slimefun.Objects.SlimefunItem.abstractItems.MachineRecipe) ArrayList(java.util.ArrayList) ItemStack(org.bukkit.inventory.ItemStack) SlimefunItemStack(io.github.thebusybiscuit.slimefun4.api.items.SlimefunItemStack)

Aggregations

MachineRecipe (me.mrCookieSlime.Slimefun.Objects.SlimefunItem.abstractItems.MachineRecipe)45 ItemStack (org.bukkit.inventory.ItemStack)42 SlimefunItemStack (io.github.thebusybiscuit.slimefun4.api.items.SlimefunItemStack)41 CustomItemStack (io.github.thebusybiscuit.slimefun4.libraries.dough.items.CustomItemStack)23 ArrayList (java.util.ArrayList)15 Nonnull (javax.annotation.Nonnull)9 Map (java.util.Map)8 SlimefunItem (io.github.thebusybiscuit.slimefun4.api.items.SlimefunItem)7 HashMap (java.util.HashMap)7 BlockMenu (me.mrCookieSlime.Slimefun.api.inventory.BlockMenu)6 CraftingOperation (io.github.thebusybiscuit.slimefun4.implementation.operations.CraftingOperation)4 Nullable (javax.annotation.Nullable)4 ParametersAreNonnullByDefault (javax.annotation.ParametersAreNonnullByDefault)2 Enchantment (org.bukkit.enchantments.Enchantment)2 JsonElement (com.google.gson.JsonElement)1 JsonObject (com.google.gson.JsonObject)1 ExoticGardenFruit (io.github.thebusybiscuit.exoticgarden.items.ExoticGardenFruit)1 AsyncAutoEnchanterProcessEvent (io.github.thebusybiscuit.slimefun4.api.events.AsyncAutoEnchanterProcessEvent)1 Slimefun (io.github.thebusybiscuit.slimefun4.implementation.Slimefun)1 SlimefunItems (io.github.thebusybiscuit.slimefun4.implementation.SlimefunItems)1