Fixes for Tag DataGen

This commit is contained in:
Frank 2022-12-04 22:13:06 +01:00
parent 2fa5c9510a
commit 0308437eaa
3 changed files with 20 additions and 15 deletions

View file

@ -48,16 +48,11 @@ public class TagDataProvider<T> extends FabricTagProvider<T> {
@Override @Override
protected void addTags(HolderLookup.Provider arg) { protected void addTags(HolderLookup.Provider arg) {
tagRegistry.forEachTag((tag, locs, tags) -> { tagRegistry.forEachTag((tag, locs, tags) -> {
if (locs.isEmpty() && tags.isEmpty()) return;
final FabricTagProvider<T>.FabricTagBuilder builder = getOrCreateTagBuilder(tag); final FabricTagProvider<T>.FabricTagBuilder builder = getOrCreateTagBuilder(tag);
locs.forEach(builder::add);
boolean modTag = shouldAdd(tag.location()); tags.forEach(builder::addTag);
locs.stream() }, (tag, loc) -> shouldAdd(tag.location()) || this.shouldAdd(loc));
.filter(loc -> modTag || this.shouldAdd(loc))
.forEach(builder::add);
tags.stream()
.filter(tagKey -> modTag || this.shouldAdd(tagKey.location()))
.forEach(builder::addTag);
});
} }
} }

View file

@ -103,7 +103,7 @@ public class TestBiomes extends TagDataProvider<Biome> {
FabricDataOutput output, FabricDataOutput output,
CompletableFuture<HolderLookup.Provider> registriesFuture CompletableFuture<HolderLookup.Provider> registriesFuture
) { ) {
super(TagManager.BIOMES, List.of(BCLib.MOD_ID, WorldsTogether.MOD_ID), output, registriesFuture); super(TagManager.BIOMES, List.of(BCLib.MOD_ID, WorldsTogether.MOD_ID, "c"), output, registriesFuture);
} }
public static void bootstrap(BootstapContext<Biome> bootstrapContext) { public static void bootstrap(BootstapContext<Biome> bootstrapContext) {

View file

@ -24,6 +24,7 @@ import com.google.common.collect.Sets;
import java.util.*; import java.util.*;
import java.util.function.BiConsumer; import java.util.function.BiConsumer;
import java.util.function.BiPredicate;
import java.util.function.Function; import java.util.function.Function;
public class TagRegistry<T> { public class TagRegistry<T> {
@ -264,16 +265,25 @@ public class TagRegistry<T> {
} }
public void forEachTag(TriConsumer<TagKey<T>, List<ResourceLocation>, List<TagKey<T>>> consumer) { public void forEachTag(TriConsumer<TagKey<T>, List<ResourceLocation>, List<TagKey<T>>> consumer) {
forEachTag(consumer, null);
}
public void forEachTag(
TriConsumer<TagKey<T>, List<ResourceLocation>, List<TagKey<T>>> consumer,
BiPredicate<TagKey<T>, ResourceLocation> allow
) {
tags.forEach((tag, set) -> { tags.forEach((tag, set) -> {
List<ResourceLocation> locations = new LinkedList<>(); List<ResourceLocation> locations = new LinkedList<>();
List<TagKey<T>> tags = new LinkedList<>(); List<TagKey<T>> tags = new LinkedList<>();
set.forEach(e -> { set.forEach(e -> {
ExtraCodecs.TagOrElementLocation t = e.elementOrTag(); ExtraCodecs.TagOrElementLocation t = e.elementOrTag();
if (t.tag()) { if (allow == null || allow.test(tag, t.id())) {
tags.add(TagKey.create(registryKey, t.id())); if (t.tag()) {
} else { tags.add(TagKey.create(registryKey, t.id()));
locations.add(t.id()); } else {
locations.add(t.id());
}
} }
}); });