[1.7.10]Как рассказать NEI что есть новый верстак и новые крафты

13
0
Есть мод на новый верстак, но для крафта нужно наличие инструмента в определенном слоте.

Собственно NEI не видит новый верстак, и не показывает крафты при нажатии R на итем.
Сам вопрос: Как заставить его прозреть?

 
Расширяешь класс "codechicken.nei.recipe.TemplateRecipeHandler" или соответствующий интерфейс (не помню как называется).
Вот образец из моего аддона:
Код:
public class IronWorkbenchRecipeHandler extends TemplateRecipeHandler
{
        private static final int workspaceItemsPosX=8-7;
        private static final int workspaceItemsPosY=8-7;
        private static final int toolsPosX=26-7;
        private static final int toolsPosY=8-7;
        private static final int materialsPosX=65-7;
        private static final int materialsPosY=8-7;
        private static final int outputPosX=116-7;
        private static final int outputPosY=8-7;
    
       public Class <? extends GuiContainer > getGuiClass()
        {
            return IronWorkbenchGui.class;
        }

           public String getRecipeName()
        {
            return "Iron workbench";
        }
           
        @Override
        public int recipiesPerPage() 
        {
            return 1;
        }

        public String getRecipeId()
        {
            return "ihl.ironWorkbench";
        }

        public String getGuiTexture()
        {
            return "ihl:textures/gui/GUIIronWorkbench.png";
        }

        public String getOverlayIdentifier()
        {
            return "ironWorkbench";
        }

        public List<IronWorkbenchRecipe> getRecipeList()
        {
            ArrayList<IronWorkbenchRecipe> rList = new ArrayList<IronWorkbenchRecipe>();
            rList.addAll(IronWorkbenchTileEntity.recipes);
            rList.add(new IronWorkbenchRecipe(null,Arrays.asList(new ItemStack[]{IHLUtils.getThisModWireItemStackWithLength("copperWire", 1),Ic2Items.rubber}),Arrays.asList(new ItemStack[] {IHLUtils.getThisModWireItemStackWithLength("flexibleCableWithClamp", 1)})));
            rList.add(new IronWorkbenchRecipe(null,Arrays.asList(new ItemStack[]{IHLUtils.getThisModWireItemStackWithLength("copperWire16x", 1),Ic2Items.rubber}),Arrays.asList(new ItemStack[] {IHLUtils.getThisModWireItemStackWithLength("flexibleCableCopper16x", 1)})));
            rList.add(new IronWorkbenchRecipe(null,Arrays.asList(new ItemStack[]{IHLUtils.getThisModWireItemStackWithLength("steelWire", 1),Ic2Items.rubber}),Arrays.asList(new ItemStack[] {IHLUtils.getThisModWireItemStackWithLength("flexibleCableSteel2", 1)})));
            rList.add(new IronWorkbenchRecipe(null,Arrays.asList(new ItemStack[]{IHLUtils.getThisModWireItemStackWithLength("steelWire16x", 1),Ic2Items.rubber}),Arrays.asList(new ItemStack[] {IHLUtils.getThisModWireItemStackWithLength("flexibleCableSteel24", 1)})));

            rList.add(new IronWorkbenchRecipe(Arrays.asList(new ItemStack[]{IHLUtils.getThisModItemStack("sharpenedCarvingKnifeBronze")}),Arrays.asList(new ItemStack[]{IHLUtils.getThisModWireItemStackWithLength("flexibleCableWithClamp", 1)}),Arrays.asList(new ItemStack[]{IHLUtils.getThisModWireItemStackWithLength("copperWire", 1),Ic2Items.rubber})));
            rList.add(new IronWorkbenchRecipe(Arrays.asList(new ItemStack[]{IHLUtils.getThisModItemStack("sharpenedCarvingKnifeBronze")}),Arrays.asList(new ItemStack[]{IHLUtils.getThisModWireItemStackWithLength("flexibleCableCopper16x", 1)}),Arrays.asList(new ItemStack[]{IHLUtils.getThisModWireItemStackWithLength("copperWire16x", 1),Ic2Items.rubber})));
            rList.add(new IronWorkbenchRecipe(Arrays.asList(new ItemStack[]{IHLUtils.getThisModItemStack("sharpenedCarvingKnifeBronze")}),Arrays.asList(new ItemStack[]{IHLUtils.getThisModWireItemStackWithLength("flexibleCableSteel2", 1)}),Arrays.asList(new ItemStack[]{IHLUtils.getThisModWireItemStackWithLength("steelWire", 1),Ic2Items.rubber})));
            rList.add(new IronWorkbenchRecipe(Arrays.asList(new ItemStack[]{IHLUtils.getThisModItemStack("sharpenedCarvingKnifeBronze")}),Arrays.asList(new ItemStack[]{IHLUtils.getThisModWireItemStackWithLength("flexibleCableSteel24", 1)}),Arrays.asList(new ItemStack[]{IHLUtils.getThisModWireItemStackWithLength("steelWire16x", 1),Ic2Items.rubber})));

            rList.add(new IronWorkbenchRecipe(Arrays.asList(new ItemStack[]{IHLUtils.getThisModItemStack("sharpenedCarvingKnifeBronze")}),Arrays.asList(new ItemStack[]{IHLUtils.getThisModWireItemStackWithLength("flexibleCableCopperVulcanizedRubber2", 1)}),Arrays.asList(new ItemStack[]{IHLUtils.getThisModWireItemStackWithLength("copperWire", 1)})));
            rList.add(new IronWorkbenchRecipe(Arrays.asList(new ItemStack[]{IHLUtils.getThisModItemStack("sharpenedCarvingKnifeBronze")}),Arrays.asList(new ItemStack[]{IHLUtils.getThisModWireItemStackWithLength("flexibleCableCopperVulcanizedRubber24", 1)}),Arrays.asList(new ItemStack[]{IHLUtils.getThisModWireItemStackWithLength("copperWire16x", 1)})));
            rList.add(new IronWorkbenchRecipe(Arrays.asList(new ItemStack[]{IHLUtils.getThisModItemStack("sharpenedCarvingKnifeBronze")}),Arrays.asList(new ItemStack[]{IHLUtils.getThisModWireItemStackWithLength("flexibleCableSteelVulcanizedRubber2", 1)}),Arrays.asList(new ItemStack[]{IHLUtils.getThisModWireItemStackWithLength("steelWire", 1)})));
            rList.add(new IronWorkbenchRecipe(Arrays.asList(new ItemStack[]{IHLUtils.getThisModItemStack("sharpenedCarvingKnifeBronze")}),Arrays.asList(new ItemStack[]{IHLUtils.getThisModWireItemStackWithLength("flexibleCableSteelVulcanizedRubber24", 1)}),Arrays.asList(new ItemStack[]{IHLUtils.getThisModWireItemStackWithLength("steelWire16x", 1)})));
            return rList;
        }

  
    public void drawBackground(int recipeNumber)
    {
        IronWorkbenchRecipeHandler.CachedIORecipe recipe = (CachedIORecipe) this.arecipes.get(recipeNumber);
        GL11.glColor4f(1.0F, 1.0F, 1.0F, 1.0F);
        GuiDraw.changeTexture(this.getGuiTexture());
        GuiDraw.drawTexturedModalRect(0, 0, 7, 7, 162, 108);
    }

    public void drawExtras(int i)
    {
        /*
        float f = this.ticks >= 20 ? (float)((this.ticks - 20) % 20) / 20.0F : 0.0F;
        this.drawProgressBar(74, 23, 176, 14, 25, 16, f, 0);
        f = this.ticks <= 20 ? (float)this.ticks / 20.0F : 1.0F;
        this.drawProgressBar(51, 25, 176, 0, 14, 14, f, 3);
        */
    }

    public void loadTransferRects()
    {
        this.transferRects.add(new RecipeTransferRect(new Rectangle(104-10, 9-10, 15, 108), this.getRecipeId(), new Object[0]));
    }

    public void loadCraftingRecipes(String outputId, Object ... results)
    {
        if (outputId.equals(this.getRecipeId()))
        {
            Iterator<IronWorkbenchRecipe> i$ = this.getRecipeList().iterator();

            while (i$.hasNext())
            {
                IronWorkbenchRecipe entry = i$.next();
                this.arecipes.add(new IronWorkbenchRecipeHandler.CachedIORecipe(entry));
            }
        }
        else
        {
            super.loadCraftingRecipes(outputId, results);
        }
    }

    public void loadCraftingRecipes(ItemStack result)
    {
        Iterator<IronWorkbenchRecipe> i$ = this.getRecipeList().iterator();

        while (i$.hasNext())
        {
            IronWorkbenchRecipe entry = i$.next();
            Iterator i$1 = entry.outputs.iterator();
            while (i$1.hasNext())
            {
                ItemStack output = (ItemStack)i$1.next();
                if (NEIServerUtils.areStacksSameTypeCrafting(output, result))
                {
                    this.arecipes.add(new IronWorkbenchRecipeHandler.CachedIORecipe(entry));
                    break;
                }
            }
        }
    }
    
    public void loadUsageRecipes(ItemStack ingredient)
    {
        Iterator<IronWorkbenchRecipe> i$ = this.getRecipeList().iterator();
        while (i$.hasNext())
        {
            IronWorkbenchRecipe entry = i$.next();
            if(entry.workspaceElements!=null && !entry.workspaceElements.isEmpty())
            {
                Iterator i$1 = entry.workspaceElements.iterator();
                while (i$1.hasNext())
                {
                    ItemStack output = (ItemStack)i$1.next();
                    if (NEIServerUtils.areStacksSameTypeCrafting(output, ingredient) || IHLUtils.isItemsHaveSameOreDictionaryEntry(output, ingredient) || output.getItem()==ingredient.getItem())
                    {
                        this.arecipes.add(new IronWorkbenchRecipeHandler.CachedIORecipe(entry));
                        break;
                    }
                }
            }
            
            if(entry.tools!=null && !entry.tools.isEmpty())
            {
                Iterator<IRecipeInput>  i$1 = entry.tools.iterator();
                while (i$1.hasNext())
                {
                    IRecipeInput output = i$1.next();
                    if (output.matches(ingredient))
                    {
                        this.arecipes.add(new IronWorkbenchRecipeHandler.CachedIORecipe(entry));
                        break;
                    }
                }
            }
            if(entry.materials!=null && !entry.materials.isEmpty())
            {
            Iterator<IRecipeInput> i$2 = entry.materials.iterator();
            while (i$2.hasNext())
            {
                    IRecipeInput output = i$2.next();
                    if (output.matches(ingredient))
                    {
                        this.arecipes.add(new IronWorkbenchRecipeHandler.CachedIORecipe(entry));
                        break;
                    }
                }
            }
        }
    }

    public class CachedIORecipe extends CachedRecipe
    {
        private final List<PositionedStack> ingredients = new ArrayList();
        private final PositionedStack output;
        private final List<PositionedStack> otherStacks = new ArrayList();

        public List<PositionedStack> getIngredients()
        {
            return this.getCycledIngredients(IronWorkbenchRecipeHandler.this.cycleticks / 20, this.ingredients);
        }

        public PositionedStack getResult()
        {
            return this.output;
        }

        public List<PositionedStack> getOtherStacks()
        {
            return this.otherStacks;
        }

        public CachedIORecipe(IronWorkbenchRecipe recipe)
        {
            super();
            if (recipe == null)
            {
                throw new NullPointerException("Recipe must not be null.");
            }
            else
            {
                this.ingredients.add(new PositionedStack(new ItemStack(IHLMod.ironWorkbench), workspaceItemsPosX, workspaceItemsPosY));
                if(recipe.workspaceElements!=null && !recipe.workspaceElements.isEmpty())
                {
                    Iterator i = recipe.workspaceElements.iterator();
                    int index = 1;
                    while (i.hasNext())
                    {
                        int x = workspaceItemsPosX;
                        int y = workspaceItemsPosY + index * 18;
                        ItemStack stack = (ItemStack)i.next();
                        this.ingredients.add(new PositionedStack(stack, x, y));
                        index++;
                    }
                }
                if(recipe.tools!=null && !recipe.tools.isEmpty())
                {
                    Iterator i = recipe.tools.iterator();
                    int index = 0;
                    while (i.hasNext())
                    {
                        int x = toolsPosX + (index % 2) * 18;
                        int y = toolsPosY + index / 2 * 18;
                        IRecipeInput rInput = (IRecipeInput)i.next();
                        this.ingredients.add(new PositionedStack(rInput.getInputs(), x, y));
                        index++;
                    }
                }
                
                if(recipe.materials!=null && !recipe.materials.isEmpty())
                {
                    Iterator i = recipe.materials.iterator();
                    int index = 0;
                    while (i.hasNext())
                    {
                        int x = materialsPosX + (index % 2) * 18;
                        int y = materialsPosY + index / 2 * 18;
                        IRecipeInput rInput = (IRecipeInput)i.next();
                        Iterator<ItemStack> rInputsi = rInput.getInputs().iterator();
                        List<ItemStack> itemInputs = new ArrayList();
                        while(rInputsi.hasNext())
                        {
                            ItemStack stack = rInputsi.next().copy();
                            if(!(stack.getItem() instanceof IWire))
                            {
                                stack.stackSize=rInput.getAmount();
                            }
                            itemInputs.add(stack);
                        }
                        this.ingredients.add(new PositionedStack(itemInputs, x, y));
                        index++;
                    }
                }
                this.output=new PositionedStack(recipe.outputs.get(0), outputPosX, outputPosY);
                Iterator i = recipe.outputs.iterator();
                int index = 0;
                while (i.hasNext())
                {
                      int x = outputPosX + (index % 3) * 18;
                       int y = outputPosY + index / 3 * 18;
                    ItemStack stack = (ItemStack)i.next();
                    if(index>0)
                    {
                        this.otherStacks.add(new PositionedStack(stack, x, y));
                    }
                       index++;
                }
            }
        }

    }
}
Ключевые функции - loadUsageRecipes(...) и loadCraftingRecipes(...)

Затем регистрируешь свой обработчик рецептов в NEI:
Код:
public class NEIIHLConfig implements IConfigureNEI
{
    public void loadConfig()
    {
        API.registerRecipeHandler(new EvaporatorRecipeHandler());
        API.registerUsageHandler(new EvaporatorRecipeHandler());
        API.registerGuiOverlay(EvaporatorGui.class, "evaporator", 5, 11);
//И так далее
 
Как то слишком умно и не понятно.Можно просто прописать рецепт для отображения без чтения файлов,листов?
 
Я даже не знаю как оно работает.Именно поэтому и спрашиваю как.
 
XuPuPG написал(а):
Как то слишком умно и не понятно.Можно просто прописать рецепт для отображения без чтения файлов,листов?
Ну, если у тебя только один рецепт в верстаке - то можно. Файлы у меня там и так не читаются - читается список рецептов из TileEntity класса, который же и используется для определения результата сборки.
([font=monospace, sans-serif]rList[/font][font=monospace, sans-serif].[/font][font=monospace, sans-serif]addAll[/font][font=monospace, sans-serif]([/font][font=monospace, sans-serif]IronWorkbenchTileEntity[/font][font=monospace, sans-serif].[/font][font=monospace, sans-serif]recipes[/font][font=monospace, sans-serif]);[/font]) Ну а ниже добавляются недостающие рецепты, которые реализованы иным образом.
NEI очень гибкий инструмент: показывать через него можно все, что угодно - был бы ItemStack на входе. Так что можешь просто включить интерфейс ICraftingHandler и написать во включенных функциях все, что тебе угодно.
 
Назад
Сверху