Jump to content

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


Recommended Posts

Posted

I have already registered the ore and it's in the game, I just want to know how I get the ore to generate like coal, iron, gold, and diamonds.

  • Like 1
Posted
  On 11/26/2020 at 10:28 PM, 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).

Expand  

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
Posted
  On 11/27/2020 at 3:54 PM, 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

Expand  

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. 

  On 11/27/2020 at 3:54 PM, 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?

Expand  

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

Posted
  On 11/27/2020 at 6:05 PM, 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.

Expand  

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)

 

Posted
  On 11/27/2020 at 7:08 PM, 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) );

Expand  

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.

  On 11/27/2020 at 7:08 PM, 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)

Expand  

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. 

Posted (edited)
  On 11/28/2020 at 6:13 AM, 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.

Expand  

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
Posted

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

Posted

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

Posted
  On 11/28/2020 at 2:31 PM, 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?

Expand  

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.

Posted (edited)
  On 11/28/2020 at 4:45 PM, 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.

Expand  

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
Posted
  On 11/28/2020 at 5:17 PM, 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

Expand  

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

Posted
  On 11/28/2020 at 5:03 PM, 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?

Expand  

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

Posted
  On 11/28/2020 at 8:56 PM, ChampionAsh5357 said:

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

Expand  

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());
        }
    };
}

 

Posted
  On 11/28/2020 at 10:07 PM, ChampionAsh5357 said:

Initialize the variable within the method event.

Expand  

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);
        
    }
}

 

Posted

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.

Posted
  On 11/28/2020 at 10:24 PM, 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.

Expand  

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

Posted
  On 11/28/2020 at 10:40 PM, 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.

Expand  

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

Posted
  On 11/28/2020 at 10:58 PM, kiou.23 said:

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

Expand  

Yes, the method should be static though.

  On 11/28/2020 at 10:58 PM, kiou.23 said:

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

Expand  

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

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

    • You are using Create 6 - some addons are not compatible with it Remove all addons and add these one by one littlecontraptions is mentioned - keep this one removed
    • Different problem now. https://paste.ee/p/iDo8lS35
    • I would like to have a BoP sapling drop from my block if it is also installed. I think I have done everything and I cannot pinpoint the problem, which is the error in the logs that appears when joining a world:   [Worker-Main-11/ERROR] [ne.mi.co.ForgeHooks/]: Couldn't parse element loot_tables:grasses:blocks/leaves_block com.google.gson.JsonSyntaxException: Expected name to be an item, was unknown string 'biomesoplenty:magic_sapling' My code:   LootItemConditions.CONDITIONS.register(modEventBus); public class LootItemConditions { public static final DeferredRegister<LootItemConditionType> CONDITIONS = DeferredRegister.create(Registries.LOOT_CONDITION_TYPE, Grasses.MOD_ID); public static final RegistryObject<LootItemConditionType> IS_MOD_LOADED = CONDITIONS.register("is_mod_loaded", () -> new LootItemConditionType(new IsModLoaded.ConditionSerializer())); } public class IsModLoaded implements LootItemCondition { private final boolean exists; private final String modID; public IsModLoaded(String modID) { this.exists = ModList.get().isLoaded(modID); this.modID = modID; } @Override public LootItemConditionType getType() { return LootItemConditions.IS_MOD_LOADED.get(); } @Override public boolean test(LootContext context) { return this.exists; } public static LootItemCondition.Builder builder(String modid) { return () -> new IsModLoaded(modid); } public static class ConditionSerializer implements Serializer<IsModLoaded> { @Override public void serialize(JsonObject json, IsModLoaded instance, JsonSerializationContext ctx) { json.addProperty("modid", instance.modID); } @Override public IsModLoaded deserialize(JsonObject json, JsonDeserializationContext ctx) { return new IsModLoaded(GsonHelper.getAsString(json, "modid")); } } } protected LootTable.Builder createLeavesDropsWithModIDCheck(Block selfBlock, Item sapling, Property<?>[] properties, String modIDToCheck, float... chances) { CopyBlockState.Builder blockStateCopyBuilder = CopyBlockState.copyState(selfBlock); for(Property<?> property : properties) { blockStateCopyBuilder.copy(property); } return LootTable.lootTable() .withPool(LootPool.lootPool().setRolls(ConstantValue.exactly(1.0F)) .add(LootItem.lootTableItem(selfBlock) .when(HAS_SHEARS_OR_SILK_TOUCH) .apply(blockStateCopyBuilder))) .withPool(LootPool.lootPool().setRolls(ConstantValue.exactly(1.0F)) .add(this.applyExplosionCondition(selfBlock, LootItem.lootTableItem(sapling)) .when(IsModLoaded.builder(modIDToCheck))) .when(BonusLevelTableCondition.bonusLevelFlatChance(Enchantments.BLOCK_FORTUNE, chances)) .when(HAS_NO_SHEARS_OR_SILK_TOUCH)) .withPool(LootPool.lootPool().name("sticks").setRolls(ConstantValue.exactly(1.0F)) .add(this.applyExplosionDecay(selfBlock, LootItem.lootTableItem(Items.STICK). apply(SetItemCountFunction.setCount(UniformGenerator.between(1.0F, 2.0F)))) .when(BonusLevelTableCondition.bonusLevelFlatChance(Enchantments.BLOCK_FORTUNE, NORMAL_LEAVES_STICK_CHANCES)) .when(HAS_NO_SHEARS_OR_SILK_TOUCH))); } I don't know. Am I making a mistake somewhere? Am I forgetting something? Should there be something else?
  • Topics

×
×
  • Create New...

Important Information

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