package info.u_team.u_team_core.data;

import java.io.IOException;
import java.nio.file.Path;
import java.util.*;
import java.util.Map.Entry;
import java.util.stream.Collectors;

import com.google.common.collect.Maps;
import com.google.gson.JsonObject;

import net.minecraft.data.DirectoryCache;
import net.minecraft.tags.*;
import net.minecraft.util.ResourceLocation;
import net.minecraftforge.registries.*;

public abstract class CommonTagsProvider<T extends IForgeRegistryEntry<T>> extends CommonProvider {
	
	protected final IForgeRegistry<T> registry;
	protected final Map<Tag<T>, Tag.Builder<T>> tagToBuilder = Maps.newLinkedHashMap();
	
	public CommonTagsProvider(GenerationData data, IForgeRegistry<T> registry) {
		super(data);
		this.registry = registry;
	}
	
	protected abstract void registerTags();
	
	@Override
	public void act(DirectoryCache cache) {
		tagToBuilder.clear();
		registerTags();
		
		final TagCollection<T> collection = new TagCollection<>(id -> Optional.empty(), "", false, "generated");
		final Map<ResourceLocation, Tag.Builder<T>> map = tagToBuilder.entrySet().stream().collect(Collectors.toMap(entry -> entry.getKey().getId(), Entry::getValue));
		
		collection.registerAll(map);
		collection.getTagMap().forEach((location, tag) -> {
			final JsonObject object = tag.serialize(registry::getKey);
			final Path path = makePath(location);
			try {
				write(cache, object, path);
			} catch (final IOException ex) {
				LOGGER.error(marker, "Could not write data.", ex);
			}
			
		});
		setCollection(collection);
	}
	
	protected abstract void setCollection(TagCollection<T> collection);
	
	protected abstract Path makePath(ResourceLocation location);
	
	protected Tag.Builder<T> getBuilder(Tag<T> tag) {
		final Optional<Tag.Builder<T>> optional = tagToBuilder.entrySet().stream().filter(entry -> entry.getKey().getId().equals(tag.getId())).findAny().map(Entry::getValue);
		if (optional.isPresent()) {
			return optional.get();
		} else {
			return tagToBuilder.computeIfAbsent(tag, otherTag -> Tag.Builder.create());
		}
	}
}
package info.u_team.u_team_core.data;

import java.io.IOException;
import java.nio.file.Path;
import java.util.*;
import java.util.Map.Entry;
import java.util.stream.Collectors;

import com.google.common.collect.Maps;
import com.google.gson.JsonObject;

import net.minecraft.data.*;
import net.minecraft.tags.*;
import net.minecraft.util.ResourceLocation;
import net.minecraftforge.registries.*;

public abstract class CommonTagsProvider<T extends IForgeRegistryEntry<T>> extends CommonProvider {
	
	protected final IForgeRegistry<T> registry;
	protected final Map<ResourceLocation, ITag.Builder> tagToBuilder = Maps.newLinkedHashMap();
	
	public CommonTagsProvider(GenerationData data, IForgeRegistry<T> registry) {
		super(data);
		this.registry = registry;
	}
	
	protected abstract void registerTags();
	
	@Override
	public void act(DirectoryCache cache) {
		tagToBuilder.clear();
		registerTags();
		
		tagToBuilder.forEach((location, builder) -> {
			final List<ITag.Proxy> list = builder.func_232963_b_(id -> tagToBuilder.containsKey(id) ? Tag.func_241284_a_() : null, id -> registry.getValue(id)).collect(Collectors.toList());
			if (!list.isEmpty()) {
				throw new IllegalArgumentException(String.format("Couldn't define tag %s as it is missing following references: %s", location, list.stream().map(Objects::toString).collect(Collectors.joining(","))));
			}
			final JsonObject object = builder.func_232965_c_();
			final Path path = makePath(location);
			try {
				write(cache, object, path);
			} catch (final IOException ex) {
				LOGGER.error(marker, "Could not write data.", ex);
			}
		});
	}
	
	protected abstract Path makePath(ResourceLocation location);
	
	protected TagsProvider.Builder<T> func_240522_a_(ITag.INamedTag<T> p_240522_1_) {
		ITag.Builder itag$builder = this.func_240525_b_(p_240522_1_);
		return new TagsProvider.Builder<>(itag$builder, this.registry, modid);
	}
	
	protected ITag.Builder func_240525_b_(ITag.INamedTag<T> p_240525_1_) {
		return this.tagToBuilder.computeIfAbsent(p_240525_1_.func_230234_a_(), (p_240526_0_) -> {
			return new ITag.Builder();
		});
	}
	
	protected Tag.Builder<T> getBuilder(Tag<T> tag) {
		final Optional<Tag.Builder<T>> optional = tagToBuilder.entrySet().stream().filter(entry -> entry.getKey().getId().equals(tag.getId())).findAny().map(Entry::getValue);
		if (optional.isPresent()) {
			return optional.get();
		} else {
			return tagToBuilder.computeIfAbsent(tag, otherTag -> Tag.Builder.create());
		}
	}
}
Update the act method in common Tags provider to work hopefully :)