Jump to content

Recommended Posts

Posted
2 minutes ago, diesieben07 said:

If you do not register your configured features you will break any other mods with world generation. 
Register your configured features in FMLCommonSetupEvent#enqueueWork.

Yes I did it.

Posted (edited)

So, going back to what I was saying, this was my solution after so much talk:

 

The Main:

@Mod(ExampleMod.modid)
public class ExampleMod {
    public static final String modid = "examplemod";
    private static final Logger LOGGER = LogManager.getLogger("examplemod");
    public static final CreativeModeTab examplemod = new ExampleTab();

    public ExampleMod() {
        IEventBus modEventbus = FMLJavaModLoadingContext.get().getModEventBus();

        ExampleBlocks.BLOCKS.register(modEventbus);
        ExampleItems.ITEMS.register(modEventbus);

        FMLJavaModLoadingContext.get().getModEventBus().addListener(this::setup);
        FMLJavaModLoadingContext.get().getModEventBus().addListener(this::clientSetup);

        ModLoadingContext.get().registerConfig(Type.COMMON, GWorldConfig.SPEC, "example-common.toml");

        MinecraftForge.EVENT_BUS.register(this);
    }

    private void setup(final FMLCommonSetupEvent event) {
        event.enqueueWork(() -> {
            OreGeneration.registerConfiguredFeatures();
        });
        LOGGER.info("Hello from preinit");
        LOGGER.info("Dirt block >> {}", Blocks.DIRT.getRegistryName());
    }

    @OnlyIn(Dist.CLIENT)
    public void clientSetup(FMLClientSetupEvent event) {
        LOGGER.info("Hello from client setup");
    }

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

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

        @SubscribeEvent
        public static void registerBlocks(final RegistryEvent.Register<Block> event) {
            LOGGER.info("Hello from Register Block");
        }
    }
}

 

 

The Config: 

public class ExampleConfig {
    public static final Builder BUILDER = new Builder();
    public static final ForgeConfigSpec SPEC;
    public static final ConfigValue<Boolean> EXAMPLE_ORE_GENERATION;
    public static final ConfigValue<Integer> EXAMPLE_ORE_SIZE;
    public static final ConfigValue<Integer> EXAMPLE_ORE_MIN_HEIGHT;
    public static final ConfigValue<Integer> EXAMPLE_ORE_MAX_HEIGHT;
    public static final ConfigValue<Integer> EXAMPLE_ORE_CHANCE;

    public ExampleConfig() {
    }

    static {
        BUILDER.push("Example ore generation");
        EXAMPLE_ORE_GENERATION = BUILDER.define("Generate kyptoite ore", true);
        EXAMPLE_ORE_SIZE = BUILDER.define("Example ore vein size", 4);
        EXAMPLE_ORE_MIN_HEIGHT = BUILDER.define("Minimum example ore generation height", 0);
        EXAMPLE_ORE_MAX_HEIGHT = BUILDER.define("Maximum example ore generation height", 16);
        EXAMPLE_ORE_CHANCE = BUILDER.define("Chance of generate example ore", 1);
        BUILDER.pop();
        SPEC = BUILDER.build();
    }
}

 

 

The OreGeneration: 

@EventBusSubscriber
public class OreGeneration {
    public static ImmutableList<TargetBlockState> EXAMPLE_ORE_TARGET_LIST;
    public static ConfiguredFeature<?, ?> EXAMPLE_ORE;

    public OreGeneration() {
    }

    public static void registerConfiguredFeatures() {
        EXAMPLE_ORE_TARGET_LIST = ImmutableList.of(OreConfiguration.target(Predicates.NATURAL_STONE, ((Block) ExampleBlocks.KYPTOITE_ORE.get()).defaultBlockState()), OreConfiguration.target(Predicates.STONE_ORE_REPLACEABLES, ((Block) ExampleBlocks.KYPTOITE_ORE.get()).defaultBlockState()));
        EXAMPLE_ORE = (ConfiguredFeature)((ConfiguredFeature)((ConfiguredFeature) Feature.ORE.configured(new OreConfiguration(EXAMPLE_ORE_TARGET_LIST, (Integer) ExampleConfig.EXAMPLE_ORE_SIZE.get())).rangeUniform(VerticalAnchor.absolute((Integer) ExampleConfig.EXAMPLE_ORE_MIN_HEIGHT.get()), VerticalAnchor.absolute((Integer) ExampleConfig.EXAMPLE_ORE_MAX_HEIGHT.get()))).squared()).count((Integer) ExampleConfig.EXAMPLE_ORE_CHANCE.get());
        Registry.register(BuiltinRegistries.CONFIGURED_FEATURE, new ResourceLocation("examplemod", "example_ore"), EXAMPLE_ORE);
    }

    @SubscribeEvent(priority = EventPriority.HIGH)
    public static void registerBiomeModification(BiomeLoadingEvent event) {
        event.getGeneration().getFeatures(Decoration.UNDERGROUND_ORES).add(() -> {
            return EXAMPLE_ORE;
        });
    }
}

 

 

And this was the solution that I found with the help of Grookey, Luis_ST and diesieben07

Edited by Gianka1485

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



×
×
  • Create New...

Important Information

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