Generalized Tag-Provider
This commit is contained in:
parent
982b3aa274
commit
ef1e899589
2 changed files with 113 additions and 61 deletions
|
@ -0,0 +1,63 @@
|
|||
package org.betterx.bclib.api.v3.datagen;
|
||||
|
||||
import org.betterx.worlds.together.tag.v3.TagRegistry;
|
||||
|
||||
import net.minecraft.core.HolderLookup;
|
||||
import net.minecraft.resources.ResourceLocation;
|
||||
|
||||
import net.fabricmc.fabric.api.datagen.v1.FabricDataOutput;
|
||||
import net.fabricmc.fabric.api.datagen.v1.provider.FabricTagProvider;
|
||||
|
||||
import java.util.List;
|
||||
import java.util.concurrent.CompletableFuture;
|
||||
import org.jetbrains.annotations.Nullable;
|
||||
|
||||
public class TagDataProvider<T> extends FabricTagProvider<T> {
|
||||
@Nullable
|
||||
protected final List<String> modIDs;
|
||||
|
||||
protected final TagRegistry<T> tagRegistry;
|
||||
|
||||
/**
|
||||
* Constructs a new {@link FabricTagProvider} with the default computed path.
|
||||
*
|
||||
* <p>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 output the {@link FabricDataOutput} instance
|
||||
* @param registriesFuture the backing registry for the tag type
|
||||
*/
|
||||
public TagDataProvider(
|
||||
TagRegistry<T> tagRegistry,
|
||||
@Nullable List<String> modIDs,
|
||||
FabricDataOutput output,
|
||||
CompletableFuture<HolderLookup.Provider> registriesFuture
|
||||
) {
|
||||
super(output, tagRegistry.registryKey, registriesFuture);
|
||||
this.tagRegistry = tagRegistry;
|
||||
this.modIDs = modIDs;
|
||||
}
|
||||
|
||||
protected boolean shouldAdd(ResourceLocation loc) {
|
||||
return modIDs == null || modIDs.contains(loc.getNamespace());
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void addTags(HolderLookup.Provider arg) {
|
||||
tagRegistry.forEachTag((tag, locs, tags) -> {
|
||||
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);
|
||||
});
|
||||
}
|
||||
}
|
|
@ -4,11 +4,12 @@ import org.betterx.bclib.BCLib;
|
|||
import org.betterx.bclib.api.v2.levelgen.biomes.BCLBiome;
|
||||
import org.betterx.bclib.api.v2.levelgen.biomes.BCLBiomeBuilder;
|
||||
import org.betterx.bclib.api.v2.levelgen.biomes.BCLBiomeContainer;
|
||||
import org.betterx.bclib.api.v3.datagen.TagDataProvider;
|
||||
import org.betterx.datagen.bclib.BCLibDatagen;
|
||||
import org.betterx.worlds.together.WorldsTogether;
|
||||
import org.betterx.worlds.together.tag.v3.TagManager;
|
||||
|
||||
import net.minecraft.core.HolderLookup;
|
||||
import net.minecraft.core.registries.Registries;
|
||||
import net.minecraft.data.worldgen.BootstapContext;
|
||||
import net.minecraft.world.level.biome.Biome;
|
||||
import net.minecraft.world.level.block.Blocks;
|
||||
|
@ -16,9 +17,10 @@ import net.minecraft.world.level.block.Blocks;
|
|||
import net.fabricmc.fabric.api.datagen.v1.FabricDataOutput;
|
||||
import net.fabricmc.fabric.api.datagen.v1.provider.FabricTagProvider;
|
||||
|
||||
import java.util.List;
|
||||
import java.util.concurrent.CompletableFuture;
|
||||
|
||||
public class TestBiomes extends FabricTagProvider<Biome> {
|
||||
public class TestBiomes extends TagDataProvider<Biome> {
|
||||
static BCLBiomeContainer<BCLBiome> THE_YELLOW = BCLBiomeBuilder
|
||||
.start(BCLib.makeID("the_yellow"))
|
||||
.precipitation(Biome.Precipitation.NONE)
|
||||
|
@ -49,6 +51,46 @@ public class TestBiomes extends FabricTagProvider<Biome> {
|
|||
.endLandBiome()
|
||||
.build();
|
||||
|
||||
static BCLBiomeContainer<BCLBiome> THE_GRAY = BCLBiomeBuilder
|
||||
.start(BCLib.makeID("the_gray"))
|
||||
.precipitation(Biome.Precipitation.NONE)
|
||||
.temperature(1.0f)
|
||||
.wetness(1.0f)
|
||||
.fogColor(0xFFFFFF)
|
||||
.waterColor(0x777777)
|
||||
.waterFogColor(0xFFFFFF)
|
||||
.skyColor(0xAAAAAA)
|
||||
.addNetherClimateParamater(-1, 1)
|
||||
.surface(Blocks.GRAY_CONCRETE)
|
||||
.endVoidBiome()
|
||||
.build();
|
||||
static BCLBiomeContainer<BCLBiome> THE_ORANGE = BCLBiomeBuilder
|
||||
.start(BCLib.makeID("the_orange"))
|
||||
.precipitation(Biome.Precipitation.NONE)
|
||||
.temperature(1.0f)
|
||||
.wetness(1.0f)
|
||||
.fogColor(0xFF7700)
|
||||
.waterColor(0x773300)
|
||||
.waterFogColor(0xFF7700)
|
||||
.skyColor(0xAA7700)
|
||||
.addNetherClimateParamater(-1, 1.1f)
|
||||
.surface(Blocks.ORANGE_CONCRETE)
|
||||
.netherBiome()
|
||||
.build();
|
||||
static BCLBiomeContainer<BCLBiome> THE_PURPLE = BCLBiomeBuilder
|
||||
.start(BCLib.makeID("the_purple"))
|
||||
.precipitation(Biome.Precipitation.NONE)
|
||||
.temperature(1.0f)
|
||||
.wetness(1.0f)
|
||||
.fogColor(0xFF00FF)
|
||||
.waterColor(0x770077)
|
||||
.waterFogColor(0xFF00FF)
|
||||
.skyColor(0xAA00AA)
|
||||
.addNetherClimateParamater(-1.1f, 1)
|
||||
.surface(Blocks.PURPLE_CONCRETE)
|
||||
.netherBiome()
|
||||
.build();
|
||||
|
||||
/**
|
||||
* Constructs a new {@link FabricTagProvider} with the default computed path.
|
||||
*
|
||||
|
@ -61,71 +103,18 @@ public class TestBiomes extends FabricTagProvider<Biome> {
|
|||
FabricDataOutput output,
|
||||
CompletableFuture<HolderLookup.Provider> registriesFuture
|
||||
) {
|
||||
super(output, Registries.BIOME, registriesFuture);
|
||||
super(TagManager.BIOMES, List.of(BCLib.MOD_ID, WorldsTogether.MOD_ID), output, registriesFuture);
|
||||
}
|
||||
|
||||
public static void bootstrap(BootstapContext<Biome> bootstrapContext) {
|
||||
BCLib.LOGGER.info("Bootstrap Biomes");
|
||||
if (BCLibDatagen.ADD_TESTS && BCLib.isDevEnvironment()) {
|
||||
BCLib.LOGGER.info("Bootstrap Biomes");
|
||||
|
||||
THE_YELLOW = THE_YELLOW.register(bootstrapContext);
|
||||
THE_BLUE = THE_BLUE.register(bootstrapContext);
|
||||
|
||||
BCLBiome theGray = BCLBiomeBuilder
|
||||
.start(BCLib.makeID("the_gray"))
|
||||
.precipitation(Biome.Precipitation.NONE)
|
||||
.temperature(1.0f)
|
||||
.wetness(1.0f)
|
||||
.fogColor(0xFFFFFF)
|
||||
.waterColor(0x777777)
|
||||
.waterFogColor(0xFFFFFF)
|
||||
.skyColor(0xAAAAAA)
|
||||
.addNetherClimateParamater(-1, 1)
|
||||
.surface(Blocks.GRAY_CONCRETE)
|
||||
.endVoidBiome()
|
||||
.build()
|
||||
.register(bootstrapContext).biome();
|
||||
|
||||
BCLBiome theOrange = BCLBiomeBuilder
|
||||
.start(BCLib.makeID("the_orange"))
|
||||
.precipitation(Biome.Precipitation.NONE)
|
||||
.temperature(1.0f)
|
||||
.wetness(1.0f)
|
||||
.fogColor(0xFF7700)
|
||||
.waterColor(0x773300)
|
||||
.waterFogColor(0xFF7700)
|
||||
.skyColor(0xAA7700)
|
||||
.addNetherClimateParamater(-1, 1.1f)
|
||||
.surface(Blocks.ORANGE_CONCRETE)
|
||||
.netherBiome()
|
||||
.build()
|
||||
.register(bootstrapContext).biome();
|
||||
|
||||
BCLBiome thePurple = BCLBiomeBuilder
|
||||
.start(BCLib.makeID("the_purple"))
|
||||
.precipitation(Biome.Precipitation.NONE)
|
||||
.temperature(1.0f)
|
||||
.wetness(1.0f)
|
||||
.fogColor(0xFF00FF)
|
||||
.waterColor(0x770077)
|
||||
.waterFogColor(0xFF00FF)
|
||||
.skyColor(0xAA00AA)
|
||||
.addNetherClimateParamater(-1.1f, 1)
|
||||
.surface(Blocks.PURPLE_CONCRETE)
|
||||
.netherBiome()
|
||||
.build()
|
||||
.register(bootstrapContext).biome();
|
||||
THE_GRAY = THE_GRAY.register(bootstrapContext);
|
||||
THE_ORANGE = THE_ORANGE.register(bootstrapContext);
|
||||
THE_PURPLE = THE_PURPLE.register(bootstrapContext);
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void addTags(HolderLookup.Provider arg) {
|
||||
TagManager.BIOMES.forEachTag((tag, locs, tags) -> {
|
||||
final FabricTagProvider<Biome>.FabricTagBuilder builder = getOrCreateTagBuilder(tag);
|
||||
boolean modTag = tag.location().getNamespace().equals(BCLib.MOD_ID);
|
||||
locs.stream().filter(l -> modTag || l.getNamespace().equals(BCLib.MOD_ID)).forEach(builder::add);
|
||||
tags.stream()
|
||||
.filter(t -> modTag || t.location().getNamespace().equals(BCLib.MOD_ID))
|
||||
.forEach(builder::addTag);
|
||||
});
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue