Jump to content

[1.12.2 ] Approaches to create many items of one kind but with different nbt data by using one instance of that item class


Recommended Posts

Posted

Maybe the problem is not explained clearly in the topic. For short, I am going to create a number of chips to act as keys for some machine, but those chips are different instances of one class with different nbt data to make some differences. Thus, using this approach, there need huge codes to realize registry events and I think that is kind of unpractical. Therefore, I want to know whether there is an efficient way to realize this thing because, for blocks, I only need to create a PropertyEnum variable and an Enum class to write down different block states. I really appreciate any help or hints

  • Like 1
Posted

for code example, right now, what i have done is like this:

 

public static final ItemChip ID_CHIP_1 = null;

 

public static final ItemChip ID_CHIP_2 = null;

 

but what i want to realize is like this

 

public static final ItemChip ID_CHIP = null; 

 

and this line of code will give me enough items in my tab

Posted

If I understood correctly, you can try looking up and overriding Block#getSubBlocks and Item#getSubItem.

Make sure you set Item#setHasSubtypes and Block#setHasSubtypes to true though.

Some tips:

Spoiler

Modder Support:

Spoiler

1. Do not follow tutorials on YouTube, especially TechnoVision (previously called Loremaster) and HarryTalks, due to their promotion of bad practice and usage of outdated code.

2. Always post your code.

3. Never copy and paste code. You won't learn anything from doing that.

4. 

Quote

Programming via Eclipse's hotfixes will get you nowhere

5. Learn to use your IDE, especially the debugger.

6.

Quote

The "picture that's worth 1000 words" only works if there's an obvious problem or a freehand red circle around it.

Support & Bug Reports:

Spoiler

1. Read the EAQ before asking for help. Remember to provide the appropriate log(s).

2. Versions below 1.11 are no longer supported due to their age. Update to a modern version of Minecraft to receive support.

 

 

Posted
4 minutes ago, DavidM said:

If I understood correctly, you can try looking up and overriding Block#getSubBlocks and Item#getSubItem.

Make sure you set Item#setHasSubtypes and Block#setHasSubtypes to true though.

so can I use enum class to set different meta number to define different items? For blocks, it provides the function to get data from meta. For items, I do not know whether it is enough to just override gueSubItems() function. Maybe I can write down my individual class to realize? 

Posted
16 minutes ago, DavidM said:

If I understood correctly, you can try looking up and overriding Block#getSubBlocks and Item#getSubItem.

Make sure you set Item#setHasSubtypes and Block#setHasSubtypes to true though.

For now, there is no time for me to code, I will try it tomorrow. Anyway, thx for the hint :) 

Posted
4 minutes ago, QingyangYu16 said:

so can I use enum class to set different meta number to define different items?

If I understood correctly, yes.

In one of my mods I used subitems for items with different metadata. If needed, you can take a look here.

The enum (which turned out to be quite useless in my case) can be viewed here.

Some tips:

Spoiler

Modder Support:

Spoiler

1. Do not follow tutorials on YouTube, especially TechnoVision (previously called Loremaster) and HarryTalks, due to their promotion of bad practice and usage of outdated code.

2. Always post your code.

3. Never copy and paste code. You won't learn anything from doing that.

4. 

Quote

Programming via Eclipse's hotfixes will get you nowhere

5. Learn to use your IDE, especially the debugger.

6.

Quote

The "picture that's worth 1000 words" only works if there's an obvious problem or a freehand red circle around it.

Support & Bug Reports:

Spoiler

1. Read the EAQ before asking for help. Remember to provide the appropriate log(s).

2. Versions below 1.11 are no longer supported due to their age. Update to a modern version of Minecraft to receive support.

 

 

Posted

With metadata being pretty much removed in 1.13, you should be using separate items. Just make an item that takes in a Tier enum in the constructor and instantiate and register the items in a for loop

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.