Jump to content

[1.12/1.13] Use NBT data in crafting


Brickmotion

Recommended Posts

While coding my new mod, I ran into a problem: I want to use the water bottle item from vanilla in my crafting recipe, yet when I use "minecraft:potion_item" as an ingredient, the recipe can use any potion from the game. I do, however, specifically want to use the water bottle, not any other potion. How can I set the NBT data in the recipe to only match that variation of the item, so it won't use any of the other potions?

I'm currently working in 1.12, but I will switch to 1.13 as soon as it's released and a Forge version for it is published, so if this is only possible in 1.13, that would be okay (though if it works in 1.12 as well, that would be even better, as I wouldn't have to wait for 1.13).

 

I hope for a quick reply.

Link to comment
Share on other sites

I checked my code again and realized that I already used "minecraft:potion" instead of "minecraft:potion_item" (potion_item used to be the name it went by in earlier versions, so I got the two mixed up), yet that is exactly where I run into the problem that NBT data is ignored and any potion can be used.

I tried to figure this out by looking at the tipped arrow recipes in the vanilla code, which use specific lingering potions, yet they seem to be implemented in some other way than JSON that I don't know where to look for. ?

Link to comment
Share on other sites

On 6/13/2018 at 11:57 PM, Brickmotion said:

I checked my code again and realized that I already used "minecraft:potion" instead of "minecraft:potion_item" (potion_item used to be the name it went by in earlier versions, so I got the two mixed up), yet that is exactly where I run into the problem that NBT data is ignored and any potion can be used.

I tried to figure this out by looking at the tipped arrow recipes in the vanilla code, which use specific lingering potions, yet they seem to be implemented in some other way than JSON that I don't know where to look for. ?

Yep, those recipes are built-in

net.minecraft.item.crafting.CraftingManager.class

public class CraftingManager
{
    private static final Logger LOGGER = LogManager.getLogger();
    private static int nextAvailableId;
    public static final RegistryNamespaced<ResourceLocation, IRecipe> REGISTRY = net.minecraftforge.registries.GameData.getWrapper(IRecipe.class);

    public static boolean init()
    {
        try
        {
            register("armordye", new RecipesArmorDyes());
            register("bookcloning", new RecipeBookCloning());
            register("mapcloning", new RecipesMapCloning());
            register("mapextending", new RecipesMapExtending());
            register("fireworks", new RecipeFireworks());
            register("repairitem", new RecipeRepairItem());
            register("tippedarrow", new RecipeTippedArrow());
            register("bannerduplicate", new RecipesBanners.RecipeDuplicatePattern());
            register("banneraddpattern", new RecipesBanners.RecipeAddPattern());
            register("shielddecoration", new ShieldRecipes.Decoration());
            register("shulkerboxcoloring", new ShulkerBoxRecipes.ShulkerBoxColoring());
            return parseJsonRecipes();
        }
        catch (Throwable var1)
        {
            return false;
        }
    }

 

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

  • 2 months later...

I hope I'm not resurrecting a dead thread, since it's only been a couple months, but I think I can help you.  If you use a json recipe for your crafting, it allows you to get the NBT data for potions.  Here's an example for you:

 

{
    "type": "minecraft:crafting_shaped",
    
    "pattern":
    [
    	"PPP",
        "PBP",
        "PPP"
    ], 
    
    "key":
    {
        "P":
        {
           "item": "minecraft:potion",
			"data":0
        },
		
	"B":
	{
		"item": "minecraft:bucket"
	}
				
 },
    
    "result":
    {
        "item": "minecraft:water_bucket",
		
        "count": 1
    }
}


I hope this helps. Moreover, I hope you already found the answer you needed and I'm just late to the party, but maybe it can help the next person who sees this. :)

Link to comment
Share on other sites

On 6/13/2018 at 8:57 AM, Brickmotion said:

I checked my code again and realized that I already used "minecraft:potion" instead of "minecraft:potion_item" (potion_item used to be the name it went by in earlier versions, so I got the two mixed up), yet that is exactly where I run into the problem that NBT data is ignored and any potion can be used.

I tried to figure this out by looking at the tipped arrow recipes in the vanilla code, which use specific lingering potions, yet they seem to be implemented in some other way than JSON that I don't know where to look for. ?

the issue with nbt is you need a hasTagsMethod() well NBTTagCompounds could be inside of NBTTagCompounds and inside of that a tag list with another NBTTagCompound and inside of that you get it.

So you need a method for deep comparison then you go how do you compare all tags with .equals() <= >= or simply tag.equals(tag). If your looking for tag.equals(tag) it's very simply to make but, the issue with this is your recipes will break if any other tag is added. now if you want to simply know if it contains tags you need a deep comparison for the nbt. 

I used to have an api for this but, it didn't use recursion so I am going to re-write it. So your options are write an api, use an api, or make an IRecipe which literally checks for tag.equals(tag) which will fail if any other data is there

if you only wanted specific tags and not a deep comparison then you can simply make your own implementation of IRecipe which doesn't check for everything only the things you are going to be checking. The issue with that is you need one IRecipe class per implementation rather then one for everything. 

Edited by jredfox
Link to comment
Share on other sites

10 hours ago, Maideniles said:

I hope I'm not resurrecting a dead thread, since it's only been a couple months, but I think I can help you.  If you use a json recipe for your crafting, it allows you to get the NBT data for potions.  Here's an example for you:

 


{
    "type": "minecraft:crafting_shaped",
    
    "pattern":
    [
    	"PPP",
        "PBP",
        "PPP"
    ], 
    
    "key":
    {
        "P":
        {
           "item": "minecraft:potion",
			"data":0
        },
		
	"B":
	{
		"item": "minecraft:bucket"
	}
				
 },
    
    "result":
    {
        "item": "minecraft:water_bucket",
		
        "count": 1
    }
}


I hope this helps. Moreover, I hope you already found the answer you needed and I'm just late to the party, but maybe it can help the next person who sees this. :)

That solution doesn't work, I can still use any potion in the recipe. :/

Link to comment
Share on other sites

You need a custom Recipe implementation I think

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

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

    • I have been following these exact tutorials for quite a while, I must agree that they are amazing and easy to follow. I have registered the item in the ModFoods class, I tried to do it in ModItems (Where all the items should be registered) but got errors, I think I may need to revert this and figure it out from there. Once again, thank you for your help! 👍 Just looking back, I have noticed in your code you added ITEMS.register, which I am guessing means that they are being registered in ModFoods, I shall go through the process of trial and error to figure this out.
    • ♈+2349027025197ஜ Are you a pastor, business man or woman, politician, civil engineer, civil servant, security officer, entrepreneur, Job seeker, poor or rich Seeking how to join a brotherhood for protection and wealth here’s is your opportunity, but you should know there’s no ritual without repercussions but with the right guidance and support from this great temple your destiny is certain to be changed for the better and equally protected depending if you’re destined for greatness Call now for enquiry +2349027025197☎+2349027025197₩™ I want to join ILLUMINATI occult without human sacrificeGREATORLDRADO BROTHERHOOD OCCULT , Is The Club of the Riches and Famous; is the world oldest and largest fraternity made up of 3 Millions Members. We are one Family under one father who is the Supreme Being. In Greatorldrado BROTHERHOOD we believe that we were born in paradise and no member should struggle in this world. Hence all our new members are given Money Rewards once they join in order to upgrade their lifestyle.; interested viewers should contact us; on. +2349027025197 ۝ஐℰ+2349027025197 ₩Greatorldrado BROTHERHOOD OCCULT IS A SACRED FRATERNITY WITH A GRAND LODGE TEMPLE SITUATED IN G.R.A PHASE 1 PORT HARCOURT NIGERIA, OUR NUMBER ONE OBLIGATION IS TO MAKE EVERY INITIATE MEMBER HERE RICH AND FAMOUS IN OTHER RISE THE POWERS OF GUARDIANS OF AGE+. +2349027025197   SEARCHING ON HOW TO JOIN THE Greatorldrado BROTHERHOOD MONEY RITUAL OCCULT IS NOT THE PROBLEM BUT MAKE SURE YOU'VE THOUGHT ABOUT IT VERY WELL BEFORE REACHING US HERE BECAUSE NOT EVERYONE HAS THE HEART TO DO WHAT IT TAKES TO BECOME ONE OF US HERE, BUT IF YOU THINK YOU'RE SERIOUS MINDED AND READY TO RUN THE SPIRITUAL RACE OF LIFE IN OTHER TO ACQUIRE ALL YOU NEED HERE ON EARTH CONTACT SPIRITUAL GRANDMASTER NOW FOR INQUIRY +2349027025197   +2349027025197 Are you a pastor, business man or woman, politician, civil engineer, civil servant, security officer, entrepreneur, Job seeker, poor or rich Seeking how to join
    • Hi, I'm trying to use datagen to create json files in my own mod. This is my ModRecipeProvider class. public class ModRecipeProvider extends RecipeProvider implements IConditionBuilder { public ModRecipeProvider(PackOutput pOutput) { super(pOutput); } @Override protected void buildRecipes(Consumer<FinishedRecipe> pWriter) { ShapedRecipeBuilder.shaped(RecipeCategory.MISC, ModBlocks.COMPRESSED_DIAMOND_BLOCK.get()) .pattern("SSS") .pattern("SSS") .pattern("SSS") .define('S', ModItems.COMPRESSED_DIAMOND.get()) .unlockedBy(getHasName(ModItems.COMPRESSED_DIAMOND.get()), has(ModItems.COMPRESSED_DIAMOND.get())) .save(pWriter); ShapelessRecipeBuilder.shapeless(RecipeCategory.MISC, ModItems.COMPRESSED_DIAMOND.get(),9) .requires(ModBlocks.COMPRESSED_DIAMOND_BLOCK.get()) .unlockedBy(getHasName(ModBlocks.COMPRESSED_DIAMOND_BLOCK.get()), has(ModBlocks.COMPRESSED_DIAMOND_BLOCK.get())) .save(pWriter); ShapedRecipeBuilder.shaped(RecipeCategory.MISC, ModItems.COMPRESSED_DIAMOND.get()) .pattern("SSS") .pattern("SSS") .pattern("SSS") .define('S', Blocks.DIAMOND_BLOCK) .unlockedBy(getHasName(ModItems.COMPRESSED_DIAMOND.get()), has(ModItems.COMPRESSED_DIAMOND.get())) .save(pWriter); } } When I try to run the runData client, it shows an error:  Caused by: java.lang.IllegalStateException: Duplicate recipe compressed:compressed_diamond I know that it's caused by the fact that there are two recipes for the ModItems.COMPRESSED_DIAMOND. But I need both of these recipes, because I need a way to craft ModItems.COMPRESSED_DIAMOND_BLOCK and restore 9 diamond blocks from ModItems.COMPRESSED_DIAMOND. Is there a way to solve this?
  • Topics

×
×
  • Create New...

Important Information

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