Custom Spawning
Page 1 of 1
Custom Spawning
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
Where gonna do this inside the Case. (after the ZCoord = Z ETC)
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
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
Simply Make a new Class Called HerbGen inside your Generation Package.
Now We gonna copy the WorldGenFlowers
Which should look like this
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
Find the line
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
add a new Private Int called SpawnBlockID
and register it in the constructor like so
if you have problems please post them in eclipse's forums
not here.[/code] [/code]
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)
{
}
}
Where gonna do this inside the Case. (after the ZCoord = Z ETC)
- Code:
BiomeGenBase biome = world.getWorldChunkManager().getBiomeGenAt(Xcoord, Zcoord);
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 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);
Simply Make a new Class Called HerbGen inside your Generation Package.
Now We gonna copy the WorldGenFlowers
Which should look like this
- Spoiler:
- Code:
package net.minecraft.world.gen.feature;
import java.util.Random;
import net.minecraft.block.Block;
import net.minecraft.world.World;
public class WorldGenFlowers extends WorldGenerator
{
/** The ID of the plant block used in this plant generator. */
private int plantBlockId;
public WorldGenFlowers(int par1)
{
this.plantBlockId = par1;
}
public boolean generate(World par1World, Random par2Random, int par3, int par4, int par5)
{
for (int l = 0; l < 64; ++l)
{
int i1 = par3 + par2Random.nextInt(8) - par2Random.nextInt(8);
int j1 = par4 + par2Random.nextInt(4) - par2Random.nextInt(4);
int k1 = par5 + par2Random.nextInt(8) - par2Random.nextInt(8);
if (par1World.isAirBlock(i1, j1, k1) && (!par1World.provider.hasNoSky || j1 < 127) && Block.blocksList[this.plantBlockId].canBlockStay(par1World, i1, j1, k1))
{
par1World.setBlock(i1, j1, k1, this.plantBlockId, 0, 2);
}
}
return true;
}
}
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;
}
- Code:
private int plantBlockId;
private int plantBlockMetaData;
- Code:
public HerbGen(int par1, int par2)
{
this.plantBlockId = par1;
this.plantBlockMetaData = par2;
}
Find the line
- Code:
par1World.setBlock(i1, j1, k1, this.plantBlockId, 0, 2);
- Code:
par1World.setBlock(i1, j1, k1, this.plantBlockId, this.plantBlockMetaData, 2);
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);
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;
}
- Code:
if (par1World.isAirBlock(i1, j1, k1) && (!par1World.provider.hasNoSky || j1 < 127) && Block.blocksList[this.plantBlockId].canBlockStay(par1World, i1, j1, k1))
- 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))
- Code:
for (int l = 0; l < 64; ++l)
- Code:
for (int l = 0; l < 640; ++l)
if you have problems please post them in eclipse's forums
not here.[/code] [/code]
Page 1 of 1
Permissions in this forum:
You cannot reply to topics in this forum
|
|