NaturesAura/src/main/java/de/ellpeck/naturesaura/data/ModData.java

54 lines
2.8 KiB
Java
Raw Normal View History

2020-01-29 00:40:28 +01:00
package de.ellpeck.naturesaura.data;
import de.ellpeck.naturesaura.NaturesAura;
import de.ellpeck.naturesaura.gen.ModFeatures;
import net.minecraft.core.HolderLookup;
import net.minecraft.core.RegistryAccess;
import net.minecraft.core.RegistrySetBuilder;
import net.minecraft.core.registries.BuiltInRegistries;
import net.minecraft.core.registries.Registries;
2023-07-24 17:56:29 +02:00
import net.minecraft.data.loot.LootTableProvider;
import net.minecraft.data.registries.VanillaRegistries;
2023-07-24 17:56:29 +02:00
import net.minecraft.world.level.storage.loot.parameters.LootContextParamSets;
2024-02-03 14:56:07 +01:00
import net.neoforged.neoforge.common.data.DatapackBuiltinEntriesProvider;
import net.neoforged.neoforge.data.event.GatherDataEvent;
import net.neoforged.bus.api.SubscribeEvent;
import net.neoforged.fml.common.Mod;
import net.neoforged.neoforge.registries.ForgeRegistries;
2020-01-29 00:40:28 +01:00
2023-07-24 17:56:29 +02:00
import java.util.List;
import java.util.Set;
import java.util.concurrent.CompletableFuture;
2023-07-24 17:56:29 +02:00
2020-01-29 00:40:28 +01:00
@Mod.EventBusSubscriber(bus = Mod.EventBusSubscriber.Bus.MOD)
public final class ModData {
@SubscribeEvent
public static void gatherData(GatherDataEvent event) {
2023-07-24 17:56:29 +02:00
var gen = event.getGenerator();
var out = gen.getPackOutput();
var lookup = event.getLookupProvider();
var existing = event.getExistingFileHelper();
var blockTags = new BlockTagProvider(out, lookup, existing);
gen.addProvider(event.includeServer(), blockTags);
gen.addProvider(event.includeServer(), new ItemTagProvider(out, lookup, blockTags.contentsGetter(), existing));
gen.addProvider(event.includeServer(), new LootTableProvider(out, Set.of(), List.of(new LootTableProvider.SubProviderEntry(BlockLootProvider::new, LootContextParamSets.BLOCK))));
gen.addProvider(event.includeServer(), new BlockStateGenerator(out, existing));
gen.addProvider(event.includeServer(), new ItemModelGenerator(out, existing));
gen.addProvider(event.includeServer(), new DatapackBuiltinEntriesProvider(out, CompletableFuture.supplyAsync(ModData::getProvider), Set.of(NaturesAura.MOD_ID)));
}
private static HolderLookup.Provider getProvider() {
final RegistrySetBuilder registryBuilder = new RegistrySetBuilder();
registryBuilder.add(Registries.CONFIGURED_FEATURE, ModFeatures.Configured::bootstrap);
registryBuilder.add(Registries.PLACED_FEATURE, ModFeatures.Placed::bootstrap);
registryBuilder.add(ForgeRegistries.Keys.BIOME_MODIFIERS, BiomeModifiers::bootstrap);
// We need the BIOME registry to be present, so we can use a biome tag, doesn't matter that it's empty
registryBuilder.add(Registries.BIOME, context -> {
});
RegistryAccess.Frozen regAccess = RegistryAccess.fromRegistryOfRegistries(BuiltInRegistries.REGISTRY);
return registryBuilder.buildPatch(regAccess, VanillaRegistries.createLookup());
2020-01-29 00:40:28 +01:00
}
}