Jump to content

[1.12] Stuck adding IRecipe


tomtomtom09

Recommended Posts

Tying to add a property which is stored inside a tile entity to a block when the block gets crafted. I can add the property with JSON files but don't want to make hundreds of files.

 

Hoping working on IRecipe for few days and hoping someone could point me in the right direction :)

 

_factory file

Spoiler

{
  "recipes":
  {
    "tent":"com.tomtomtom09.campcraft.crafting.RecipeTents$Factory"
  }
}

 

 
 
 

RecipeTents.java

Spoiler

package com.tomtomtom09.campcraft.crafting;


import com.google.gson.JsonObject;
import com.tomtomtom09.campcraft.block.BlockTent;
import com.tomtomtom09.campcraft.init.ModBlocks;
import com.tomtomtom09.campcraft.init.ModItems;
import net.minecraft.block.Block;
import net.minecraft.init.Items;
import net.minecraft.inventory.InventoryCrafting;
import net.minecraft.item.Item;
import net.minecraft.item.ItemStack;
import net.minecraft.item.crafting.IRecipe;
import net.minecraft.nbt.NBTTagCompound;
import net.minecraft.nbt.NBTTagList;
import net.minecraft.potion.PotionUtils;
import net.minecraft.util.NonNullList;
import net.minecraft.world.World;
import net.minecraftforge.common.crafting.IRecipeFactory;
import net.minecraftforge.common.crafting.JsonContext;

public class RecipeTents extends net.minecraftforge.registries.IForgeRegistryEntry.Impl<IRecipe> implements IRecipe
{
    /**
     * Used to check if a recipe matches current crafting inventory
     */
    public boolean matches(InventoryCrafting inv, World worldIn)
    {
        if(inv.getWidth() == 3 && inv.getHeight() == 3)
        {
            for (int i = 0; i < inv.getWidth(); ++i)
            {
                for (int j = 0; j < inv.getHeight(); ++j)
                {
                    ItemStack itemStack = inv.getStackInRowAndColumn(i,j);

                    if(itemStack.isEmpty())
                    {
                        return false;
                    }

                    Item item = itemStack.getItem();

                    if(i == 1 && j == 1)
                    {
                        if(item != ModItems.TENTEQUIPMENT)
                        {
                            return false;
                        }
                    }
                }
            }
            return true;
        }
        else
        {
            return false;
        }
    }

    /**
     * Returns an Item that is the result of this recipe
     */
    public ItemStack getCraftingResult(InventoryCrafting inv)
    {
        ItemStack itemstack = inv.getStackInRowAndColumn(1, 1);
        int k = 0; //tent equipment

        if(itemstack.getItem() != ModItems.TENTEQUIPMENT)
        {
            return ItemStack.EMPTY;
        }
        else
        {
            ItemStack itemstack1 = new ItemStack(ModBlocks.TENT_BLOCK);

            return itemstack1;
        }
    }

    public ItemStack getRecipeOutput()
    {
        return ItemStack.EMPTY;
    }

    public NonNullList<ItemStack> getRemainingItems(InventoryCrafting inv)
    {
        return NonNullList.<ItemStack>withSize(inv.getSizeInventory(), ItemStack.EMPTY);
    }

    public boolean isDynamic()
    {
        return true;
    }

    public boolean canFit(int width, int height)
    {
        return width >= 2 && height >= 2;
    }

    public static class Factory implements IRecipeFactory
    {
        @Override
        public IRecipe parse(final JsonContext context, final JsonObject json)
        {
            return new RecipeTents();
        }
    }
}

 

 
 
 
Edited by tomtomtom09
Updated code

Developer of CampCraft

Link to comment
Share on other sites

21 hours ago, tomtomtom09 said:

Tying to add a property which is stored inside a tile entity to a block when the block gets crafted. I can add the property with JSON files but don't want to make hundreds of files.

 

Hoping working on IRecipe for few days and hoping someone could point me in the right direction :)

 

_factory file.

  Reveal hidden contents


{
  "recipes":
  {
    "tent":"com.tomtomtom09.campcraft.crafting.RecipeTents$Factory"
  }
}

 

 
 
  Reveal hidden contents


package com.tomtomtom09.campcraft.crafting;


import com.google.gson.JsonObject;
import com.tomtomtom09.campcraft.block.BlockTent;
import com.tomtomtom09.campcraft.init.ModBlocks;
import com.tomtomtom09.campcraft.init.ModItems;
import net.minecraft.block.Block;
import net.minecraft.init.Items;
import net.minecraft.inventory.InventoryCrafting;
import net.minecraft.item.Item;
import net.minecraft.item.ItemStack;
import net.minecraft.item.crafting.IRecipe;
import net.minecraft.nbt.NBTTagCompound;
import net.minecraft.nbt.NBTTagList;
import net.minecraft.potion.PotionUtils;
import net.minecraft.util.NonNullList;
import net.minecraft.world.World;
import net.minecraftforge.common.crafting.IRecipeFactory;
import net.minecraftforge.common.crafting.JsonContext;

public class RecipeTents extends net.minecraftforge.registries.IForgeRegistryEntry.Impl<IRecipe> implements IRecipe
{
    /**
     * Used to check if a recipe matches current crafting inventory
     */
    public boolean matches(InventoryCrafting inv, World worldIn)
    {
        if(inv.getWidth() == 3 && inv.getHeight() == 3)
        {
            for (int i = 0; i < inv.getWidth(); ++i)
            {
                for (int j = 0; j < inv.getHeight(); ++j)
                {
                    ItemStack itemStack = inv.getStackInRowAndColumn(i,j);

                    if(itemStack.isEmpty())
                    {
                        return false;
                    }

                    Item item = itemStack.getItem();

                    if(i == 1 && j == 1)
                    {
                        if(item != ModItems.TENTEQUIPMENT)
                        {
                            return false;
                        }
                    }
                }
            }
            return true;
        }
        else
        {
            return false;
        }
    }

    /**
     * Returns an Item that is the result of this recipe
     */
    public ItemStack getCraftingResult(InventoryCrafting inv)
    {
        ItemStack itemstack = inv.getStackInRowAndColumn(1, 1);
        int k = 0; //tent equipment

        if(itemstack.getItem() != ModItems.TENTEQUIPMENT)
        {
            return ItemStack.EMPTY;
        }
        else
        {
            ItemStack itemstack1 = new ItemStack(ModBlocks.TENT_BLOCK);

            int size = ModItems.TENTEQUIPMENT.getMetadata(k);
            if (size != -1)
            {
                k = size;
            }

            NBTTagCompound nbtTagCompound = new NBTTagCompound();
            nbtTagCompound.setInteger("tentSize", k);
            return itemstack1;
        }
    }

    public ItemStack getRecipeOutput()
    {
        return ItemStack.EMPTY;
    }

    public NonNullList<ItemStack> getRemainingItems(InventoryCrafting inv)
    {
        return NonNullList.<ItemStack>withSize(inv.getSizeInventory(), ItemStack.EMPTY);
    }

    public boolean isDynamic()
    {
        return true;
    }

    public boolean canFit(int width, int height)
    {
        return width >= 2 && height >= 2;
    }

    public static class Factory implements IRecipeFactory
    {
        @Override
        public IRecipe parse(final JsonContext context, final JsonObject json)
        {
            return new RecipeTents();
        }
    }
}

 

 

 

If you can make them in JSON, do. This is so that they can be disabled by data packs in 1.13, and allow customisation of your mod. If you’ve got a lot of recipes, write some code to do it for you! Your a programmer, you have god powers!

About Me

Spoiler

My Discord - Cadiboo#8887

My WebsiteCadiboo.github.io

My ModsCadiboo.github.io/projects

My TutorialsCadiboo.github.io/tutorials

Versions below 1.14.4 are no longer supported on this forum. Use the latest version to receive support.

When asking support remember to include all relevant log files (logs are found in .minecraft/logs/), code if applicable and screenshots if possible.

Only download mods from trusted sites like CurseForge (minecraft.curseforge.com). A list of bad sites can be found here, with more information available at stopmodreposts.org

Edit your own signature at www.minecraftforge.net/forum/settings/signature/ (Make sure to check its compatibility with the Dark Theme)

Link to comment
Share on other sites

16 minutes ago, Cadiboo said:

If you can make them in JSON, do. This is so that they can be disabled by data packs in 1.13, and allow customisation of your mod. If you’ve got a lot of recipes, write some code to do it for you! Your a programmer, you have god powers!

I've got a lot of customisation in one block would be too many json files to even think about.

With this IRecipe file would make it easier to create the recipes, I just can't figure out how to get it to craft my block.

Do I need to register the RecipeTents file anywhere else?

Developer of CampCraft

Link to comment
Share on other sites

3 hours ago, tomtomtom09 said:

Do I need to register the RecipeTents file anywhere else?

The recommended way of adding recipes is with a JSON, why would it be too many? Create them with code if that is easier.

VANILLA MINECRAFT CLASSES ARE THE BEST RESOURCES WHEN MODDING

I will be posting 1.15.2 modding tutorials on this channel. If you want to be notified of it do the normal YouTube stuff like subscribing, ect.

Forge and vanilla BlockState generator.

Link to comment
Share on other sites

13 hours ago, tomtomtom09 said:

I've got a lot of customisation in one block would be too many json files to even think about.

With this IRecipe file would make it easier to create the recipes, I just can't figure out how to get it to craft my block.

Do I need to register the RecipeTents file anywhere else?

If it’s something like dyeing/repairing armor or making fireworks, use code. If it’s _anything_ else use json

About Me

Spoiler

My Discord - Cadiboo#8887

My WebsiteCadiboo.github.io

My ModsCadiboo.github.io/projects

My TutorialsCadiboo.github.io/tutorials

Versions below 1.14.4 are no longer supported on this forum. Use the latest version to receive support.

When asking support remember to include all relevant log files (logs are found in .minecraft/logs/), code if applicable and screenshots if possible.

Only download mods from trusted sites like CurseForge (minecraft.curseforge.com). A list of bad sites can be found here, with more information available at stopmodreposts.org

Edit your own signature at www.minecraftforge.net/forum/settings/signature/ (Make sure to check its compatibility with the Dark Theme)

Link to comment
Share on other sites

Just now, diesieben07 said:

No. Use JSON, period. Custom factories exist for a reason.

How would you implement repairing armor with json?

About Me

Spoiler

My Discord - Cadiboo#8887

My WebsiteCadiboo.github.io

My ModsCadiboo.github.io/projects

My TutorialsCadiboo.github.io/tutorials

Versions below 1.14.4 are no longer supported on this forum. Use the latest version to receive support.

When asking support remember to include all relevant log files (logs are found in .minecraft/logs/), code if applicable and screenshots if possible.

Only download mods from trusted sites like CurseForge (minecraft.curseforge.com). A list of bad sites can be found here, with more information available at stopmodreposts.org

Edit your own signature at www.minecraftforge.net/forum/settings/signature/ (Make sure to check its compatibility with the Dark Theme)

Link to comment
Share on other sites

19 hours ago, Animefan8888 said:

The recommended way of adding recipes is with a JSON, why would it be too many? Create them with code if that is easier.

Got a lot of stored types inside the block which creates a different tent depending on the crafting input.

Just an example of the planning.

Spoiler

JUNGLE TENT
	JUNGLE BED
		FENCE 1
			TORCH 1
				GLASS BLOCK 1
					SIZE SMALL.json file
						"BlockEntityTag"
						{
							"TentType":Jungle
							"BedType":Jungle
							"FenceType":1
							"TorchType":1
							"TentSize":Small
							"WindowBlock":White
						}
					SIZE MEDIUM
					SIZE LARGE
				GLASS BLOCK 2
				GLASS BLOCK 3 - 34
			TORCH 2
			TORCH 3
			TORCH 4
			TORCH 5
		FENCE 2
		FENCE 3
		FENCE 4
		FENCE 5
		FENCE 6
		FENCE 7
DESERT TENT
TUNDRA TENT
NETHER TENT
PINK TENT
YELLOW TENT
BROWN TENT
BLACK TENT
BLUE TENT
GREEN TENT

 

 
9 hours ago, diesieben07 said:

You implement IRecipeFactory to produce an IRecipe that does the repairing based on input from JSON. You could then specify the type of armor the recipe works with in JSON.

Of course you need actual code to handle the logic of the recipe, but the registration happens through JSON.

 

thank you, hopefully I can work it out :)

Developer of CampCraft

Link to comment
Share on other sites

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.
Note: Your post will require moderator approval before it will be visible.

Guest
Unfortunately, your content contains terms that we do not allow. Please edit your content to remove the highlighted words below.
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

Announcements



  • Recently Browsing

    • No registered users viewing this page.
  • Posts

    • Baba  Serege [[+27-73 590 8989]] has experience of 27 years in helping and guiding many people from all over the world. His psychic abilities may help you answer and resolve many unanswered questions. He specialize in helping women and men from all walks of life.. 1) – Bring back lost lover. even if lost for a long time. 2) – My lover is abusing alcohol, partying and cheating on me I urgently need help” 3) – Divorce or court issues. 4) – Is your love falling apart? 5) – Do you want your love to grow stronger? 6) – Is your partner losing interest in you? 7) – Do you want to catch your partner cheating on you? – We help to keep your partner faithful and loyal to you. 9) – We recover love and happiness when relationship breaks down. 10) – Making your partner loves you alone. 11) – We create loyalty and everlasting love between couples. 12) – Get a divorce settlement quickly from your ex-partner. 13) – We create everlasting love between couples. 14) – We help you look for the best suitable partner. 15) – We bring back lost lover even if lost for a long time. 16) – We strengthen bonds in all love relationship and marriages 17) – Are you an herbalist who wants to get more powers? 18) – Buy a house or car of your dream. 19) – Unfinished jobs by other doctors come to me. 20) – I help those seeking employment. 21) – Pensioners free treatment. 22) – Win business tenders and contracts. 23) – Do you need to recover your lost property? 24) – Promotion at work and better pay. 25) – Do you want to be protected from bad spirits and nightmares? 26) – Financial problems. 27) – Why you can’t keep money or lovers? 28) – Why you have a lot of enemies? 29) – Why you are fired regularly on jobs? 30) – Speed up money claim spell, delayed payments, pension and accident funds 31) – I help students pass their exams/interviews. 33) – Removal of bad luck and debts. 34) – Are struggling to sleep because of a spiritual wife or husband. 35- ) Recover stolen property
    • OLXTOTO adalah situs bandar togel online resmi terbesar dan terpercaya di Indonesia. Bergabunglah dengan OLXTOTO dan nikmati pengalaman bermain togel yang aman dan terjamin. Koleksi toto 4D dan togel toto terlengkap di OLXTOTO membuat para member memiliki pilihan taruhan yang lebih banyak. Sebagai situs togel terpercaya, OLXTOTO menjaga keamanan dan kenyamanan para membernya dengan sistem keamanan terbaik dan enkripsi data. Transaksi yang cepat, aman, dan terpercaya merupakan jaminan dari OLXTOTO. Nikmati layanan situs toto terbaik dari OLXTOTO dengan tampilan yang user-friendly dan mudah digunakan. Layanan pelanggan tersedia 24/7 untuk membantu para member. Bergabunglah dengan OLXTOTO sekarang untuk merasakan pengalaman bermain togel yang menyenangkan dan menguntungkan.
    • Baba  Serege [[+27-73 590 8989]] has experience of 27 years in helping and guiding many people from all over the world. His psychic abilities may help you answer and resolve many unanswered questions. He specialize in helping women and men from all walks of life.. 1) – Bring back lost lover. even if lost for a long time. 2) – My lover is abusing alcohol, partying and cheating on me I urgently need help” 3) – Divorce or court issues. 4) – Is your love falling apart? 5) – Do you want your love to grow stronger? 6) – Is your partner losing interest in you? 7) – Do you want to catch your partner cheating on you? – We help to keep your partner faithful and loyal to you. 9) – We recover love and happiness when relationship breaks down. 10) – Making your partner loves you alone. 11) – We create loyalty and everlasting love between couples. 12) – Get a divorce settlement quickly from your ex-partner. 13) – We create everlasting love between couples. 14) – We help you look for the best suitable partner. 15) – We bring back lost lover even if lost for a long time. 16) – We strengthen bonds in all love relationship and marriages 17) – Are you an herbalist who wants to get more powers? 18) – Buy a house or car of your dream. 19) – Unfinished jobs by other doctors come to me. 20) – I help those seeking employment. 21) – Pensioners free treatment. 22) – Win business tenders and contracts. 23) – Do you need to recover your lost property? 24) – Promotion at work and better pay. 25) – Do you want to be protected from bad spirits and nightmares? 26) – Financial problems. 27) – Why you can’t keep money or lovers? 28) – Why you have a lot of enemies? 29) – Why you are fired regularly on jobs? 30) – Speed up money claim spell, delayed payments, pension and accident funds 31) – I help students pass their exams/interviews. 33) – Removal of bad luck and debts. 34) – Are struggling to sleep because of a spiritual wife or husband. 35- ) Recover stolen property
  • Topics

×
×
  • Create New...

Important Information

By using this site, you agree to our Terms of Use.