Jump to content

[1.15.2] I'm trying to generate my custom ore but it isn't work.


Recommended Posts

Posted

I've looked at the DefaultBiomeFeatures class of the vanilla code and created this class in the mod folder in the world.gen packages:

package com.SkySibe.testmod.world.gen;

import com.SkySibe.testmod.init.BlockInit;

import net.minecraft.block.BlockState;
import net.minecraft.world.biome.Biome;
import net.minecraft.world.biome.Biomes;
import net.minecraft.world.biome.DefaultBiomeFeatures;
import net.minecraft.world.gen.GenerationStage;
import net.minecraft.world.gen.feature.Feature;
import net.minecraft.world.gen.feature.OreFeatureConfig;
import net.minecraft.world.gen.placement.CountRangeConfig;
import net.minecraft.world.gen.placement.Placement;
import net.minecraftforge.registries.ForgeRegistries;

public class genOre extends DefaultBiomeFeatures{
	private static final BlockState RUBY_ORE = BlockInit.ruby_ore.getDefaultState();
	public static void addRubyOre() {
		for (Biome biomeIn : ForgeRegistries.BIOMES) {
			if (biomeIn == Biomes.DARK_FOREST || biomeIn == Biomes.DARK_FOREST_HILLS) {
				biomeIn.addFeature(GenerationStage.Decoration.UNDERGROUND_ORES, Feature.ORE.withConfiguration(new OreFeatureConfig(OreFeatureConfig.FillerBlockType.NATURAL_STONE, RUBY_ORE, 12)).withPlacement(Placement.COUNT_RANGE.configure(new CountRangeConfig(0, 3, 9, 40))));
			} else {
				biomeIn.addFeature(GenerationStage.Decoration.UNDERGROUND_ORES, Feature.ORE.withConfiguration(new OreFeatureConfig(OreFeatureConfig.FillerBlockType.NATURAL_STONE, RUBY_ORE, 9)).withPlacement(Placement.COUNT_RANGE.configure(new CountRangeConfig(0, 1, 6, 40))));
			}
		}
	}
}

In the mod folder in the main mod class I've created the function 'loadCompleteEvent':

package com.SkySibe.testmod;


import org.apache.logging.log4j.LogManager;
import org.apache.logging.log4j.Logger;

import com.SkySibe.testmod.world.gen.genOre;

import net.minecraftforge.common.MinecraftForge;
import net.minecraftforge.eventbus.api.SubscribeEvent;
import net.minecraftforge.fml.common.Mod;
import net.minecraftforge.fml.event.lifecycle.FMLClientSetupEvent;
import net.minecraftforge.fml.event.lifecycle.FMLCommonSetupEvent;
import net.minecraftforge.fml.event.lifecycle.FMLLoadCompleteEvent;
import net.minecraftforge.fml.javafmlmod.FMLJavaModLoadingContext;

// The value here should match an entry in the META-INF/mods.toml file
@Mod("testmod")
public class TestMod
{
    // Directly reference a log4j logger.
    private static final Logger LOGGER = LogManager.getLogger();
    public static final String MOD_ID = "testmod";
    public static TestMod instance;
    
    public TestMod() {
        // Register the setup method for modloading
        FMLJavaModLoadingContext.get().getModEventBus().addListener(this::setup);
        // Register the doClientStuff method for modloading
        FMLJavaModLoadingContext.get().getModEventBus().addListener(this::doClientStuff);
        
        instance = this;
        
        // Register ourselves for server and other game events we are interested in
        MinecraftForge.EVENT_BUS.register(this);
    }

    private void setup(final FMLCommonSetupEvent event)
    {
    	
    }

    private void doClientStuff(final FMLClientSetupEvent event) {
    	
    }
    
    @SubscribeEvent
    public static void loadCompleteEvent() {
    	genOre.addRubyOre();
    }
}

I would like some help I'm pretty new to this although I've some experience with Java. 

btw I need help with adding xp to the ore mining, if you can tell me where do I find the vanilla class that doing it and how to modify it, it will help a lot.

Thank.

Posted (edited)

You are overthinking it.

You don't need to extend DefaultBiomeFeatures, just find one of the method calls in there that is adding ores, such as this from the addOres method:

      biomeIn.addFeature(GenerationStage.Decoration.UNDERGROUND_ORES, Feature.ORE.withConfiguration(new OreFeatureConfig(OreFeatureConfig.FillerBlockType.NATURAL_STONE, IRON_ORE, 9)).withPlacement(Placement.COUNT_RANGE.configure(new CountRangeConfig(20, 0, 0, 64))));

 

And then use a similar call to the Biome#addFeature method from your FMLCommonSetupEvent, using DeferredWorkQueue using your custom ore.

 

*edit: also, that event you have setup will never fire, there's no method signature to indicate what event it is subscribed to

Edited by Ugdhar
Posted
Just now, diesieben07 said:

You need to also use DeferredWorkQueue, because addFeature is not threadsafe.

Haha oops, I meant that instead of DeferredRegister, thanks, fixing it!

Posted (edited)

What should I need to do? I didn't understand...

do I need to delete this function?:

    @SubscribeEvent
    public static void loadCompleteEvent() {
        genOre.addRubyOre();
    }

and insteand in this what should I call and how?

    private void setup(final FMLCommonSetupEvent event)
    {
        
    }

and what should I change here except unusing extents?

and how do I use DeferredWorkQueue insteand of addFeature??

 

public class genOre{
    private static final BlockState RUBY_ORE = BlockInit.ruby_ore.getDefaultState();
    public static void addRubyOre() {
        for (Biome biomeIn : ForgeRegistries.BIOMES) {
            if (biomeIn == Biomes.DARK_FOREST || biomeIn == Biomes.DARK_FOREST_HILLS) {
                biomeIn.addFeature(GenerationStage.Decoration.UNDERGROUND_ORES, Feature.ORE.withConfiguration(new OreFeatureConfig(OreFeatureConfig.FillerBlockType.NATURAL_STONE, RUBY_ORE, 12)).withPlacement(Placement.COUNT_RANGE.configure(new CountRangeConfig(0, 3, 9, 40))));
            } else {
                biomeIn.addFeature(GenerationStage.Decoration.UNDERGROUND_ORES, Feature.ORE.withConfiguration(new OreFeatureConfig(OreFeatureConfig.FillerBlockType.NATURAL_STONE, RUBY_ORE, 9)).withPlacement(Placement.COUNT_RANGE.configure(new CountRangeConfig(0, 1, 6, 40))));
            }
        }
    }
}

 

Edited by SkySibe
Posted
3 hours ago, diesieben07 said:

You need to also use DeferredWorkQueue, because addFeature is not threadsafe.

 

3 hours ago, Ugdhar said:

Haha oops, I meant that instead of DeferredRegister, thanks, fixing it!

How do I do those?

Posted

Search these forums with the search bar at the top for  DeferredWorkQueue and you will find an example in one of the results I am sure.

I haven't looked, but there might also be documentation in the source for it as well.

Posted (edited)
3 hours ago, Ugdhar said:

Search these forums with the search bar at the top for  DeferredWorkQueue and you will find an example in one of the results I am sure.

I haven't looked, but there might also be documentation in the source for it as well.

I didn't find any and didn't manage it to work, I'll appreciate your help thanks by far.

Edited by SkySibe
Posted

Use DeferredWorkQueue.runLater(Runnable), DeferredWorkQueue is in the net.minecraftforge.fml package and is documented. There was an example of someone using it within the first page of search results.

 

If something doesn't work, you need to post updated code (preferably just have a github repo for the project) and updated logs, and be more descriptive than "it didn't work". When all the details are present, a solution usually presents itself :)

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.