-
Notifications
You must be signed in to change notification settings - Fork 420
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
* Add tag aliases * Document and rename tag alias internals * Make the tag alias directory singular to match Mojang's recent style * Add a note about tag aliases to client tag documentation * Support missing tags in alias groups * Support tag aliases for dynamic and reloadable registries * TagAliasGroup: Document naming conventions for c tag alias groups * Add tag alias test mod * Fix inline return checkstyle * Add test for tag alias data generation * Fix checkstyle (again) * Add tag translations to tag API testmod * Uncomment accidentally commented out code * SimpleRegistryMixin: Improve a log message * TagAliasTest: Improve assertion messages * Fix tag aliases for dynamic registries not applying on /reload * Clean up log message once again * Address review feedback * Make missing interfaces throw CCEs * Add README * Move TagAliasGroup into the impl package (cherry picked from commit a730659)
- Loading branch information
Showing
50 changed files
with
1,256 additions
and
2 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
49 changes: 49 additions & 0 deletions
49
...a-generation-api-v1/src/main/java/net/fabricmc/fabric/impl/datagen/TagAliasGenerator.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,49 @@ | ||
/* | ||
* Copyright (c) 2016, 2017, 2018, 2019 FabricMC | ||
* | ||
* Licensed under the Apache License, Version 2.0 (the "License"); | ||
* you may not use this file except in compliance with the License. | ||
* You may obtain a copy of the License at | ||
* | ||
* http://www.apache.org/licenses/LICENSE-2.0 | ||
* | ||
* Unless required by applicable law or agreed to in writing, software | ||
* distributed under the License is distributed on an "AS IS" BASIS, | ||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
* See the License for the specific language governing permissions and | ||
* limitations under the License. | ||
*/ | ||
|
||
package net.fabricmc.fabric.impl.datagen; | ||
|
||
import java.nio.file.Path; | ||
import java.util.List; | ||
import java.util.concurrent.CompletableFuture; | ||
|
||
import net.minecraft.data.DataOutput; | ||
import net.minecraft.data.DataProvider; | ||
import net.minecraft.data.DataWriter; | ||
import net.minecraft.registry.Registry; | ||
import net.minecraft.registry.RegistryKey; | ||
import net.minecraft.registry.tag.TagKey; | ||
import net.minecraft.util.Identifier; | ||
|
||
import net.fabricmc.fabric.impl.tag.TagAliasGroup; | ||
|
||
public final class TagAliasGenerator { | ||
public static String getDirectory(RegistryKey<? extends Registry<?>> registryKey) { | ||
String directory = "fabric/tag_aliases/"; | ||
Identifier registryId = registryKey.getValue(); | ||
|
||
if (!Identifier.DEFAULT_NAMESPACE.equals(registryId.getNamespace())) { | ||
directory += registryId.getNamespace() + '/'; | ||
} | ||
|
||
return directory + registryId.getPath(); | ||
} | ||
|
||
public static <T> CompletableFuture<?> writeTagAlias(DataWriter writer, DataOutput.PathResolver pathResolver, RegistryKey<? extends Registry<T>> registryRef, Identifier groupId, List<TagKey<T>> tags) { | ||
Path path = pathResolver.resolveJson(groupId); | ||
return DataProvider.writeCodecToPath(writer, TagAliasGroup.codec(registryRef), new TagAliasGroup<>(tags), path); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
6 changes: 6 additions & 0 deletions
6
...stmod/generated/data/fabric-data-gen-api-v1-testmod/fabric/tag_aliases/block/flowers.json
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,6 @@ | ||
{ | ||
"tags": [ | ||
"minecraft:flowers", | ||
"minecraft:flower_pots" | ||
] | ||
} |
6 changes: 6 additions & 0 deletions
6
...n-api-v1/src/testmod/generated/data/other_namespace/fabric/tag_aliases/block/flowers.json
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,6 @@ | ||
{ | ||
"tags": [ | ||
"minecraft:flowers", | ||
"minecraft:flower_pots" | ||
] | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,17 @@ | ||
# Fabric Tag API (v1) | ||
|
||
This module contains APIs for working with data pack tags. | ||
|
||
## Tag aliases | ||
|
||
*Tag alias groups* merge tags that refer to the same set of registry entries. | ||
The contained tags will be linked together and get the combined set of entries | ||
of all the aliased tags in a group. | ||
|
||
Tag alias groups can be defined in data packs in the `data/<mod namespace>/fabric/tag_alias/<registry>` | ||
directory. `<registry>` is the path of the registry's ID, prefixed with `<registry's namespace>/` if it's | ||
not `minecraft`. | ||
|
||
The JSON format of tag alias groups is an object with a `tags` list containing plain tag IDs. | ||
|
||
See the module javadoc for more information about tag aliases. |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,14 @@ | ||
version = getSubprojectVersion(project) | ||
|
||
loom { | ||
accessWidenerPath = file('src/main/resources/fabric-tag-api-v1.accesswidener') | ||
} | ||
|
||
moduleDependencies(project, [ | ||
'fabric-api-base', | ||
'fabric-resource-loader-v0' | ||
]) | ||
|
||
testDependencies(project, [ | ||
':fabric-lifecycle-events-v1', | ||
]) |
52 changes: 52 additions & 0 deletions
52
fabric-tag-api-v1/src/main/java/net/fabricmc/fabric/api/tag/v1/package-info.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,52 @@ | ||
/* | ||
* Copyright (c) 2016, 2017, 2018, 2019 FabricMC | ||
* | ||
* Licensed under the Apache License, Version 2.0 (the "License"); | ||
* you may not use this file except in compliance with the License. | ||
* You may obtain a copy of the License at | ||
* | ||
* http://www.apache.org/licenses/LICENSE-2.0 | ||
* | ||
* Unless required by applicable law or agreed to in writing, software | ||
* distributed under the License is distributed on an "AS IS" BASIS, | ||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
* See the License for the specific language governing permissions and | ||
* limitations under the License. | ||
*/ | ||
|
||
/** | ||
* The Fabric Tag API for working with {@linkplain net.minecraft.registry.tag.TagKey tags}. | ||
* | ||
* <h1>Aliasing tags</h1> | ||
* <dfn>Tag alias groups</dfn> are lists of tags that refer to the same set of registry entries. | ||
* The contained tags will be linked together and get the combined set of entries | ||
* of all the aliased tags in a group. | ||
* | ||
* <p>Tag alias groups can be defined in data packs in the {@code data/<mod namespace>/fabric/tag_alias/<registry>} | ||
* directory. {@code <registry>} is the path of the registry's ID, prefixed with {@code <registry's namespace>/} if it's | ||
* not {@value net.minecraft.util.Identifier#DEFAULT_NAMESPACE}. For example, an alias group for block tags would be placed | ||
* in {@code data/<mod namespace>/fabric/tag_alias/block/}. | ||
* | ||
* <p>The JSON format of tag alias groups is an object with a {@code tags} list. The list contains plain tag IDs with | ||
* no {@code #} prefix. | ||
* | ||
* <p>If multiple tag alias groups include a tag, the groups will be combined and each tag will be an alias | ||
* for the same contents. | ||
* | ||
* <h2>Tag aliases in the {@code c} namespace</h2> | ||
* | ||
* <p>For the names of shared {@code c} tag alias groups, it's important that you use a short and descriptive name. | ||
* A good way to do this is reusing the name of a contained {@code c} tag that follows the naming conventions. | ||
* For example, if the tag alias group contains the tags {@code c:flowers/tall} and {@code minecraft:tall_flowers}, | ||
* the tag alias file should be named {@code flowers/tall.json}, like the contained {@code c} tag. | ||
* | ||
* <p>Tag alias groups in the {@code c} namespace are primarily intended for merging a {@code c} tag | ||
* with an equivalent vanilla tag with no potentially unwanted gameplay behavior. If a vanilla tag affects | ||
* game mechanics (such as the water tag affecting swimming), don't alias it as a {@code c} tag. | ||
* | ||
* <p>If you want to have the contents of a {@code c} tag in your own tag, prefer including the {@code c} tag | ||
* in your tag file directly. That way, data packs can modify your tag separately. Tag aliases make their contained | ||
* tags almost fully indistinguishable since they get the exact same content, and you have to override the alias group | ||
* in a higher-priority data pack to unlink them. | ||
*/ | ||
package net.fabricmc.fabric.api.tag.v1; |
Oops, something went wrong.