Jump to content

[1.7.10] Generating bush on surface


DonKresenko

Recommended Posts

I'm trying to generate my bush block (like flower) on surface of the forest biome. It must generate on grass block only. I can't get it to work. Any ideas? I tried this:

 

 

public Random GenRand;
public int GenRandNum = 0;

public void generateSurface(World world, Random random, int i,int j) {

	GenRand = new Random();
	GenRandNum = GenRand.nextInt(50)+1;

	if(GenRandNum < 15) {
BiomeGenBase biomegenbase = world.getWorldChunkManager().getBiomeGenAt(i, j);
		if(biomegenbase == BiomeGenBase.forest) {
		for (int l=0; l<GenRandNum; l++) {
			int Xcoord1 = i + random.nextInt(16);
			int Ycoord1 = random.nextInt(90);
			int Zcoord1 = j + random.nextInt(16);

			if(world.getBlock(Xcoord1, Ycoord1-1, Zcoord1)==Blocks.grass) {
				(new WorldGenFlowers(PieCraft.RaspberryBush)).generate(world, random, Xcoord1, Ycoord1, Zcoord1);
			}
		}
	}

	}
}

 

 

But no luck..

_         

___ ___| |__  _ __ 

/ __/ __| '_ \| '_ \

\__ \__ \ | | | | | |

|___/___/_| |_|_| |_|

Link to comment
Share on other sites

Hi

 

I'd like to mention first, that it is _java convention_ to name variable in camelCase.

 

Look at the point were you get your y-coordinate. Is it normal to randomly pick the height?

Wouldn't it be better to get the 'surface' block there?

 

Thus try the following:

world.setBlock(x, world.getTopSolidBlock(x,z)+1, z, /*yourblock*/, /*your meta*/, /*flag*/ );
//for the flag see: world.setBlock(int,int,int,Block,int,int);

 

Some other questions are:

- Is your worldgen correctly registered?

- Does your bush check if it can sustain

 

For the future: some System.out.println(msg) mostly help to see what is happening...

 

I hope my reply was helpful

Sincerely -pick

Since English is not my mother tongue, my sentences may are confusing.

 

I'm coding java for a long time now - just MC and forge stop me sometimes.

Link to comment
Share on other sites

G Day

 

Excuse me, worldgen = WorldGenerator class, the class you are talking about.

 

Well, each the block class delivers some methods you could overwrite. One of them is _canPlaceBlockOn(Block test)_.

So far I can tell you, there are two ways to define 'it must be grass underneath': while the world is being decorated (within your WorldGenerator) or within the block class itself (by above mentioned method).

 

Did you try the suggested code in my previous reply?

 

To push you a little bit more into the assumed 'correct' direction:

 

//within the generateX method:
int y = world.getTopSolidOrLiquidBlock(x,z);//y now has the coordinate of the topmost solid or liquid block
if(world.getBlock(x,y,z) == /*desired block, may grass*/){
    world.setBlock(x,y+1,z, /*bush*/);
    // y+1 because you want the bush _above_ grass, right?
}

 

Remember: Don't just copy-paste the example!

 

Hope this time I was more precise

Sincerely -pick

Since English is not my mother tongue, my sentences may are confusing.

 

I'm coding java for a long time now - just MC and forge stop me sometimes.

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.



×
×
  • Create New...

Important Information

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