Jump to content

Recommended Posts

Posted

I have successfully turned off Minecraft's vanilla generation and successfully implemented my own. The problem is I say I only want one very large vein of each ore in about 1/100 chunks, but fail. It appears to successfully generate the very large veins of ore, but I don't get them far apart. I tried using code similar to Minecraft's slime chunk code to keep it seed specific and not have it happen in every chunk, but it happens many more times then the 1/100 chances I give it. Most of the time I will get these rich ore chunks on the spawn chunk, and despite me trying to restrict it so it only gets one ore a chunk, I still get several ores in the same chunk. What am I doing wrong?

package realisticOreGeneration.world;

import java.util.Random;
import net.minecraft.init.Blocks;
import net.minecraft.util.math.BlockPos;
import net.minecraft.world.World;
import net.minecraft.world.chunk.IChunkGenerator;
import net.minecraft.world.chunk.IChunkProvider;
import net.minecraft.world.gen.feature.WorldGenMinable;
import net.minecraft.world.gen.feature.WorldGenerator;
import net.minecraftforge.fml.common.IWorldGenerator;


public class oreWorldGen implements IWorldGenerator {

	private WorldGenerator gen_iron;
	private WorldGenerator gen_coal;
	private WorldGenerator gen_gold;
	private WorldGenerator gen_diamond;
	private WorldGenerator gen_redstone;
	private WorldGenerator gen_lapis;
	
	private static final int perOreGen = 99;
	
	@Override
	public void generate(Random random, int chunkX, int chunkZ, World world, IChunkGenerator chunkGenerator, IChunkProvider chunkprovider){
		long seed = world.getSeed();
		
		Random randForOres = new Random(seed +
	            (long) (chunkX * chunkX * 0x4c1906) +
	            (long) (chunkX * 0x5ac0db) + 
	            (long) (chunkZ * chunkZ) * 0x4307a7L +
	            (long) (chunkZ * 0x5f24f) ^ 0x3ad8025f);
		
		switch (world.provider.getDimension()){
		case 0: //Overworld
			
			int numForOres = randForOres.nextInt(perOreGen);
			if (numForOres == 0){
				this.runGenerator(this.gen_iron, world, random, chunkX, chunkZ, 1, 1, 50);
			}
			if (numForOres == 1){
				this.runGenerator(this.gen_coal, world, random, chunkX, chunkZ, 1, 1, 64);
			}
			if (numForOres == 2){
				this.runGenerator(this.gen_gold, world, random, chunkX, chunkZ, 1, 1, 34);
			}
			if (numForOres == 3){
				this.runGenerator(this.gen_diamond, world, random, chunkX, chunkZ, 1, 1, 16);
			}
			if (numForOres == 4){
				this.runGenerator(this.gen_redstone, world, random, chunkX, chunkZ, 1, 1, 16);
			}
			if (numForOres == 5){
				this.runGenerator(this.gen_lapis, world, random, chunkX, chunkZ, 1, 1, 34);
			}
			
			break;
		case -1: //nether
			
			break;
		case 1: //end
			
			break;
		}
	}
	
	public oreWorldGen(){
		this.gen_iron = new WorldGenMinable(Blocks.IRON_ORE.getDefaultState(), 400);
		this.gen_coal = new WorldGenMinable(Blocks.COAL_ORE.getDefaultState(), 450);
		this.gen_gold = new WorldGenMinable(Blocks.GOLD_ORE.getDefaultState(), 350);
		this.gen_diamond = new WorldGenMinable(Blocks.DIAMOND_ORE.getDefaultState(), 200);
		this.gen_redstone = new WorldGenMinable(Blocks.REDSTONE_ORE.getDefaultState(), 300);
		this.gen_lapis = new WorldGenMinable(Blocks.LAPIS_ORE.getDefaultState(), 300);
	}
	
	private void runGenerator(WorldGenerator generator, World world, Random rand, int chunk_X, int chunk_Z, int chancesToSpawn, int minHeight, int maxHeight){
		if (minHeight < 0 || maxHeight > 256 || minHeight > maxHeight)
			throw new IllegalArgumentException("Illegal Height Arguments for WorldGenerator");
		
		int heightdiff = maxHeight - minHeight +1;
		for (int i=0; i<chancesToSpawn; i++){
			int x =chunk_X * 16 +rand.nextInt(16);
			int y = minHeight + rand.nextInt(heightdiff);
			int z = chunk_Z * 16 + rand.nextInt(16);
			generator.generate(world, rand, new BlockPos(x, y, z));
		}
	}

}

 

Posted

You're calling runGenerator on every chunk, which will generate at least one vein on the chunk.

So just don't call it on 99/100 of the chunk. (Or only call it in 1% chance)

I. Stellarium for Minecraft: Configurable Universe for Minecraft! (WIP)

II. Stellar Sky, Better Star Rendering&Sky Utility mod, had separated from Stellarium.

Posted
31 minutes ago, splatterdodge said:

I tried to do that with numForOres by checking for a random number between 0-99, and if it is 0, 1, 2, 3, 4, or 5 generate ores in that chunk. Is that bad? Is there a better way?

I didn't notice that =P

 

Then you'll find an ore vain in a chunk with probability of 6/100, since each ore has generation probability of 1/100 in a chunk, and they are mutually exclusive.

Do you get more than that?

 

Also there is a minor issue: you need to use 100 instead of 99, as Random::nextInt(x) gives 0~x-1.

 

I. Stellarium for Minecraft: Configurable Universe for Minecraft! (WIP)

II. Stellar Sky, Better Star Rendering&Sky Utility mod, had separated from Stellarium.

  • 3 weeks later...
Posted

I have been trying to remove the ore generation from minecraft so I can minipulate the ores themselves. IE: let there be a small change of Iron dropping topaz or something. 
Any chance you could clue me in on how you turned off ore generation? 

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.