Jump to content

[1.12]? Registering items with data ids


jonesto95

Recommended Posts

Hi

I'm making a mod that contains, among other things, colored wood. I originally went about this in previous versions by making a separate item class for each color and each wood type combination. I know this is extremely inefficient, but I don't know how to handle data values in the code (I'll probably need two if possible, one for the color and one for the wood type). 

How do I go about working with data id values to the colored wood blocks?

Link to comment
Share on other sites

Data values and NBT tags are two different things. The data value is an integer, and you can only have one data value per item/item stack. So if you're trying to keep track of both color and wood type, unless you can represent all combinations of those things within a single integer from 0 to 15, you can't use data values for it.

But overall, even if you're using NBT tags for this, it's pretty easy. You'd register all your possible item variant model locations with ModelLoader.registerItemVariants(), then you'd supply a customMeshDefinition function that does the logic to determine which model should be used at any given time. Check out this tutorial file for a bit more clarity: https://github.com/McJty/ModTutorials/blob/master/src/main/java/mcjty/modtut/items/MultiModelItem.java

 

Note that the customMeshDefintion function can have any logic you want, whether it be based on the item stack's metadata, NBT tags, or anything else that can be obtained from an ItemStack within the Item class.

Whatever Minecraft needs, it is most likely not yet another tool tier.

Link to comment
Share on other sites

Ok, I got around to looking at the code, it seems the item just toggles between being red and blue upon a right-click. I don't see how you can make a .json recipe file that produces a red item as opposed to a blue one, which is what I ultimately need for my mod, to be able to craft these specific colors with dyes (sorry I didn't specify that before).

Let's say I'll make a class for each wood type. That now allows for us to use data values for the blocks, how would I go about doing that instead of NBT tags?

Link to comment
Share on other sites

Ok, further update.

I managed to get 16 colored blocks in using the data tags, now I only have one question:

How would I specify the names and textures of each block? I added one line in the .lang and it wound up renaming all 16 of them at once.

Link to comment
Share on other sites

On 7/1/2017 at 4:04 PM, IceMetalPunk said:

Data values and NBT tags are two different things. The data value is an integer, and you can only have one data value per item/item stack. So if you're trying to keep track of both color and wood type, unless you can represent all combinations of those things within a single integer from 0 to 15, you can't use data values for it.

Uh.

The 0-15 limit is for blocks. Item stacks have a limit of 0-32,000 (and a bit).

Apparently I'm a complete and utter jerk and come to this forum just like to make fun of people, be confrontational, and make your personal life miserable.  If you think this is the case, JUST REPORT ME.  Otherwise you're just going to get reported when you reply to my posts and point it out, because odds are, I was trying to be nice.

 

Exception: If you do not understand Java, I WILL NOT HELP YOU and your thread will get locked.

 

DO NOT PM ME WITH PROBLEMS. No help will be given.

Link to comment
Share on other sites

Blocks and ItemBlocks aren't the same thing, still.

Blocks in the world can only contain metadata (0-15) and nothing else. If you want additional data, you need a TileEntity (NBT does not apply to blocks).

Apparently I'm a complete and utter jerk and come to this forum just like to make fun of people, be confrontational, and make your personal life miserable.  If you think this is the case, JUST REPORT ME.  Otherwise you're just going to get reported when you reply to my posts and point it out, because odds are, I was trying to be nice.

 

Exception: If you do not understand Java, I WILL NOT HELP YOU and your thread will get locked.

 

DO NOT PM ME WITH PROBLEMS. No help will be given.

Link to comment
Share on other sites

5 hours ago, Draco18s said:

Blocks and ItemBlocks aren't the same thing, still.

Blocks in the world can only contain metadata (0-15) and nothing else. If you want additional data, you need a TileEntity (NBT does not apply to blocks).

Right, but if you try representing more than 16 blocks with an ItemBlock, then as soon as it's placed in the world, all hell will break loose. (And by that, I mean "it won't work".)

 

5 hours ago, jonesto95 said:

I've settled with making separate ColoredOak, ColoredBirch, etc. classes, so now I'm just dealing with the color per wood type (just like wool, concrete, beds, etc.)

Which you can easily do by using the data value of the ItemBlock; as far as I know, when an ItemBlock is placed in the world, it calls the block's getStateForPlacement() method and passes its metadata in (which, by default, passes the metadata into the getStateFromMeta() method). So you can take that metadata in that method and convert it to the proper block state for your color, and return that.

Edited by IceMetalPunk

Whatever Minecraft needs, it is most likely not yet another tool tier.

Link to comment
Share on other sites

49 minutes ago, IceMetalPunk said:

Right, but if you try representing more than 16 blocks with an ItemBlock, then as soon as it's placed in the world, all hell will break loose. (And by that, I mean "it won't work".)

Only if you naively try to convert from item meta to block meta.

But yes.

Apparently I'm a complete and utter jerk and come to this forum just like to make fun of people, be confrontational, and make your personal life miserable.  If you think this is the case, JUST REPORT ME.  Otherwise you're just going to get reported when you reply to my posts and point it out, because odds are, I was trying to be nice.

 

Exception: If you do not understand Java, I WILL NOT HELP YOU and your thread will get locked.

 

DO NOT PM ME WITH PROBLEMS. No help will be given.

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.