Custom tags in NeoForge Minecraft modding are reusable groupings of items, blocks, or other game elements that allow modders to avoid hardcoding lists in multiple places. To create custom tags, you define a Java class with static tag keys using BlockTags.create() for blocks or ItemTags.create() for items, then populate them through data generation providers. These tags can be referenced in mod code using the is() method to check if a block or item belongs to the tag, enabling features like metal detectors that detect specific ores or magic blocks that transform particular items.
Inmersión profunda
Prerrequisito
- No hay datos disponibles.
Próximos pasos
- No hay datos disponibles.
Inmersión profunda
NeoForge Modding Tutorial - Minecraft 26.1: Custom Tags | #13Añadido:
Let's add custom tags to our Minecraft mod. If you want to go deeper, the 26.x modding courses are linked down below.
30 plus hours covering complex block entities with fluid and energy handling, custom mobs, custom networking, and even custom biomes and dimensions. Everything you need for 26.x all in one place, linked down below in the description.
All right, we finally got back into the ones more and in this tutorial we're going to be adding custom tags. Now, these are not the name tags. No, no, no.
These are tags that group together items, blocks, or other things, which we've seen previously with the minable tag as well as the needs eggs tool tag.
And yes, we will expand this as well to include our custom ones. For this, we're going to make a new Java class. First of all, we need to turn on my package, a new package called tags. And inside there, we'll make the mod tags class.
There we go. Now, inside here, we'll actually have static class So, we'll first make the public static class of blocks, which is going to contain the block tags, and then the items as well.
But let's just do the private static tag key. It is the tag key of type block, making sure, very important, we choose net.minecraft.world.level.block otherwise it's not going to properly work. This is the create tag method with a string name parameter. And here we're going to return block tags.create and passing in an identifier from namespace and path with tutorialmod.mored and the name here as well. As per usual, the code is available to you down below, so you can double check it there. We're going to duplicate the blocks over here and make it the items. Change the block tag or the tag key from block to item, and then here just change to, can you guess it? Exactly, item tags.create.
Boom. And just like that, we got ourselves two, well, classes which are going to allow us to actually create our own custom tag. Now, why do we need custom tags? Well, in our case, we have two places that we sort of, well, we're basically hardcoding things. That is once in the metal detector where we say, well, iron, diamond, deepslate, and deepslate diamond ore over here, these are the valuable blocks right here, okay? And then in the in the block over here in the magic block, we're saying the same thing but with items to change when we throw them on the magic block.
Now, interestingly enough, both of those are perfectly amazing moments to use tags. So, in the blocks one, we're going to make a public static final tag key of type block, and this is going to be our metal detectables equal to the create tag method passing in a string over here with the name metadetectable metadetectables. There we go. I mean, you can call them whatever you want in theory, but, you know, obviously, making a name that sort of makes sense is sensible. Now, this is for blocks as the metal detector literally detects blocks, and the magic block, well, that one actually needs items. So, for that, we're going to have an item tag. This is going to be a public static final tag key of type item, and we're going to call here this the transformable _items.
Sure, there we go. Create the tag the transformable _ No, that's not quite right. There we go. Items. Easy enough. Now, before we use these tags, let's actually first of all populate them. And to populate them, let's start with the block one because we already have the blocks tags provider over here. This goes the same way that we've seen this previously with the other tags. We call the tag method over here. Of course, this is all done via data gen. We call modtags.blocks.metadetectables, and then we add whatever blocks we want.
So, let's say, for example, blocks.
I think we can literally just say ores.
So, that would be actually be the add tag method over here cuz I'm pretty sure the ores they have all of the ores in there. And if you are like, "I actually want to kind of just get all of the ores, right?" So those would be copper ores, diamond ores, all of those, then we can just do that with the manure, but I think butter boom. That's it. And now it's going to be able to detect all of the ores. Now you might say, "But couldn't we just also use the ores tag and like use that right here?" Um we could, but this is a bit more specific. Also maybe we want to add different blocks over here as well, right? You might say maybe or maybe you want to add a different type of block. Maybe you want to add metal bars or something like that. So it's it's possible that you wanted to expand this in the future as well. Or there's all sorts of different reasons or or things that you might be able to do here. So yeah, for the time being we're just going to keep it like this and add the tag cuz of course you can add tags to tags. There's no reason why you couldn't. And we'll keep it like this. Then to make the item tag we actually need another class because we need the item tags provider. So mod items and mod item tags provider over here in the data gen package, which will extends the item tags provider over here if I'm not mistaken. That will should be correct. Implement the add tags method.
Hover over again create constructor matching super. Of course we're going to remove the mod ID because we can simply replace it with tutorial mod that mod ID. Easy enough. And in these ones in in the add tags, the same thing. We call the tag method over here. This is mod tags.items.transformableitems.
And then here we can add those items.
What do we have right now? Let's take double check in the in the magic blocks.
We have ingot, the iron ingot, the redstone, and asherite. Okay, so let's do items. No, no, no, let's do items.iron_ingot.
Then we do redstone. And then just like add another one over here.
Maybe not the copper block, maybe a maybe a copper ingot as well. I think that that's okay. And then our own custom one as well. Absolutely, that's going to be mod items. dot Azurite you know Azurite over here. dot get of course let's not forget the dot get call for our custom one as this is of course saved as a deferred item while the normal items are all saved as items. That is why we need to call the dot get method in order for this to properly work. For the mod item tags provider, we can simply call this I mean super easy mod item tags provider passing in the pack output as well as the lookup provider over here. Just add it to the gather client data event.
Nothing complicated over here in this case what we've seen couple of times over here with data gen already. Now that we've populated those, we of course still need to run the data gen a run configuration in a second but once we do that, well then what we can do is we're going to be able to use it but we can already use it right here. So here we're just going to say if the block state is mod tags. blocks.
metal detectables. Boom. Done right here for the metal detector and literally the same thing. We're going to use the is method here again as well. mod tags.
items. transformable items. And just like that we're using our tags. So let's run the data gen task over here for our custom tags to generate. Those will now also generate under our tutorial mod package over here or under the name space and you can see metal detectables as well as the transformable items. So we can see here we're just literally pointing to the ores tag and then here we have the other ones. Pretty freaking neat and with all of that done, I think that let's jump into the game man. See if it works. All right fans I'm back in Minecraft. Let's first of all see if I can detect some new stuff. Look at that deepslate redstone ore we well we didn't weren't able to detect that before. We got some coal right here. Let's see if we can find another Oh, there's some diamonds right there. Bing bing bing look at that. I found me some diamonds.
Absolutely fantastic. So, you can see that all works wonders. And of course, throwing copper on here, boom, it works.
Throwing iron ingots on here, that's going to work as well. And redstone also is going to work. However, you know, other stuff does not work exactly like we, you know, expect to. And that's custom tags. Pretty freaking cool, man.
Know that with the membership you get 2 weeks of early access to these videos, but that's going to be it for this tutorial right here. And next time we'll talk about custom stairs. Hope to see you there. So, yeah.
Videos Relacionados
Agentforce NOW AMA: Build with React and Salesforce Multi-Framework
SalesforceDevs
490 views•2026-05-28
How agent o11y differs from traditional o11y — Phil Hetzel, Braintrust
aiDotEngineer
450 views•2026-05-28
Re: 🗣️📍theprophedu📍2026 GST 103 CLASS (E-EXAM REVISION)
theprophedu
636 views•2026-06-04
WEB TECHNOLOGIES UNIT-2 | Degree 4th sem BCOM Computers web technologies unit-2 full explanation💯✅
LearnwithSahera
1K views•2026-05-29
More tests are always better? How to use AI to identify tests that bring little value
Alliance4Qualification
335 views•2026-05-29
Search Algorithms Explained in 60 Seconds! 🤖💨
samarthtuliofficial
218 views•2026-06-01
People of Game of Thrones using JavaScript DOM
AltCampus
296 views•2026-05-30
Instagram accounts got PWNed
EricParker
13K views•2026-06-03











