Search in sources :

Example 21 with Ingredient

use of net.minecraft.item.crafting.Ingredient in project Tropicraft by Tropicraft.

the class Encyclopedia method getFormattedRecipe.

public RecipeEntry getFormattedRecipe(IRecipe recipe) {
    // TODO support other kinds of recipes
    if (recipe instanceof ShapedRecipes) {
        ShapedRecipes shaped = (ShapedRecipes) recipe;
        int width = shaped.recipeWidth;
        int height = shaped.recipeHeight;
        NonNullList<Ingredient> items = shaped.recipeItems;
        ItemStack output = recipe.getRecipeOutput();
        return new RecipeEntry(width, height, items, output);
    } else if (recipe instanceof ShapelessRecipes) {
        return new RecipeEntry(3, 3, recipe.getIngredients(), recipe.getRecipeOutput());
    }
    return null;
}
Also used : ShapedRecipes(net.minecraft.item.crafting.ShapedRecipes) Ingredient(net.minecraft.item.crafting.Ingredient) ItemStack(net.minecraft.item.ItemStack) ShapelessRecipes(net.minecraft.item.crafting.ShapelessRecipes)

Example 22 with Ingredient

use of net.minecraft.item.crafting.Ingredient in project BloodMagic by WayofTime.

the class BloodMagicRecipeRegistrar method addTartaricForge.

@Override
public void addTartaricForge(@Nonnull ItemStack output, @Nonnegative double minimumSouls, @Nonnegative double soulDrain, @Nonnull Ingredient... input) {
    Preconditions.checkNotNull(output, "output cannot be null.");
    Preconditions.checkArgument(minimumSouls >= 0, "minimumSouls cannot be negative.");
    Preconditions.checkArgument(soulDrain >= 0, "soulDrain cannot be negative.");
    Preconditions.checkNotNull(input, "input cannot be null.");
    NonNullList<Ingredient> inputs = NonNullList.from(Ingredient.EMPTY, input);
    tartaricForgeRecipes.add(new RecipeTartaricForge(inputs, output, minimumSouls, soulDrain));
}
Also used : Ingredient(net.minecraft.item.crafting.Ingredient) RecipeTartaricForge(WayofTime.bloodmagic.api.impl.recipe.RecipeTartaricForge)

Example 23 with Ingredient

use of net.minecraft.item.crafting.Ingredient in project MC-Prefab by Brian-Wuest.

the class ShapedRecipeForFile method createFromShapedRecipe.

public static ShapedRecipeForFile createFromShapedRecipe(ShapedRecipes recipe) {
    ShapedRecipeForFile convertedRecipe = new ShapedRecipeForFile();
    convertedRecipe.group = recipe.getGroup();
    ItemStack resultStack = recipe.getRecipeOutput();
    convertedRecipe.result.count = resultStack.getCount();
    convertedRecipe.result.item.item = resultStack.getItem().getRegistryName().toString();
    if (resultStack.getItemDamage() != -1) {
        convertedRecipe.result.item.data = resultStack.getItemDamage();
    }
    convertedRecipe.registryName = recipe.getRegistryName().getResourcePath();
    NonNullList<Ingredient> ingredients = recipe.getIngredients();
    String patternLine = "";
    HashMap<String, ItemName> mappedItems = new HashMap();
    mappedItems.put("a", null);
    mappedItems.put("b", null);
    mappedItems.put("c", null);
    mappedItems.put("d", null);
    mappedItems.put("e", null);
    mappedItems.put("f", null);
    mappedItems.put("g", null);
    mappedItems.put("h", null);
    mappedItems.put("i", null);
    for (int i = 0; i < 9; i++) {
        if (i == 3 || i == 6) {
            convertedRecipe.pattern.add(patternLine);
            patternLine = "";
        }
        Ingredient ingredient = ingredients.get(i);
        ItemStack[] stacks = ingredient.getMatchingStacks();
        if (stacks.length > 0) {
            ItemStack stack = stacks[0];
            if (stack != ItemStack.EMPTY) {
                ItemName itemName = new ItemName();
                itemName.item = stack.getItem().getRegistryName().toString();
                if (stack.getItemDamage() != -1) {
                    itemName.data = stack.getItemDamage();
                }
                String key = "";
                for (Entry<String, ItemName> entry : mappedItems.entrySet()) {
                    if (entry.getValue() != null && entry.getValue().item.equals(stack.getItem().getRegistryName().toString())) {
                        key = "existingItem";
                        patternLine = patternLine + entry.getKey();
                        break;
                    } else if (entry.getValue() == null) {
                        // This entry is blank, set it.
                        key = entry.getKey();
                        break;
                    }
                }
                if (!key.equals("")) {
                    if (!key.equals("existingItem")) {
                        mappedItems.put(key, itemName);
                        patternLine = patternLine + key;
                        switch(key) {
                            case "a":
                                {
                                    convertedRecipe.key.a = itemName;
                                    break;
                                }
                            case "b":
                                {
                                    convertedRecipe.key.b = itemName;
                                    break;
                                }
                            case "c":
                                {
                                    convertedRecipe.key.c = itemName;
                                    break;
                                }
                            case "d":
                                {
                                    convertedRecipe.key.d = itemName;
                                    break;
                                }
                            case "e":
                                {
                                    convertedRecipe.key.e = itemName;
                                    break;
                                }
                            case "f":
                                {
                                    convertedRecipe.key.f = itemName;
                                    break;
                                }
                            case "g":
                                {
                                    convertedRecipe.key.g = itemName;
                                    break;
                                }
                            case "h":
                                {
                                    convertedRecipe.key.h = itemName;
                                    break;
                                }
                            case "i":
                                {
                                    convertedRecipe.key.i = itemName;
                                    break;
                                }
                        }
                    }
                } else {
                    patternLine = patternLine + " ";
                }
            } else {
                patternLine = patternLine + " ";
            }
        } else {
            patternLine = patternLine + " ";
        }
    }
    convertedRecipe.pattern.add(patternLine);
    return convertedRecipe;
}
Also used : Ingredient(net.minecraft.item.crafting.Ingredient) HashMap(java.util.HashMap) ItemStack(net.minecraft.item.ItemStack)

Example 24 with Ingredient

use of net.minecraft.item.crafting.Ingredient in project Wizardry by TeamWizardry.

the class IStructure method craftItemFromInventory.

static ItemStack craftItemFromInventory(EntityPlayer player, ItemStack output) {
    HashSet<IRecipe> recipes = getRecipesForItem(output);
    if (recipes.isEmpty())
        return ItemStack.EMPTY;
    HashMap<ItemStack, Integer> finalInv = new HashMap<>();
    IRecipe finalRecipe = null;
    mainLoop: for (IRecipe recipe : recipes) {
        if (recipe == null)
            continue;
        finalInv.clear();
        finalRecipe = recipe;
        ingLoop: for (Ingredient ingredient : recipe.getIngredients()) {
            if (ingredient.getMatchingStacks().length <= 0)
                continue;
            // Check if has items
            {
                HashMap<Item, Integer> countStacks = new HashMap<>();
                HashMap<Item, Integer> countAgainstStacks = new HashMap<>();
                for (ItemStack stack : player.inventory.mainInventory) {
                    if (stack.isEmpty())
                        continue;
                    countStacks.put(stack.getItem(), countStacks.getOrDefault(stack.getItem(), 0) + stack.getCount());
                }
                for (ItemStack stack : finalInv.keySet()) {
                    countAgainstStacks.put(stack.getItem(), countAgainstStacks.getOrDefault(stack.getItem(), 0) + finalInv.get(stack));
                }
                for (Item countStack : countStacks.keySet()) {
                    if (countStacks.get(countStack) < countAgainstStacks.getOrDefault(countStack, 0)) {
                        finalInv.clear();
                        finalRecipe = null;
                        continue mainLoop;
                    }
                }
            }
            for (ItemStack variant : ingredient.getMatchingStacks()) {
                ItemStack stack;
                if (player.inventory.hasItemStack(variant)) {
                    stack = player.inventory.getStackInSlot(player.inventory.getSlotFor(variant));
                } else {
                    stack = craftItemFromInventory(player, variant);
                    if (!stack.isEmpty()) {
                        player.inventory.addItemStackToInventory(stack);
                        player.inventory.markDirty();
                    }
                }
                if (stack.isEmpty())
                    continue ingLoop;
                finalInv.put(stack, (finalInv.getOrDefault(stack, 0)) + variant.getCount());
                continue ingLoop;
            }
            continue mainLoop;
        }
        break;
    }
    if (finalRecipe == null)
        return ItemStack.EMPTY;
    if (finalInv.isEmpty())
        return ItemStack.EMPTY;
    else {
        for (ItemStack stack : finalInv.keySet()) {
            stack.shrink(finalInv.get(stack));
        }
        return finalRecipe.getRecipeOutput().copy();
    }
}
Also used : Item(net.minecraft.item.Item) IRecipe(net.minecraft.item.crafting.IRecipe) HashMap(java.util.HashMap) Ingredient(net.minecraft.item.crafting.Ingredient) ItemStack(net.minecraft.item.ItemStack)

Example 25 with Ingredient

use of net.minecraft.item.crafting.Ingredient in project Wizardry by TeamWizardry.

the class BlockFluidMana method onEntityUpdate.

@SubscribeEvent
public static void onEntityUpdate(EntityUpdateEvent event) {
    Entity entityIn = event.getEntity();
    BlockPos pos = entityIn.getPosition();
    World world = entityIn.world;
    IBlockState state = world.getBlockState(pos);
    if (state.getBlock() == ModFluids.MANA.getActualBlock()) {
        // Fizz all entities in the pool
        if (world.isRemote)
            run(world, pos, state.getBlock(), entityIn, entity -> true, entity -> LibParticles.FIZZING_AMBIENT(world, entityIn.getPositionVector()));
        // Nullify gravity of player
        if (!world.isRemote)
            run(world, pos, state.getBlock(), entityIn, entity -> entity instanceof EntityLivingBase, entity -> {
                ((EntityLivingBase) entityIn).addPotionEffect(new PotionEffect(ModPotions.NULLIFY_GRAVITY, 100, 0, true, false));
                if (RandUtil.nextInt(50) == 0)
                    entity.attackEntityFrom(DamageSourceMana.INSTANCE, 0.1f);
            });
        // Subtract player food
        run(world, pos, state.getBlock(), entityIn, entity -> entity instanceof EntityPlayer, entity -> {
            if (!world.isRemote) {
                MinecraftServer server = FMLCommonHandler.instance().getMinecraftServerInstance();
                Advancement advancement = server.getAdvancementManager().getAdvancement(new ResourceLocation(Wizardry.MODID, "advancements/advancement_crunch.json"));
                if (advancement == null)
                    return;
                AdvancementProgress progress = ((EntityPlayerMP) entity).getAdvancements().getProgress(advancement);
                for (String s : progress.getRemaningCriteria()) {
                    ((EntityPlayerMP) entity).getAdvancements().grantCriterion(advancement, s);
                }
            }
            if (!((EntityPlayer) entity).capabilities.isCreativeMode && RandUtil.nextInt(50) == 0)
                ((EntityPlayer) entity).getFoodStats().addExhaustion(1f);
        });
        // Explode explodable items
        run(world, pos, state.getBlock(), entityIn, entity -> entity instanceof EntityItem && ((EntityItem) entity).getItem().getItem() instanceof IExplodable, entity -> FluidTracker.INSTANCE.addManaCraft(entity.world, entity.getPosition(), new ManaRecipes.ExplodableCrafter()));
    }
    run(world, pos, state.getBlock(), entityIn, entity -> entity instanceof EntityItem && ManaRecipes.RECIPES.keySet().stream().anyMatch(item -> item.apply(((EntityItem) entity).getItem())), entity -> {
        List<Map.Entry<Ingredient, FluidRecipeLoader.FluidCrafter>> allEntries = ManaRecipes.RECIPES.entries().stream().filter(entry -> entry.getValue().getFluid().getBlock() == state.getBlock() && entry.getKey().apply(((EntityItem) entity).getItem())).collect(Collectors.toList());
        allEntries.forEach(crafter -> FluidTracker.INSTANCE.addManaCraft(entity.world, entity.getPosition(), crafter.getValue().build()));
    });
}
Also used : Ingredient(net.minecraft.item.crafting.Ingredient) AxisAlignedBB(net.minecraft.util.math.AxisAlignedBB) ManaRecipes(com.teamwizardry.wizardry.crafting.mana.ManaRecipes) FMLCommonHandler(net.minecraftforge.fml.common.FMLCommonHandler) Random(java.util.Random) EntityPlayerMP(net.minecraft.entity.player.EntityPlayerMP) PotionEffect(net.minecraft.potion.PotionEffect) BlockModFluid(com.teamwizardry.librarianlib.features.base.fluid.BlockModFluid) ModFluid(com.teamwizardry.librarianlib.features.base.fluid.ModFluid) MinecraftServer(net.minecraft.server.MinecraftServer) Block(net.minecraft.block.Block) Vec3d(net.minecraft.util.math.Vec3d) Map(java.util.Map) FluidRecipeLoader(com.teamwizardry.wizardry.crafting.mana.FluidRecipeLoader) Nonnull(javax.annotation.Nonnull) EntityItem(net.minecraft.entity.item.EntityItem) Entity(net.minecraft.entity.Entity) AdvancementProgress(net.minecraft.advancements.AdvancementProgress) World(net.minecraft.world.World) Predicate(java.util.function.Predicate) Wizardry(com.teamwizardry.wizardry.Wizardry) ModPotions(com.teamwizardry.wizardry.init.ModPotions) Advancement(net.minecraft.advancements.Advancement) BlockPos(net.minecraft.util.math.BlockPos) Collectors(java.util.stream.Collectors) DamageSourceMana(com.teamwizardry.wizardry.common.core.DamageSourceMana) EntityUpdateEvent(com.teamwizardry.librarianlib.features.forgeevents.EntityUpdateEvent) FluidTracker(com.teamwizardry.wizardry.api.block.FluidTracker) Consumer(java.util.function.Consumer) IBlockState(net.minecraft.block.state.IBlockState) List(java.util.List) IFluidBlock(net.minecraftforge.fluids.IFluidBlock) IExplodable(com.teamwizardry.wizardry.api.item.IExplodable) Material(net.minecraft.block.material.Material) EntityLivingBase(net.minecraft.entity.EntityLivingBase) LibParticles(com.teamwizardry.wizardry.client.fx.LibParticles) EntityPlayer(net.minecraft.entity.player.EntityPlayer) ResourceLocation(net.minecraft.util.ResourceLocation) SubscribeEvent(net.minecraftforge.fml.common.eventhandler.SubscribeEvent) RandUtil(com.teamwizardry.wizardry.api.util.RandUtil) Entity(net.minecraft.entity.Entity) AdvancementProgress(net.minecraft.advancements.AdvancementProgress) IBlockState(net.minecraft.block.state.IBlockState) PotionEffect(net.minecraft.potion.PotionEffect) World(net.minecraft.world.World) MinecraftServer(net.minecraft.server.MinecraftServer) IExplodable(com.teamwizardry.wizardry.api.item.IExplodable) ResourceLocation(net.minecraft.util.ResourceLocation) EntityLivingBase(net.minecraft.entity.EntityLivingBase) EntityPlayer(net.minecraft.entity.player.EntityPlayer) BlockPos(net.minecraft.util.math.BlockPos) FluidRecipeLoader(com.teamwizardry.wizardry.crafting.mana.FluidRecipeLoader) Advancement(net.minecraft.advancements.Advancement) EntityItem(net.minecraft.entity.item.EntityItem) SubscribeEvent(net.minecraftforge.fml.common.eventhandler.SubscribeEvent)

Aggregations

Ingredient (net.minecraft.item.crafting.Ingredient)57 ItemStack (net.minecraft.item.ItemStack)49 ResourceLocation (net.minecraft.util.ResourceLocation)12 ArrayList (java.util.ArrayList)10 JsonElement (com.google.gson.JsonElement)8 JsonObject (com.google.gson.JsonObject)7 List (java.util.List)7 IRecipe (net.minecraft.item.crafting.IRecipe)7 JsonArray (com.google.gson.JsonArray)6 Block (net.minecraft.block.Block)6 Item (net.minecraft.item.Item)6 HashMap (java.util.HashMap)5 IBlockState (net.minecraft.block.state.IBlockState)5 ShapelessRecipes (net.minecraft.item.crafting.ShapelessRecipes)5 FluidStack (net.minecraftforge.fluids.FluidStack)5 JsonParser (com.google.gson.JsonParser)4 File (java.io.File)4 FileNotFoundException (java.io.FileNotFoundException)4 FileReader (java.io.FileReader)4 EntityItem (net.minecraft.entity.item.EntityItem)4