Jump to content

Surface world Generation


SteezyFleeces

Recommended Posts

I am having trouble spawning a block on the surface, the console prints out "block placed" but I will search all over and not see one, could I get some help fixing this?

 

package myown.worldgen;

import java.util.Random;

import myown.basicinfo.Ids;
import myown.blocks.Blocks;
import net.minecraft.block.Block;
import net.minecraft.world.World;
import net.minecraft.world.chunk.IChunkProvider;
import net.minecraft.world.gen.feature.WorldGenMinable;
import net.minecraft.world.gen.feature.WorldGenTallGrass;
import cpw.mods.fml.common.IWorldGenerator;
import cpw.mods.fml.common.IWorldGenerator;
import cpw.mods.fml.common.registry.GameRegistry;


public class WorldGeneratorHSM implements IWorldGenerator {

public static void init(){

	GameRegistry.registerWorldGenerator(new WorldGeneratorHSM());
}

@Override
public void generate(Random random, int chunkX, int chunkZ, World world,
		IChunkProvider chunkGenerator, IChunkProvider chunkProvider) {
	// TODO Auto-generated method stub
	switch(world.provider.dimensionId){
	//case -1: generateNether(world, random,chunkX*16,chunkZ*16);
	case 0 : generateSurface(world, random,chunkX*16,chunkZ*16);
	}
}

private void generateSurface(World world, Random random, int BlockX, int BlockZ) {

	for(int i =0; i<10;i++){
		int Xcoord = BlockX + random.nextInt(16);
		int Zcoord = BlockZ + random.nextInt(16);
		int Ycoord = random.nextInt(30);
		(new WorldGenMinable(Ids.AlloBlock, 4)).generate(world, random, Xcoord, Ycoord, Zcoord);
	}

	for(int i =0; i<100;i++){
		int Xcoord = BlockX + random.nextInt(16);
		int Zcoord = BlockZ + random.nextInt(16);
		int Ycoord = world.getHeightValue(Xcoord, Zcoord)+random.nextInt(4);
		if(world.isAirBlock(Xcoord, Ycoord, Zcoord) && world.getBlockId(Xcoord, Ycoord-1, Zcoord) == Block.grass.blockID && Blocks.block1.canPlaceBlockAt(world, Xcoord, Ycoord, Zcoord)){
			System.out.println("block placed");
			(new WorldGenMinable(Ids.SapphireOre, 1)).generate(world, random, Xcoord, Ycoord, Zcoord);
		}
	}
}
}

Link to comment
Share on other sites

You're generating minables (stuff below the surface) with coordinates that are up in the air (up to 4 blocks above the terrain). Why would you expect to find some stone to replace with an ore up there?

 

The generate function of WorldGenMinable checks for stone to replace, otherwise it doesn't place anything.

Link to comment
Share on other sites

Please sign in to comment

You will be able to leave a comment after signing in



Sign In Now

Announcements



×
×
  • Create New...

Important Information

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