start fixing up AkashicTreeGrower to datagen the ConfiguredFeatures, and fix some other datagen stuff.

This commit is contained in:
Talia-12 2023-06-21 18:43:15 +10:00
parent 36b631eadb
commit 9d8bf7c568
7 changed files with 84 additions and 48 deletions

View file

@ -0,0 +1,29 @@
package at.petrak.hexcasting.common.lib;
import net.minecraft.data.worldgen.BootstapContext;
import net.minecraft.data.worldgen.features.FeatureUtils;
import net.minecraft.resources.ResourceKey;
import net.minecraft.world.level.levelgen.feature.ConfiguredFeature;
import net.minecraft.world.level.levelgen.feature.Feature;
public class HexConfiguredFeatures {
public static void bootstrap(BootstapContext<ConfiguredFeature<?, ?>> context) {
context.register(AMETHYST_EDIFIED_TREE, new ConfiguredFeature<>(
Feature.TREE,
HexFeatureConfigs.AMETHYST_EDIFIED_TREE_CONFIG
));
context.register(AVENTURINE_EDIFIED_TREE, new ConfiguredFeature<>(
Feature.TREE,
HexFeatureConfigs.AVENTURINE_EDIFIED_TREE_CONFIG
));
context.register(CITRINE_EDIFIED_TREE, new ConfiguredFeature<>(
Feature.TREE,
HexFeatureConfigs.CITRINE_EDIFIED_TREE_CONFIG
));
}
public static final ResourceKey<ConfiguredFeature<?, ?>> AMETHYST_EDIFIED_TREE = FeatureUtils.createKey("amethyst_edified_tree");
public static final ResourceKey<ConfiguredFeature<?, ?>> AVENTURINE_EDIFIED_TREE = FeatureUtils.createKey("aventurine_edified_tree");
public static final ResourceKey<ConfiguredFeature<?, ?>> CITRINE_EDIFIED_TREE = FeatureUtils.createKey("citrine_edified_tree");
}

View file

@ -0,0 +1,38 @@
package at.petrak.hexcasting.common.lib;
import net.minecraft.util.random.SimpleWeightedRandomList;
import net.minecraft.util.valueproviders.ConstantInt;
import net.minecraft.world.level.block.Block;
import net.minecraft.world.level.block.state.BlockState;
import net.minecraft.world.level.levelgen.feature.configurations.TreeConfiguration;
import net.minecraft.world.level.levelgen.feature.featuresize.TwoLayersFeatureSize;
import net.minecraft.world.level.levelgen.feature.foliageplacers.FancyFoliagePlacer;
import net.minecraft.world.level.levelgen.feature.stateproviders.BlockStateProvider;
import net.minecraft.world.level.levelgen.feature.stateproviders.WeightedStateProvider;
import net.minecraft.world.level.levelgen.feature.trunkplacers.FancyTrunkPlacer;
import java.util.OptionalInt;
public class HexFeatureConfigs {
public static final TreeConfiguration AMETHYST_EDIFIED_TREE_CONFIG = akashicTree(HexBlocks.AMETHYST_EDIFIED_LEAVES, HexBlocks.EDIFIED_LOG_AMETHYST);
public static final TreeConfiguration AVENTURINE_EDIFIED_TREE_CONFIG = akashicTree(HexBlocks.AVENTURINE_EDIFIED_LEAVES, HexBlocks.EDIFIED_LOG_AVENTURINE);
public static final TreeConfiguration CITRINE_EDIFIED_TREE_CONFIG = akashicTree(HexBlocks.CITRINE_EDIFIED_LEAVES, HexBlocks.EDIFIED_LOG_CITRINE);
private static TreeConfiguration akashicTree(Block leaves, Block altLog) {
return new TreeConfiguration.TreeConfigurationBuilder(
new WeightedStateProvider(
SimpleWeightedRandomList.<BlockState>builder()
.add(HexBlocks.EDIFIED_LOG.defaultBlockState(), 8)
.add(altLog.defaultBlockState(), 1)
.build()),
// baseHeight, heightRandA, heightRandB
new FancyTrunkPlacer(5, 5, 3),
BlockStateProvider.simple(leaves),
// radius, offset, height
new FancyFoliagePlacer(ConstantInt.of(1), ConstantInt.of(5), 5),
// limit, lower size, upper size, minclippedheight
new TwoLayersFeatureSize(0, 0, 0, OptionalInt.of(6))
).build();
}
}

View file

@ -1,60 +1,23 @@
package at.petrak.hexcasting.common.misc;
import at.petrak.hexcasting.api.HexAPI;
import at.petrak.hexcasting.common.lib.HexBlocks;
import at.petrak.hexcasting.common.lib.HexConfiguredFeatures;
import com.google.common.collect.Lists;
import net.minecraft.core.Holder;
import net.minecraft.data.worldgen.BootstapContext;
import net.minecraft.data.worldgen.features.FeatureUtils;
import net.minecraft.resources.ResourceKey;
import net.minecraft.util.RandomSource;
import net.minecraft.util.random.SimpleWeightedRandomList;
import net.minecraft.util.valueproviders.ConstantInt;
import net.minecraft.world.level.block.Block;
import net.minecraft.world.level.block.grower.AbstractTreeGrower;
import net.minecraft.world.level.block.state.BlockState;
import net.minecraft.world.level.levelgen.feature.ConfiguredFeature;
import net.minecraft.world.level.levelgen.feature.Feature;
import net.minecraft.world.level.levelgen.feature.configurations.TreeConfiguration;
import net.minecraft.world.level.levelgen.feature.featuresize.TwoLayersFeatureSize;
import net.minecraft.world.level.levelgen.feature.foliageplacers.FancyFoliagePlacer;
import net.minecraft.world.level.levelgen.feature.stateproviders.BlockStateProvider;
import net.minecraft.world.level.levelgen.feature.stateproviders.WeightedStateProvider;
import net.minecraft.world.level.levelgen.feature.trunkplacers.FancyTrunkPlacer;
import java.util.List;
import java.util.OptionalInt;
public class AkashicTreeGrower extends AbstractTreeGrower {
public static final AkashicTreeGrower INSTANCE = new AkashicTreeGrower();
public static final List<Holder<ConfiguredFeature<TreeConfiguration, ?>>> GROWERS = Lists.newArrayList();
public static final List<ResourceKey<ConfiguredFeature<?, ?>>> GROWERS = Lists.newArrayList();
public static void init() {
GROWERS.add(buildTreeFeature(HexBlocks.AMETHYST_EDIFIED_LEAVES, HexBlocks.EDIFIED_LOG_AMETHYST, "1"));
GROWERS.add(buildTreeFeature(HexBlocks.AVENTURINE_EDIFIED_LEAVES, HexBlocks.EDIFIED_LOG_AVENTURINE, "2"));
GROWERS.add(buildTreeFeature(HexBlocks.CITRINE_EDIFIED_LEAVES, HexBlocks.EDIFIED_LOG_CITRINE, "3"));
}
private static Holder<ConfiguredFeature<TreeConfiguration, ?>> buildTreeFeature(BootstapContext<ConfiguredFeature<?, ?>> context, Block leaves, Block altLog, String name) {
return FeatureUtils.register(context,
null,
null,
new TreeConfiguration.TreeConfigurationBuilder(
new WeightedStateProvider(
SimpleWeightedRandomList.<BlockState>builder()
.add(HexBlocks.EDIFIED_LOG.defaultBlockState(), 8)
.add(altLog.defaultBlockState(), 1)
.build()),
// baseHeight, heightRandA, heightRandB
new FancyTrunkPlacer(5, 5, 3),
BlockStateProvider.simple(leaves),
// radius, offset, height
new FancyFoliagePlacer(ConstantInt.of(1), ConstantInt.of(5), 5),
// limit, lower size, upper size, minclippedheight
new TwoLayersFeatureSize(0, 0, 0, OptionalInt.of(6))
).build()
);
GROWERS.add(HexConfiguredFeatures.AMETHYST_EDIFIED_TREE);
GROWERS.add(HexConfiguredFeatures.AVENTURINE_EDIFIED_TREE);
GROWERS.add(HexConfiguredFeatures.CITRINE_EDIFIED_TREE);
}
@Override

View file

@ -49,6 +49,7 @@ import net.fabricmc.fabric.api.registry.FlammableBlockRegistry
import net.minecraft.commands.synchronization.SingletonArgumentInfo
import net.minecraft.core.Registry
import net.minecraft.core.registries.BuiltInRegistries
import net.minecraft.core.registries.Registries
import net.minecraft.resources.ResourceLocation
import net.minecraft.world.InteractionResult
import net.minecraft.world.entity.player.Player
@ -139,6 +140,8 @@ object FabricHexInitializer : ModInitializer {
HexParticles.registerParticles(bind(BuiltInRegistries.PARTICLE_TYPE))
HexConfiguredFeatures.registerConfiguredFeatures(bind(Registries.CONFIGURED_FEATURE))
HexLootFunctions.registerSerializers(bind(BuiltInRegistries.LOOT_FUNCTION_TYPE))
HexIotaTypes.registerTypes(bind(IXplatAbstractions.INSTANCE.iotaTypeRegistry))

View file

@ -45,9 +45,10 @@ public class ForgeHexDataGenerators {
HexAPI.LOGGER.info("Starting cross-platform datagen");
DataGenerator gen = ev.getGenerator();
var output = gen.getPackOutput();
ExistingFileHelper efh = ev.getExistingFileHelper();
gen.addProvider(ev.includeClient(), new HexItemModels(gen, efh));
gen.addProvider(ev.includeClient(), new HexBlockStatesAndModels(gen, efh));
gen.addProvider(ev.includeClient(), new HexItemModels(output, efh));
gen.addProvider(ev.includeClient(), new HexBlockStatesAndModels(output, efh));
gen.addProvider(ev.includeServer(), new HexAdvancements());
}

View file

@ -9,6 +9,7 @@ import at.petrak.hexcasting.common.lib.HexBlocks;
import at.petrak.paucal.api.forge.datagen.PaucalBlockStateAndModelProvider;
import net.minecraft.core.Direction;
import net.minecraft.data.DataGenerator;
import net.minecraft.data.PackOutput;
import net.minecraft.resources.ResourceLocation;
import net.minecraft.world.level.block.Block;
import net.minecraft.world.level.block.state.properties.BlockStateProperties;
@ -20,8 +21,8 @@ import net.minecraftforge.common.data.ExistingFileHelper;
import static net.minecraftforge.client.model.generators.ModelProvider.BLOCK_FOLDER;
public class HexBlockStatesAndModels extends PaucalBlockStateAndModelProvider {
public HexBlockStatesAndModels(DataGenerator gen, ExistingFileHelper exFileHelper) {
super(gen, HexAPI.MOD_ID, exFileHelper);
public HexBlockStatesAndModels(PackOutput output, ExistingFileHelper exFileHelper) {
super(output, HexAPI.MOD_ID, exFileHelper);
}
@Override

View file

@ -16,6 +16,7 @@ import at.petrak.hexcasting.common.lib.HexItems;
import at.petrak.paucal.api.forge.datagen.PaucalItemModelProvider;
import net.minecraft.client.renderer.block.model.ItemTransforms;
import net.minecraft.data.DataGenerator;
import net.minecraft.data.PackOutput;
import net.minecraft.resources.ResourceLocation;
import net.minecraft.world.item.DyeColor;
import net.minecraft.world.item.Item;
@ -28,8 +29,8 @@ import java.util.Objects;
import java.util.function.BiFunction;
public class HexItemModels extends PaucalItemModelProvider {
public HexItemModels(DataGenerator generator, ExistingFileHelper existingFileHelper) {
super(generator, HexAPI.MOD_ID, existingFileHelper);
public HexItemModels(PackOutput output, ExistingFileHelper existingFileHelper) {
super(output, HexAPI.MOD_ID, existingFileHelper);
}
private static final String[] PHIAL_SIZES = {"small", "medium", "large", "larger", "largest"};