Jump to content

Ores Will Not Spawn In The Nether


Icefox

Recommended Posts

I have been working on an ores mod but I cant seem to figure out how to get ores to generate in the nether. This is my code:

 

package com.ice922.betterores.world;
 
import java.util.Random;

import com.google.common.base.Predicate;
import com.ice922.betterores.init.ModBlocks;

import net.minecraft.block.Block;
import net.minecraft.block.state.IBlockState;
import net.minecraft.block.state.pattern.BlockMatcher;
import net.minecraft.init.Blocks;
import net.minecraft.util.math.BlockPos;
import net.minecraft.world.World;
import net.minecraft.world.chunk.IChunkProvider;
import net.minecraft.world.gen.IChunkGenerator;
import net.minecraft.world.gen.feature.WorldGenMinable;
import net.minecraftforge.fml.common.IWorldGenerator;
 
public class ModNetherGen implements IWorldGenerator 
{
	public class OreGen implements IWorldGenerator {
		
		@Override
		public void generate(Random random, int chunkX, int chunkZ, World world, IChunkGenerator chunkGenerator, IChunkProvider chunkProvider) 
		{
			switch(world.provider.getDimension()) {
			//Nether
			case -1:
				runGenerator(ModBlocks.AMETHYST_ORE_BLOCK.getDefaultState(), 7, 10, 12, 50, BlockMatcher.forBlock(Blocks.NETHERRACK), world, random, chunkX, chunkZ);
			  break;
			//Overworld
			case 0:
			  break;
			//End
			case 1:
			  break;
			//Everything else
			default:
			  break;
			}
		}
		
		private void runGenerator(IBlockState blockToGen, int blockAmount,  int chancesToSpawn, int minHeight, int maxHeight, Predicate<IBlockState> blockToReplace, World world, Random rand, int chunk_X, int chunk_Z) 
		{

		}
	}

	@Override
	public void generate(Random random, int chunkX, int chunkZ, World world, IChunkGenerator chunkGenerator,
			IChunkProvider chunkProvider) {
		
	}
}

 

Please help me figure this out.

Link to comment
Share on other sites

First I would delete the generate() method in ModNetherGen, take everything from inside OreGen and move it into ModNetherGen, then delete OreGen.

 

 

Next, I'd make sure to call 

GameRegistry.registerWorldGenerator(new ModNetherGen(), 0);

In one of the FML init events, such as the FMLPreInitializationEvent, which should already exist in your main mod class.

 

 

At this point, the generator itself should actually *run*, but won't do anything yet.  You can test it if you want by putting a breakpoint or printline inside your runGenerator method, eg.

System.out.println("Generator ran");

 

 

Now all that's left is to make it actually generate something.  If there is a way to make the system do this in a somewhat automated fashion, I don't know it.  I've only done worldgen once so far, and had to literally place each block in my own code.  In other words, your runGenerator function is going to look pretty beefy by the time you're done.  You'll have to program your own logic which uses the arguments you've passed in to conditionally replace existing blocks in the world.

 

I'm not sure I want to show you what I did, because mine is dealing with tile entities, not normal blocks.  That being said, here are some useful bits:

 

To get the current chunk you're generating within:

world.getChunkFromChunkCoords(chunkX, chunkZ)

 

To get the chunk that a specified BlockPos lives in:

world.getChunkFromBlockCoords(blockPos)

 

To get the IBlockState of a block at a specified BlockPos:

world.getBlockState(blockPos)

 

To set the IBlockState of a block at a specified BlockPos:

world.setBlockState(blockPos, iBlockState);

 

Those bits of code should be enough for basic oregen, along with the arguments you have.  If it were me though, I would also change runGenerator() so that it takes an IBlockState instead of a Predicate<IBlockState>, and then pass in Blocks.NETHERRACK instead of BlockMatcher.forBlock(Blocks.NETHERRACK)

Edited by Laike_Endaril
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.

Announcements



×
×
  • Create New...

Important Information

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