Search in sources :

Example 36 with Ingredient

use of net.minecraft.item.crafting.Ingredient in project takumicraft by TNTModders.

the class EntityDestructionCreeper method takumiExplodeEvent.

@Override
public boolean takumiExplodeEvent(Detonate event) {
    if (!this.world.isRemote) {
        float power = this.getPowered() ? 8f : 4f;
        if (event.getExplosion() instanceof TakumiExplosion) {
            power = ((TakumiExplosion) event.getExplosion()).getSize();
        }
        if (power > 0.5) {
            for (BlockPos pos : event.getAffectedBlocks()) {
                if (!this.world.isRemote && this.world.getBlockState(pos).getBlock().hasTileEntity(this.world.getBlockState(pos)) && this.world.getBlockState(pos).getBlock().createTileEntity(this.world, this.world.getBlockState(pos)) instanceof IInventory && TakumiUtils.takumiGetBlockResistance(this, this.world.getBlockState(pos), pos) != -1) {
                    // this.world.setBlockToAir(pos);
                    TakumiUtils.takumiCreateExplosion(this.world, this, pos.getX() + 0.5, pos.getY() + 0.5, pos.getZ() + 0.5, power - 0.15f, false, true);
                }
            }
        }
        Map<IBlockState, IRecipe> map = new HashMap<>();
        Map<IBlockState, Integer> count = new HashMap<>();
        for (BlockPos pos : event.getAffectedBlocks()) {
            IBlockState state = this.world.getBlockState(pos);
            if (state.getMaterial() != Material.AIR) {
                ItemStack stack = state.getBlock().getPickBlock(state, null, this.world, pos, null);
                boolean flg = false;
                for (IRecipe recipe : Lists.newArrayList(CraftingManager.REGISTRY.iterator())) {
                    if (recipe.getRecipeOutput().getItem() == stack.getItem() && recipe.getRecipeOutput().getMetadata() == stack.getMetadata()) {
                        if (!map.containsValue(recipe)) {
                            map.put(state, recipe);
                        }
                        flg = true;
                    }
                }
                if (flg) {
                    if (count.containsKey(state)) {
                        count.replace(state, count.get(state) + 1);
                    } else {
                        count.put(state, 1);
                    }
                }
            }
            this.world.setBlockToAir(pos);
        }
        if (!map.isEmpty()) {
            for (Entry<IBlockState, IRecipe> entry : Lists.newArrayList(map.entrySet())) {
                IRecipe recipe = entry.getValue();
                int i = count.get(entry.getKey());
                List<ItemStack> stackList = new ArrayList<>();
                for (Ingredient ingredient : recipe.getIngredients()) {
                    for (ItemStack stack : ingredient.getMatchingStacks()) {
                        if (!stackList.contains(stack)) {
                            stackList.add(stack);
                        }
                    }
                }
                for (ItemStack stack : stackList) {
                    stack.setCount(i);
                    this.world.spawnEntity(new EntityItem(this.world, posX, posY, posZ, stack));
                }
            }
        }
        // event.getAffectedBlocks().clear();
        event.getAffectedEntities().clear();
    }
    return true;
}
Also used : IInventory(net.minecraft.inventory.IInventory) IBlockState(net.minecraft.block.state.IBlockState) IRecipe(net.minecraft.item.crafting.IRecipe) HashMap(java.util.HashMap) ArrayList(java.util.ArrayList) TakumiExplosion(com.tntmodders.takumi.world.TakumiExplosion) Ingredient(net.minecraft.item.crafting.Ingredient) BlockPos(net.minecraft.util.math.BlockPos) ItemStack(net.minecraft.item.ItemStack) EntityItem(net.minecraft.entity.item.EntityItem)

Example 37 with Ingredient

use of net.minecraft.item.crafting.Ingredient in project Random-Things by lumien231.

the class ModRecipes method addGlowingMushroomRecipes.

public static void addGlowingMushroomRecipes() {
    try {
        Field listField = PotionHelper.class.getDeclaredField(MCPNames.field("field_185213_a"));
        ReflectionUtil.makeModifiable(listField);
        Field inputField = MixPredicate.class.getDeclaredField(MCPNames.field("field_185198_a"));
        ReflectionUtil.makeModifiable(inputField);
        Field reagentField = MixPredicate.class.getDeclaredField(MCPNames.field("field_185199_b"));
        ReflectionUtil.makeModifiable(reagentField);
        Field outputField = MixPredicate.class.getDeclaredField(MCPNames.field("field_185200_c"));
        ReflectionUtil.makeModifiable(outputField);
        List<PotionHelper.MixPredicate<PotionType>> conversionList = (List<MixPredicate<PotionType>>) listField.get(null);
        List<MixPredicate<PotionType>> toAdd = new ArrayList<MixPredicate<PotionType>>();
        for (MixPredicate<PotionType> p : conversionList) {
            Ingredient reagent = (Ingredient) reagentField.get(p);
            if (reagent.test(new ItemStack(Items.GLOWSTONE_DUST))) {
                PotionType input = (PotionType) inputField.get(p);
                PotionType output = (PotionType) outputField.get(p);
                toAdd.add(new MixPredicate<PotionType>(input, Ingredient.fromItem(Item.getItemFromBlock(ModBlocks.glowingMushroom)), output));
            }
        }
        RandomThings.instance.logger.log(Level.DEBUG, "Added " + toAdd.size() + " Glowing Mushroom Recipes");
        conversionList.addAll(toAdd);
    } catch (Exception e) {
        RandomThings.instance.logger.log(Level.ERROR, "Couldn't add glowing mushroom potion recipes, please report this as a bug");
        e.printStackTrace();
    }
}
Also used : Field(java.lang.reflect.Field) Ingredient(net.minecraft.item.crafting.Ingredient) ItemIngredient(lumien.randomthings.item.ItemIngredient) ArrayList(java.util.ArrayList) MixPredicate(net.minecraft.potion.PotionHelper.MixPredicate) ArrayList(java.util.ArrayList) NonNullList(net.minecraft.util.NonNullList) List(java.util.List) PotionType(net.minecraft.potion.PotionType) ItemStack(net.minecraft.item.ItemStack)

Example 38 with Ingredient

use of net.minecraft.item.crafting.Ingredient in project SecurityCraft by Geforce132.

the class RegistrationHandler method registerItemWithCustomRecipe.

/**
 * Registers the given item with GameData.register_implItem(), and adds the help info for the item to the SecurityCraft manual item.
 * Also overrides the default recipe that would've been drawn in the manual with a new recipe.
 */
private static void registerItemWithCustomRecipe(Item item, ItemStack... customRecipe) {
    GameData.register_impl(item);
    NonNullList<Ingredient> recipeItems = NonNullList.<Ingredient>withSize(customRecipe.length, Ingredient.EMPTY);
    for (int i = 0; i < recipeItems.size(); i++) recipeItems.set(i, Ingredient.fromStacks(customRecipe[i]));
    SecurityCraft.instance.manualPages.add(new SCManualPage(item, "help." + item.getUnlocalizedName().substring(5) + ".info", recipeItems));
}
Also used : Ingredient(net.minecraft.item.crafting.Ingredient) SCManualPage(net.geforcemods.securitycraft.misc.SCManualPage)

Example 39 with Ingredient

use of net.minecraft.item.crafting.Ingredient in project Charset by CharsetMC.

the class RecipeReplacement method process.

public void process(Collection<IRecipe> registry) {
    for (IRecipe recipe : registry) {
        ResourceLocation recipeName = recipe.getRegistryName();
        boolean dirty = false;
        if (recipe instanceof ShapedRecipes || recipe instanceof ShapelessRecipes || recipe instanceof ShapedOreRecipe || recipe instanceof ShapelessOreRecipe) {
            NonNullList<Ingredient> ingredients = recipe.getIngredients();
            for (int i = 0; i < ingredients.size(); i++) {
                Ingredient ing = ingredients.get(i);
                Ingredient ingNew = replaceIngredient(ing);
                if (ingNew != null) {
                    ingredients.set(i, ingNew);
                    dirty = true;
                }
            }
        } else if (recipe instanceof RecipeCharset) {
            TCharObjectMap<Ingredient> charToIngredient = ((RecipeCharset) recipe).charToIngredient;
            NonNullList<Ingredient> ingredients = recipe.getIngredients();
            for (int i = 0; i < ingredients.size(); i++) {
                Ingredient ing = ingredients.get(i);
                Ingredient ingNew = replaceIngredient(ing);
                if (ingNew != null) {
                    ingredients.set(i, ingNew);
                    TCharIterator iterator = charToIngredient.keySet().iterator();
                    while (iterator.hasNext()) {
                        char c = iterator.next();
                        if (charToIngredient.get(c) == ing) {
                            charToIngredient.put(c, ing);
                        }
                    }
                    dirty = true;
                }
            }
        }
        if (dirty) {
            ModCharset.logger.info("Successfully edited " + recipeName + "!");
        }
    }
}
Also used : ShapedRecipes(net.minecraft.item.crafting.ShapedRecipes) IRecipe(net.minecraft.item.crafting.IRecipe) ShapedOreRecipe(net.minecraftforge.oredict.ShapedOreRecipe) TCharIterator(gnu.trove.iterator.TCharIterator) TCharObjectMap(gnu.trove.map.TCharObjectMap) Ingredient(net.minecraft.item.crafting.Ingredient) OreIngredient(net.minecraftforge.oredict.OreIngredient) NonNullList(net.minecraft.util.NonNullList) ResourceLocation(net.minecraft.util.ResourceLocation) ShapelessOreRecipe(net.minecraftforge.oredict.ShapelessOreRecipe) ShapelessRecipes(net.minecraft.item.crafting.ShapelessRecipes)

Example 40 with Ingredient

use of net.minecraft.item.crafting.Ingredient in project Charset by CharsetMC.

the class KeyOutputSupplier method getCraftingResult.

@Override
public ItemStack getCraftingResult(RecipeCharset recipe, IngredientMatcher matcher, InventoryCrafting inv) {
    if (duplicate) {
        for (Ingredient i : matcher.getMatchedIngredients()) {
            if (i.apply(output)) {
                ItemStack key = matcher.getStack(i);
                ItemStack result = output.copy();
                NBTTagCompound cpd = new NBTTagCompound();
                cpd.setString("key", ((ItemKey) key.getItem()).getKey(key));
                result.setTagCompound(cpd);
                return result;
            }
        }
        return null;
    } else {
        ItemStack result = output.copy();
        NBTTagCompound cpd = new NBTTagCompound();
        cpd.setString("key", new UUID(rand.nextLong(), rand.nextLong()).toString());
        result.setTagCompound(cpd);
        return result;
    }
}
Also used : Ingredient(net.minecraft.item.crafting.Ingredient) NBTTagCompound(net.minecraft.nbt.NBTTagCompound) ItemStack(net.minecraft.item.ItemStack) UUID(java.util.UUID)

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