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 was just trying to play my modded world when i randomly got this crash for no reason. I sorted through like every mod and eventually I realized it was LLibrary but I can't seem to find a solution to fix the crashing. I can't lose the world that I have that uses this mod please help me. Here's the report: https://pastebin.com/0D00B79i If anyone has a solution please let me know.  
    • 🤑DAFTAR & LOGIN🤑 🤑DAFTAR & LOGIN🤑 🤑DAFTAR & LOGIN🤑   Daftar Slot Ligawin88 adalah bocoran slot rekomendasi gacor dari Ligawin88 yang bisa anda temukan di SLOT Ligawin88. Situs SLOT Ligawin88 hari ini yang kami bagikan di sini adalah yang terbaik dan bersiaplah untuk mengalami sensasi tak terlupakan dalam permainan slot online. Temukan game SLOT Ligawin88 terbaik dengan 100 pilihan provider ternama yang dipercaya akan memberikan kepuasan dan kemenangan hari ini untuk meraih x500. RTP SLOT Ligawin88 merupakan SLOT Ligawin88 hari ini yang telah menjadi pilihan utama bagi pemain judi online di seluruh Indonesia. Setiap harinya jutaan pemain memasuki dunia maya untuk memperoleh hiburan seru dan kemenangan besar dalam bermain slot dengan adanya bocoran RTP SLOT Ligawin88. Tidak ada yang lebih menyenangkan daripada mengungguli mesin slot dan meraih jackpot x500 yang menggiurkan di situs SLOT Ligawin88 hari ini yang telah disediakan SLOT Ligawin88. Menangkan jackpot besar x500 rajanya maxwin dari segala slot dan raih kemenangan spektakuler di situs Ligawin88 terbaik 2024 adalah tempat yang menyediakan mesin slot dengan peluang kemenangan lebih tinggi daripada situs slot lainnya. Bagi anda yang mencari pengalaman judi slot paling seru dan mendebarkan, situs bo SLOT Ligawin88 terbaik 2024 adalah pilihan yang tepat. Jelajahi dunia slot online melalui situs SLOT Ligawin88 di link SLOT Ligawin88.
    • 🤑DAFTAR & LOGIN🤑 🤑DAFTAR & LOGIN🤑 🤑DAFTAR & LOGIN🤑   Daftar Slot Asusslot adalah bocoran slot rekomendasi gacor dari Asusslot yang bisa anda temukan di SLOT Asusslot. Situs SLOT Asusslot hari ini yang kami bagikan di sini adalah yang terbaik dan bersiaplah untuk mengalami sensasi tak terlupakan dalam permainan slot online. Temukan game SLOT Asusslot terbaik dengan 100 pilihan provider ternama yang dipercaya akan memberikan kepuasan dan kemenangan hari ini untuk meraih x500. RTP SLOT Asusslot merupakan SLOT Asusslot hari ini yang telah menjadi pilihan utama bagi pemain judi online di seluruh Indonesia. Setiap harinya jutaan pemain memasuki dunia maya untuk memperoleh hiburan seru dan kemenangan besar dalam bermain slot dengan adanya bocoran RTP SLOT Asusslot. Tidak ada yang lebih menyenangkan daripada mengungguli mesin slot dan meraih jackpot x500 yang menggiurkan di situs SLOT Asusslot hari ini yang telah disediakan SLOT Asusslot. Menangkan jackpot besar x500 rajanya maxwin dari segala slot dan raih kemenangan spektakuler di situs Asusslot terbaik 2024 adalah tempat yang menyediakan mesin slot dengan peluang kemenangan lebih tinggi daripada situs slot lainnya. Bagi anda yang mencari pengalaman judi slot paling seru dan mendebarkan, situs bo SLOT Asusslot terbaik 2024 adalah pilihan yang tepat. Jelajahi dunia slot online melalui situs SLOT Asusslot di link SLOT Asusslot.
    • 🤑DAFTAR & LOGIN🤑 🤑DAFTAR & LOGIN🤑 🤑DAFTAR & LOGIN🤑 Daftar Slot Galeri555 adalah bocoran slot rekomendasi gacor dari Galeri555 yang bisa anda temukan di SLOT Galeri555. Situs SLOT Galeri555 hari ini yang kami bagikan di sini adalah yang terbaik dan bersiaplah untuk mengalami sensasi tak terlupakan dalam permainan slot online. Temukan game SLOT Galeri555 terbaik dengan 100 pilihan provider ternama yang dipercaya akan memberikan kepuasan dan kemenangan hari ini untuk meraih x500. RTP SLOT Galeri555 merupakan SLOT Galeri555 hari ini yang telah menjadi pilihan utama bagi pemain judi online di seluruh Indonesia. Setiap harinya jutaan pemain memasuki dunia maya untuk memperoleh hiburan seru dan kemenangan besar dalam bermain slot dengan adanya bocoran RTP SLOT Galeri555. Tidak ada yang lebih menyenangkan daripada mengungguli mesin slot dan meraih jackpot x500 yang menggiurkan di situs SLOT Galeri555 hari ini yang telah disediakan SLOT Galeri555. Menangkan jackpot besar x500 rajanya maxwin dari segala slot dan raih kemenangan spektakuler di situs Galeri555 terbaik 2024 adalah tempat yang menyediakan mesin slot dengan peluang kemenangan lebih tinggi daripada situs slot lainnya. Bagi anda yang mencari pengalaman judi slot paling seru dan mendebarkan, situs bo SLOT Galeri555 terbaik 2024 adalah pilihan yang tepat. Jelajahi dunia slot online melalui situs SLOT Galeri555 di link SLOT Galeri555.
    • 🤑DAFTAR & LOGIN🤑 🤑DAFTAR & LOGIN🤑 🤑DAFTAR & LOGIN🤑 Daftar Slot Kocok303 adalah bocoran slot rekomendasi gacor dari Kocok303 yang bisa anda temukan di SLOT Kocok303. Situs SLOT Kocok303 hari ini yang kami bagikan di sini adalah yang terbaik dan bersiaplah untuk mengalami sensasi tak terlupakan dalam permainan slot online. Temukan game SLOT Kocok303 terbaik dengan 100 pilihan provider ternama yang dipercaya akan memberikan kepuasan dan kemenangan hari ini untuk meraih x500. RTP SLOT Kocok303 merupakan SLOT Kocok303 hari ini yang telah menjadi pilihan utama bagi pemain judi online di seluruh Indonesia. Setiap harinya jutaan pemain memasuki dunia maya untuk memperoleh hiburan seru dan kemenangan besar dalam bermain slot dengan adanya bocoran RTP SLOT Kocok303. Tidak ada yang lebih menyenangkan daripada mengungguli mesin slot dan meraih jackpot x500 yang menggiurkan di situs SLOT Kocok303 hari ini yang telah disediakan SLOT Kocok303. Menangkan jackpot besar x500 rajanya maxwin dari segala slot dan raih kemenangan spektakuler di situs Kocok303 terbaik 2024 adalah tempat yang menyediakan mesin slot dengan peluang kemenangan lebih tinggi daripada situs slot lainnya. Bagi anda yang mencari pengalaman judi slot paling seru dan mendebarkan, situs bo SLOT Kocok303 terbaik 2024 adalah pilihan yang tepat. Jelajahi dunia slot online melalui situs SLOT Kocok303 di link SLOT Kocok303.
  • Topics

×
×
  • Create New...

Important Information

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