diff --git a/fabric-tag-extensions-v0/src/main/java/net/fabricmc/fabric/api/tag/FabricDataGeneratorTagBuilder.java b/fabric-tag-extensions-v0/src/main/java/net/fabricmc/fabric/api/tag/FabricDataGeneratorTagBuilder.java new file mode 100644 index 000000000..8e491cf08 --- /dev/null +++ b/fabric-tag-extensions-v0/src/main/java/net/fabricmc/fabric/api/tag/FabricDataGeneratorTagBuilder.java @@ -0,0 +1,44 @@ +/* + * 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; + +import net.minecraft.tag.Tag; +import net.minecraft.util.Identifier; + +/** + * Interface implemented by {@link net.minecraft.data.server.AbstractTagProvider.ObjectBuilder} instances when + * Fabric API is present. Useful for data generators. + */ +public interface FabricDataGeneratorTagBuilder { + /** + * Add an optional entry of type {@code } to the tag. + * The object identified by {@code id} is not required to be present on load, + * which is useful for integration with other mods. + * @param id The ID of the object to add + * @see net.minecraft.data.server.AbstractTagProvider.ObjectBuilder#add(T) for the non-optional version of this method. + */ + void addOptionalObject(Identifier id); + + /** + * Add an optional tag entry to the tag. + * The tag identified by {@code id} is not required to be present on load, + * which is useful for integration with other mods. + * @param id The ID of the tag to add + * @see net.minecraft.data.server.AbstractTagProvider.ObjectBuilder#addTag(Tag.Identified) for the non-optional version of this method. + */ + void addOptionalTag(Identifier id); +} diff --git a/fabric-tag-extensions-v0/src/main/java/net/fabricmc/fabric/mixin/tag/extension/MixinObjectBuilder.java b/fabric-tag-extensions-v0/src/main/java/net/fabricmc/fabric/mixin/tag/extension/MixinObjectBuilder.java new file mode 100644 index 000000000..86382a0e2 --- /dev/null +++ b/fabric-tag-extensions-v0/src/main/java/net/fabricmc/fabric/mixin/tag/extension/MixinObjectBuilder.java @@ -0,0 +1,46 @@ +/* + * 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.mixin.tag.extension; + +import org.spongepowered.asm.mixin.Final; +import org.spongepowered.asm.mixin.Mixin; +import org.spongepowered.asm.mixin.Shadow; + +import net.minecraft.data.server.AbstractTagProvider; +import net.minecraft.tag.Tag; +import net.minecraft.util.Identifier; + +import net.fabricmc.fabric.api.tag.FabricDataGeneratorTagBuilder; + +@Mixin(AbstractTagProvider.ObjectBuilder.class) +public class MixinObjectBuilder implements FabricDataGeneratorTagBuilder { + @Shadow + @Final private Tag.Builder field_23960; + + @Shadow + @Final private String field_23962; + + @Override + public void addOptionalObject(Identifier id) { + field_23960.add(new Tag.OptionalObjectEntry(id), field_23962); + } + + @Override + public void addOptionalTag(Identifier id) { + field_23960.add(new Tag.OptionalTagEntry(id), field_23962); + } +} diff --git a/fabric-tag-extensions-v0/src/main/resources/fabric-tag-extensions-v0.mixins.json b/fabric-tag-extensions-v0/src/main/resources/fabric-tag-extensions-v0.mixins.json index 69d9e1270..1b6485c06 100644 --- a/fabric-tag-extensions-v0/src/main/resources/fabric-tag-extensions-v0.mixins.json +++ b/fabric-tag-extensions-v0/src/main/resources/fabric-tag-extensions-v0.mixins.json @@ -4,6 +4,7 @@ "compatibilityLevel": "JAVA_8", "mixins": [ "AccessorFluidTags", + "MixinObjectBuilder", "MixinTagImpl", "MixinTagBuilder" ],