Difference between revisions of "Datageneration/Tags"

From Forge Community Wiki
(Update to 1.17)
(Update to 1.18.2)
Line 7: Line 7:
  
 
==Items/Blocks==
 
==Items/Blocks==
First you should make a <code>Tag$Named</code> with <code>ItemTags#bind</code> for Items or <code>BlockTags#bind</code> for blocks, this will take the name of you Tag, see [[Tags#Conventions]]
+
First you should make a <code>TagKey</code> with <code>ItemTags#create</code> for Items or <code>BlockTags#create</code> for blocks, this will take the name of you Tag, see [[Tags#Conventions]]
for more info. After you have the <code>Tag$Named</code> you can start with the actual creation of the Tag, you would first call <code>TagsProvider#tag</code> which takes the tag as an argument, this returns a <code>TagsProvider$TagAppender</code>. Now you can with <code>TagsProvider$TagAppender#add</code> add one or more Items/Blocks or other Tags to your own Tags.  
+
for more info. After you have the <code>TagKey</code> you can start with the actual creation of the Tag, you would first call <code>TagsProvider#tag</code> which takes the tag as an argument, this returns a <code>TagsProvider$TagAppender</code>. Now you can with <code>TagsProvider$TagAppender#add</code> add one or more Items/Blocks or other Tags to your own Tags.  
  
 
Example for an Item Tag:
 
Example for an Item Tag:
 
<syntaxhighlight lang="java">
 
<syntaxhighlight lang="java">
Tag.Named<Item> copperTag = ItemTags.bind("forge:ore/copper");
+
TagKey<Item> copperTag = ItemTags.create(new ResourceLocation("forge", "ore/copper"));
 
tag(copperTag).add(Init.COPPER_ORE_ITEM.get());
 
tag(copperTag).add(Init.COPPER_ORE_ITEM.get());
 
</syntaxhighlight>
 
</syntaxhighlight>

Revision as of 12:27, 22 March 2022

This page is under construction.

This page is incomplete, and needs more work. Feel free to edit and improve this page!

Tags can be generated by extending the ItemTagsProvider for Items or BlockTagsProvider for Blocks. For Custom Objects you would need to expand TagsProvider and give it the Object you want tags for. For the registration of you Tags you need to override the TagsProvider#addTags method.


Information

You can still use TagsProvider for Items and Blocks but you would need to implement a lot of stuff that is already done in ItemTagsProvider and BlockTagsProvider

Items/Blocks

First you should make a TagKey with ItemTags#create for Items or BlockTags#create for blocks, this will take the name of you Tag, see Tags#Conventions for more info. After you have the TagKey you can start with the actual creation of the Tag, you would first call TagsProvider#tag which takes the tag as an argument, this returns a TagsProvider$TagAppender. Now you can with TagsProvider$TagAppender#add add one or more Items/Blocks or other Tags to your own Tags.

Example for an Item Tag:

TagKey<Item> copperTag = ItemTags.create(new ResourceLocation("forge", "ore/copper"));
tag(copperTag).add(Init.COPPER_ORE_ITEM.get());


Custom Type for Tags

TBD