Search in sources :

Example 1 with RecipeLayout

use of mezz.jei.gui.recipes.RecipeLayout in project GregTech by GregTechCEu.

the class RGNode method transferRecipe.

public boolean transferRecipe(ModularUIContainer x, IRecipeLayout recipeLayout, EntityPlayer player, boolean maxTransfer, boolean doTransfer) {
    if (isSelected) {
        Object obj = recipeLayout.getFocus() == null ? null : recipeLayout.getFocus().getValue();
        if (head instanceof ItemStack && obj instanceof ItemStack) {
            if (!((ItemStack) head).isItemEqual((ItemStack) obj)) {
                return false;
            }
        } else if (head instanceof FluidStack && obj instanceof FluidStack) {
            if (!((FluidStack) head).isFluidEqual((FluidStack) obj)) {
                return false;
            }
        } else {
            return false;
        }
        if (!doTransfer)
            return true;
        RGNode.this.recipePer = 0;
        // items
        List<ItemStack> itemInputs = new ArrayList<>();
        recipeLayout.getItemStacks().getGuiIngredients().values().forEach(it -> {
            if (it.isInput() && it.getDisplayedIngredient() != null) {
                ItemStack input = it.getDisplayedIngredient();
                for (ItemStack itemInput : itemInputs) {
                    if (itemInput.isItemEqual(input)) {
                        itemInput.setCount(itemInput.getCount() + input.getCount());
                        return;
                    }
                }
                itemInputs.add(input.copy());
            } else if (head instanceof ItemStack && !it.isInput()) {
                for (ItemStack ingredient : it.getAllIngredients()) {
                    if (((ItemStack) head).isItemEqual(ingredient)) {
                        RGNode.this.recipePer += ingredient.getCount();
                        break;
                    }
                }
            }
        });
        // fluids
        List<FluidStack> fluidInputs = new ArrayList<>();
        recipeLayout.getFluidStacks().getGuiIngredients().values().forEach(it -> {
            if (it.isInput() && it.getDisplayedIngredient() != null) {
                FluidStack input = it.getDisplayedIngredient();
                for (FluidStack fluidInput : fluidInputs) {
                    if (fluidInput.isFluidEqual(input)) {
                        fluidInput.amount += input.amount;
                        return;
                    }
                }
                fluidInputs.add(input.copy());
            } else if (head instanceof FluidStack && !it.isInput()) {
                for (FluidStack ingredient : it.getAllIngredients()) {
                    if (((FluidStack) head).isFluidEqual(ingredient)) {
                        RGNode.this.recipePer += ingredient.amount;
                        break;
                    }
                }
            }
        });
        // CHECK GTCE RECIPES
        Recipe recipe = null;
        if (recipeLayout instanceof RecipeLayout) {
            IRecipeWrapper recipeWrapper = ObfuscationReflectionHelper.getPrivateValue(RecipeLayout.class, (RecipeLayout) recipeLayout, "recipeWrapper");
            if (recipeWrapper instanceof GTRecipeWrapper) {
                recipe = ((GTRecipeWrapper) recipeWrapper).getRecipe();
            }
        }
        IRecipeCategory<?> category = recipeLayout.getRecipeCategory();
        List<Object> catalysts = GTJeiPlugin.jeiRuntime.getRecipeRegistry().getRecipeCatalysts(category);
        ItemStack catalyst = null;
        if (recipe != null) {
            // GT
            int tierRequire = GTUtility.getTierByVoltage(recipe.getEUt());
            for (Object o : catalysts) {
                if (o instanceof ItemStack) {
                    MetaTileEntity mte = MachineItemBlock.getMetaTileEntity((ItemStack) o);
                    if (mte instanceof SimpleMachineMetaTileEntity) {
                        if (tierRequire < ((SimpleMachineMetaTileEntity) mte).getTier()) {
                            catalyst = (ItemStack) o;
                            break;
                        }
                    }
                }
            }
        }
        if (catalyst == null) {
            for (Object o : catalysts) {
                if (o instanceof ItemStack) {
                    catalyst = (ItemStack) o;
                    break;
                }
            }
        }
        setRecipe(itemInputs, fluidInputs, catalyst, recipePer);
        return true;
    }
    return false;
}
Also used : GTRecipeWrapper(gregtech.integration.jei.recipe.GTRecipeWrapper) SimpleMachineMetaTileEntity(gregtech.api.metatileentity.SimpleMachineMetaTileEntity) Recipe(gregtech.api.recipes.Recipe) FluidStack(net.minecraftforge.fluids.FluidStack) IRecipeLayout(mezz.jei.api.gui.IRecipeLayout) RecipeLayout(mezz.jei.gui.recipes.RecipeLayout) IRecipeWrapper(mezz.jei.api.recipe.IRecipeWrapper) SimpleMachineMetaTileEntity(gregtech.api.metatileentity.SimpleMachineMetaTileEntity) MetaTileEntity(gregtech.api.metatileentity.MetaTileEntity) ItemStack(net.minecraft.item.ItemStack)

Aggregations

MetaTileEntity (gregtech.api.metatileentity.MetaTileEntity)1 SimpleMachineMetaTileEntity (gregtech.api.metatileentity.SimpleMachineMetaTileEntity)1 Recipe (gregtech.api.recipes.Recipe)1 GTRecipeWrapper (gregtech.integration.jei.recipe.GTRecipeWrapper)1 IRecipeLayout (mezz.jei.api.gui.IRecipeLayout)1 IRecipeWrapper (mezz.jei.api.recipe.IRecipeWrapper)1 RecipeLayout (mezz.jei.gui.recipes.RecipeLayout)1 ItemStack (net.minecraft.item.ItemStack)1 FluidStack (net.minecraftforge.fluids.FluidStack)1