Jump to content

Recommended Posts

Posted

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.

Posted

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. ?

Posted
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)

  • 2 months later...
Posted

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. :)

Posted (edited)
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
Posted
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. :/

Posted

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)

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



×
×
  • Create New...

Important Information

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