Skip to content

Commit

Permalink
datagen crash
Browse files Browse the repository at this point in the history
  • Loading branch information
mrsterner committed Oct 28, 2023
1 parent c151136 commit de4257c
Show file tree
Hide file tree
Showing 16 changed files with 184 additions and 271 deletions.
2 changes: 1 addition & 1 deletion build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -164,7 +164,7 @@ dependencies {

implementation(fg.deobf("curse.maven:farmers_delight-398521:4638874"))
implementation(fg.deobf("curse.maven:create-328085:4626108"))
implementation(fg.deobf("curse.maven:jeed-532286:4599236"))
//implementation(fg.deobf("curse.maven:jeed-532286:4599236"))
runtimeOnly(fg.deobf("curse.maven:world-stripper-250603:4578579"))
runtimeOnly(fg.deobf("curse.maven:spark-361579:4587309"))
}
Expand Down
2 changes: 1 addition & 1 deletion gradle.properties
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ modJavaVersion=17
minecraftVersion=1.20.1
minecraftVersionRange=[1.20.1,1.21]
# Forge Versions
forgeVersion=47.1.0
forgeVersion=47.2.1
forgeVersionRange=[47,)
loaderVersionRange=[47,)

Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
{
"values": [
"#minecraft:is_overworld"
]
}
Original file line number Diff line number Diff line change
@@ -1,4 +0,0 @@
{
"type": "malum:soulwood_tree",
"config": {}
}
47 changes: 10 additions & 37 deletions src/main/java/com/sammy/malum/MalumMod.java
Original file line number Diff line number Diff line change
Expand Up @@ -6,32 +6,37 @@
import com.sammy.malum.config.CommonConfig;
import com.sammy.malum.data.MalumBiomeTags;
import com.sammy.malum.data.MalumLang;
import com.sammy.malum.data.MalumRecipes;
import com.sammy.malum.data.MalumWorldgenProvider;
import com.sammy.malum.data.RegistryDataGenerator;
import com.sammy.malum.data.block.MalumBlockLootTables;
import com.sammy.malum.data.block.MalumBlockStates;
import com.sammy.malum.data.block.MalumBlockTags;
import com.sammy.malum.data.item.MalumItemModels;
import com.sammy.malum.data.item.MalumItemTags;
import com.sammy.malum.data.recipe.*;
import com.sammy.malum.registry.common.item.tabs.CreativeTabRegistry;
import net.minecraft.DetectedVersion;
import net.minecraft.core.HolderLookup;
import net.minecraft.data.DataGenerator;
import net.minecraft.data.PackOutput;
import net.minecraft.data.metadata.PackMetadataGenerator;
import net.minecraft.network.chat.Component;
import net.minecraft.resources.ResourceLocation;
import net.minecraft.server.packs.PackType;
import net.minecraft.server.packs.metadata.pack.PackMetadataSection;
import net.minecraft.util.RandomSource;
import net.minecraftforge.common.data.BlockTagsProvider;
import net.minecraftforge.common.data.ExistingFileHelper;
import net.minecraftforge.data.event.GatherDataEvent;
import net.minecraftforge.eventbus.api.IEventBus;
import net.minecraftforge.eventbus.api.SubscribeEvent;
import net.minecraftforge.fml.ModLoadingContext;
import net.minecraftforge.fml.common.Mod;
import net.minecraftforge.fml.config.ModConfig;
import net.minecraftforge.fml.javafmlmod.FMLJavaModLoadingContext;
import org.apache.logging.log4j.LogManager;
import org.apache.logging.log4j.Logger;

import java.util.Arrays;
import java.util.concurrent.CompletableFuture;
import java.util.function.Function;
import java.util.stream.Collectors;

import static com.sammy.malum.registry.client.ParticleRegistry.PARTICLES;
import static com.sammy.malum.registry.common.AttributeRegistry.ATTRIBUTES;
Expand Down Expand Up @@ -83,41 +88,9 @@ public MalumMod() {
CreateCompat.init();

modBus.addListener(CreativeTabRegistry::populateItemGroups);
modBus.addListener(DataOnly::gatherData);
}

public static ResourceLocation malumPath(String path) {
return new ResourceLocation(MALUM, path);
}

public static class DataOnly {
public static void gatherData(GatherDataEvent event) {
DataGenerator generator = event.getGenerator();
PackOutput output = generator.getPackOutput();
CompletableFuture<HolderLookup.Provider> provider = event.getLookupProvider();
ExistingFileHelper helper = event.getExistingFileHelper();


MalumItemModels itemModelsProvider = new MalumItemModels(output, helper);
MalumBlockTags blockTagsProvider = new MalumBlockTags(output, provider, helper);

generator.addProvider(event.includeClient(), new MalumBlockStates(output, helper, itemModelsProvider));
generator.addProvider(event.includeClient(), itemModelsProvider);
generator.addProvider(event.includeClient(), new MalumLang(output));

//TODO generator.addProvider(event.includeServer(), blockTagsProvider);
generator.addProvider(event.includeServer(), new MalumBlockLootTables(output));
//TODO generator.addProvider(event.includeServer(), new MalumItemTags(output, provider, blockTagsProvider.contentsGetter(), helper));

generator.addProvider(event.includeServer(), new MalumRecipes(output));
generator.addProvider(event.includeServer(), new MalumVanillaRecipeReplacements(output));
generator.addProvider(event.includeServer(), new MalumSpiritInfusionRecipes(output));
generator.addProvider(event.includeServer(), new MalumSpiritFocusingRecipes(output));
generator.addProvider(event.includeServer(), new MalumSpiritTransmutationRecipes(output));
generator.addProvider(event.includeServer(), new MalumVoidFavorRecipes(output));

generator.addProvider(event.includeServer(), new MalumWorldgenProvider(output, provider));
generator.addProvider(event.includeServer(), new MalumBiomeTags(output, provider, helper));
}
}
}
62 changes: 62 additions & 0 deletions src/main/java/com/sammy/malum/data/BiomeModifications.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,62 @@
package com.sammy.malum.data;

import com.sammy.malum.MalumMod;
import com.sammy.malum.registry.common.worldgen.BiomeTagRegistry;
import com.sammy.malum.registry.common.worldgen.PlacedFeatureRegistry;
import net.minecraft.core.Holder;
import net.minecraft.core.HolderSet;
import net.minecraft.core.registries.Registries;
import net.minecraft.data.worldgen.BootstapContext;
import net.minecraft.resources.ResourceKey;
import net.minecraft.tags.TagKey;
import net.minecraft.world.level.biome.Biome;
import net.minecraft.world.level.levelgen.GenerationStep;
import net.minecraft.world.level.levelgen.placement.PlacedFeature;
import net.minecraftforge.common.world.BiomeModifier;
import net.minecraftforge.common.world.ForgeBiomeModifiers;
import net.minecraftforge.registries.ForgeRegistries;

import java.util.ArrayList;
import java.util.List;
import java.util.function.Supplier;

public class BiomeModifications {
public static void bootstrap(BootstapContext<BiomeModifier> context) {
register(context, "soulstone_ore", () ->
addFeatureModifier(context,
getPlacedHolderSet(context, PlacedFeatureRegistry.ORE_SOULSTONE),
BiomeTagRegistry.HAS_SOULSTONE, GenerationStep.Decoration.UNDERGROUND_ORES));

register(context, "brilliant_ore", () ->
addFeatureModifier(context,
getPlacedHolderSet(context, PlacedFeatureRegistry.ORE_BRILLIANT),
BiomeTagRegistry.HAS_BRILLIANT, GenerationStep.Decoration.UNDERGROUND_ORES));

register(context, "natural_quartz_ore", () ->
addFeatureModifier(context,
getPlacedHolderSet(context, PlacedFeatureRegistry.ORE_NATURAL_QUARTZ),
BiomeTagRegistry.HAS_SOULSTONE, GenerationStep.Decoration.UNDERGROUND_ORES));

register(context, "runwood_tree", () ->
addFeatureModifier(context,
getPlacedHolderSet(context, PlacedFeatureRegistry.RUNEWOOD_TREE),
BiomeTagRegistry.HAS_RUNEWOOD, GenerationStep.Decoration.VEGETAL_DECORATION));

}

public static HolderSet<PlacedFeature> getPlacedHolderSet(BootstapContext<?> context, ResourceKey<PlacedFeature>... placedFeatures) {
List<Holder<PlacedFeature>> holders = new ArrayList<>();
for (ResourceKey<PlacedFeature> feature : placedFeatures) {
holders.add(context.lookup(Registries.PLACED_FEATURE).getOrThrow(feature));
}
return HolderSet.direct(holders);
}

private static ForgeBiomeModifiers.AddFeaturesBiomeModifier addFeatureModifier(BootstapContext<BiomeModifier> context, HolderSet<PlacedFeature> placedSet, TagKey<Biome> biomeTag, GenerationStep.Decoration decoration) {
return new ForgeBiomeModifiers.AddFeaturesBiomeModifier(context.lookup(Registries.BIOME).getOrThrow(biomeTag), placedSet, decoration);
}

private static void register(BootstapContext<BiomeModifier> context, String name, Supplier<? extends BiomeModifier> modifier) {
context.register(ResourceKey.create(ForgeRegistries.Keys.BIOME_MODIFIERS, MalumMod.malumPath(name)), modifier.get());
}
}
62 changes: 62 additions & 0 deletions src/main/java/com/sammy/malum/data/DataGenerators.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,62 @@
package com.sammy.malum.data;

import com.sammy.malum.MalumMod;
import com.sammy.malum.data.block.MalumBlockLootTables;
import com.sammy.malum.data.block.MalumBlockStates;
import com.sammy.malum.data.block.MalumBlockTags;
import com.sammy.malum.data.item.MalumItemModels;
import com.sammy.malum.data.recipe.*;
import net.minecraft.DetectedVersion;
import net.minecraft.core.HolderLookup;
import net.minecraft.data.DataGenerator;
import net.minecraft.data.PackOutput;
import net.minecraft.data.metadata.PackMetadataGenerator;
import net.minecraft.network.chat.Component;
import net.minecraft.server.packs.PackType;
import net.minecraft.server.packs.metadata.pack.PackMetadataSection;
import net.minecraftforge.common.data.DatapackBuiltinEntriesProvider;
import net.minecraftforge.common.data.ExistingFileHelper;
import net.minecraftforge.data.event.GatherDataEvent;
import net.minecraftforge.eventbus.api.SubscribeEvent;
import net.minecraftforge.fml.common.Mod;

import java.util.Arrays;
import java.util.concurrent.CompletableFuture;
import java.util.function.Function;
import java.util.stream.Collectors;

@Mod.EventBusSubscriber(modid = MalumMod.MALUM, bus = Mod.EventBusSubscriber.Bus.MOD)
public class DataGenerators {

@SubscribeEvent
public static void gatherData(GatherDataEvent event) {
DataGenerator generator = event.getGenerator();
PackOutput output = generator.getPackOutput();
CompletableFuture<HolderLookup.Provider> provider = event.getLookupProvider();
ExistingFileHelper helper = event.getExistingFileHelper();


MalumItemModels itemModelsProvider = new MalumItemModels(output, helper);
MalumBlockTags blockTagsProvider = new MalumBlockTags(output, provider, helper);

generator.addProvider(event.includeClient(), new MalumBlockStates(output, helper, itemModelsProvider));
generator.addProvider(event.includeClient(), itemModelsProvider);


//TODO generator.addProvider(event.includeServer(), blockTagsProvider);
generator.addProvider(event.includeServer(), new MalumBlockLootTables(output));
//TODO generator.addProvider(event.includeServer(), new MalumItemTags(output, provider, blockTagsProvider.contentsGetter(), helper));

generator.addProvider(event.includeServer(), new MalumRecipes(output));
generator.addProvider(event.includeServer(), new MalumVanillaRecipeReplacements(output));
generator.addProvider(event.includeServer(), new MalumSpiritInfusionRecipes(output));
generator.addProvider(event.includeServer(), new MalumSpiritFocusingRecipes(output));
generator.addProvider(event.includeServer(), new MalumSpiritTransmutationRecipes(output));
generator.addProvider(event.includeServer(), new MalumVoidFavorRecipes(output));

generator.addProvider(event.includeServer(), new MalumBiomeTags(output, provider, helper));

generator.addProvider(event.includeServer(), new RegistryDataGenerator(output, provider));
generator.addProvider(event.includeClient(), new MalumLang(output));
}
}
82 changes: 0 additions & 82 deletions src/main/java/com/sammy/malum/data/MalumWorldgenProvider.java

This file was deleted.

41 changes: 41 additions & 0 deletions src/main/java/com/sammy/malum/data/RegistryDataGenerator.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,41 @@
package com.sammy.malum.data;

import com.sammy.malum.MalumMod;
import com.sammy.malum.registry.common.worldgen.BiomeTagRegistry;
import com.sammy.malum.registry.common.worldgen.ConfiguredFeatureRegistry;
import com.sammy.malum.registry.common.worldgen.PlacedFeatureRegistry;
import com.sammy.malum.registry.common.worldgen.StructureRegistry;
import net.minecraft.core.Holder;
import net.minecraft.core.HolderLookup;
import net.minecraft.core.HolderSet;
import net.minecraft.core.RegistrySetBuilder;
import net.minecraft.core.registries.Registries;
import net.minecraft.data.PackOutput;
import net.minecraft.data.worldgen.BootstapContext;
import net.minecraft.resources.ResourceKey;
import net.minecraft.tags.TagKey;
import net.minecraft.world.level.biome.Biome;
import net.minecraft.world.level.levelgen.GenerationStep;
import net.minecraft.world.level.levelgen.placement.PlacedFeature;
import net.minecraftforge.common.data.DatapackBuiltinEntriesProvider;
import net.minecraftforge.common.world.BiomeModifier;
import net.minecraftforge.common.world.ForgeBiomeModifiers;
import net.minecraftforge.registries.ForgeRegistries;

import java.util.ArrayList;
import java.util.List;
import java.util.Set;
import java.util.concurrent.CompletableFuture;
import java.util.function.Supplier;

public class RegistryDataGenerator extends DatapackBuiltinEntriesProvider {

private static final RegistrySetBuilder BUILDER = new RegistrySetBuilder()
.add(Registries.CONFIGURED_FEATURE, ConfiguredFeatureRegistry::bootstrap)
.add(Registries.PLACED_FEATURE, PlacedFeatureRegistry::bootstrap)
.add(ForgeRegistries.Keys.BIOME_MODIFIERS, BiomeModifications::bootstrap);

public RegistryDataGenerator(PackOutput output, CompletableFuture<HolderLookup.Provider> registries) {
super(output, registries, BUILDER, Set.of("minecraft", MalumMod.MALUM));
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -47,15 +47,12 @@ public class ConfiguredFeatureRegistry {
OreConfiguration.target(DEEPSLATE_ORE_REPLACEABLES, BlockRegistry.DEEPSLATE_QUARTZ_ORE.get().defaultBlockState()));

public static void bootstrap(BootstapContext<ConfiguredFeature<?, ?>> context) {
HolderGetter<ConfiguredFeature<?, ?>> features = context.lookup(Registries.CONFIGURED_FEATURE);


context.register(ConfiguredFeatureRegistry.CONFIGURED_SOULSTONE_ORE, addOreConfig(SOULSTONE_TARGET_LIST, 30));
context.register(ConfiguredFeatureRegistry.CONFIGURED_BRILLIANT_ORE, addOreConfig(BRILLIANT_TARGET_LIST, 30));
context.register(ConfiguredFeatureRegistry.CONFIGURED_NATURAL_QUARTZ_ORE, addOreConfig(NATURAL_QUARTZ_TARGET_LIST, 30));

context.register(ConfiguredFeatureRegistry.CONFIGURED_RUNEWOOD_TREE, addTreeConfig(FeatureRegistry.RUNEWOOD_TREE.get()));
//register(context, ConfiguredFeatureRegistry.CONFIGURED_SOULWOOD_TREE, () -> addTreeConfig(FeatureRegistry.SOULWOOD_TREE.get()));
context.register(ConfiguredFeatureRegistry.CONFIGURED_SOULWOOD_TREE, addTreeConfig(FeatureRegistry.SOULWOOD_TREE.get()));
}

private static ConfiguredFeature<?,?> addTreeConfig(Feature<NoneFeatureConfiguration> feature) {
Expand Down
Loading

0 comments on commit de4257c

Please sign in to comment.