Jump to content
View in the app

A better way to browse. Learn more.

Forge Forums

A full-screen app on your home screen with push notifications, badges and more.

To install this app on iOS and iPadOS
  1. Tap the Share icon in Safari
  2. Scroll the menu and tap Add to Home Screen.
  3. Tap Add in the top-right corner.
To install this app on Android
  1. Tap the 3-dot menu (⋮) in the top-right corner of the browser.
  2. Tap Add to Home screen or Install app.
  3. Confirm by tapping Install.

Featured Replies

Posted

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.

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

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...

Important Information

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

Configure browser push notifications

Chrome (Android)
  1. Tap the lock icon next to the address bar.
  2. Tap Permissions → Notifications.
  3. Adjust your preference.
Chrome (Desktop)
  1. Click the padlock icon in the address bar.
  2. Select Site settings.
  3. Find Notifications and adjust your preference.