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

[1.16.5]Why ore is not generated?


KakUserTask
 Share

Recommended Posts

This is the main mod file. I assumed that onBiomeLoading is not being called. But I still did not understand why it was not called. Tried making the method static, but then an exception is thrown (java.lang.IllegalArgumentException: Method public static void has @SubscribeEvent annotation, but takes an argument that is not a subtype of the base type interface net.minecraftforge.fml.event.lifecycle.IModBusEvent: class net.minecraftforge.event.world.BiomeLoadingEvent). Tell me what I'm doing wrong. Thanks!

import static my.first.mod.myfirstmod.RegistryHandler.COPPER_ORE;

@Mod("myfirstmod")
public class MyFirstMod {

    private static final Logger LOGGER = LogManager.getLogger();
    public static final String MODID = "myfirstmod";

    public MyFirstMod() {
        FMLJavaModLoadingContext.get().getModEventBus().addListener(this::setup);
        FMLJavaModLoadingContext.get().getModEventBus().addListener(this::enqueueIMC);
        FMLJavaModLoadingContext.get().getModEventBus().addListener(this::processIMC);
        FMLJavaModLoadingContext.get().getModEventBus().addListener(this::doClientStuff);

        MinecraftForge.EVENT_BUS.register(this);

        RegistryHandler.init();
    }

    private void setup(final FMLCommonSetupEvent event) {
        LOGGER.info("HELLO FROM PREINIT");
        LOGGER.info("DIRT BLOCK >> {}", Blocks.DIRT.getRegistryName());
    }

    private void doClientStuff(final FMLClientSetupEvent event) {
        LOGGER.info("Got game settings {}", event.getMinecraftSupplier().get().gameSettings);
    }

    private void enqueueIMC(final InterModEnqueueEvent event) {
        InterModComms.sendTo("my-first-mod", "helloworld", () -> {
            LOGGER.info("Hello world from the MDK");
            return "Hello world";
        });
    }

    private void processIMC(final InterModProcessEvent event) {
        LOGGER.info("Got IMC {}", event.getIMCStream().
                map(m -> m.getMessageSupplier().get()).
                collect(Collectors.toList()));
    }

    @SubscribeEvent
    public void onServerStarting(FMLServerStartingEvent event) {
        LOGGER.info("HELLO from server starting");
    }

    @Mod.EventBusSubscriber(bus = Mod.EventBusSubscriber.Bus.MOD)
    public static class RegistryEvents {

        public static ConfiguredFeature<?, ?> ORE_COPPER_CONFIG;
        public static int veinSize = 12;
        public static int veinCount = 5;
        public static int maxHeight = 120;

        @SubscribeEvent
        public static void setup(FMLCommonSetupEvent event) {
            ORE_COPPER_CONFIG = Registry.register(
                    WorldGenRegistries.CONFIGURED_FEATURE,
                    "copper_ore",
                    Feature.ORE.withConfiguration(
                        new OreFeatureConfig(
                                OreFeatureConfig.FillerBlockType.BASE_STONE_OVERWORLD,
                                COPPER_ORE.get().getDefaultState(),
                                veinSize
                        )
                    ).range(maxHeight).square().count(veinCount)
            );

            LOGGER.info("'setup' function called");
        }

        @SubscribeEvent(priority = EventPriority.HIGH)
        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(() -> ORE_COPPER_CONFIG);
            LOGGER.info("'OnBiomeLoading' function called");
        }

        @SubscribeEvent
        public static void onBlocksRegistry(final RegistryEvent.Register<Block> blockRegistryEvent) {

            LOGGER.info("HELLO from Register Block");
        }
    }
}
Edited by KakUserTask
Link to comment
Share on other sites

23 minutes ago, diesieben07 said:
  • Specify your ModID when using @EventBusSubscriber.
  • BiomeLoadingEvent is fired on the forge event bus, not the mod event bus.

Is this how it should be? But the method is still not called

@Mod.EventBusSubscriber(modid = MODID, bus = Mod.EventBusSubscriber.Bus.FORGE)

 

Edited by KakUserTask
Link to comment
Share on other sites

1 minute ago, diesieben07 said:

Show updated code.

package my.first.mod.myfirstmod;

...

import static my.first.mod.myfirstmod.RegistryHandler.COPPER_ORE;

@Mod("myfirstmod")
public class MyFirstMod {

    private static final Logger LOGGER = LogManager.getLogger();
    public static final String MODID = "myfirstmod";

    public MyFirstMod() {
        FMLJavaModLoadingContext.get().getModEventBus().addListener(this::setup);
        FMLJavaModLoadingContext.get().getModEventBus().addListener(this::enqueueIMC);
        FMLJavaModLoadingContext.get().getModEventBus().addListener(this::processIMC);
        FMLJavaModLoadingContext.get().getModEventBus().addListener(this::doClientStuff);

        MinecraftForge.EVENT_BUS.register(this);

        RegistryHandler.init();
    }

    private void setup(final FMLCommonSetupEvent event) {
        LOGGER.info("HELLO FROM PREINIT");
        LOGGER.info("DIRT BLOCK >> {}", Blocks.DIRT.getRegistryName());
    }

    private void doClientStuff(final FMLClientSetupEvent event) {
        LOGGER.info("Got game settings {}", event.getMinecraftSupplier().get().gameSettings);
    }

    private void enqueueIMC(final InterModEnqueueEvent event) {
        InterModComms.sendTo("my-first-mod", "helloworld", () -> {
            LOGGER.info("Hello world from the MDK");
            return "Hello world";
        });
    }

    private void processIMC(final InterModProcessEvent event) {
        LOGGER.info("Got IMC {}", event.getIMCStream().
                map(m -> m.getMessageSupplier().get()).
                collect(Collectors.toList()));
    }

    @SubscribeEvent
    public void onServerStarting(FMLServerStartingEvent event) {
        LOGGER.info("HELLO from server starting");
    }

    @Mod.EventBusSubscriber(modid = MODID, bus = Mod.EventBusSubscriber.Bus.FORGE)
    public static class RegistryEvents {

        public static ConfiguredFeature<?, ?> ORE_COPPER_CONFIG;
        public static int veinSize = 50;
        public static int veinCount = 50;
        public static int maxHeight = 120;

        @SubscribeEvent
        public static void setup(FMLCommonSetupEvent event) {
            ORE_COPPER_CONFIG = Registry.register(
                    WorldGenRegistries.CONFIGURED_FEATURE,
                    "copper_ore",
                    Feature.ORE.withConfiguration(
                        new OreFeatureConfig(
                                OreFeatureConfig.FillerBlockType.BASE_STONE_OVERWORLD,
                                COPPER_ORE.get().getDefaultState(),
                                veinSize
                        )
                    ).range(maxHeight).square().count(veinCount)
            );

            LOGGER.info("'setup' function called");
        }

        @SubscribeEvent(priority = EventPriority.HIGH)
        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(() -> ORE_COPPER_CONFIG);
            LOGGER.info("'OnBiomeLoading' function called");
        }

        @SubscribeEvent
        public static void onBlocksRegistry(final RegistryEvent.Register<Block> blockRegistryEvent) {
            LOGGER.info("HELLO from Register Block");
        }
    }
}

This is the updated code (as I understood it needed to be changed).

Link to comment
Share on other sites

10 minutes ago, diesieben07 said:

Now you are using the forge event bus, but RegistryEvent.Register and FMLCommonSetupEvent fire on the mod event bus. You need separate event handlers for both.

Your onBiomeLoading method is also still not static, meaning @EventBusSubscriber will not register it.

It helped, thank you!
Here is the new code:

package my.first.mod.myfirstmod;

...

import static my.first.mod.myfirstmod.RegistryHandler.COPPER_ORE;

@Mod("myfirstmod")
public class MyFirstMod {

    private static final Logger LOGGER = LogManager.getLogger();
    public static final String MODID = "myfirstmod";

    public MyFirstMod() {
        FMLJavaModLoadingContext.get().getModEventBus().addListener(this::setup);
        FMLJavaModLoadingContext.get().getModEventBus().addListener(this::enqueueIMC);
        FMLJavaModLoadingContext.get().getModEventBus().addListener(this::processIMC);
        FMLJavaModLoadingContext.get().getModEventBus().addListener(this::doClientStuff);

        MinecraftForge.EVENT_BUS.register(this);

        RegistryHandler.init();
    }

    private void setup(final FMLCommonSetupEvent event) {
        LOGGER.info("HELLO FROM PREINIT");
        LOGGER.info("DIRT BLOCK >> {}", Blocks.DIRT.getRegistryName());
    }

    private void doClientStuff(final FMLClientSetupEvent event) {
        LOGGER.info("Got game settings {}", event.getMinecraftSupplier().get().gameSettings);
    }

    private void enqueueIMC(final InterModEnqueueEvent event) {
        InterModComms.sendTo("my-first-mod", "helloworld", () -> {
            LOGGER.info("Hello world from the MDK");
            return "Hello world";
        });
    }

    private void processIMC(final InterModProcessEvent event) {
        LOGGER.info("Got IMC {}", event.getIMCStream().
                map(m -> m.getMessageSupplier().get()).
                collect(Collectors.toList()));
    }

    @SubscribeEvent
    public void onServerStarting(FMLServerStartingEvent event) {
        LOGGER.info("HELLO from server starting");
    }

    @Mod.EventBusSubscriber(modid = MODID, bus = Mod.EventBusSubscriber.Bus.MOD)
    public static class RegistryEvents2 {

        public static ConfiguredFeature<?, ?> ORE_COPPER_CONFIG;
        public static int veinSize = 50;
        public static int veinCount = 50;
        public static int maxHeight = 120;

        @SubscribeEvent()
        public static void setup(FMLCommonSetupEvent event) {
            ORE_COPPER_CONFIG = Registry.register(
                    WorldGenRegistries.CONFIGURED_FEATURE,
                    "copper_ore",
                    Feature.ORE.withConfiguration(
                            new OreFeatureConfig(
                                    OreFeatureConfig.FillerBlockType.BASE_STONE_OVERWORLD,
                                    COPPER_ORE.get().getDefaultState(),
                                    veinSize
                            )
                    ).range(maxHeight).square().count(veinCount)
            );

            LOGGER.info("'setup' function called");
        }

        @SubscribeEvent
        public static void onBlocksRegistry(final RegistryEvent.Register<Block> blockRegistryEvent) {
            LOGGER.info("HELLO from Register Block");
        }
    }

    @Mod.EventBusSubscriber(modid = MODID, bus = Mod.EventBusSubscriber.Bus.FORGE)
    public static class RegistryEvents {
        @SubscribeEvent(priority = EventPriority.HIGH)
        public static 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(() -> RegistryEvents2.ORE_COPPER_CONFIG);
            LOGGER.info("'OnBiomeLoading' function called");
        }
    }
}

 

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.