Jump to content

Recommended Posts

Posted (edited)

Hi all,

 

I have been bashing my head against the wall for hours trying to get ore generation working in my mod. I have tried to follow a few tutorials with little success.

Forge: 39.0.5


ForgeBusSubscriber:

Spoiler
package com.tcn.cosmosportals.core.management;

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

import com.tcn.cosmosportals.CosmosPortals;

import net.minecraft.data.worldgen.features.FeatureUtils;
import net.minecraft.data.worldgen.features.OreFeatures;
import net.minecraft.data.worldgen.placement.PlacementUtils;
import net.minecraft.world.level.levelgen.GenerationStep.Decoration;
import net.minecraft.world.level.levelgen.VerticalAnchor;
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.placement.BiomeFilter;
import net.minecraft.world.level.levelgen.placement.CountPlacement;
import net.minecraft.world.level.levelgen.placement.HeightRangePlacement;
import net.minecraft.world.level.levelgen.placement.InSquarePlacement;
import net.minecraft.world.level.levelgen.placement.PlacedFeature;
import net.minecraft.world.level.levelgen.placement.PlacementModifier;
import net.minecraftforge.event.world.BiomeLoadingEvent;
import net.minecraftforge.eventbus.api.EventPriority;
import net.minecraftforge.eventbus.api.SubscribeEvent;
import net.minecraftforge.fml.common.Mod;
import net.minecraftforge.fml.common.Mod.EventBusSubscriber;

@SuppressWarnings("unused")
@Mod.EventBusSubscriber(modid = CosmosPortals.MOD_ID, bus = EventBusSubscriber.Bus.FORGE)
public class EventManager {

	private static final List<PlacedFeature> overworldOres = new ArrayList<>();

    @SubscribeEvent(priority = EventPriority.HIGHEST)
	public static void onBiomeLoadingEvent(final BiomeLoadingEvent event) {
		final List<Supplier<PlacedFeature>> features = event.getGeneration().getFeatures(Decoration.UNDERGROUND_ORES);
		
		switch (event.getCategory()) {
			default -> {
				overworldOres.forEach((ore) -> features.add(() -> ore));
				CosmosPortals.CONSOLE.info("<biomeloadingevent> Ore Registration complete. { " + features.get(features.size() - 1).get().getFeatures().findFirst().get().toString() + " }");
			}
		}
	}

	public static void registerOresForGeneration() {
		final ConfiguredFeature<?, ?> cosmicOre = FeatureUtils.register("cosmic_ore", 
			Feature.ORE.configured(new OreConfiguration(List.of( 
				OreConfiguration.target(OreFeatures.STONE_ORE_REPLACEABLES, ModBusManager.COSMIC_ORE.defaultBlockState())
			),
		8)));
		
		final PlacedFeature placedCosmicOre = PlacementUtils.register("cosmic_ore", 
			cosmicOre.placed(HeightRangePlacement.uniform(VerticalAnchor.bottom(), VerticalAnchor.aboveBottom(64)), InSquarePlacement.spread(), CountPlacement.of(100))
		);
		
		overworldOres.add(placedCosmicOre);
		
		CosmosPortals.CONSOLE.info("Ores Registred for placement: " + overworldOres.get(0).getFeatures().findFirst().get().toString());
	}
}

 

Mod Class:

 

 

Spoiler
package com.tcn.cosmosportals;

import com.tcn.cosmoslibrary.common.runtime.CosmosConsoleManager;
import com.tcn.cosmosportals.core.management.ConfigurationManager;
import com.tcn.cosmosportals.core.management.EventManager;
import com.tcn.cosmosportals.core.management.ModBusManager;
import com.tcn.cosmosportals.core.management.NetworkManager;

import net.minecraftforge.common.MinecraftForge;
import net.minecraftforge.fml.ModLoadingContext;
import net.minecraftforge.fml.common.Mod;
import net.minecraftforge.fml.config.ModConfig;
import net.minecraftforge.fml.event.lifecycle.FMLClientSetupEvent;
import net.minecraftforge.fml.event.lifecycle.FMLCommonSetupEvent;
import net.minecraftforge.fml.javafmlmod.FMLJavaModLoadingContext;

@Mod(CosmosPortals.MOD_ID)
public class CosmosPortals {
	
	//This must NEVER EVER CHANGE!
	public static final String MOD_ID = "cosmosportals";

	public static final CosmosConsoleManager CONSOLE = new CosmosConsoleManager(CosmosPortals.MOD_ID, ConfigurationManager.getInstance().getDebugMessage(), ConfigurationManager.getInstance().getInfoMessage());

	public CosmosPortals() {
		FMLJavaModLoadingContext.get().getModEventBus().addListener(this::onFMLCommonSetup);
		FMLJavaModLoadingContext.get().getModEventBus().addListener(this::onFMLClientSetup);
		MinecraftForge.EVENT_BUS.register(this);
		
		ModLoadingContext.get().registerConfig(ModConfig.Type.COMMON, ConfigurationManager.spec, "cosmos-portals-common.toml");
	}

	public void onFMLCommonSetup(final FMLCommonSetupEvent event) {
		event.enqueueWork(() -> {
			EventManager.registerOresForGeneration();
			
			NetworkManager.register();
		});
		
		CONSOLE.startup("CosmosPortals Common Setup complete.");
	}

	public void onFMLClientSetup(final FMLClientSetupEvent event) {
		final ModLoadingContext context = ModLoadingContext.get();
		
		ModBusManager.registerClient(context);
		ModBusManager.onFMLClientSetup(event);
		
		CONSOLE.startup("CosmosPortals Client Setup complete.");
	}
}

I have had no luck in getting anything to spawn, despite checking that the biomeloading events features do contain my placed feature.

 

Any help as always is appreciated.

Edited by Zeher_Monkey
  • Zeher_Monkey changed the title to [1.18.1] Ore Generation troubles [SOLVED]
  • 2 months later...

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.