Jump to content

Recommended Posts

Posted

I'm making a mod that adds various ores and materials to the game. Some of (not all) of the materials are failing to generate, and I can't figure it out for the life of me. It's been two days of trying to figure it out myself, but nothing's worked so I came here.

 

The Configured Features class (the ores that work are the following - Tin, Deepslate Tin, Crimson Shroomite, and Chorite):

package com.teineone.new_world.world.feature;

import com.google.common.base.Suppliers;
import com.teineone.new_world.NewWorld;
import com.teineone.new_world.block.ModBlocks;
import net.minecraft.core.Registry;
import net.minecraft.data.worldgen.features.OreFeatures;
import net.minecraft.world.level.block.Blocks;
import net.minecraft.world.level.levelgen.feature.ConfiguredFeature;
import net.minecraft.world.level.levelgen.feature.Feature;
import net.minecraft.world.level.levelgen.feature.configurations.OreConfiguration;
import net.minecraft.world.level.levelgen.structure.templatesystem.BlockMatchTest;
import net.minecraftforge.eventbus.api.IEventBus;
import net.minecraftforge.registries.DeferredRegister;
import net.minecraftforge.registries.RegistryObject;

import java.util.List;
import java.util.function.Supplier;

public class ModConfiguredFeatures {
    public static final DeferredRegister<ConfiguredFeature<?, ?>> CONFIGURED_FEATURES =
            DeferredRegister.create(Registry.CONFIGURED_FEATURE_REGISTRY, NewWorld.MOD_ID);

    public static final Supplier<List<OreConfiguration.TargetBlockState>> OVERWORLD_ORES = Suppliers.memoize(() -> List.of(
            OreConfiguration.target(OreFeatures.STONE_ORE_REPLACEABLES, ModBlocks.TIN_ORE.get().defaultBlockState()),
            OreConfiguration.target(OreFeatures.DEEPSLATE_ORE_REPLACEABLES, ModBlocks.DEEPSLATE_TIN_ORE.get().defaultBlockState()),
            OreConfiguration.target(OreFeatures.DEEPSLATE_ORE_REPLACEABLES, ModBlocks.MITHRIL_ORE.get().defaultBlockState())));
    public static final Supplier<List<OreConfiguration.TargetBlockState>> NETHER_ORES = Suppliers.memoize(() -> List.of(
            OreConfiguration.target(OreFeatures.NETHER_ORE_REPLACEABLES, ModBlocks.CRIMSON_SHROOMITE_ORE.get().defaultBlockState()),
            OreConfiguration.target(OreFeatures.NETHER_ORE_REPLACEABLES, ModBlocks.WARPED_SHROOMITE_ORE.get().defaultBlockState()),
            OreConfiguration.target(OreFeatures.NETHER_ORE_REPLACEABLES, ModBlocks.TITANIUM_ORE.get().defaultBlockState())));
    public static final Supplier<List<OreConfiguration.TargetBlockState>> END_ORES = Suppliers.memoize(() -> List.of(
            OreConfiguration.target(new BlockMatchTest(Blocks.END_STONE), ModBlocks.CHORITE_ORE.get().defaultBlockState()),
            OreConfiguration.target(new BlockMatchTest(Blocks.END_STONE), ModBlocks.TUNGSTEN_ORE.get().defaultBlockState()),
            OreConfiguration.target(new BlockMatchTest(Blocks.END_STONE), ModBlocks.ADAMANTINE_ORE.get().defaultBlockState())));

    public static final RegistryObject<ConfiguredFeature<?, ?>> TIN_ORE = CONFIGURED_FEATURES.register("tin_ore",
            () -> new ConfiguredFeature<>(Feature.ORE, new OreConfiguration(OVERWORLD_ORES.get(), 7)));
    public static final RegistryObject<ConfiguredFeature<?, ?>> DEEPSLATE_TIN_ORE = CONFIGURED_FEATURES.register("deepslate_tin_ore",
            () -> new ConfiguredFeature<>(Feature.ORE, new OreConfiguration(OVERWORLD_ORES.get(), 7)));
    public static final RegistryObject<ConfiguredFeature<?, ?>> MITHRIL_ORE = CONFIGURED_FEATURES.register("mithril_ore",
            () -> new ConfiguredFeature<>(Feature.ORE, new OreConfiguration(OVERWORLD_ORES.get(), 7)));
    public static final RegistryObject<ConfiguredFeature<?, ?>> CRIMSON_SHROOMITE_ORE = CONFIGURED_FEATURES.register("crimson_shroomite_ore",
            () -> new ConfiguredFeature<>(Feature.ORE, new OreConfiguration(NETHER_ORES.get(), 9)));
    public static final RegistryObject<ConfiguredFeature<?, ?>> WARPED_SHROOMITE_ORE = CONFIGURED_FEATURES.register("warped_shroomite_ore",
            () -> new ConfiguredFeature<>(Feature.ORE, new OreConfiguration(NETHER_ORES.get(), 9)));
    public static final RegistryObject<ConfiguredFeature<?, ?>> TITANIUM_ORE = CONFIGURED_FEATURES.register("titanium_ore",
            () -> new ConfiguredFeature<>(Feature.ORE, new OreConfiguration(NETHER_ORES.get(), 7)));
    public static final RegistryObject<ConfiguredFeature<?, ?>> CHORITE_ORE = CONFIGURED_FEATURES.register("chorite_ore",
            () -> new ConfiguredFeature<>(Feature.ORE, new OreConfiguration(END_ORES.get(), 9)));
    public static final RegistryObject<ConfiguredFeature<?, ?>> TUNGSTEN_ORE = CONFIGURED_FEATURES.register("tungsten_ore",
            () -> new ConfiguredFeature<>(Feature.ORE, new OreConfiguration(END_ORES.get(), 7)));
    public static final RegistryObject<ConfiguredFeature<?, ?>> ADAMANTINE_ORE = CONFIGURED_FEATURES.register("adamantine_ore",
            () -> new ConfiguredFeature<>(Feature.ORE, new OreConfiguration(END_ORES.get(), 7)));

    public static void register(IEventBus eventBus) {
        CONFIGURED_FEATURES.register(eventBus);
    }
}

The placed features class (again, functioning ores are mentioned above):

package com.teineone.new_world.world.feature;

import com.teineone.new_world.NewWorld;
import net.minecraft.core.Registry;
import net.minecraft.world.level.levelgen.VerticalAnchor;
import net.minecraft.world.level.levelgen.placement.*;
import net.minecraftforge.eventbus.api.IEventBus;
import net.minecraftforge.fml.common.Mod;
import net.minecraftforge.registries.DeferredRegister;
import net.minecraftforge.registries.RegistryObject;

import java.util.List;

public class ModPlacedFeatures {
    public static final DeferredRegister<PlacedFeature> PLACED_FEATURES =
            DeferredRegister.create(Registry.PLACED_FEATURE_REGISTRY, NewWorld.MOD_ID);


    public static final RegistryObject<PlacedFeature> TIN_ORE_PLACED = PLACED_FEATURES.register("tin_ore_placed",
            () -> new PlacedFeature(ModConfiguredFeatures.TIN_ORE.getHolder().get(), commonOrePlacement(18,
                            HeightRangePlacement.triangle(VerticalAnchor.absolute(-0), VerticalAnchor.absolute(128)))));
    public static final RegistryObject<PlacedFeature> DEEPSLATE_TIN_ORE_PLACED = PLACED_FEATURES.register("deepslate_tin_ore_placed",
            () -> new PlacedFeature(ModConfiguredFeatures.DEEPSLATE_TIN_ORE.getHolder().get(), commonOrePlacement(12,
                    HeightRangePlacement.triangle(VerticalAnchor.absolute(-64), VerticalAnchor.absolute(0)))));
    public static final RegistryObject<PlacedFeature> MITHRIL_ORE_PLACED = PLACED_FEATURES.register("mithril_ore_placed",
            () -> new PlacedFeature(ModConfiguredFeatures.MITHRIL_ORE.getHolder().get(), commonOrePlacement(12,
                    HeightRangePlacement.triangle(VerticalAnchor.absolute(-64), VerticalAnchor.absolute(0)))));

    public static final RegistryObject<PlacedFeature> CRIMSON_SHROOMITE_ORE_PLACED = PLACED_FEATURES.register("crimson_shroomite_ore_placed",
            () -> new PlacedFeature(ModConfiguredFeatures.CRIMSON_SHROOMITE_ORE.getHolder().get(), commonOrePlacement(12,
                    HeightRangePlacement.triangle(VerticalAnchor.absolute(0), VerticalAnchor.absolute(128)))));
    public static final RegistryObject<PlacedFeature> WARPED_SHROOMITE_ORE_PLACED = PLACED_FEATURES.register("warped_shroomite_ore_placed",
            () -> new PlacedFeature(ModConfiguredFeatures.WARPED_SHROOMITE_ORE.getHolder().get(), commonOrePlacement(12,
                    HeightRangePlacement.triangle(VerticalAnchor.absolute(0), VerticalAnchor.absolute(128)))));
    public static final RegistryObject<PlacedFeature> TITANIUM_ORE_PLACED = PLACED_FEATURES.register("titanium_ore_placed",
            () -> new PlacedFeature(ModConfiguredFeatures.TITANIUM_ORE.getHolder().get(), commonOrePlacement(7,
                    HeightRangePlacement.triangle(VerticalAnchor.absolute(0), VerticalAnchor.absolute(128)))));

    public static final RegistryObject<PlacedFeature> CHORITE_ORE_PLACED = PLACED_FEATURES.register("chorite_ore_placed",
            () -> new PlacedFeature(ModConfiguredFeatures.CHORITE_ORE.getHolder().get(), commonOrePlacement(7,
                    HeightRangePlacement.triangle(VerticalAnchor.absolute(0), VerticalAnchor.absolute(128)))));
    public static final RegistryObject<PlacedFeature> TUNGSTEN_ORE_PLACED = PLACED_FEATURES.register("tungsten_ore_placed",
            () -> new PlacedFeature(ModConfiguredFeatures.TUNGSTEN_ORE.getHolder().get(), commonOrePlacement(7,
                    HeightRangePlacement.triangle(VerticalAnchor.absolute(0), VerticalAnchor.absolute(128)))));
    public static final RegistryObject<PlacedFeature> ADAMANTINE_ORE_PLACED = PLACED_FEATURES.register("adamantine_ore_placed",
            () -> new PlacedFeature(ModConfiguredFeatures.ADAMANTINE_ORE.getHolder().get(), commonOrePlacement(7,
                    HeightRangePlacement.triangle(VerticalAnchor.absolute(0), VerticalAnchor.absolute(128)))));


    public static List<PlacementModifier> orePlacement(PlacementModifier p_195347_, PlacementModifier p_195348_) {
        return List.of(p_195347_, InSquarePlacement.spread(), p_195348_, BiomeFilter.biome());
    }
    public static List<PlacementModifier> commonOrePlacement(int p_195344_, PlacementModifier p_195345_) {
        return orePlacement(CountPlacement.of(p_195344_), p_195345_);
    }
    public static List<PlacementModifier> rareOrePlacement(int p_195350_, PlacementModifier p_195351_) {
        return orePlacement(RarityFilter.onAverageOnceEvery(p_195350_), p_195351_);
    }


    public static void register(IEventBus eventBus) {
        PLACED_FEATURES.register(eventBus);
    }
}

All of the .json files for ore generation function, as they're literal copies of each other and the game generates worlds without coming up with a "datapacks invalid" error. Ore counts are greatly exaggerated as a response to them not generating, me being me, I just thought they were too rare. Nope.

Side note: It may have something to do with the supplier creation in ConfiguredFeatures? I've tried a bunch of stuff on it and nothing's worked, but I've noticed that the ores that don't generate are lower down in the declarations.

Any and all help is appreciated, and thank you ahead of time.

Posted
Quote

public static final Supplier<List<OreConfiguration.TargetBlockState>> OVERWORLD_ORES = Suppliers.memoize(() -> List.of(

  OreConfiguration.target(OreFeatures.STONE_ORE_REPLACEABLES, ModBlocks.TIN_ORE.get().defaultBlockState()),

  OreConfiguration.target(OreFeatures.DEEPSLATE_ORE_REPLACEABLES, ModBlocks.DEEPSLATE_TIN_ORE.get().defaultBlockState()),

  OreConfiguration.target(OreFeatures.DEEPSLATE_ORE_REPLACEABLES, ModBlocks.MITHRIL_ORE.get().defaultBlockState())));

This will always replace deepslate blocks with deepslate tin. It is the first test to match those blocks.

Since mithril has exactly the same conditions there is no case where it could be used.

 

Similary, for the NETHER and END ores only the first could ever be used.

 

If you really do want to mix these ores together in the same "veins", you will need to write your own Feature whose ConfiguredFeature uses a WeightedRandomList or similar mechanic.

Otherwise each ConfiguredFeature will need its own List of TargetBlockStates.

 

By the way, don't just post code snippets in the forums.

Post all your code on github that is relevant to reproduce the issue (sometimes we have to run/debug the code for ourselves to see issues that are not obvious from just reading the code).

Boilerplate:

If you don't post your logs/debug.log we can't help you. For curseforge you need to enable the forge debug.log in its minecraft settings. You should also post your crash report if you have one.

If there is no error in the log file and you don't have a crash report then post the launcher_log.txt from the minecraft folder. Again for curseforge this will be in your curseforge/minecraft/Install

Large files should be posted to a file sharing site like https://gist.github.com  You should also read the support forum sticky post.

Posted (edited)

Alright, thank you. I thought it had something to do with the order of how they were written, but wasn't sure.
I'll avoid posting code snippets on the forum from now on.

Edited by TeineOne

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.