-
Notifications
You must be signed in to change notification settings - Fork 413
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
22 changed files
with
750 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
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.api.tag.v1.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
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,10 @@ | ||
version = getSubprojectVersion(project) | ||
|
||
loom { | ||
accessWidenerPath = file('src/main/resources/fabric-tag-api-v1.accesswidener') | ||
} | ||
|
||
moduleDependencies(project, [ | ||
'fabric-api-base', | ||
'fabric-resource-loader-v0' | ||
]) |
56 changes: 56 additions & 0 deletions
56
fabric-tag-api-v1/src/main/java/net/fabricmc/fabric/api/tag/v1/TagAliasGroup.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,56 @@ | ||
/* | ||
* 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.api.tag.v1; | ||
|
||
import java.util.List; | ||
|
||
import com.mojang.serialization.Codec; | ||
|
||
import net.minecraft.registry.Registry; | ||
import net.minecraft.registry.RegistryKey; | ||
import net.minecraft.registry.tag.TagKey; | ||
|
||
/** | ||
* A group of tags that refer to the same set of registry entries. | ||
* | ||
* <p>Tag alias groups can be defined in data packs in the {@code data/<mod namespace>/fabric/tag_aliases/<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}. | ||
* | ||
* <p>The JSON format of tag alias groups is an object with a {@code tags} list containing plain tag IDs. | ||
* | ||
* <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. | ||
* | ||
* @param tags the tags in the group, must be from the same registry | ||
* @param <T> the type of registry entries in the tags | ||
*/ | ||
public record TagAliasGroup<T>(List<TagKey<T>> tags) { | ||
/** | ||
* {@return the codec for tag alias groups in the specified registry} | ||
* | ||
* @param registryKey the key of the registry where the tags are from | ||
* @param <T> the entry type | ||
*/ | ||
public static <T> Codec<TagAliasGroup<T>> codec(RegistryKey<? extends Registry<T>> registryKey) { | ||
return TagKey.unprefixedCodec(registryKey) | ||
.listOf() | ||
.fieldOf("tags") | ||
.xmap(TagAliasGroup::new, TagAliasGroup::tags) | ||
.codec(); | ||
} | ||
} |
22 changes: 22 additions & 0 deletions
22
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,22 @@ | ||
/* | ||
* 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}. | ||
* | ||
* @see net.fabricmc.fabric.api.tag.v1.TagAliasGroup | ||
*/ | ||
package net.fabricmc.fabric.api.tag.v1; |
21 changes: 21 additions & 0 deletions
21
fabric-tag-api-v1/src/main/java/net/fabricmc/fabric/impl/tag/SimpleRegistryExtension.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,21 @@ | ||
/* | ||
* 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.tag; | ||
|
||
public interface SimpleRegistryExtension extends TagAliasEnabledRegistry { | ||
void fabric_applyPendingTagAliases(); | ||
} |
26 changes: 26 additions & 0 deletions
26
fabric-tag-api-v1/src/main/java/net/fabricmc/fabric/impl/tag/TagAliasEnabledRegistry.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,26 @@ | ||
/* | ||
* 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.tag; | ||
|
||
import java.util.Map; | ||
import java.util.Set; | ||
|
||
import net.minecraft.registry.tag.TagKey; | ||
|
||
public interface TagAliasEnabledRegistry { | ||
void fabric_applyTagAliases(Map<TagKey<?>, Set<TagKey<?>>> aliasGroups); | ||
} |
Oops, something went wrong.