Add tag builder method for the new optional entries (#1173)

* Add tag builder method for the new optional entries

* Address comments

* Rename addOptional to addOptionalObject

* Flesh out doc

* Move mixin to target proper class
This commit is contained in:
Vincent Lee 2020-11-28 13:47:30 -06:00 committed by GitHub
parent 3f591ea5c5
commit 7b0dfdfd06
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
3 changed files with 91 additions and 0 deletions

View file

@ -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<T> {
/**
* Add an optional entry of type {@code <T>} 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);
}

View file

@ -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<T> implements FabricDataGeneratorTagBuilder<T> {
@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);
}
}

View file

@ -4,6 +4,7 @@
"compatibilityLevel": "JAVA_8", "compatibilityLevel": "JAVA_8",
"mixins": [ "mixins": [
"AccessorFluidTags", "AccessorFluidTags",
"MixinObjectBuilder",
"MixinTagImpl", "MixinTagImpl",
"MixinTagBuilder" "MixinTagBuilder"
], ],