Search in sources :

Example 16 with IItemStack

use of crafttweaker.api.item.IItemStack in project artisan-worktables by codetaylor.

the class CTArtisanRecipe method getStacksArray.

/**
 * Sets the given stacks array to the matrix items re-ordered to match the recipe's ingredient list order.
 *
 * @return false if no recipe match
 */
private boolean getStacksArray(IItemStack[] stacks, int[] indices, List<IArtisanIngredient> ingredients, ICraftingMatrixStackHandler craftingMatrix, int startX, int startY, int width, int height, boolean mirror) {
    for (int x = 0; x < craftingMatrix.getWidth(); ++x) {
        for (int y = 0; y < craftingMatrix.getHeight(); ++y) {
            int subX = x - startX;
            int subY = y - startY;
            IArtisanIngredient ingredient = ArtisanIngredient.EMPTY;
            int index = 0;
            if (subX >= 0 && subY >= 0 && subX < width && subY < height) {
                if (mirror) {
                    index = width - subX - 1 + subY * width;
                    ingredient = ingredients.get(index);
                } else {
                    index = subX + subY * width;
                    ingredient = ingredients.get(index);
                }
            }
            int matrixIndex = x + y * craftingMatrix.getWidth();
            ItemStack candidate = craftingMatrix.getStackInSlot(matrixIndex);
            if (!ingredient.matches(candidate)) {
                return false;
            }
            // index is the recipe's ingredient index
            stacks[index] = CraftTweakerMC.getIItemStack(candidate);
            indices[index] = matrixIndex;
        }
    }
    return true;
}
Also used : ItemStack(net.minecraft.item.ItemStack) IItemStack(crafttweaker.api.item.IItemStack)

Example 17 with IItemStack

use of crafttweaker.api.item.IItemStack in project artisan-worktables by codetaylor.

the class CTArtisanRecipe method getStacksShapeless.

/**
 * @return the matrix items re-ordered to match the recipe's ingredient list order
 */
private MatchInfo getStacksShapeless(ICraftingContext context) {
    List<IArtisanIngredient> ingredients = this.getIngredientList();
    ICraftingMatrixStackHandler matrixHandler = context.getCraftingMatrixHandler();
    List<ItemStack> itemList = new ArrayList<>(matrixHandler.getSlots());
    List<Integer> indexList = new ArrayList<>(matrixHandler.getSlots());
    IItemStack[] stacks = new IItemStack[ingredients.size()];
    int[] indices = new int[ingredients.size()];
    for (int i = 0; i < matrixHandler.getSlots(); i++) {
        ItemStack itemStack = matrixHandler.getStackInSlot(i);
        if (!itemStack.isEmpty()) {
            itemList.add(itemStack);
            indexList.add(i);
        }
    }
    List<Ingredient> ingredientList = new ArrayList<>(ingredients.size());
    for (IArtisanIngredient ingredient : ingredients) {
        ingredientList.add(ingredient.toIngredient());
    }
    int[] matches = RecipeMatcher.findMatches(itemList, ingredientList);
    for (int i = 0; i < matches.length; i++) {
        stacks[matches[i]] = CraftTweakerMC.getIItemStack(itemList.get(i));
        indices[matches[i]] = indexList.get(i);
    }
    return new MatchInfo(stacks, indices);
}
Also used : ArrayList(java.util.ArrayList) Ingredient(net.minecraft.item.crafting.Ingredient) IIngredient(crafttweaker.api.item.IIngredient) IItemStack(crafttweaker.api.item.IItemStack) ItemStack(net.minecraft.item.ItemStack) IItemStack(crafttweaker.api.item.IItemStack)

Example 18 with IItemStack

use of crafttweaker.api.item.IItemStack in project CraftTweaker by CraftTweaker.

the class MCMod method getItems.

@Override
public IItemStack[] getItems() {
    List<IItemStack> stacks = new ArrayList<>();
    List<Item> items = BracketHandlerItem.getItemNames().values().stream().filter(item -> item.getRegistryName().getResourceDomain().equals(mod.getModId())).collect(Collectors.toList());
    for (Item item : items) {
        if (item == null)
            continue;
        NonNullList<ItemStack> list = NonNullList.create();
        item.getSubItems(CreativeTabs.SEARCH, list);
        for (ItemStack stack : list) {
            stacks.add(CraftTweakerMC.getIItemStack(stack));
        }
    }
    return stacks.toArray(new IItemStack[0]);
}
Also used : BracketHandlerItem(crafttweaker.mc1120.brackets.BracketHandlerItem) IMod(crafttweaker.api.mods.IMod) java.util(java.util) IItemStack(crafttweaker.api.item.IItemStack) CraftTweakerMC(crafttweaker.api.minecraft.CraftTweakerMC) net.minecraft.item(net.minecraft.item) CreativeTabs(net.minecraft.creativetab.CreativeTabs) NonNullList(net.minecraft.util.NonNullList) ModContainer(net.minecraftforge.fml.common.ModContainer) Collectors(java.util.stream.Collectors) BracketHandlerItem(crafttweaker.mc1120.brackets.BracketHandlerItem) IItemStack(crafttweaker.api.item.IItemStack) IItemStack(crafttweaker.api.item.IItemStack)

Example 19 with IItemStack

use of crafttweaker.api.item.IItemStack in project CraftTweaker by CraftTweaker.

the class MCPlayer method give.

@Override
public void give(IItemStack stack) {
    ItemStack itemstack = CraftTweakerMC.getItemStack(stack).copy();
    boolean flag = player.inventory.addItemStackToInventory(itemstack);
    if (flag) {
        player.world.playSound(null, player.posX, player.posY, player.posZ, SoundEvents.ENTITY_ITEM_PICKUP, SoundCategory.PLAYERS, 0.2F, ((player.getRNG().nextFloat() - player.getRNG().nextFloat()) * 0.7F + 1.0F) * 2.0F);
        player.inventoryContainer.detectAndSendChanges();
    }
    if (flag && itemstack.isEmpty()) {
        itemstack.setCount(1);
        EntityItem entityitem1 = player.dropItem(itemstack, false);
        if (entityitem1 != null) {
            entityitem1.makeFakeItem();
        }
    } else {
        EntityItem entityitem = player.dropItem(itemstack, false);
        if (entityitem != null) {
            entityitem.setNoPickupDelay();
            entityitem.setOwner(player.getName());
        }
    }
}
Also used : ItemStack(net.minecraft.item.ItemStack) IItemStack(crafttweaker.api.item.IItemStack) EntityItem(net.minecraft.entity.item.EntityItem)

Example 20 with IItemStack

use of crafttweaker.api.item.IItemStack in project CraftTweaker by CraftTweaker.

the class VanillaBrewingPlus method getOutput.

@Override
public ItemStack getOutput(ItemStack input, ItemStack ingredient) {
    IItemStack _input = CraftTweakerMC.getIItemStack(input);
    IItemStack _ingredient = CraftTweakerMC.getIItemStack(ingredient);
    if (removedRecipes.stream().anyMatch(t -> t.getFirst().matches(_input) && t.getSecond().matches(_ingredient))) {
        return ItemStack.EMPTY;
    }
    return super.getOutput(input, ingredient);
}
Also used : IItemStack(crafttweaker.api.item.IItemStack)

Aggregations

IItemStack (crafttweaker.api.item.IItemStack)24 ItemStack (net.minecraft.item.ItemStack)18 ZenMethod (stanhebben.zenscript.annotations.ZenMethod)14 IIngredient (crafttweaker.api.item.IIngredient)4 FluidStack (net.minecraftforge.fluids.FluidStack)4 IAction (crafttweaker.IAction)2 IngredientStack (crafttweaker.api.item.IngredientStack)2 CraftTweakerMC (crafttweaker.api.minecraft.CraftTweakerMC)2 IOreDictEntry (crafttweaker.api.oredict.IOreDictEntry)2 PackingRecipe (betterwithaddons.crafting.recipes.PackingRecipe)1 IngredientCraftTweaker (betterwithaddons.util.IngredientCraftTweaker)1 BrewedGrainRecipe (binnie.extratrees.machines.brewery.recipes.BrewedGrainRecipe)1 BreweryRecipe (binnie.extratrees.machines.brewery.recipes.BreweryRecipe)1 FruitPressRecipe (binnie.extratrees.machines.fruitpress.recipes.FruitPressRecipe)1 LumbermillRecipe (binnie.extratrees.machines.lumbermill.recipes.LumbermillRecipe)1 ComparableItemStack (blusunrize.immersiveengineering.api.ComparableItemStack)1 MetalPressRecipe (blusunrize.immersiveengineering.api.crafting.MetalPressRecipe)1 GristSet (com.mraof.minestuck.util.GristSet)1 IMod (crafttweaker.api.mods.IMod)1 BracketHandlerItem (crafttweaker.mc1120.brackets.BracketHandlerItem)1