Jump to content
View in the app

A better way to browse. Learn more.

Forge Forums

A full-screen app on your home screen with push notifications, badges and more.

To install this app on iOS and iPadOS
  1. Tap the Share icon in Safari
  2. Scroll the menu and tap Add to Home Screen.
  3. Tap Add in the top-right corner.
To install this app on Android
  1. Tap the 3-dot menu (⋮) in the top-right corner of the browser.
  2. Tap Add to Home screen or Install app.
  3. Confirm by tapping Install.

Featured Replies

Posted

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

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.

  • Author

Thank you for anser, I didn't know that event even exist, I'll use it instead. :)

Edited by Maciej916

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
Unfortunately, your content contains terms that we do not allow. Please edit your content to remove the highlighted words below.
Reply to this topic...

Important Information

By using this site, you agree to our Terms of Use.

Configure browser push notifications

Chrome (Android)
  1. Tap the lock icon next to the address bar.
  2. Tap Permissions → Notifications.
  3. Adjust your preference.
Chrome (Desktop)
  1. Click the padlock icon in the address bar.
  2. Select Site settings.
  3. Find Notifications and adjust your preference.