diff --git a/src/main/java/org/betterx/bclib/api/v3/datagen/TagDataProvider.java b/src/main/java/org/betterx/bclib/api/v3/datagen/TagDataProvider.java index 5d3e1858..dacfe8fd 100644 --- a/src/main/java/org/betterx/bclib/api/v3/datagen/TagDataProvider.java +++ b/src/main/java/org/betterx/bclib/api/v3/datagen/TagDataProvider.java @@ -4,12 +4,14 @@ import org.betterx.worlds.together.tag.v3.TagRegistry; import net.minecraft.core.HolderLookup; import net.minecraft.resources.ResourceLocation; +import net.minecraft.tags.TagKey; import net.fabricmc.fabric.api.datagen.v1.FabricDataOutput; import net.fabricmc.fabric.api.datagen.v1.provider.FabricTagProvider; import java.util.Comparator; import java.util.List; +import java.util.Set; import java.util.concurrent.CompletableFuture; import org.jetbrains.annotations.Nullable; @@ -19,6 +21,8 @@ public class TagDataProvider extends FabricTagProvider { protected final TagRegistry tagRegistry; + private final Set> forceWrite; + /** * Constructs a new {@link FabricTagProvider} with the default computed path. * @@ -36,10 +40,34 @@ public class TagDataProvider extends FabricTagProvider { @Nullable List modIDs, FabricDataOutput output, CompletableFuture registriesFuture + ) { + this(tagRegistry, modIDs, Set.of(), output, registriesFuture); + } + + /** + * Constructs a new {@link FabricTagProvider} with the default computed path. + * + *

Common implementations of this class are provided. + * + * @param tagRegistry + * @param modIDs List of ModIDs that are allowed to inlcude data. All Resources in the namespace of the + * mod will be written to the tag. If null all elements get written, and empty list will + * write nothing + * @param forceWriteKeys the keys that should allways get written + * @param output the {@link FabricDataOutput} instance + * @param registriesFuture the backing registry for the tag type + */ + public TagDataProvider( + TagRegistry tagRegistry, + @Nullable List modIDs, + Set> forceWriteKeys, + FabricDataOutput output, + CompletableFuture registriesFuture ) { super(output, tagRegistry.registryKey, registriesFuture); this.tagRegistry = tagRegistry; this.modIDs = modIDs; + this.forceWrite = forceWriteKeys; } protected boolean shouldAdd(ResourceLocation loc) { @@ -49,7 +77,7 @@ public class TagDataProvider extends FabricTagProvider { @Override protected void addTags(HolderLookup.Provider arg) { tagRegistry.forEachTag((tag, locs, tags) -> { - if (locs.isEmpty() && tags.isEmpty()) return; + if (!forceWrite.contains(tag) && locs.isEmpty() && tags.isEmpty()) return; final FabricTagProvider.FabricTagBuilder builder = getOrCreateTagBuilder(tag); @@ -58,6 +86,6 @@ public class TagDataProvider extends FabricTagProvider { locs.forEach(builder::add); tags.forEach(builder::forceAddTag); - }, (tag, loc) -> shouldAdd(tag.location()) || this.shouldAdd(loc)); + }, (tag, loc) -> forceWrite.contains(tag) || shouldAdd(tag.location()) || this.shouldAdd(loc)); } }