Search in sources :

Example 1 with IFocus

use of mezz.jei.api.recipe.IFocus in project HorsePower by GoryMoon.

the class ShapedChoppingCraftingWrapper method setRecipe.

@Override
public void setRecipe(IRecipeLayout recipeLayout, IIngredients ingredients) {
    IGuiItemStackGroup guiItemStacks = recipeLayout.getItemStacks();
    List<List<ItemStack>> inputs = ingredients.getInputs(ItemStack.class);
    List<ItemStack> outputs = ingredients.getOutputs(ItemStack.class).get(0);
    // determine the focused stack
    IFocus<?> ifocus = recipeLayout.getFocus();
    Object focusObj = ifocus.getValue();
    // if the thing in focus is an itemstack
    if (focusObj instanceof ItemStack) {
        IGuiIngredientGroup<ItemStack> guiIngredients = recipeLayout.getIngredientsGroup(ItemStack.class);
        ItemStack focus = (ItemStack) focusObj;
        IFocus.Mode mode = ifocus.getMode();
        // input means we clicked on an ingredient, make sure it is one that affects the base
        if (mode == IFocus.Mode.INPUT && isOutputBlock(focus)) {
            // first, get the output recipe
            BlockHPChoppingBase block = (BlockHPChoppingBase) Block.getBlockFromItem(recipe.getSimpleRecipeOutput().getItem());
            // then create a stack with the focus item (which we already validated above)
            ItemStack outputFocus = BlockChopper.createItemStack(block, 1, focus);
            // and finally, set the focus override for the recipe
            guiIngredients.setOverrideDisplayFocus(HorsePowerPlugin.recipeRegistry.createFocus(IFocus.Mode.OUTPUT, outputFocus));
        } else // if we clicked the chopping block, remove all items which affect the base textures that are not the base item
        if (mode == IFocus.Mode.OUTPUT) {
            // so determine the base
            ItemStack base = new ItemStack(focus.hasTagCompound() ? focus.getTagCompound().getCompoundTag("textureBlock") : new NBTTagCompound());
            if (Block.getBlockFromItem(recipe.outputBlocks.get(0).getItem()) instanceof BlockHPChoppingBase) {
                base = recipe.outputBlocks.get(0).copy();
                NBTTagCompound tag = new NBTTagCompound();
                tag.setTag("textureBlock", focus.hasTagCompound() ? focus.getTagCompound().getCompoundTag("textureBlock") : new NBTTagCompound());
                base.setTagCompound(tag);
            }
            if (!base.isEmpty()) {
                // and loop through all slots removing leg affecting inputs which don't match
                guiIngredients.setOverrideDisplayFocus(HorsePowerPlugin.recipeRegistry.createFocus(IFocus.Mode.INPUT, base));
            }
        }
    }
    // add the itemstacks to the grid
    HorsePowerPlugin.craftingGridHelper.setInputs(guiItemStacks, inputs, this.getWidth(), this.getHeight());
    recipeLayout.getItemStacks().set(0, outputs);
}
Also used : IGuiItemStackGroup(mezz.jei.api.gui.IGuiItemStackGroup) NBTTagCompound(net.minecraft.nbt.NBTTagCompound) List(java.util.List) ImmutableList(com.google.common.collect.ImmutableList) NonNullList(net.minecraft.util.NonNullList) ItemStack(net.minecraft.item.ItemStack) BlockHPChoppingBase(se.gory_moon.horsepower.blocks.BlockHPChoppingBase) IFocus(mezz.jei.api.recipe.IFocus)

Example 2 with IFocus

use of mezz.jei.api.recipe.IFocus in project HorsePower by GoryMoon.

the class ShapelessChoppingCraftingWrapper method setRecipe.

@Override
public void setRecipe(IRecipeLayout recipeLayout, IIngredients ingredients) {
    recipeLayout.setShapeless();
    IGuiItemStackGroup guiItemStacks = recipeLayout.getItemStacks();
    List<List<ItemStack>> inputs = ingredients.getInputs(ItemStack.class);
    List<ItemStack> outputs = ingredients.getOutputs(ItemStack.class).get(0);
    // determine the focused stack
    IFocus<?> ifocus = recipeLayout.getFocus();
    Object focusObj = ifocus.getValue();
    // if the thing in focus is an itemstack
    if (focusObj instanceof ItemStack) {
        IGuiIngredientGroup<ItemStack> guiIngredients = recipeLayout.getIngredientsGroup(ItemStack.class);
        ItemStack focus = (ItemStack) focusObj;
        IFocus.Mode mode = ifocus.getMode();
        // input means we clicked on an ingredient, make sure it is one that affects the base
        if (mode == IFocus.Mode.INPUT && isOutputBlock(focus)) {
            // first, get the output recipe
            BlockHPChoppingBase block = (BlockHPChoppingBase) Block.getBlockFromItem(recipe.getSimpleRecipeOutput().getItem());
            // then create a stack with the focus item (which we already validated above)
            ItemStack outputFocus = BlockChopper.createItemStack(block, 1, focus);
            // and finally, set the focus override for the recipe
            guiIngredients.setOverrideDisplayFocus(HorsePowerPlugin.recipeRegistry.createFocus(IFocus.Mode.OUTPUT, outputFocus));
        } else // if we clicked the chopping block, remove all items which affect the base textures that are not the base item
        if (mode == IFocus.Mode.OUTPUT) {
            // so determine the base
            ItemStack base = new ItemStack(focus.hasTagCompound() ? focus.getTagCompound().getCompoundTag("textureBlock") : new NBTTagCompound());
            if (Block.getBlockFromItem(recipe.outputBlocks.get(0).getItem()) instanceof BlockHPChoppingBase) {
                base = recipe.outputBlocks.get(0).copy();
                NBTTagCompound tag = new NBTTagCompound();
                tag.setTag("textureBlock", focus.hasTagCompound() ? focus.getTagCompound().getCompoundTag("textureBlock") : new NBTTagCompound());
                base.setTagCompound(tag);
            }
            if (!base.isEmpty()) {
                // and loop through all slots removing leg affecting inputs which don't match
                guiIngredients.setOverrideDisplayFocus(HorsePowerPlugin.recipeRegistry.createFocus(IFocus.Mode.INPUT, base));
            }
        }
    }
    // add the itemstacks to the grid
    HorsePowerPlugin.craftingGridHelper.setInputs(guiItemStacks, inputs);
    recipeLayout.getItemStacks().set(0, outputs);
}
Also used : IGuiItemStackGroup(mezz.jei.api.gui.IGuiItemStackGroup) NBTTagCompound(net.minecraft.nbt.NBTTagCompound) List(java.util.List) ImmutableList(com.google.common.collect.ImmutableList) NonNullList(net.minecraft.util.NonNullList) ItemStack(net.minecraft.item.ItemStack) BlockHPChoppingBase(se.gory_moon.horsepower.blocks.BlockHPChoppingBase) IFocus(mezz.jei.api.recipe.IFocus)

Example 3 with IFocus

use of mezz.jei.api.recipe.IFocus in project HorsePower by GoryMoon.

the class ChoppingBlockCraftingWrapper method setRecipe.

@Override
public void setRecipe(IRecipeLayout recipeLayout, IIngredients ingredients) {
    IGuiItemStackGroup guiItemStacks = recipeLayout.getItemStacks();
    List<List<ItemStack>> inputs = ingredients.getInputs(ItemStack.class);
    List<ItemStack> outputs = ingredients.getOutputs(ItemStack.class).get(0);
    // determine the focused stack
    IFocus<?> ifocus = recipeLayout.getFocus();
    Object focusObj = ifocus.getValue();
    // if the thing in focus is an itemstack
    if (focusObj instanceof ItemStack) {
        IGuiIngredientGroup<ItemStack> guiIngredients = recipeLayout.getIngredientsGroup(ItemStack.class);
        ItemStack focus = (ItemStack) focusObj;
        IFocus.Mode mode = ifocus.getMode();
        // input means we clicked on an ingredient, make sure it is one that affects the legs
        if (mode == IFocus.Mode.INPUT && isOutputBlock(focus)) {
            // first, get the output recipe
            BlockHPChoppingBase block = (BlockHPChoppingBase) Block.getBlockFromItem(recipe.getSimpleRecipeOutput().getItem());
            // then create a stack with the focus item (which we already validated above)
            ItemStack outputFocus = BlockChopper.createItemStack(block, Block.getBlockFromItem(focus.getItem()), focus.getItemDamage());
            // and finally, set the focus override for the recipe
            guiIngredients.setOverrideDisplayFocus(HorsePowerPlugin.recipeRegistry.createFocus(IFocus.Mode.OUTPUT, outputFocus));
        } else // if we clicked the table, remove all items which affect the legs textures that are not the leg item
        if (mode == IFocus.Mode.OUTPUT) {
            // so determine the legs
            ItemStack base = new ItemStack(focus.hasTagCompound() ? focus.getTagCompound().getCompoundTag("textureBlock") : new NBTTagCompound());
            if (!base.isEmpty()) {
                // and loop through all slots removing leg affecting inputs which don't match
                guiIngredients.setOverrideDisplayFocus(HorsePowerPlugin.recipeRegistry.createFocus(IFocus.Mode.INPUT, base));
            }
        }
    }
    // add the itemstacks to the grid
    HorsePowerPlugin.craftingGridHelper.setInputs(guiItemStacks, inputs, this.getWidth(), this.getHeight());
    recipeLayout.getItemStacks().set(0, outputs);
}
Also used : IGuiItemStackGroup(mezz.jei.api.gui.IGuiItemStackGroup) NBTTagCompound(net.minecraft.nbt.NBTTagCompound) List(java.util.List) ImmutableList(com.google.common.collect.ImmutableList) ItemStack(net.minecraft.item.ItemStack) BlockHPChoppingBase(se.gory_moon.horsepower.blocks.BlockHPChoppingBase) IFocus(mezz.jei.api.recipe.IFocus)

Example 4 with IFocus

use of mezz.jei.api.recipe.IFocus in project GregTech by GregTechCEu.

the class JEIOptional method getWorldSceneRenderer.

@Optional.Method(modid = "jei")
public static WorldSceneRenderer getWorldSceneRenderer(MultiblockControllerBase controllerBase) {
    IRecipeRegistry rr = GTJeiPlugin.jeiRuntime.getRecipeRegistry();
    IFocus<ItemStack> focus = rr.createFocus(IFocus.Mode.INPUT, controllerBase.getStackForm());
    return rr.getRecipeCategories(focus).stream().map(c -> (IRecipeCategory<IRecipeWrapper>) c).map(c -> rr.getRecipeWrappers(c, focus)).flatMap(List::stream).filter(MultiblockInfoRecipeWrapper.class::isInstance).findFirst().map(MultiblockInfoRecipeWrapper.class::cast).map(MultiblockInfoRecipeWrapper::getCurrentRenderer).orElse(null);
}
Also used : IFocus(mezz.jei.api.recipe.IFocus) ItemStack(net.minecraft.item.ItemStack) List(java.util.List) MultiblockControllerBase(gregtech.api.metatileentity.multiblock.MultiblockControllerBase) WorldSceneRenderer(gregtech.client.renderer.scene.WorldSceneRenderer) MultiblockInfoRecipeWrapper(gregtech.integration.jei.multiblock.MultiblockInfoRecipeWrapper) Optional(net.minecraftforge.fml.common.Optional) IRecipeRegistry(mezz.jei.api.IRecipeRegistry) IRecipeCategory(mezz.jei.api.recipe.IRecipeCategory) IRecipeWrapper(mezz.jei.api.recipe.IRecipeWrapper) IRecipeRegistry(mezz.jei.api.IRecipeRegistry) MultiblockInfoRecipeWrapper(gregtech.integration.jei.multiblock.MultiblockInfoRecipeWrapper) IRecipeCategory(mezz.jei.api.recipe.IRecipeCategory) ItemStack(net.minecraft.item.ItemStack)

Aggregations

List (java.util.List)4 IFocus (mezz.jei.api.recipe.IFocus)4 ItemStack (net.minecraft.item.ItemStack)4 ImmutableList (com.google.common.collect.ImmutableList)3 IGuiItemStackGroup (mezz.jei.api.gui.IGuiItemStackGroup)3 NBTTagCompound (net.minecraft.nbt.NBTTagCompound)3 BlockHPChoppingBase (se.gory_moon.horsepower.blocks.BlockHPChoppingBase)3 NonNullList (net.minecraft.util.NonNullList)2 MultiblockControllerBase (gregtech.api.metatileentity.multiblock.MultiblockControllerBase)1 WorldSceneRenderer (gregtech.client.renderer.scene.WorldSceneRenderer)1 MultiblockInfoRecipeWrapper (gregtech.integration.jei.multiblock.MultiblockInfoRecipeWrapper)1 IRecipeRegistry (mezz.jei.api.IRecipeRegistry)1 IRecipeCategory (mezz.jei.api.recipe.IRecipeCategory)1 IRecipeWrapper (mezz.jei.api.recipe.IRecipeWrapper)1 Optional (net.minecraftforge.fml.common.Optional)1