Jump to content

Forge 1.12 - NBT-Data in MetaData-Item and JSON-Recipes


CyberPunkBln

Recommended Posts

Hello,

 

a short question. I have an Item with MetaDatas with SubItems. All functioned perfectly but i use only the MetaDatas for Textures, Models and Recipes. The NBT-Data i use for the durability.

 

Now i have a:

 

GameRegistry.addSmelting(new ItemStack(this, 1, 2), new ItemStack(this, 1, 4), 0);

 

and a ConfigVariable from a Config-File for the max Durability.

 

The max Durability is an NBT-Data. And now i have the Problem that the Recipes accepts the Items with all Durability and make an Item with full Durability.

 

I think i can use NBT-Data like:

 

"nbt":
            {
                "durability": 5
            }

 

in accpeted Items in the Receipt. But when is okay to use NBT-Data not in the ouput so in the input.

 

Where can say forge to use my Config-Variable from the Config-File maxDurability?

 

Give it Variables in the JSON-Recipe-Files?

 

thx

 

Edit: No NBT-Data in Inputs from JSON-Recipes don't functioned. That the question how can i use NBT-Data for inputs in Smelting and Crafting Recipes?

Edited by CyberPunkBln
Link to comment
Share on other sites

Short and Dirty Hack :),

 

i have found a short hack, but this can not be reason:(.

 

When the Item become duranility lost i change the MetaData to one Int higher and then all functioned and the Items will not be used in the Recipes, why the Recipes uses the MetaDatas.

 

Also one count above the registered subitems.

 

But how i say this can not be the reason and it must be possible to use nbt-data in crafting- and smelting-recipes and with an config-variables. I found this Dirty Hack functioned to well:).

Link to comment
Share on other sites

Hi,

thx for that help. I will use first nbt-data without an variable.

 

A custom ingredient, can you explain this? Where i must define this custom ingredient?

 

And another crossside question with the smelting recipes. How can i made smelting recipes that only accept items with an specific nbt-data (can i expand the StackObject with nbt-data?))?

And how can i set nbt-data after smelting done? All my smelted items will be smelted without nbt-data?

Link to comment
Share on other sites

8 minutes ago, CyberPunkBln said:

A custom ingredient, can you explain this? Where i must define this custom ingredient?

 

Create a class that extends Ingredient or a subclass like IngredientNBT. Override Ingredient#getMatchingStacks and/or Ingredient#apply if you need to.

 

Create a class that implements IIngredientFactory and returns a new instance of your Ingredient from the parse method. Specify the IIngredientFactory class in recipes/_factories.json.

 

FurnaceRecipes doesn't check NBT, so you can't restrict smelting ingredients to specific NBT values. It does preserve the original NBT data of the smelting result, though.

Please don't PM me to ask for help. Asking your question in a public thread preserves it for people who are having the same problem in the future.

Link to comment
Share on other sites

Hello,

 

thx this will me help.

 

@Choonster

I use GameRegistry.addSmelting(new ItemStack(this, 1, 3), new ItemStack(this, 1, 4), 0); for registry Smelting Recipes why i can use an ItemStack with MetaData.

And after the Smelting the Item all NBT are lost.

 

Should i use FurnaceRecipes, should this preserve my nbt-data?

 

Link to comment
Share on other sites

10 minutes ago, CyberPunkBln said:

I use GameRegistry.addSmelting(new ItemStack(this, 1, 3), new ItemStack(this, 1, 4), 0); for registry Smelting Recipes why i can use an ItemStack with MetaData.

And after the Smelting the Item all NBT are lost.

 

Should i use FurnaceRecipes, should this preserve my nbt-data?

 

Each overload of GameRegistry.addSmelting calls the corresponding FurnaceRecipes method. There's no difference between the GameRegistry and FurnaceRecipes methods.

 

The NBT data on the result ItemStack you pass to these methods will be copied to the smelting result. The NBT data on the ingredient ItemStack is completely ignored.

Please don't PM me to ask for help. Asking your question in a public thread preserves it for people who are having the same problem in the future.

Link to comment
Share on other sites

:)

 

Yes i have read wrong, my fault.

 

GameRegistry make an instance of FurnaceRecipes :).

 

And gives it an option set the nbt-data after smelting? I mean @Override public void onCreated(ItemStack stack, World worldIn, EntityPlayer playerIn) ist the wrongest way or? When i cannot gives an Item after the smelting an nbt-data hours of coding are for nothing :) .

Link to comment
Share on other sites

Item#onCreated can be used to add NBT data to the result ItemStack of a crafting, smelting or merchant recipe; but it can't do so based on the ingredients.

Please don't PM me to ask for help. Asking your question in a public thread preserves it for people who are having the same problem in the future.

Link to comment
Share on other sites

Yes when i want to write ro an already smelted item i became an null pointer exception.


 

@Override
    public void onCreated(ItemStack stack, World worldIn, EntityPlayer playerIn)
    {
        NBTTagCompound nbt = stack.getTagCompound();
        if (nbt != null)
        {
            nbt.setInteger ("durability",ModConfig.plastic_durability);
            System.out.println ("NO NBT");
        }
        else
        {
            System.out.println ("NBT");
            nbt.setInteger ("durability",ModConfig.plastic_durability);
        }
    }

 

The console output says me that the nbt set and when i take the item from the furnace /ct nbt says No NBT.

 

Are this two events one onCreated for the smelted item and one onCreated for taking the item? Can it be that the result ItemStack and the Ingredient Item Stack will be called in this Event? I'm confused, how can use the result ItemStack to attach nbt-data on?

 

I think onCreated are my last chance. So i must make an Transferitem that comes from the furnace and will be made right after burning with a shapeless recipe.

 

 

Edited by CyberPunkBln
Link to comment
Share on other sites

1 hour ago, CyberPunkBln said:

The console output says me that the nbt set and when i take the item from the furnace /ct nbt says No NBT.

 

Your code is incorrect, you're printing "NO NBT" when the ItemStack when nbt isn't null (i.e. when it has a compound tag) and calling a method on nbt when it is null (causing the NullPointerException).

 

If ItemStack#getTagCompound returns null or ItemStack#hasTagCompound returns false, you need to create an NBTTagCompound and call ItemStack#setTagCompound to set it as the ItemStack's compound tag.

 

I use this method in my code to get or create an ItemStack's compound tag. You can also use ItemStack#getOrCreateSubCompound to get or create a sub-compound of the ItemStack's compound tag or ItemStack#setTagInfo to set a key of the ItemStack's compound tag to the specified NBT tag. These will both create the compound tag if necessary.

Please don't PM me to ask for help. Asking your question in a public thread preserves it for people who are having the same problem in the future.

Link to comment
Share on other sites

1 hour ago, CyberPunkBln said:

Are this two events one onCreated for the smelted item and one onCreated for taking the item? Can it be that the result ItemStack and the Ingredient Item Stack will be called in this Event? I'm confused, how can use the result ItemStack to attach nbt-data on?

 

Item#onCreated is called when the ItemStack is taken from the output slot of a furnace, crafting table or villager trade GUI.

 

You wouldn't need to set the durability when the item is crafted if you used Minecraft's system of 0 being fully-repaired and X (where X is some positive number) being fully-damaged.

Edited by Choonster

Please don't PM me to ask for help. Asking your question in a public thread preserves it for people who are having the same problem in the future.

Link to comment
Share on other sites

Hi,

 

oh no what a failure :) , i have this failure in another part and have say, not two times. But this with the != and == i make at a rolling band. Thanx, i have was thinking "this cannot be, only when i refer on an not existend object it can be a null pingter exception in this matter.

 

Yes wonderful i was started with clean code (iam mainly a php coder, with that oop knowledge for years, and now i pull my old j2me knowledge for this, but when i read forum threads it give darker minecraft mod-dev times:)) and i have make an code with an Item/Subitem where the metatag was taken for durability and main-texture, after hours i have seen only a Tool with Durability or an with SubItems not both. But then nbt-tags was the Resolution for my problem that Items with subitems and setMaxDamage don't have SubTextures, but nbt-tags are very very usefull.

 

And every looks at the moment good and the in my mind comes, uh i have forgot to test the furnace and what happends with my Config-Vars in nbt-tags in json-recipes.

 

Cool Thanx a lot, i go and test first with the right condition set:).

Link to comment
Share on other sites

Great its functioned and i have all my NBT-Data Problems solved. My hack from my first answer on my post itself is at the momet fully usable, but i know it gives other and better methods that i will learn the next days. At the moment i test this on my real modpack.

 

@Override
	public void onCreated(ItemStack stack, World worldIn, EntityPlayer playerIn)
    {
		if (!stack.hasTagCompound())
		{
			stack.setTagCompound(new NBTTagCompound());
			NBTTagCompound nbt = stack.getTagCompound();
			nbt.setInteger ("canteen_uses",ModConfig.plastic_durability);
		}
    }

 

But i think in the next hours i put all my functions in util-classes i study your code very intrested. Object Orientated is one thing, the right structure the other.

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



×
×
  • Create New...

Important Information

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