Search in sources :

Example 1 with Ingredient

use of net.minecraft.recipe.Ingredient in project nbt-crafting by Siphalor.

the class MixinIngredient method ofAdvancedEntries.

@Unique
private static Ingredient ofAdvancedEntries(Stream<? extends IngredientEntry> entries) {
    if (entries == null)
        NbtCrafting.logError("Internal error: can't construct ingredient from null entry stream!");
    try {
        Ingredient ingredient;
        // noinspection ConstantConditions
        ingredient = (Ingredient) ((ICloneable) (Object) Ingredient.EMPTY).clone();
        ((IIngredient) (Object) ingredient).nbtCrafting$setAdvancedEntries(entries);
        return ingredient;
    } catch (CloneNotSupportedException e) {
        e.printStackTrace();
    }
    return Ingredient.EMPTY;
}
Also used : ICloneable(de.siphalor.nbtcrafting.util.duck.ICloneable) Ingredient(net.minecraft.recipe.Ingredient) Unique(org.spongepowered.asm.mixin.Unique)

Example 2 with Ingredient

use of net.minecraft.recipe.Ingredient in project MCDoom by AzureDoom.

the class GunTableScreenHandler method switchTo.

public void switchTo(int recipeIndex) {
    // index out of bounds
    if (this.getRecipes().size() > recipeIndex) {
        GunTableRecipe gunTableRecipe = getRecipes().get(recipeIndex);
        for (int i = 0; i < 5; i++) {
            ItemStack slotStack = gunTableInventory.getStack(i);
            if (!slotStack.isEmpty()) {
                // if all positions can't be filled, transfer nothing
                if (!this.insertItem(slotStack, 6, 39, false)) {
                    return;
                }
                gunTableInventory.setStack(i, slotStack);
            }
        }
        for (int i = 0; i < 5; i++) {
            Ingredient ingredient = gunTableRecipe.getIngredientForSlot(i);
            if (!ingredient.isEmpty()) {
                ItemStack[] possibleItems = ((IngredientAccess) (Object) ingredient).getMatchingStacksMod();
                if (possibleItems != null) {
                    ItemStack first = new ItemStack(possibleItems[0].getItem(), gunTableRecipe.countRequired(i));
                    autofill(i, first);
                }
            }
        }
    }
}
Also used : Ingredient(net.minecraft.recipe.Ingredient) IngredientAccess(mod.azure.doom.mixin.IngredientAccess) GunTableRecipe(mod.azure.doom.util.recipes.GunTableRecipe) ItemStack(net.minecraft.item.ItemStack)

Example 3 with Ingredient

use of net.minecraft.recipe.Ingredient in project MCDoom by AzureDoom.

the class GunTableRecipe method matches.

@Override
public boolean matches(GunTableInventory inv, World world) {
    for (int i = 0; i < 5; i++) {
        ItemStack slotStack = inv.getStack(i);
        Pair<Ingredient, Integer> pair = ingredients[i];
        Ingredient ingredient = pair.getLeft();
        int count = pair.getRight();
        if (slotStack.getCount() < count || !(ingredient.test(slotStack))) {
            return false;
        }
    }
    return true;
}
Also used : Ingredient(net.minecraft.recipe.Ingredient) ItemStack(net.minecraft.item.ItemStack)

Example 4 with Ingredient

use of net.minecraft.recipe.Ingredient in project bewitchment by MoriyaShiine.

the class SmeltItemsRitualFunction method tick.

@Override
public void tick(World world, BlockPos glyphPos, BlockPos effectivePos, boolean catFamiliar) {
    int radius = catFamiliar ? 9 : 3;
    if (!world.isClient) {
        if (world.getTime() % 20 == 0) {
            for (ItemEntity itemEntity : world.getEntitiesByType(EntityType.ITEM, new Box(effectivePos).expand(radius, 0, radius), entity -> true)) {
                if (world.random.nextFloat() < 1 / 4f) {
                    world.getRecipeManager().listAllOfType(RecipeType.SMELTING).forEach(smeltingRecipe -> {
                        for (Ingredient ingredient : smeltingRecipe.getIngredients()) {
                            if (ingredient.test(itemEntity.getStack())) {
                                world.playSound(null, itemEntity.getBlockPos(), SoundEvents.BLOCK_FURNACE_FIRE_CRACKLE, SoundCategory.BLOCKS, 1, 1);
                                ItemScatterer.spawn(world, itemEntity.getX(), itemEntity.getY(), itemEntity.getZ(), smeltingRecipe.getOutput().copy());
                                world.spawnEntity(new ExperienceOrbEntity(world, itemEntity.getX(), itemEntity.getY(), itemEntity.getZ(), 1));
                                itemEntity.getStack().decrement(1);
                            }
                        }
                    });
                }
            }
        }
    } else {
        world.addParticle(ParticleTypes.FLAME, effectivePos.getX() + MathHelper.nextDouble(world.random, -radius, radius), effectivePos.getY() + 0.5, effectivePos.getZ() + MathHelper.nextDouble(world.random, -radius, radius), 0, 0, 0);
    }
}
Also used : ItemEntity(net.minecraft.entity.ItemEntity) Ingredient(net.minecraft.recipe.Ingredient) Box(net.minecraft.util.math.Box) ExperienceOrbEntity(net.minecraft.entity.ExperienceOrbEntity)

Example 5 with Ingredient

use of net.minecraft.recipe.Ingredient in project bewitchment by MoriyaShiine.

the class RitualRecipe method matches.

public static boolean matches(Inventory inv, DefaultedList<Ingredient> input) {
    List<ItemStack> checklist = new ArrayList<>();
    for (int i = 0; i < inv.size(); i++) {
        ItemStack stack = inv.getStack(i);
        if (!stack.isEmpty()) {
            checklist.add(stack);
        }
    }
    if (input.size() != checklist.size()) {
        return false;
    }
    for (Ingredient ingredient : input) {
        boolean found = false;
        for (ItemStack stack : checklist) {
            if (ingredient.test(stack)) {
                found = true;
                checklist.remove(stack);
                break;
            }
        }
        if (!found) {
            return false;
        }
    }
    return true;
}
Also used : Ingredient(net.minecraft.recipe.Ingredient) ArrayList(java.util.ArrayList) ItemStack(net.minecraft.item.ItemStack)

Aggregations

Ingredient (net.minecraft.recipe.Ingredient)7 ItemStack (net.minecraft.item.ItemStack)4 ICloneable (de.siphalor.nbtcrafting.util.duck.ICloneable)1 IntAVLTreeSet (it.unimi.dsi.fastutil.ints.IntAVLTreeSet)1 IntCollection (it.unimi.dsi.fastutil.ints.IntCollection)1 ArrayList (java.util.ArrayList)1 IngredientAccess (mod.azure.doom.mixin.IngredientAccess)1 GunTableRecipe (mod.azure.doom.util.recipes.GunTableRecipe)1 ExperienceOrbEntity (net.minecraft.entity.ExperienceOrbEntity)1 ItemEntity (net.minecraft.entity.ItemEntity)1 Identifier (net.minecraft.util.Identifier)1 Box (net.minecraft.util.math.Box)1 Unique (org.spongepowered.asm.mixin.Unique)1