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

[1.16.4] How do I make my ore generate thru the world?


Recommended Posts

17 hours ago, ChampionAsh5357 said:

1. Create a ConfiguredFeature and register it (look at the Features class for examples).

2. Attach it via BiomeLoadingEvent (read the javadocs on the event as applicable to your situation).

I have the same questions. From what I gathered from this reply I made a ModFeatures class, where I register the ConfiguredFeatures, however how do I attach it to the BiomeLoadingEvent? I tried using the deferred registries the same way I did for blocks and items but it errors out because the block to generate isn't registered yet, even tho I am calling the register method in the Features Deferred Register after the Blocks Deferred Register

  • Like 1
Link to post
Share on other sites
2 hours ago, kiou.23 said:

I tried using the deferred registries the same way I did for blocks and items but it errors out because the block to generate isn't registered yet, even tho I am calling the register method in the Features Deferred Register after the Blocks Deferred Register

You should post your repo so that we don't have to guess. If I had to, you're probably create static final variables without considering loading order for the configured feature. In which case, they need to be registered during common setup or at least after placements. 

2 hours ago, kiou.23 said:

From what I gathered from this reply I made a ModFeatures class, where I register the ConfiguredFeatures, however how do I attach it to the BiomeLoadingEvent?

BiomeLoadingEvent holds methods. Read the javadoc and look through the method to find which one is used to add a configured feature.

Link to post
Share on other sites
1 hour ago, ChampionAsh5357 said:

You should post your repo so that we don't have to guess. If I had to, you're probably create static final variables without considering loading order for the configured feature. In which case, they need to be registered during common setup or at least after placements. 

BiomeLoadingEvent holds methods. Read the javadoc and look through the method to find which one is used to add a configured feature.

I managed to get it working! thanks, I want to know if this is the proper way of doing it tho

this is my ModFeatures class:

public class ModFeatures {

    public static final DeferredRegister<Feature<?>> FEATURES = DeferredRegister.create(ForgeRegistries.FEATURES, TutorialMod.MOD_ID);

    public static final ConfiguredFeature<?, ?> ORE_SILVER = register("ore_silver",
        Feature.ORE.withConfiguration(
            new OreFeatureConfig(
                OreFeatureConfig.FillerBlockType.BASE_STONE_OVERWORLD,
                ModBlocks.SILVER_ORE.get().getDefaultState(), 9
        )).range(64).square().func_242731_b(20)
    );

    private static <FC extends IFeatureConfig> ConfiguredFeature<FC, ?> register(String key, ConfiguredFeature<FC, ?> configuredFeature) {
        return Registry.register(WorldGenRegistries.CONFIGURED_FEATURE, key, configuredFeature);
    }
}

And this is the main Mod class:

@Mod(TutorialMod.MOD_ID)
public class TutorialMod
{
    public static final String MOD_ID = "tutorial";
    public static final Logger LOGGER = LogManager.getLogger();

    public TutorialMod() {
        IEventBus modEventBus = FMLJavaModLoadingContext.get().getModEventBus();

        ModEntities.ENTITY_TYPES.register(modEventBus);
        ModContainerTypes.CONTAINER_TYPES.register(modEventBus);
        ModTileEntityTypes.TILE_ENTITY_TYPES.register(modEventBus);
        ModBlocks.BLOCKS.register(modEventBus);
        ModItems.ITEMS.register(modEventBus);

        modEventBus.addListener(this::setup);
        modEventBus.addListener(this::doClientStuff);

        MinecraftForge.EVENT_BUS.register(this);
    }

    private void setup(final FMLCommonSetupEvent event) {
        IEventBus modEventBus = FMLJavaModLoadingContext.get().getModEventBus();

        ModFeatures.FEATURES.register(modEventBus);
    }

    private void doClientStuff(final FMLClientSetupEvent event) {
        DeferredWorkQueue.runLater(() -> {
            ScreenManager.registerFactory(ModContainerTypes.TRANSMUTER.get(), TransmuterScreen::new);
            ScreenManager.registerFactory(ModContainerTypes.CHARGER.get(), ChargerScreen::new);
        });
    }

    @SubscribeEvent
    public void biomeGeneration(final BiomeLoadingEvent event) {
        event.getGeneration().getFeatures(GenerationStage.Decoration.UNDERGROUND_ORES)
            .add(() -> ModFeatures.ORE_SILVER);
    }

    public static final ItemGroup ITEM_GROUP = new ItemGroup(TutorialMod.MOD_ID) {
        @Override
        public ItemStack createIcon() {
            return new ItemStack(ModItems.SILVER_INGOT.get());
        }
    };
}

 

 

Additionally, I would like to know how this piece of code works, I have a vgue idea, but I basically just copied it from the Iron Ore Feature

Feature.ORE.withConfiguration(
            new OreFeatureConfig(
                OreFeatureConfig.FillerBlockType.BASE_STONE_OVERWORLD,
                ModBlocks.SILVER_ORE.get().getDefaultState(), 9
        )).range(64).square().func_242731_b(20)

 

Link to post
Share on other sites
10 hours ago, kiou.23 said:

public static final ConfiguredFeature<?, ?> ORE_SILVER = register("ore_silver", Feature.ORE.withConfiguration( new OreFeatureConfig( OreFeatureConfig.FillerBlockType.BASE_STONE_OVERWORLD, ModBlocks.SILVER_ORE.get().getDefaultState(), 9 )).range(64).square().func_242731_b(20) );

The configured feature should be deferred and registered during common setup. In most cases, this would throw an NPE as the registries would not have been populated yet. You're technically cheating by lazily loading the class using a register method for a deferred registry. They should always be attached within the constructor. Just simply register normally in common setup instead of lazily loading a class in a potential error way. Since you're also not creating a feature, it makes no sense to attach the register.

11 hours ago, kiou.23 said:

Feature.ORE.withConfiguration( new OreFeatureConfig( OreFeatureConfig.FillerBlockType.BASE_STONE_OVERWORLD, ModBlocks.SILVER_ORE.get().getDefaultState(), 9 )).range(64).square().func_242731_b(20)

This creates a configured feature using the standard ore algorithm feature which replaces anything within the stone tag (BASE_STONE_OVERWORLD) with silver ore in up to veins of 9. Reading inward, the feature is placed 20 times (func_242731_b) based on a random x/z position in the chunk (square) from 0 - 64. If the block the placement lands on is not valid, it will not generate the ore in that location. 

Link to post
Share on other sites
8 hours ago, ChampionAsh5357 said:

The configured feature should be deferred and registered during common setup. In most cases, this would throw an NPE as the registries would not have been populated yet. You're technically cheating by lazily loading the class using a register method for a deferred registry. They should always be attached within the constructor. Just simply register normally in common setup instead of lazily loading a class in a potential error way. Since you're also not creating a feature, it makes no sense to attach the register.

So instead of calling Registry.register, I should call FEATURES.register? and since I'm registering FEATURES in the setup it should be fine, right?

 

edit: I tried that, but FEATURES.register complains that Feature.ORE.withConfiguration doesn't extends Feature<?>, so how should I go about registering the feature?

Edited by kiou.23
update
Link to post
Share on other sites

Okay, I declared a Deferred Register of type Feature<?> and registered to it like so:

    public static final DeferredRegister<Feature<?>> FEATURES = DeferredRegister.create(ForgeRegistries.FEATURES, TutorialMod.MOD_ID);

    public static final RegistryObject<Feature<?>> ORE_SILVER = FEATURES.register("ore_silver", () ->
        Feature.ORE.withConfiguration(
            new OreFeatureConfig(
                OreFeatureConfig.FillerBlockType.BASE_STONE_OVERWORLD,
                ModBlocks.SILVER_ORE.get().getDefaultState(),
                9
            )
        ).range(64).square().func_242731_b(20).feature
    );

This doesn't seem to be correct also as for adding the feature to the biome it asks for a configured feature

Link to post
Share on other sites

like this? this doesn't look right at all

public class ModFeatures {

    public static final DeferredRegister<Feature<?>> FEATURES = DeferredRegister.create(ForgeRegistries.FEATURES, TutorialMod.MOD_ID);

    public static final ConfiguredFeature<?, ?> ORE_SILVER_CONFIG = Feature.ORE.withConfiguration(
        new OreFeatureConfig(
            OreFeatureConfig.FillerBlockType.BASE_STONE_OVERWORLD,
            ModBlocks.SILVER_ORE.get().getDefaultState(),
            9
        )
    ).range(64).square().func_242731_b(20);

    public static final RegistryObject<Feature<?>> ORE_SILVER = FEATURES.register("ore_silver", () ->
        ORE_SILVER_CONFIG.feature
    );
}
    @SubscribeEvent
    public void biomeGeneration(final BiomeLoadingEvent biome) {
        if(biome.getCategory() == Biome.Category.NETHER || biome.getCategory() == Biome.Category.THEEND) return;

        biome.getGeneration().getFeatures(GenerationStage.Decoration.UNDERGROUND_ORES)
            .add(() -> ModFeatures.ORE_SILVER_CONFIG);
    }

 

sorry for posting repeatedly, I'm just trying to undesrtand how to do this

Link to post
Share on other sites
2 hours ago, kiou.23 said:

So instead of calling Registry.register, I should call FEATURES.register? and since I'm registering FEATURES in the setup it should be fine, right?

 

edit: I tried that, but FEATURES.register complains that Feature.ORE.withConfiguration doesn't extends Feature<?>, so how should I go about registering the feature?

No, that's not what I said. I said the feature registry is irrelevant, you're not using it. The ConfiguredFeature should be initialized and registered during common setup.

Link to post
Share on other sites
17 minutes ago, ChampionAsh5357 said:

No, that's not what I said. I said the feature registry is irrelevant, you're not using it. The ConfiguredFeature should be initialized and registered during common setup.

OHHHHH I got it, I don't need the Feature Register at all! I commented it out to check and it still generates, I just need the ConfiguredFeatures and then add them to the biomes in a BiomeLoadingEvent Handler (right?)

I would need the Feature Register if I were to register a whole new type of feature, correct?

Edited by kiou.23
corrected spelling
Link to post
Share on other sites
5 minutes ago, I'mBadAtModding said:

how do you get the filler block to be End Stone? I got it working in the overworld, but not in The End

I would think you need to create your own Rule Test, and match it against the End Stone Block, like so:

 new BlockMatchRuleTest(Blocks.END_STONE)

and then pass it in the place for the Filler Block Type in the Configured Feature. And in your BiomeLoadingEvent Handler you can test if the Category is equal to Biome.Category.THEEND

Link to post
Share on other sites
3 hours ago, kiou.23 said:

OHHHHH I got it, I don't need the Feature Register at all! I commented it out to check and it still generates, I just need the ConfiguredFeatures and then add them to the biomes in a BiomeLoadingEvent Handler (right?)

I would need the Feature Register if I were to register a whole new type of feature, correct?

Yes, I would still like to verify that you deferred initialization and registry of the ConfiguredFeature to the common setup event.

Link to post
Share on other sites
57 minutes ago, ChampionAsh5357 said:

Yes, I would still like to verify that you deferred initialization and registry of the ConfiguredFeature to the common setup event.

And how would I do that?... I think so, but I'm not sure I did because I only had the Features deferred Register in the common setup

public class ModFeatures {

    public static final ConfiguredFeature<?, ?> ORE_SILVER_CONFIG = Feature.ORE.withConfiguration(
        new OreFeatureConfig(
            OreFeatureConfig.FillerBlockType.BASE_STONE_OVERWORLD,
            ModBlocks.SILVER_ORE.get().getDefaultState(),
            9
        )
    ).range(64).square().func_242731_b(20);

}
@Mod(TutorialMod.MOD_ID)
public class TutorialMod
{
    public static final String MOD_ID = "tutorial";
    public static final Logger LOGGER = LogManager.getLogger();

    public TutorialMod() {
        IEventBus modEventBus = FMLJavaModLoadingContext.get().getModEventBus();

        ModEntities.ENTITY_TYPES.register(modEventBus);
        ModContainerTypes.CONTAINER_TYPES.register(modEventBus);
        ModTileEntityTypes.TILE_ENTITY_TYPES.register(modEventBus);
        ModBlocks.BLOCKS.register(modEventBus);
        ModItems.ITEMS.register(modEventBus);

        modEventBus.addListener(this::setup);
        modEventBus.addListener(this::clientSetup);

        MinecraftForge.EVENT_BUS.register(this);
    }

    private void setup(final FMLCommonSetupEvent event) {
        
    }

    private void clientSetup(final FMLClientSetupEvent event) {
        DeferredWorkQueue.runLater(() -> {
            ScreenManager.registerFactory(ModContainerTypes.TRANSMUTER.get(), TransmuterScreen::new);
            ScreenManager.registerFactory(ModContainerTypes.CHARGER.get(), ChargerScreen::new);
        });
    }

    @SubscribeEvent
    public void onBiomeLoading(final BiomeLoadingEvent biome) {
        if(biome.getCategory() == Biome.Category.NETHER || biome.getCategory() == Biome.Category.THEEND) return;

        biome.getGeneration().getFeatures(GenerationStage.Decoration.UNDERGROUND_ORES)
            .add(() -> ModFeatures.ORE_SILVER_CONFIG);
    }

    public static final ItemGroup ITEM_GROUP = new ItemGroup(TutorialMod.MOD_ID) {
        @Override
        public ItemStack createIcon() {
            return new ItemStack(ModItems.SILVER_INGOT.get());
        }
    };
}

 

Link to post
Share on other sites
11 minutes ago, ChampionAsh5357 said:

Initialize the variable within the method event.

Like so?

@Mod.EventBusSubscriber(modid = TutorialMod.MOD_ID, bus = Mod.EventBusSubscriber.Bus.MOD)
public class ModFeatures {

    @SubscribeEvent
    public void onBiomeLoading(BiomeLoadingEvent biome) {
        final ConfiguredFeature<?, ?> ORE_SILVER_CONFIG = Feature.ORE.withConfiguration(
            new OreFeatureConfig(
                OreFeatureConfig.FillerBlockType.BASE_STONE_OVERWORLD,
                ModBlocks.SILVER_ORE.get().getDefaultState(),
                9
            )
        ).range(64).square().func_242731_b(20);

        if(biome.getCategory() == Biome.Category.NETHER || biome.getCategory() == Biome.Category.THEEND) return;

        biome.getGeneration().getFeatures(GenerationStage.Decoration.UNDERGROUND_ORES)
                .add(() -> ORE_SILVER_CONFIG);
        
    }
}

 

Link to post
Share on other sites
3 minutes ago, ChampionAsh5357 said:

No, that will create the ConfiguredFeature every single time the event is called, which is too many times. This is not to mention you are no longer registering the ConfiguredFeature. Create a global field and initialize it within the common setup.

So like so?

public class ModFeatures {

    public static ConfiguredFeature<?, ?> ORE_SILVER_CONFIG;

    @SubscribeEvent
    public void setup(FMLCommonSetupEvent event) {
        ORE_SILVER_CONFIG = Feature.ORE.withConfiguration(
            new OreFeatureConfig(
                    OreFeatureConfig.FillerBlockType.BASE_STONE_OVERWORLD,
                    ModBlocks.SILVER_ORE.get().getDefaultState(),
                    9
            )
        ).range(64).square().func_242731_b(20);
    }
}

 

and then adding it to the biomes in the main Class like I was doing before

Link to post
Share on other sites
16 minutes ago, ChampionAsh5357 said:

You still need to register it but yes, that's exactly how you would do it. Take a look at the Features class for the registry method to copy and use. Since it returns the object itself, you can just modify as needed.

Got it, so just to confirm, like this right?

@Mod.EventBusSubscriber(modid = TutorialMod.MOD_ID, bus = Mod.EventBusSubscriber.Bus.MOD)
public class ModFeatures {

    public static ConfiguredFeature<?, ?> ORE_SILVER_CONFIG;

    @SubscribeEvent
    public void setup(FMLCommonSetupEvent event) {
        ORE_SILVER_CONFIG = register("ore_silver",
            Feature.ORE.withConfiguration(
                new OreFeatureConfig(
                    OreFeatureConfig.FillerBlockType.BASE_STONE_OVERWORLD,
                    ModBlocks.SILVER_ORE.get().getDefaultState(),
                    9
                )
        ).range(64).square().func_242731_b(20));
    }

    private <FC extends IFeatureConfig> ConfiguredFeature<FC, ?> register(String key, ConfiguredFeature<FC, ?> configuredFeature) {
        return Registry.register(WorldGenRegistries.CONFIGURED_FEATURE, key, configuredFeature);
    }
}

 

What happens if I don't register it tho? because it was generating just fine

Link to post
Share on other sites
1 hour ago, kiou.23 said:

Got it, so just to confirm, like this right?

Yes, the method should be static though.

1 hour ago, kiou.23 said:

What happens if I don't register it tho? because it was generating just fine

You won't see any issues in a standalone, but with other mods it will bottleneck other features from generating due to how codecs are handled with unregistered objects.

  • Thanks 1
Link to post
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.

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.



×
×
  • Create New...

Important Information

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