Sacred Daijutsi Corporation
Welcome to our Forums.
Please register if you haven't.


Join the forum, it's quick and easy

Sacred Daijutsi Corporation
Welcome to our Forums.
Please register if you haven't.
Sacred Daijutsi Corporation
Would you like to react to this message? Create an account in a few clicks or log in to continue.

Custom Spawning

Go down

Custom Spawning Empty Custom Spawning

Post by Nekpek Sun Sep 22, 2013 8:59 pm

Hello this tutorial will teach how to set a special spawn system for your block in the world

let's say you want to spawn things like flower and want's metadata with it, you can't now because of the way the WorldGenFlowers works.
Or lets say you have a plant that must grow on a specific block only but it may spawn in any biome, you can't d o that either.
lastly it will also tell you how to only spawn in a specific Biome.

This tutorials require you to already have completed the OreGeneration code from Eclipse's Tutorial
we will use files from that.


First to Only spawn Blocks inside a specific biome where gonna spawn a Block, any where (just like flowers)
but it is using a metadata of "1"

Open your ModGeneration.java File which should look about this
Code:

public class EsquireWorldGeneration implements IWorldGenerator
    {
        @Override
        public void generate(Random random, int chunkX, int chunkZ, World world, IChunkProvider chunkGenerator, IChunkProvider chunkProvider)
            {
                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 X, int Z)
            {
                int Xcoord = X + random.nextInt(16);
                int Ycoord = random.nextInt(255);
                int Zcoord = Z + random.nextInt(16);
            }

        private void generateNether(World world, Random random, int X, int Z)
            {
            }

    }
First where gonna look after biomes, to refer it easy many time where gonna add it to a variable.
Where gonna do this inside the Case. (after the ZCoord = Z ETC)
Code:

 BiomeGenBase biome = world.getWorldChunkManager().getBiomeGenAt(Xcoord, Zcoord);
What this does it checking each Chunck which biome it is. and saving it to a word Called Biome.
with this we can easily check if Biome is Desert or another.

Now when we have done this we have to check for the biome we use a IF statement to do that.

Like so
Code:

if (biome instanceof BiomeGenDesert)
                    {
//DO STUFF
}
Now This will check biome (which is the word we made before) if it is A Desert, (for Costum Biome use the Registered Biome name)
Now inside the DO STUFF where gonna add the generation registration.
Remember where gonna spawn it as a flower but with metadata and WorldGenFlowers only take on Integer which is Block MetaData
No worries we make our own.

To do so add this line instead off //DO STUFF

Code:

new HerbGen(blockID, BlockMetaData).generate(world, random, Xcoord, Ycoord, Zcoord);                      
An error should come, lining from HerbGen.
Simply Make a new Class Called HerbGen inside your Generation Package.
Now We gonna copy the WorldGenFlowers
Which should look like this
Spoiler:

Now Copy any thing from the First Import down the bottom

Fine the line

public class WorldGenFlowers extends WorldGenerator
and
public WorldGenFlowers(int par1)
change it to
public class HerbGen extends WorldGenerator
and
public HerbGen(int par1, int par2)

Save it.

Now Lets go to the Constructor it should look something like this

Code:

private int plantBlockId;

    public HerbGen(int par1, int par2)
    {
        this.plantBlockId = par1;
    }
Inside that add a new Private Int called plantBlockMetaData

Code:

private int plantBlockId;
private int plantBlockMetaData;
Once done make par2 the Metadata like so

Code:

    public HerbGen(int par1, int par2)
    {
        this.plantBlockId = par1;
        this.plantBlockMetaData = par2;
    }
Good now the constructor is made lets go inside the actual generations code,

Find the line
Code:

par1World.setBlock(i1, j1, k1, this.plantBlockId, 0, 2);
And change it to

Code:

par1World.setBlock(i1, j1, k1, this.plantBlockId, this.plantBlockMetaData, 2);
Now save it and go back to your first Generation file and import HerbGen
The errors should now be all gone. and it should work

To only let it spawn on one kind of block. where gonna add a new integer.
So the generation registeration will be like this
Code:

new HerbGen(blockID, BlockMetaData, BlockSpawnID).generate(world, random, Xcoord, Ycoord, Zcoord);
Now open HerbGen
add a new Private Int called SpawnBlockID
and register it in the constructor like so

Code:

private int plantBlockId;
private int plantBlockMetaData;
Private Int plantSpawnBlock;

    public HerbGen(int par1, int par2, int par3)
    {
        this.plantBlockId = par1;
       this.plantBlockMetaData = par2;
        this.plantSpawnBlock = par3;
    }
Now find the code
Code:

if (par1World.isAirBlock(i1, j1, k1) && (!par1World.provider.hasNoSky || j1 < 127) && Block.blocksList[this.plantBlockId].canBlockStay(par1World, i1, j1, k1))
            
And change it to
Code:

if (par1World.isAirBlock(i1, j1, k1) && (!par1World.provider.hasNoSky || j1 < 127) && Block.blocksList[this.plantBlockId].canBlockStay(par1World, i1, j1, k1) && (par1World.getBlockId(i1, j1 - 1, k1)) == this.plantSpawnBlock))
now to make it a bit less rare change this line
Code:

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

Code:

for (int l = 0; l < 640; ++l)
Now that should be it.
if you have problems please post them in eclipse's forums
not here.[/code]  [/code]
Nekpek
Nekpek
Owner
Owner

Antal indlæg : 20
Points : 56
Reputation : 0
Join date : 2012-02-13
Age : 30
Geografisk sted : Gmt +1 (Just over there, No that to long)

http://daijutsi.dk/

Back to top Go down

Back to top


 
Permissions in this forum:
You cannot reply to topics in this forum