Jump to content

IWorldGenerator Help


TLHPoE

Recommended Posts

It only has x/z because it gets an entire chunk, which is 16x16 blocks area 256 blocks tall, so all of the y coordinates are included.

 

Try setting y to a high value such as 128 and then use a while loop to find the ground level, then add your block at that position:

// Check for solid surface only above around ocean level
while (!world.doesBlockHaveSolidTopSurface(x, y, z) && y > 62)
{
--y;
}
// If you didn't find a solid surface, return; check if your flower can stay at this point
if (!world.doesBlockHaveSolidTopSurface(x, y, z))
{
return;
}
// generate your flower 

I'd recommend checking out Wuppy's tutorial series, specifically 1.3.2 because he covers lots of world gen stuff there that is still relevant. This one in particular applies to your situtation, though it generates ore: http://wuppy29.blogspot.nl/2012/08/modding-ore-generation.html

Link to comment
Share on other sites

The way you're doing it, you'll want to place the while loop within the for loop, and when you check if there was not a solid surface, instead of 'return' you'll want to use 'continue'.

 

Chunk coordinates x and z define the start position of the chunk, not any actual coordinates within it; when you get the coordinates, you don't need to add and then subtract random ints, just add nextInt(16) and you'll be fine. y doesn't need to be random at all, just set it back to 128 each iteration.

 

Are your flowers generating at all? If not, maybe you forgot to register your IWorldGenerator in the main mod class.

Link to comment
Share on other sites

I registered it, and did all the changes. Still not generating. :|

 

package tlhpoe.worldgen;

import java.util.Random;

import tlhpoe.helper.BlockHelper;

import net.minecraft.block.Block;
import net.minecraft.world.World;
import net.minecraft.world.chunk.IChunkProvider;
import cpw.mods.fml.common.IWorldGenerator;

public class WorldGenEverything implements IWorldGenerator
{

@Override
public void generate(Random random, int chunkX, int chunkZ, World world, IChunkProvider chunkGenerator, IChunkProvider chunkProvider)
{

        for(int l = 0; l < 64; ++l)
        {
    		int x = chunkX;
    		int y = 128;
    		int z = chunkZ;
    		
    		while(!world.doesBlockHaveSolidTopSurface(x, y, z) && y > 128)
    		{
    			
    			--y;
    			
    		}
    		
    		if(!world.doesBlockHaveSolidTopSurface(x, y, z))
    		{
    			
    			continue;
    			
    		}
        	
            int i1 = chunkX + random.nextInt(16);
            int j1 = y + random.nextInt(4) - random.nextInt(4);
            int k1 = chunkZ + random.nextInt(16);

            if (world.isAirBlock(i1, j1, k1) && (!world.provider.hasNoSky || j1 < 127) && Block.blocksList[blockHelper.heartFlower.blockID].canBlockStay(world, i1, j1, k1))
            {
                world.setBlock(i1, j1, k1, BlockHelper.heartFlower.blockID, 0, 2);
            }
        }

}

}

Kain

Link to comment
Share on other sites

You are still assigning y to a random int after you've found the ground, meaning you are probably trying to generate your block underground or in the air. Also, you failed to assign coordinates before checking for ground, meaning the while loop is pretty much useless, as it isn't looking at the coordinates you want to place the block.

 

Also this: (!world.provider.hasNoSky || j1 < 127) should all be handled in your heart block's canBlockStay method.

 

One final note is that when you find the ground, that's what you've found. Try generating your block at y+1 to set the block ABOVE ground to your flower.

 

Try this code:

@Override
public void generate(Random random, int chunkX, int chunkZ, World world, IChunkProvider chunkGenerator, IChunkProvider chunkProvider)
{

for(int l = 0; l < 64; ++l)
{
int x = chunkX + random.nextInt(16);
int y = 128;
int z = chunkZ + random.nextInt(16);
    		
while(!world.doesBlockHaveSolidTopSurface(x, y, z) && y > 128)
{
--y;
}
    		
if(!world.doesBlockHaveSolidTopSurface(x, y, z))
{
continue;
}

if (world.isAirBlock(x, y+1, z) && Block.blocksList[blockHelper.heartFlower.blockID].canBlockStay(world, x, y+1, z))
{
world.setBlock(x, y+1, z, BlockHelper.heartFlower.blockID, 0, 2);
}
}		
}

If it still doesn't work, put some println in there and see if it is being called like you think.

Link to comment
Share on other sites

Everything prints except for HI3 :I

 

 

 

 

package tlhpoe.worldgen;

import java.util.Random;

import tlhpoe.helper.BlockHelper;
import tlhpoe.util.InfoUtil;

import net.minecraft.block.Block;
import net.minecraft.world.World;
import net.minecraft.world.chunk.IChunkProvider;
import cpw.mods.fml.common.IWorldGenerator;

public class WorldGenEverything implements IWorldGenerator
{

@Override
public void generate(Random random, int chunkX, int chunkZ, World world, IChunkProvider chunkGenerator, IChunkProvider chunkProvider)
{

	InfoUtil.print("HI1");

	for(int l = 0; l < 64; ++l)
	{

		InfoUtil.print("HI2");

		int x = chunkX + random.nextInt(16);

		int y = 128;

		int z = chunkZ + random.nextInt(16);

		while(!world.doesBlockHaveSolidTopSurface(x, y, z) && y > 128)
		{--y;}

		if(!world.doesBlockHaveSolidTopSurface(x, y, z))
		{continue;}

		if (world.isAirBlock(x, y+1, z) && Block.blocksList[blockHelper.heartFlower.blockID].canBlockStay(world, x, y+1, z))
		{
			world.setBlock(x, y+1, z, BlockHelper.heartFlower.blockID, 0, 2);
			InfoUtil.print("HI3");

		}

	}
}

}

 

 

Kain

Link to comment
Share on other sites

Then the problem is either the block at (x, y+1, z) is not an air block or your custom Block's canBlockStay method is incorrect.

 

Print out the block id at those coordinates (before the if statement) to see what it is. I'm guessing it's grass or some such. If that's the case, you can try something like this:

if (world.isAirBlock(x, y+1, z) || (Block.blocksList[world.getBlockId(x, y+1, z)] != null
&& !Block.blocksList[world.getBlockId(x, y+1, z)].blockMaterial.blocksMovement()))

It checks if the block allows movement and if so, still let's you place your block.

 

What's your block's canBlockStay method look like?

Link to comment
Share on other sites

I edited my code a little, and it only printed 0 (which I'm guessing is the air block ID).

 

Here's my canBlockStay method:

 

 

@Override
    public boolean canBlockStay(World par1World, int par2, int par3, int par4)
    {
    	
        Block soil = blocksList[par1World.getBlockId(par2, par3 - 1, par4)];
        return (par1World.getFullBlockLightValue(par2, par3, par4) >= 8 || par1World.canBlockSeeTheSky(par2, par3, par4)) && (soil != null && soil.canSustainPlant(par1World, par2, par3 - 1, par4, ForgeDirection.UP, this));
        
    }

 

 

 

WorldGenEverything:

 

 

package tlhpoe.worldgen;

import java.util.Random;

import tlhpoe.helper.BlockHelper;
import tlhpoe.util.InfoUtil;

import net.minecraft.block.Block;
import net.minecraft.world.World;
import net.minecraft.world.chunk.IChunkProvider;
import cpw.mods.fml.common.IWorldGenerator;

public class WorldGenEverything implements IWorldGenerator
{

@Override
public void generate(Random random, int chunkX, int chunkZ, World world, IChunkProvider chunkGenerator, IChunkProvider chunkProvider)
{

	for(int l = 0; l < 64; ++l)
	{

		int x = chunkX + random.nextInt(16);

		int y = 128;

		int z = chunkZ + random.nextInt(16);

		while(!world.doesBlockHaveSolidTopSurface(x, y, z) && y > 256)
		{--y;}

		if(world.doesBlockHaveSolidTopSurface(x, y, z))
		{continue;}

		if (world.isAirBlock(x, y+1, z) && Block.blocksList[blockHelper.heartFlower.blockID].canBlockStay(world, x, y+1, z))
		{
			world.setBlock(x, y+1, z, BlockHelper.heartFlower.blockID, 0, 2);
			InfoUtil.print("HI3");

		}

	}
}

}

 

 

Kain

Link to comment
Share on other sites

It printed '0' for getBlockId(x, y+1, z) ? Try at (x, y, z) and see what that block is. If it is also air, then that would be your problem.

 

Just experiment a little on your own with the values, printing out block id s at each one, trying with your canBlockStay check and without it, etc. You'll find the problem much more easily that way than waiting for someone else to try to figure it out from snippets of code.

Link to comment
Share on other sites

Yes, you did:

while(!(world.getBlockId(x, y, z) == Block.grass.blockID))
{--y;}

There's nothing in there to stop the while loop other than hitting a grass block, but if you never encounter a grass block, it will keep going forever. Add '&& y > 2' or something like that if you want to stop that low (like in a superflat world) or '&& y > 62' or something for around ocean level.

Link to comment
Share on other sites

Aghh, won't generate anything or print anything.

 

package tlhpoe.rpgadditions.worldgen;

import java.util.Random;
import net.minecraft.block.Block;
import net.minecraft.world.World;
import net.minecraft.world.chunk.IChunkProvider;
import tlhpoe.rpgadditions.helper.BlockHelper;
import tlhpoe.rpgadditions.util.InfoUtil;
import cpw.mods.fml.common.IWorldGenerator;

public class WorldGenEverything implements IWorldGenerator
{

@Override
public void generate(Random random, int chunkX, int chunkZ, World world, IChunkProvider chunkGenerator, IChunkProvider chunkProvider)
{

	for(int l = 0; l < 64; ++l)
	{

		int x = chunkX + random.nextInt(16);

		int y = 128;

		int z = chunkZ + random.nextInt(16);

		while(!(world.getBlockId(x, y, z) == Block.grass.blockID || world.getBlockId(x, y, z) == Block.sand.blockID) && y > 64)
		{--y;}

		if(world.getBlockId(x, y, z) == Block.grass.blockID || world.getBlockId(x, y, z) == Block.sand.blockID)
		{continue;}

		world.setBlock(x, y+1, z, BlockHelper.heartFlower.blockID, 0, 2);

	}

}

}

Kain

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.