Jump to content

[1.15.2] Generate Ore in Endstone - And bad code?


Maxi07

Recommended Posts

I am making a mod which adds a few new ores. Some ores generate in the overworld and some in the nether the way I want it.

But now I want to generate ores in the end (replace endstone). What is the easiest and most uncomplicated method to do this?

I am new to forge modding and dont know very much about forge and java.

Thanks for Help!

 

EDIT: The ore now generates in the end! Thanks!

Edited by Maxi07
Link to comment
Share on other sites

Add a configurated feature in the biome (probably an OreFeature if generated in clusters) with your own FillerBlockType created using FillerBlockType#create. If you're generating clusters of one, use ReplaceBlockFeature where you only need to provide a blockstate of the target and new state. Remember to call these methods within a DeferredWorkQueue within your FMLCommonSetupEvent as they are not thread-safe.

  • Like 1
Link to comment
Share on other sites

But now I have another question about this:

What is a DeferredWorkQueue or DefferedRegister? My Mod works without this.

I am using the IForgeRegistry from the item register event to register my items (If I understand my own code right). Here is the code:

package maxi.ores_cores.init;

import maxi.ores_cores.OresCores;
import maxi.ores_cores.items.*;
import net.minecraft.item.Item;
import net.minecraftforge.event.RegistryEvent.Register;
import net.minecraftforge.eventbus.api.SubscribeEvent;
import net.minecraftforge.fml.common.Mod.EventBusSubscriber;
import net.minecraftforge.fml.common.Mod.EventBusSubscriber.Bus;
import net.minecraftforge.registries.IForgeRegistry;

@EventBusSubscriber(modid = OresCores.MODID, bus = Bus.MOD)
public class RegisterItems {
	
	public static final EmoulriteIngotItem EMOULRITE_INGOT = new EmoulriteIngotItem();
	public static final EmoulriteFragmentItem EMOULRITE_FRAGMENT = new EmoulriteFragmentItem();
	public static final TeleriteIngotItem TELERITE_INGOT = new TeleriteIngotItem();

	@SubscribeEvent
	public static void registerItem(Register<Item> event) {
		final IForgeRegistry<Item> registry = event.getRegistry();
		registry.register(EMOULRITE_INGOT.setRegistryName(OresCores.MODID, "emoulrite_ingot"));
		registry.register(EMOULRITE_FRAGMENT.setRegistryName(OresCores.MODID, "emoulrite_fragment"));
		registry.register(TELERITE_INGOT.setRegistryName(OresCores.MODID, "telerite_ingot"));
	}
}

Because I am new my code isnt very good I think. I want to learn much more about java and forge to write better code and create better mods.

And here is the code for the ore gen for my end ore:

package maxi.ores_cores.world.gen;

import maxi.ores_cores.init.RegisterBlocks;
import net.minecraft.block.Blocks;
import net.minecraft.block.pattern.BlockMatcher;
import net.minecraft.world.biome.Biome;
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.ConfiguredPlacement;
import net.minecraft.world.gen.placement.CountRangeConfig;
import net.minecraft.world.gen.placement.Placement;
import net.minecraftforge.registries.ForgeRegistries;

public class TeleriteOreGen {
	
	public static void generateOre() {
		for(Biome biome : ForgeRegistries.BIOMES) {
			ConfiguredPlacement<CountRangeConfig> genPlacementConfig = Placement.COUNT_RANGE.configure(new CountRangeConfig(1, 0, 0, 256));
			biome.addFeature(GenerationStage.Decoration.UNDERGROUND_ORES, Feature.ORE
					.withConfiguration(new OreFeatureConfig(OreFeatureConfig.FillerBlockType.create("END_STONE", "end_stone", new BlockMatcher(Blocks.END_STONE)), RegisterBlocks.TELERITE_ORE.getDefaultState(), 6))
					.withPlacement(genPlacementConfig));
		}
	}

}
package maxi.ores_cores.init;

import maxi.ores_cores.OresCores;
import maxi.ores_cores.world.gen.*;
import net.minecraftforge.eventbus.api.SubscribeEvent;
import net.minecraftforge.fml.common.Mod.EventBusSubscriber;
import net.minecraftforge.fml.common.Mod.EventBusSubscriber.Bus;
import net.minecraftforge.fml.event.lifecycle.FMLLoadCompleteEvent;

@EventBusSubscriber(modid = OresCores.MODID, bus = Bus.MOD)
public class RegisterWorldGen {

	@SubscribeEvent
	public static void registerWorldGen(FMLLoadCompleteEvent event) { //Should I use FMLCommonSetupEvent instead of FMLLoadCompleteEvent?
		EmoulriteOreGen.generateOre();
		TeleriteOreGen.generateOre();
	}
	
}

Is this code bad? It works, but I dont know if this is the best way.

12 hours ago, ChampionAsh5357 said:

Remember to call these methods within a DeferredWorkQueue within your FMLCommonSetupEvent as they are not thread-safe.

 

Link to comment
Share on other sites

Is this right? My IDE marks all as warnings because DeferredWorkQueue is deprecated. Should I just use @SuppressWarnings("deprecation")?

package maxi.ores_cores.init;

import maxi.ores_cores.OresCores;
import maxi.ores_cores.world.gen.*;
import net.minecraftforge.eventbus.api.SubscribeEvent;
import net.minecraftforge.fml.DeferredWorkQueue;
import net.minecraftforge.fml.common.Mod.EventBusSubscriber;
import net.minecraftforge.fml.common.Mod.EventBusSubscriber.Bus;
import net.minecraftforge.fml.event.lifecycle.FMLCommonSetupEvent;

@EventBusSubscriber(modid = OresCores.MODID, bus = Bus.MOD)
public class RegisterWorldGen {

	@SubscribeEvent
	public static void registerWorldGen(FMLCommonSetupEvent event) {
		DeferredWorkQueue.runLater(new Runnable() {
			@Override
			public void run() {
				
				EmoulriteOreGen.generateOre();
				TeleriteOreGen.generateOre();
				
			}
		});
	}
	
}
Link to comment
Share on other sites

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.



×
×
  • Create New...

Important Information

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