Jump to content
Search In
  • More options...
Find results that contain...
Find results in...

[1.16.3] Add custom generation


Maciej916
 Share

Recommended Posts

Hello, I'm having troubles with adding custom generation on 1.16.3. I used solution from this post https://forums.minecraftforge.net/topic/90560-1162-how-to-add-custom-ore-to-world-generation/ and it's working for ores but i also want to add new tree and Im getting cast error

RubberTreeBlockStateProvider cannot be cast to net.minecraft.world.gen.blockstateprovider.SimpleBlockStateProvider

 Code I use:

    public static void initGen() {
        Registry.register(
                WorldGenRegistries.CONFIGURED_FEATURE,
                ModBlocks.COPPER_ORE.getRegistryName(),
                Feature.ORE
                        .withConfiguration(new OreFeatureConfig(OreFeatureConfig.FillerBlockType.field_241882_a /* base_stone_overworld */, ModBlocks.COPPER_ORE.getDefaultState(), ModConfig.worldgen_copper_size))
                        .withPlacement(Placement.field_242907_l/* RANGE */.configure(new TopSolidRangeConfig(ModConfig.worldgen_copper_min_height, 0, ModConfig.worldgen_copper_max_height)))
                        .func_242728_a() /* spreadHorizontally */
                        .func_242731_b(ModConfig.worldgen_copper_size) /* repeat */
        );


        Registry.register(
                WorldGenRegistries.CONFIGURED_FEATURE /* Feature Registering */,
                ModBlocks.RUBBER_SAPLING.getRegistryName() /* Resource Location */,
                Feature.TREE /* no_surface_ore */.withConfiguration(RUBBER_TREE_CONFIG)
                        .withPlacement(Placement.field_242902_f/* RANGE */.configure(new AtSurfaceWithExtraConfig(12, 12, 72)))
        );

    }

    public static void setupGen() {
        for (Map.Entry<RegistryKey<Biome>, Biome> biome : WorldGenRegistries.BIOME.getEntries() /* Collection of Biome Entries */) {
            if (!biome.getValue().getCategory().equals(Biome.Category.NETHER) && !biome.getValue().getCategory().equals(Biome.Category.THEEND)) {

                addFeatureToBiome(
                        biome.getValue(),
                        GenerationStage.Decoration.UNDERGROUND_ORES,
                        WorldGenRegistries.CONFIGURED_FEATURE.getOrDefault(ModBlocks.COPPER_ORE.getRegistryName())
                );

                addFeatureToBiome(
                        biome.getValue(),
                        GenerationStage.Decoration.VEGETAL_DECORATION,
                        WorldGenRegistries.CONFIGURED_FEATURE.getOrDefault(ModBlocks.RUBBER_SAPLING.getRegistryName())
                );
            }
        }
    }

    public static void addFeatureToBiome(Biome biome, GenerationStage.Decoration decoration, ConfiguredFeature<?, ?> configuredFeature) {
        List<List<Supplier<ConfiguredFeature<?, ?>>>> biomeFeatures = new ArrayList<>(
                biome.getGenerationSettings().getFeatures()/* List of Configured Features */
        );

        while (biomeFeatures.size() <= decoration.ordinal()) {
            biomeFeatures.add(Lists.newArrayList());
        }

        List<Supplier<ConfiguredFeature<?, ?>>> features = new ArrayList<>(biomeFeatures.get(decoration.ordinal()));
        features.add(() -> configuredFeature);
        biomeFeatures.set(decoration.ordinal(), features);

        ObfuscationReflectionHelper.setPrivateValue(BiomeGenerationSettings.class, biome.getGenerationSettings(), biomeFeatures, "features");
    }

 

Rubber tree:

public class RubberTree extends Tree {

    public static final BaseTreeFeatureConfig RUBBER_TREE_CONFIG = (
            new BaseTreeFeatureConfig.Builder(
                    new RubberTreeBlockStateProvider(ModBlocks.RUBBER_LOG.getDefaultState()),
                    new SimpleBlockStateProvider(ModBlocks.RUBBER_LEAVES.getDefaultState()),
                    new RubberFoliagePlacer(2, 0),
                    new StraightTrunkPlacer(4, 2, 0),
                    new TwoLayerFeature(1, 0, 1))
    ).build();

    @Nullable
    @Override
    protected ConfiguredFeature<BaseTreeFeatureConfig, ?> getTreeFeature(Random randomIn, boolean p_225546_2_) {
        return Feature.TREE.withConfiguration(RUBBER_TREE_CONFIG);
    }
}

 

Is there a simple solution to fix this? I can add that tree is working correctly in game, Im only having troubles to add it to generation.

Edited by Maciej916
Link to comment
Share on other sites

1 minute ago, Maciej916 said:

RubberTreeBlockStateProvider cannot be cast to net.minecraft.world.gen.blockstateprovider.SimpleBlockStateProvider

I think that statement should be self explanatory if you understand java well enough.

 

Also, 1.16.3 has a new way of registering features for biomes via BiomeLoadingEvent. Use that instead over this outdated makeshift answer which would result in a lot of concurrency issues.

Link to comment
Share on other sites

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.
Note: Your post will require moderator approval before it will be visible.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

 Share



×
×
  • Create New...

Important Information

By using this site, you agree to our Privacy Policy.