Jump to content

[1.16.4] [Solved] Ore generation using BiomeLoadingEvent


GenElectrovise

Recommended Posts

I am adding natural Amethyst Ore generation to the world.

 

I am receiving the loading error:

[ne.mi.fm.ja.FMLModContainer/LOADING]: Failed to register automatic subscribers. ModID: magiksmostevile, class genelectrovise.magiksmostevile.common.core.MagiksMostEvile
java.lang.IllegalArgumentException: Method public static void genelectrovise.magiksmostevile.common.world.gen.ore.OreFeatureRegistry.addOresToBiomes(net.minecraftforge.event.world.BiomeLoadingEvent) 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

... which is fairly obvious from looking through the heirarchy.

 

All of these posts say to use BiomeLoadingEvent to register features:

https://forums.minecraftforge.net/topic/92868-1163-biomeloadingevent/

https://forums.minecraftforge.net/topic/94945-1164how-to-generate-ores/

https://forums.minecraftforge.net/topic/90560-1162-how-to-add-custom-ore-to-world-generation/

https://forums.minecraftforge.net/topic/91702-1163-add-custom-generation/

 

... but FML doesn't like me doing this.

 

Should I be using another Event? Am I using this one correcly?

 

My subscribed methods:

/**
   * Form the lists of ores to register
   * 
   * @param event
   */
  @SubscribeEvent
  public static void createOreLists(final FMLCommonSetupEvent event) {
    overworldOres();
    netherOres();
    endOres();
  }

  /**
   * Trigger ore registration.
   * 
   * @param event
   */
  @SubscribeEvent(priority = EventPriority.HIGH)
  public static void addOresToBiomes(final BiomeLoadingEvent event) {
    registerOres(event);
  }

  private static void overworldOres() {
    overworldOres
        .add(new SimpleConfiguredOreFeature.Builder().withSimpleOreFeature(new SimpleOreFeature())
            .withSimpleOreFeatureConfiguration(
                new SimpleOreFeatureConfiguration(Blocks.STONE.getDefaultState(),
                    EvileDeferredRegistry.AMETHYST_ORE_OVERWORLD.get().getDefaultState(), 10, true))
            .build());
  }

 

Where I subscribe them:

  public MagiksMostEvile() {
    LOGGER.info("Magiks Most Evile is being loaded by FML");

    EVENT_BUS = FMLJavaModLoadingContext.get().getModEventBus();

    registerCommonEvents();

    EvileDeferredRegistry.init(FMLJavaModLoadingContext.get().getModEventBus());
  }


  public static void registerCommonEvents() {
    LOGGER.debug("Registering MME common events");
    EVENT_BUS.register(OreFeatureRegistry.class);
  }

 

The active branch of my GitHub repository:

https://github.com/GenElectrovise/MagiksMostEvile/tree/feature/1.16.4/update_to_1.16.4/src/main/java/genelectrovise/magiksmostevile/common/world/gen

 

Thanks!

Edited by GenElectrovise
Submitted too early

How to ask a good coding question: https://stackoverflow.com/help/how-to-ask

Give logs, code, desired effects, and actual effects. Be thorough or we can't help you. Don't post code without putting it in a code block (the <> button on the post - select "C-type Language"): syntax highlighting makes everything easier, and it keeps the post tidy.

 

My own mod, Magiks Most Evile: GitHub (https://github.com/GenElectrovise/MagiksMostEvile) Wiki (https://magiksmostevile.fandom.com/wiki/Magiks_Most_Evile_Wiki)

Edit your own signature at https://www.minecraftforge.net/forum/settings/signature/

Link to comment
Share on other sites

Thanks @Beethoven92:

 

I tried only using @Mod.EventBusSubscriber(modid = MagiksMostEvile.MODID, bus = Bus.FORGE), and combining the two methods into one call:

/**
   * Called on {@link Bus.Forge}. Trigger ore registration.
   * 
   * @param event
   */
  @SubscribeEvent(priority = EventPriority.HIGH)
  public static void addOresToBiomes(final BiomeLoadingEvent event) {
    MagiksMostEvile.LOGGER.debug("Adding MME ores: Biome=" + event.getName());
    createOreLists();


    registerOres(event);
  }

  /**
   * Form the lists of ores to register
   * 
   * @param event
   */
  public static void createOreLists() {
    MagiksMostEvile.LOGGER.debug("Creating ore lists for MME feature addition!");
    overworldOres();
    netherOres();
    endOres();
  }

(Result: Auto-subscribing genelectrovise.magiksmostevile.common.world.gen.ore.OreFeatureRegistry to FORGE)

 

Two things:

1) This doesn't seem like the right way to handle this, though? Registering the features should not be done every time a biome is loaded - that seems wrong to me.

2) Whenever I try to join a world with that code active, I get this very odd error:

 


[12:11:46] [Server thread/DEBUG] [ne.mi.fm.ne.FMLHandshakeHandler/FMLHANDSHAKE]: Handshake complete!
[12:11:46] [Netty Local Client IO #0/INFO] [ne.mi.fm.ne.NetworkHooks/]: Connected to a modded server.
[12:11:46] [Server thread/INFO] [ne.mi.co.AdvancementLoadFix/]: Using new advancement loading for net.minecraft.advancements.PlayerAdvancements@55ab5742
[12:11:46] [Server thread/INFO] [minecraft/PlayerList]: Dev[local:E:26a17569] logged in with entity id 257 at (-20.12474734205128, 72.0, 90.2353098908319)
[12:11:46] [Server thread/INFO] [minecraft/MinecraftServer]: Dev joined the game
[12:11:46] [Server thread/INFO] [minecraft/ServerPlayNetHandler]: Dev lost connection: Internal Exception: java.lang.ClassCastException: net.minecraft.network.login.ServerLoginNetHandler cannot be cast to net.minecraft.client.network.play.IClientPlayNetHandler
[12:11:46] [Server thread/INFO] [minecraft/MinecraftServer]: Dev left the game
[12:11:46] [Server thread/INFO] [minecraft/ServerPlayNetHandler]: Stopping singleplayer server as player logged out
[12:11:46] [Server thread/INFO] [minecraft/MinecraftServer]: Stopping server

 

Could this be a result of (1)? Maybe some strange de-sync issue?

How to ask a good coding question: https://stackoverflow.com/help/how-to-ask

Give logs, code, desired effects, and actual effects. Be thorough or we can't help you. Don't post code without putting it in a code block (the <> button on the post - select "C-type Language"): syntax highlighting makes everything easier, and it keeps the post tidy.

 

My own mod, Magiks Most Evile: GitHub (https://github.com/GenElectrovise/MagiksMostEvile) Wiki (https://magiksmostevile.fandom.com/wiki/Magiks_Most_Evile_Wiki)

Edit your own signature at https://www.minecraftforge.net/forum/settings/signature/

Link to comment
Share on other sites

I've made some additions - what stages should everything be occurring at?

 

If I should use BiomeLoadingEvent to add features to a biome, which event should I be using to make and register the features themselves?
Is there a way to do this with DeferredRegister?

How to ask a good coding question: https://stackoverflow.com/help/how-to-ask

Give logs, code, desired effects, and actual effects. Be thorough or we can't help you. Don't post code without putting it in a code block (the <> button on the post - select "C-type Language"): syntax highlighting makes everything easier, and it keeps the post tidy.

 

My own mod, Magiks Most Evile: GitHub (https://github.com/GenElectrovise/MagiksMostEvile) Wiki (https://magiksmostevile.fandom.com/wiki/Magiks_Most_Evile_Wiki)

Edit your own signature at https://www.minecraftforge.net/forum/settings/signature/

Link to comment
Share on other sites

I've resolved the error:
It was resulting from a NullPointerException while I was adding my features to biomes, which was concealed behind a resulting exception which was traced back to the mouseClickEventHandler which was triggered when I loaded the world.

I was adding my features to a static ConfiguredFeature<?,?> [ ], before they were actually loaded, with the expectation that the array references would be updated as well, but I guess concurrency decided that wouldn't happen. Now the final call of my event handler populates the arrays and everything works fine.

 

My new code is:

OreFeaures.java

  

  public static ConfiguredFeature<?, ?>[] OVERWORLD_ORES;
  public static ConfiguredFeature<?, ?>[] NETHER_ORES;
  public static ConfiguredFeature<?, ?>[] END_ORES;

@SubscribeEvent //Subbed to MOD
  public static void createConfiguredOreFeatures(FMLCommonSetupEvent event) {
    MagiksMostEvile.LOGGER.debug("Creating MME configured ore features");

    // Amethyst Ore Overworld
    AMETHYST_ORE_OVERWORLD = Registry.register( //
        WorldGenRegistries.CONFIGURED_FEATURE, //
        "amethyst_ore_overworld_generation", //
        Feature.ORE.withConfiguration( //
            new OreFeatureConfig( //
                new TagMatchRuleTest(ModdedTags.AMETHYST_ORE_SPAWNABLE), //
                EvileDeferredRegistry.AMETHYST_ORE_OVERWORLD.get().getDefaultState(), //
                7)) //
            .withPlacement(Placement.DEPTH_AVERAGE.configure( //
                new DepthAverageConfig(32, 32))) //
            .range(16)); //

    applyToLists();
  }

private static void applyToLists() {
    OVERWORLD_ORES = new ConfiguredFeature<?, ?>[] {AMETHYST_ORE_OVERWORLD, LEAD_ORE_OVERWORLD};
    NETHER_ORES = new ConfiguredFeature<?, ?>[] {AMETHYST_ORE_NETHER, LEAD_ORE_NETHER};
    END_ORES = new ConfiguredFeature<?, ?>[] {AMETHYST_ORE_END, LEAD_ORE_END};
  }

 

OreFeatureAdditionManager.java

  /**
   * Apply {@value #overworldOres()}, {@value #netherOres} and {@value #endOres} to {@link Biome}s
   * of their various {@link Biome.Category}.
   * 
   * @param event
   */
  @SubscribeEvent(priority = EventPriority.HIGH) //Subbed to FORGE
  public static void registerOres(final BiomeLoadingEvent event) {
    MagiksMostEvile.LOGGER.debug("Adding MME ores to biome: " + event.getName());

    BiomeGenerationSettingsBuilder generation = event.getGeneration();

    switch (event.getCategory()) {
      case NETHER:
        for (ConfiguredFeature<?, ?> simpleConfiguredOreFeature : OreFeatures.NETHER_ORES) {
          registerTo(generation, simpleConfiguredOreFeature);
        }
        break;

      case THEEND:
        for (ConfiguredFeature<?, ?> simpleConfiguredOreFeature : OreFeatures.END_ORES) {
          registerTo(generation, simpleConfiguredOreFeature);
        }
        break;

      default:
        for (ConfiguredFeature<?, ?> simpleConfiguredOreFeature : OreFeatures.OVERWORLD_ORES) {
          registerTo(generation, simpleConfiguredOreFeature);
        }
        break;
    }

  }

  /**
   * Convenience method to tidy up {@link #registerOres(BiomeLoadingEvent)} by abstracting away
   * {@link BiomeGenerationSettingsBuilder} calls.
   * 
   * @param builder
   * @param feature
   */
  private static void registerTo(BiomeGenerationSettingsBuilder builder,
      ConfiguredFeature<?, ?> feature) {
    
    builder.withFeature(GenerationStage.Decoration.UNDERGROUND_ORES, feature);
  }

 

How to ask a good coding question: https://stackoverflow.com/help/how-to-ask

Give logs, code, desired effects, and actual effects. Be thorough or we can't help you. Don't post code without putting it in a code block (the <> button on the post - select "C-type Language"): syntax highlighting makes everything easier, and it keeps the post tidy.

 

My own mod, Magiks Most Evile: GitHub (https://github.com/GenElectrovise/MagiksMostEvile) Wiki (https://magiksmostevile.fandom.com/wiki/Magiks_Most_Evile_Wiki)

Edit your own signature at https://www.minecraftforge.net/forum/settings/signature/

Link to comment
Share on other sites

15 hours ago, GenElectrovise said:

I've resolved the error:
It was resulting from a NullPointerException while I was adding my features to biomes, which was concealed behind a resulting exception which was traced back to the mouseClickEventHandler which was triggered when I loaded the world.

I was adding my features to a static ConfiguredFeature<?,?> [ ], before they were actually loaded, with the expectation that the array references would be updated as well, but I guess concurrency decided that wouldn't happen. Now the final call of my event handler populates the arrays and everything works fine.

 

My new code is:

OreFeaures.java


  

  public static ConfiguredFeature<?, ?>[] OVERWORLD_ORES;
  public static ConfiguredFeature<?, ?>[] NETHER_ORES;
  public static ConfiguredFeature<?, ?>[] END_ORES;

@SubscribeEvent //Subbed to MOD
  public static void createConfiguredOreFeatures(FMLCommonSetupEvent event) {
    MagiksMostEvile.LOGGER.debug("Creating MME configured ore features");

    // Amethyst Ore Overworld
    AMETHYST_ORE_OVERWORLD = Registry.register( //
        WorldGenRegistries.CONFIGURED_FEATURE, //
        "amethyst_ore_overworld_generation", //
        Feature.ORE.withConfiguration( //
            new OreFeatureConfig( //
                new TagMatchRuleTest(ModdedTags.AMETHYST_ORE_SPAWNABLE), //
                EvileDeferredRegistry.AMETHYST_ORE_OVERWORLD.get().getDefaultState(), //
                7)) //
            .withPlacement(Placement.DEPTH_AVERAGE.configure( //
                new DepthAverageConfig(32, 32))) //
            .range(16)); //

    applyToLists();
  }

private static void applyToLists() {
    OVERWORLD_ORES = new ConfiguredFeature<?, ?>[] {AMETHYST_ORE_OVERWORLD, LEAD_ORE_OVERWORLD};
    NETHER_ORES = new ConfiguredFeature<?, ?>[] {AMETHYST_ORE_NETHER, LEAD_ORE_NETHER};
    END_ORES = new ConfiguredFeature<?, ?>[] {AMETHYST_ORE_END, LEAD_ORE_END};
  }

 

OreFeatureAdditionManager.java


  /**
   * Apply {@value #overworldOres()}, {@value #netherOres} and {@value #endOres} to {@link Biome}s
   * of their various {@link Biome.Category}.
   * 
   * @param event
   */
  @SubscribeEvent(priority = EventPriority.HIGH) //Subbed to FORGE
  public static void registerOres(final BiomeLoadingEvent event) {
    MagiksMostEvile.LOGGER.debug("Adding MME ores to biome: " + event.getName());

    BiomeGenerationSettingsBuilder generation = event.getGeneration();

    switch (event.getCategory()) {
      case NETHER:
        for (ConfiguredFeature<?, ?> simpleConfiguredOreFeature : OreFeatures.NETHER_ORES) {
          registerTo(generation, simpleConfiguredOreFeature);
        }
        break;

      case THEEND:
        for (ConfiguredFeature<?, ?> simpleConfiguredOreFeature : OreFeatures.END_ORES) {
          registerTo(generation, simpleConfiguredOreFeature);
        }
        break;

      default:
        for (ConfiguredFeature<?, ?> simpleConfiguredOreFeature : OreFeatures.OVERWORLD_ORES) {
          registerTo(generation, simpleConfiguredOreFeature);
        }
        break;
    }

  }

  /**
   * Convenience method to tidy up {@link #registerOres(BiomeLoadingEvent)} by abstracting away
   * {@link BiomeGenerationSettingsBuilder} calls.
   * 
   * @param builder
   * @param feature
   */
  private static void registerTo(BiomeGenerationSettingsBuilder builder,
      ConfiguredFeature<?, ?> feature) {
    
    builder.withFeature(GenerationStage.Decoration.UNDERGROUND_ORES, feature);
  }

 

BiomeGenerationSettingsBuilder#withFeature() returns a new Builder with the passed in feature, it doesn't add the feature to the biomes generation. what you want to call is BiomeGenerationSettingsBuilder#getFeatures().add()

you'll pass the generation stage you want your features to be generated in (Decoration.UNDERGROUND_ORES), and you pass a supplier of your feature to the add() method

Link to comment
Share on other sites

On 12/27/2020 at 3:08 AM, kiou.23 said:

BiomeGenerationSettingsBuilder#withFeature() returns a new Builder with the passed in feature, it doesn't add the feature to the biomes generation. what you want to call is BiomeGenerationSettingsBuilder#getFeatures().add()

you'll pass the generation stage you want your features to be generated in (Decoration.UNDERGROUND_ORES), and you pass a supplier of your feature to the add() method

Hmmm... strange. It seems to be working for me right now? By my researching withFeature(feature) both returns the builder, and adds the feature. I'll try changing that and see how that works.

How to ask a good coding question: https://stackoverflow.com/help/how-to-ask

Give logs, code, desired effects, and actual effects. Be thorough or we can't help you. Don't post code without putting it in a code block (the <> button on the post - select "C-type Language"): syntax highlighting makes everything easier, and it keeps the post tidy.

 

My own mod, Magiks Most Evile: GitHub (https://github.com/GenElectrovise/MagiksMostEvile) Wiki (https://magiksmostevile.fandom.com/wiki/Magiks_Most_Evile_Wiki)

Edit your own signature at https://www.minecraftforge.net/forum/settings/signature/

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

Announcements



  • Recently Browsing

    • No registered users viewing this page.
  • Posts

    • Yes... You're right, this mod conflicts with very many other mods causing this error.
    • Hi, the microphone mod is not working on my Mac. It says “launcher does not support MacOS microphone permissions” Thank you in advance for answering.
    • Make sure you have Optifine installed as a mod. Go into Options > Video Settings > Shaders > and then click the shader you want Make sure the shader.zip files are in the shaderpacks folder inside the minecraft folder
    • It sounds like you're probably registering the item in the wrong place, try looking at this tutorial for how to register items:  Forge Modding Tutorial - Minecraft 1.20: Custom Items & Creative Mode Tab | #2 This (free) tutorial series is excellent, by the way, and I'd highly recommend watching through some or all of the videos. There may also be an error in the code I showed above since I was in a hurry, but it should be enough for the general idea. I can't be more specific since I don't know exactly what you plan to do.
    • Realizing I was a victim of a scam was a devastating blow. My initial investment of $89,000, driven by dreams of financial success and the buzz surrounding a new cryptocurrency project, turned into a nightmare. The project promised high returns and rapid gains, attracting many eager investors like myself. However, as time passed and inconsistencies began to surface, it became evident that I had made a grave mistake by not thoroughly vetting the brokerage company handling the investment. Feeling anxious and betrayed, I desperately searched for a way to recover my funds. It was during this frantic search that I stumbled upon the Lee Ultimate Hacker tool through a Facebook post. With little left to lose, I decided to reach out to their team for help. To my relief, they were quick to respond and immediately started recovering my compromised email and regaining access to my cryptocurrency wallets. The team at Lee Ultimate Hacker was incredibly professional and transparent throughout the process. They meticulously traced the digital footprints left by the scammers, employing advanced technological methods to unravel the complex network that had ensnared my funds. Their expertise in cybersecurity and recovery strategies gradually began to turn the tide in my favor. Although the scammers had already siphoned off $30,000 worth of Bitcoin, Lee Ultimate Hacker was relentless in their pursuit. They managed to expose the fraudulent activities of the scam operators, revealing their identities and the mechanisms they used to lure investors. This exposure was crucial not only for my case but also as a warning to the wider community about the perils of unverified investment schemes. As we progressed, it became a race against time to retrieve the remaining $59,000 before the scammers could vanish completely. Each step forward was met with new challenges, as these criminals constantly shifted tactics and moved their digital assets to evade capture. Nonetheless, the determination and skill of the recovery team kept us hopeful. Throughout this ordeal, I learned the hard value of caution and due diligence in investment, especially within the volatile world of cryptocurrency. The experience has been incredibly taxing, both emotionally and financially, but the support and results provided by Lee Ultimate Hacker have been indispensable. The recovery process is ongoing, and while the final outcome remains uncertain, the progress made so far gives me hope. The battle to recover the full amount of my investment continues, and with the expertise of Lee Ultimate Hacker, I remain optimistic about the eventual recovery of my funds. Their commitment to their clients and proficiency in handling such complex cases truly sets them apart in the field of cyber recovery. LEEULTIMATEHACKER@ AOL. COM   Support @ leeultimatehacker . com.  telegram:LEEULTIMATE   wh@tsapp +1  (715) 314  -  9248     
  • Topics

×
×
  • Create New...

Important Information

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