tutorial:tags
Differences
This shows you the differences between two versions of the page.
Both sides previous revisionPrevious revisionNext revision | Previous revisionNext revisionBoth sides next revision | ||
tutorial:tags [2022/04/29 09:35] – [1.18.1 and below (Requires Fabric API)] solidblock | tutorial:tags [2022/06/22 07:40] – external edit 127.0.0.1 | ||
---|---|---|---|
Line 14: | Line 14: | ||
The ''" | The ''" | ||
- | For some cases, you might want to have tags checked on code, which will require you to register them: | + | ===== Using tags in code ===== |
- | ==== 1.18.2 and above ==== | + | For some cases, you might want to have tags as registered objects on code. For example, methods like '' |
- | <code java> | + | |
- | import net.minecraft.block.Block; | + | Vanilla tag objects can be found in class ''< |
- | import net.minecraft.tag.TagKey; | + | |
- | import net.minecraft.util.Identifier; | + | |
- | import net.minecraft.util.registry.Registry; | + | |
- | public class BlockTags | + | === 1.18.2 and above === |
- | public static final TagKey<Block> EXAMPLE_ORES = TagKey.of(Registry.BLOCK_KEY, new Identifier(" | + | < |
+ | public class ModBlockTags | ||
+ | public static final TagKey<class_2248> EXAMPLE_ORES = TagKey.of(class_2378.field_25105, new class_2960(" | ||
} | } | ||
- | </code> | + | </yarncode> |
==== 1.18.1 and below (Requires Fabric API) ==== | ==== 1.18.1 and below (Requires Fabric API) ==== | ||
- | <code java> | + | <yarncode |
- | import net.fabricmc.fabric.api.tag.TagFactory; | + | public class ModBlockTags |
- | import net.minecraft.block.Block; | + | public static final Tag<class_2248> EXAMPLE_ORES = TagFactory.BLOCK.create(new |
- | import net.minecraft.tag.Tag; | + | |
- | import net.minecraft.util.Identifier; | + | |
- | + | ||
- | public class BlockTags | + | |
- | public static final Tag<Block> EXAMPLE_ORES = TagFactory.BLOCK.create(new | + | |
} | } | ||
- | </code> | + | </yarncode> |
- | + | ||
- | ==== 1.16.5 and below (Requires Fabric API) ==== | + | |
- | <code java> | + | |
- | public class BlockTags | + | ==== 1.17 and below, not including 1.17.1 (Requires Fabric API) ==== |
- | public static final Tag<Block> EXAMPLE_ORES = TagRegistry.block(new | + | < |
+ | public class ModBlockTags | ||
+ | public static final Tag<class_2248> EXAMPLE_ORES = TagRegistry.block(new | ||
} | } | ||
- | </code> | + | </yarncode> |
+ | Note that `TagRegistry` is deprecated since Fabric API 0.46.0 where `TagFactory` is added, and which does not support 1.17. | ||
===== Common Tags vs Mod Tags ===== | ===== Common Tags vs Mod Tags ===== | ||
- | If your tag applies ONLY to items in your mod, and no other mod is likely to have similar items, or you specifically want to only include your mod's items in that tag, then use '' | + | If your tag applies ONLY to items in your mod, and no other mod is likely to have similar items, or you specifically want to only include your mod's items in that tag, then use '' |
======= Creating New Common Tags ======= | ======= Creating New Common Tags ======= | ||
Common tags should be named with the syntax '' | Common tags should be named with the syntax '' | ||
- | ======= Existing Common Tags ======= | + | ====== Existing Common Tags ====== |
This section was [[https:// | This section was [[https:// | ||
tutorial/tags.txt · Last modified: 2024/06/12 18:34 by cph101