Jump to content

Recommended Posts

Posted

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);
		}
	}
}
}

Posted

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.

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.