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
protected void addTags(HolderLookup.Provider arg) {
tagRegistry.forEachTag((tag, locs, tags) -> {
if (locs.isEmpty() && tags.isEmpty()) return;
final FabricTagProvider<T>.FabricTagBuilder builder = getOrCreateTagBuilder(tag);
boolean modTag = shouldAdd(tag.location());
locs.stream()
.filter(loc -> modTag || this.shouldAdd(loc))
.forEach(builder::add);
tags.stream()
.filter(tagKey -> modTag || this.shouldAdd(tagKey.location()))
.forEach(builder::addTag);
});
locs.forEach(builder::add);
tags.forEach(builder::addTag);
}, (tag, loc) -> shouldAdd(tag.location()) || this.shouldAdd(loc));
}
}

View file

@ -103,7 +103,7 @@ public class TestBiomes extends TagDataProvider<Biome> {
FabricDataOutput output,
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) {

View file

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