Jump to content

Recommended Posts

Posted (edited)

Hi, after my last thread, someone on the Forge Discord server gave me some code to generate ores. However, this code doesn't appear to be generating my block anywhere, and I was wondering if anyone could tell me why.

 

Here is my code:

OreGen class:

package linky132.waywardcraft;

import net.minecraft.block.BlockState;
import net.minecraft.util.registry.Registry;
import net.minecraft.util.registry.WorldGenRegistries;
import net.minecraft.world.gen.GenerationStage;
import net.minecraft.world.gen.feature.ConfiguredFeature;
import net.minecraft.world.gen.feature.Feature;
import net.minecraft.world.gen.feature.OreFeatureConfig;
import net.minecraftforge.event.world.BiomeLoadingEvent;
import net.minecraftforge.eventbus.api.SubscribeEvent;

import java.util.ArrayList;

public class OreGen
{
    public static final ArrayList<ConfiguredFeature<?,?>> ORE_GENERATORS = new ArrayList<>();

    public static void register()
    {
        registerOreGenerator(RegistryHandler.SALT_BLOCK.get().getDefaultState(),16,200,"salt_block");
    }

    public static void registerOreGenerator(BlockState blockState, int patchSize, int maxHeight, String name)
    {
        Registry<ConfiguredFeature<?, ?>> registry = WorldGenRegistries.CONFIGURED_FEATURE;
        ConfiguredFeature<?,?> configuredFeature = Feature.ORE.withConfiguration(new OreFeatureConfig(OreFeatureConfig.FillerBlockType.BASE_STONE_OVERWORLD,blockState,patchSize)).range(maxHeight).square().func_242731_b(157);
        ORE_GENERATORS.add(configuredFeature);
        Registry.register(registry,WaywardCraft.MODID + name,configuredFeature);
    }

    @SubscribeEvent
    public void loadBiomes(BiomeLoadingEvent event)
    {
        for(ConfiguredFeature<?,?> feature : ORE_GENERATORS)
        {
            event.getGeneration().withFeature(GenerationStage.Decoration.UNDERGROUND_ORES,feature);
        }
    }
}

 

Main mod class:

package linky132.waywardcraft;

import net.minecraftforge.common.MinecraftForge;
import net.minecraftforge.fml.common.Mod;
import net.minecraftforge.fml.event.lifecycle.FMLCommonSetupEvent;

@Mod(WaywardCraft.MODID)
public class WaywardCraft
{
    public static final String MODID = "waywardcraft";

    public WaywardCraft()
    {
        MinecraftForge.EVENT_BUS.register(this);

        RegistryHandler.init();

        MinecraftForge.EVENT_BUS.register(new OreGen());
    }
    void commonSetup(FMLCommonSetupEvent event)
    {
        event.enqueueWork(this::afterCommonSetup);
    }
    private void afterCommonSetup()
    {
        OreGen.register();
    }
}

 

Thank you.

Edited by Linky132
Posted (edited)

Thanks for replying. I just checked it by using a print method, and the funny thing is that the "loadBiomes" method is firing, but the contents of the for loop are never executed. Any idea why that could be?

Edited by Linky132
Posted

Huh, that's weird, apparently the list is empty. That doesn't make sense, though, since configuredFeature is being added to it, and looks to be valid. I can also confirm that it's not a problem with my block, as it also doesn't work with vanilla blocks. Any ideas?

Posted

Aha, so that's the problem! the afterCommonSetup method is never called, which is probably due to the commonSetup method not being called either. I assume I did something wrong with the event bus or the listener?

Posted

Okay, so using that information, I tried replacing the forge bus line with

FMLJavaModLoadingContext.get().getModEventBus().register(new OreGen());

but it resulted in an error while loading the mod, basically just saying:

java.lang.IllegalArgumentException: Method public void linky132.waywardcraft.OreGen.loadBiomes(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

 

Posted

You had this in your class constructor:

    public WaywardCraft()
    {
        MinecraftForge.EVENT_BUS.register(this);

        RegistryHandler.init();

        MinecraftForge.EVENT_BUS.register(new OreGen());
    }
    

With the third line you are registering the OreGen class to the Forge bus, this means that loadBiomes will correctly listen to the BiomeLoadingEvent (FORGE bus).

With the first line you are instead registering the main mod class (this) to the Forge bus, so any event handler in the main class will listen only to Forge bus events, but FMLCommonSetupEvent is fired on the MOD bus. So you need to register you main class to the MOD bus, which you can get from:

FMLJavaModLoadingContext.get().getModEventBus();

Instead of subscribing your whole class, you can also add listeners to the Mod bus with:

FMLJavaModLoadingContext.get().getModEventBus().addListener(your_listener_method)

 

  • Thanks 1

Check out the port of the BetterEnd fabric mod (WIP): https://www.curseforge.com/minecraft/mc-mods/betterend-forge-port

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

    • My name is Richie Leo, and I’m sharing this message with a heart full of gratitude and hope. Several months ago, I was a victim of a devastating online scam that cost me a staggering $873,463. I was devastated, confused, and had nearly given up on ever recovering my money — until I came across Wizard George Cyber Service. Through their exceptional cyber recovery expertise and deep investigative skills, Wizard George and his team were able to trace, track, and recover the full amount that was stolen from me. Their professionalism, speed, and transparency truly amazed me. If you’re reading this and you’ve been scammed — whether it’s crypto, investment fraud, or any kind of online theft — don’t give up. I strongly recommend reaching out to Wizard George Cyber Service. 📧 Em: wizardgeorgecyberservice(AT) g m a l L. C o M
    • Alright, here is the log file https://mclo.gs/5eCwafV
    • Please read the FAQ (https://forums.minecraftforge.net/topic/125488-rules-and-frequently-asked-questions-faq/) and post log files as described there, using a site such as https://mclo.gs/ and post the link here.  
    • I tried updating the mods in my modpack which caused incompatibilities so i have tried to revert them back to their older versions i was using before. In the logs it doesnt show me any clear incompatibilities except for tfmg & entity texture features, but when i try to remove those it still doesn't work. I have tried removing the forge-client.toml file which was a suggestion i found on  a few other posts. This is the log file i get. [inline log removed] Any help would be appreciated. Thanks in advance
    • I don't use KubeJS, never even heard of it. But after doing what "Ugdhar" suggested earlier in this post with the "config/Mekanism/generator-storage.toml", I tried going into an individual save's serverconfig folder, and just deleting everything except the parcool folder (I have that mod installed.) Then, a bit of loading and temporary freezing later, seems to have worked. Even when quitting to menu and loading back in, or also when quitting to menu, exiting to desktop, and re-launching MC, choose a save and loading it.
  • Topics

×
×
  • Create New...

Important Information

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