Modding: Easy structure creation part 5: Finishing the WorldGen file

Now to get the structure generating in your own Minecraft world you have to open up eclipse. In there you need to go to the common package of you mod and create a file that has the same name as the structure you have made. The file you create should look something like this.


package Tutorial.common;

public class WorldGenHouse
{

}


Another thing that you should do is open the file you converted in the Output folder of the converter. The file should look something like this.


/*
*** MADE BY MITHION’S .SCHEMATIC TO JAVA CONVERTING TOOL v1.6 ***
*/

package net.minecraft.src;
import java.util.Random;

public class WorldGenHouse extends WorldGenerator
{
protected int[] GetValidSpawnBlocks() {
return new int[] {
Block.stone.blockID,
Block.grass.blockID,
Block.dirt.blockID
};
}

public boolean LocationIsValidSpawn(World world, int i, int j, int k){
int distanceToAir = 0;
int checkID = world.getBlockId(i, j, k);

while (checkID != 0){
distanceToAir++;
checkID = world.getBlockId(i, j + distanceToAir, k);
}

if (distanceToAir > 0){
return false;
}
j += distanceToAir – 1;

int blockID = world.getBlockId(i, j, k);
int blockIDAbove = world.getBlockId(i, j+1, k);
int blockIDBelow = world.getBlockId(i, j-1, k);
for (int x : GetValidSpawnBlocks()){
if (blockIDAbove != 0){
return false;
}
if (blockID == x){
return true;
}else if (blockID == Block.snow.blockID && blockIDBelow == x){
return true;
}
}
return false;
}

public WorldGenHouse() { }

public boolean generate(World world, Random rand, int i, int j, int k) {
//check that each corner is one of the valid spawn blocks
if(!LocationIsValidSpawn(world, i, j, k) || !LocationIsValidSpawn(world, i + 4, j, k) || !LocationIsValidSpawn(world, i + 4, j, k + 4) || !LocationIsValidSpawn(world, i, j, k + 4))
{
return false;
}

world.setBlock(i + 0, j + 0, k + 0, Block.stoneBrick.blockID);
world.setBlock(i + 0, j + 0, k + 1, Block.stoneBrick.blockID);
world.setBlock(i + 0, j + 0, k + 2, Block.stoneBrick.blockID);
world.setBlock(i + 0, j + 0, k + 3, Block.stoneBrick.blockID);
world.setBlock(i + 0, j + 0, k + 4, Block.stoneBrick.blockID);
world.setBlock(i + 0, j + 1, k + 0, Block.stoneBrick.blockID);
world.setBlock(i + 0, j + 1, k + 1, Block.stoneBrick.blockID);
world.setBlock(i + 0, j + 1, k + 3, Block.stoneBrick.blockID);
world.setBlock(i + 0, j + 1, k + 4, Block.stoneBrick.blockID);
world.setBlock(i + 0, j + 2, k + 0, Block.stoneBrick.blockID);
world.setBlock(i + 0, j + 2, k + 1, Block.stoneBrick.blockID);
world.setBlock(i + 0, j + 2, k + 3, Block.stoneBrick.blockID);
world.setBlock(i + 0, j + 2, k + 4, Block.stoneBrick.blockID);
world.setBlock(i + 0, j + 3, k + 0, Block.stoneBrick.blockID);
world.setBlock(i + 0, j + 3, k + 1, Block.stoneBrick.blockID);
world.setBlock(i + 0, j + 3, k + 2, Block.stoneBrick.blockID);
world.setBlock(i + 0, j + 3, k + 3, Block.stoneBrick.blockID);
world.setBlock(i + 0, j + 3, k + 4, Block.stoneBrick.blockID);
world.setBlock(i + 1, j + 0, k + 0, Block.stoneBrick.blockID);
world.setBlock(i + 1, j + 0, k + 1, Block.stoneBrick.blockID);
world.setBlock(i + 1, j + 0, k + 2, Block.stoneBrick.blockID);
world.setBlock(i + 1, j + 0, k + 3, Block.stoneBrick.blockID);
world.setBlock(i + 1, j + 0, k + 4, Block.stoneBrick.blockID);
world.setBlock(i + 1, j + 1, k + 0, Block.stoneBrick.blockID);
world.setBlock(i + 1, j + 1, k + 4, Block.stoneBrick.blockID);
world.setBlock(i + 1, j + 2, k + 0, Block.stoneBrick.blockID);
world.setBlock(i + 1, j + 2, k + 4, Block.stoneBrick.blockID);
world.setBlock(i + 1, j + 3, k + 0, Block.stoneBrick.blockID);
world.setBlock(i + 1, j + 3, k + 1, Block.stoneBrick.blockID);
world.setBlock(i + 1, j + 3, k + 2, Block.stoneBrick.blockID);
world.setBlock(i + 1, j + 3, k + 3, Block.stoneBrick.blockID);
world.setBlock(i + 1, j + 3, k + 4, Block.stoneBrick.blockID);
world.setBlock(i + 2, j + 0, k + 0, Block.stoneBrick.blockID);
world.setBlock(i + 2, j + 0, k + 1, Block.stoneBrick.blockID);
world.setBlock(i + 2, j + 0, k + 2, Block.stoneBrick.blockID);
world.setBlock(i + 2, j + 0, k + 3, Block.stoneBrick.blockID);
world.setBlock(i + 2, j + 0, k + 4, Block.stoneBrick.blockID);
world.setBlock(i + 2, j + 1, k + 0, Block.stoneBrick.blockID);
world.setBlock(i + 2, j + 1, k + 4, Block.stoneBrick.blockID);
world.setBlock(i + 2, j + 2, k + 0, Block.stoneBrick.blockID);
world.setBlock(i + 2, j + 2, k + 4, Block.stoneBrick.blockID);
world.setBlock(i + 2, j + 3, k + 0, Block.stoneBrick.blockID);
world.setBlock(i + 2, j + 3, k + 1, Block.stoneBrick.blockID);
world.setBlock(i + 2, j + 3, k + 2, Block.stoneBrick.blockID);
world.setBlock(i + 2, j + 3, k + 3, Block.stoneBrick.blockID);
world.setBlock(i + 2, j + 3, k + 4, Block.stoneBrick.blockID);
world.setBlock(i + 3, j + 0, k + 0, Block.stoneBrick.blockID);
world.setBlock(i + 3, j + 0, k + 1, Block.stoneBrick.blockID);
world.setBlock(i + 3, j + 0, k + 2, Block.stoneBrick.blockID);
world.setBlock(i + 3, j + 0, k + 3, Block.stoneBrick.blockID);
world.setBlock(i + 3, j + 0, k + 4, Block.stoneBrick.blockID);
world.setBlock(i + 3, j + 1, k + 0, Block.stoneBrick.blockID);
world.setBlock(i + 3, j + 1, k + 4, Block.stoneBrick.blockID);
world.setBlock(i + 3, j + 2, k + 0, Block.stoneBrick.blockID);
world.setBlock(i + 3, j + 2, k + 4, Block.stoneBrick.blockID);
world.setBlock(i + 3, j + 3, k + 0, Block.stoneBrick.blockID);
world.setBlock(i + 3, j + 3, k + 1, Block.stoneBrick.blockID);
world.setBlock(i + 3, j + 3, k + 2, Block.stoneBrick.blockID);
world.setBlock(i + 3, j + 3, k + 3, Block.stoneBrick.blockID);
world.setBlock(i + 3, j + 3, k + 4, Block.stoneBrick.blockID);
world.setBlock(i + 4, j + 0, k + 0, Block.stoneBrick.blockID);
world.setBlock(i + 4, j + 0, k + 1, Block.stoneBrick.blockID);
world.setBlock(i + 4, j + 0, k + 2, Block.stoneBrick.blockID);
world.setBlock(i + 4, j + 0, k + 3, Block.stoneBrick.blockID);
world.setBlock(i + 4, j + 0, k + 4, Block.stoneBrick.blockID);
world.setBlock(i + 4, j + 1, k + 0, Block.stoneBrick.blockID);
world.setBlock(i + 4, j + 1, k + 1, Block.stoneBrick.blockID);
world.setBlock(i + 4, j + 1, k + 2, Block.stoneBrick.blockID);
world.setBlock(i + 4, j + 1, k + 3, Block.stoneBrick.blockID);
world.setBlock(i + 4, j + 1, k + 4, Block.stoneBrick.blockID);
world.setBlock(i + 4, j + 2, k + 0, Block.stoneBrick.blockID);
world.setBlock(i + 4, j + 2, k + 1, Block.fenceIron.blockID);
world.setBlock(i + 4, j + 2, k + 2, Block.fenceIron.blockID);
world.setBlock(i + 4, j + 2, k + 3, Block.fenceIron.blockID);
world.setBlock(i + 4, j + 2, k + 4, Block.stoneBrick.blockID);
world.setBlock(i + 4, j + 3, k + 0, Block.stoneBrick.blockID);
world.setBlock(i + 4, j + 3, k + 1, Block.stoneBrick.blockID);
world.setBlock(i + 4, j + 3, k + 2, Block.stoneBrick.blockID);
world.setBlock(i + 4, j + 3, k + 3, Block.stoneBrick.blockID);
world.setBlock(i + 4, j + 3, k + 4, Block.stoneBrick.blockID);
world.setBlockWithNotify(i + 3, j + 2, k + 1, Block.torchWood.blockID);

return true;
}
}


Now copy what is in there and paste it inside of your WorldGen file. You will get several errors.
The first thing that you will have to do is press: Ctrl, Shift, O. This will import all the files needed. You should also press: Ctrl, Shift, F. This will format your code.
The last thing you have to do is hover you mouse over net.minecraft.src and click Change package declaration to ‘your package’. This will fix all the errors in your file. One thing that you might want to do is remove the comment at the top of the file.
The file should now look something like this.


package Tutorial.common;

import java.util.Random;

import net.minecraft.src.Block;
import net.minecraft.src.World;
import net.minecraft.src.WorldGenerator;

public class WorldGenHouse extends WorldGenerator
{
protected int[] GetValidSpawnBlocks()
{
return new int[] { Block.stone.blockID, Block.grass.blockID, Block.dirt.blockID };
}

public boolean LocationIsValidSpawn(World world, int i, int j, int k)
{
int distanceToAir = 0;
int checkID = world.getBlockId(i, j, k);

while (checkID != 0)
{
distanceToAir++;
checkID = world.getBlockId(i, j + distanceToAir, k);
}

if (distanceToAir > 0)
{
return false;
}
j += distanceToAir – 1;

int blockID = world.getBlockId(i, j, k);
int blockIDAbove = world.getBlockId(i, j + 1, k);
int blockIDBelow = world.getBlockId(i, j – 1, k);
for (int x : GetValidSpawnBlocks())
{
if (blockIDAbove != 0)
{
return false;
}
if (blockID == x)
{
return true;
} else if (blockID == Block.snow.blockID && blockIDBelow == x)
{
return true;
}
}
return false;
}

public WorldGenHouse()
{
}

public boolean generate(World world, Random rand, int i, int j, int k)
{
// check that each corner is one of the valid spawn blocks
if (!LocationIsValidSpawn(world, i, j, k) || !LocationIsValidSpawn(world, i + 4, j, k) || !LocationIsValidSpawn(world, i + 4, j, k + 4) || !LocationIsValidSpawn(world, i, j, k + 4))
{
return false;
}

world.setBlock(i + 0, j + 0, k + 0, Block.stoneBrick.blockID);
world.setBlock(i + 0, j + 0, k + 1, Block.stoneBrick.blockID);
world.setBlock(i + 0, j + 0, k + 2, Block.stoneBrick.blockID);
world.setBlock(i + 0, j + 0, k + 3, Block.stoneBrick.blockID);
world.setBlock(i + 0, j + 0, k + 4, Block.stoneBrick.blockID);
world.setBlock(i + 0, j + 1, k + 0, Block.stoneBrick.blockID);
world.setBlock(i + 0, j + 1, k + 1, Block.stoneBrick.blockID);
world.setBlock(i + 0, j + 1, k + 3, Block.stoneBrick.blockID);
world.setBlock(i + 0, j + 1, k + 4, Block.stoneBrick.blockID);
world.setBlock(i + 0, j + 2, k + 0, Block.stoneBrick.blockID);
world.setBlock(i + 0, j + 2, k + 1, Block.stoneBrick.blockID);
world.setBlock(i + 0, j + 2, k + 3, Block.stoneBrick.blockID);
world.setBlock(i + 0, j + 2, k + 4, Block.stoneBrick.blockID);
world.setBlock(i + 0, j + 3, k + 0, Block.stoneBrick.blockID);
world.setBlock(i + 0, j + 3, k + 1, Block.stoneBrick.blockID);
world.setBlock(i + 0, j + 3, k + 2, Block.stoneBrick.blockID);
world.setBlock(i + 0, j + 3, k + 3, Block.stoneBrick.blockID);
world.setBlock(i + 0, j + 3, k + 4, Block.stoneBrick.blockID);
world.setBlock(i + 1, j + 0, k + 0, Block.stoneBrick.blockID);
world.setBlock(i + 1, j + 0, k + 1, Block.stoneBrick.blockID);
world.setBlock(i + 1, j + 0, k + 2, Block.stoneBrick.blockID);
world.setBlock(i + 1, j + 0, k + 3, Block.stoneBrick.blockID);
world.setBlock(i + 1, j + 0, k + 4, Block.stoneBrick.blockID);
world.setBlock(i + 1, j + 1, k + 0, Block.stoneBrick.blockID);
world.setBlock(i + 1, j + 1, k + 4, Block.stoneBrick.blockID);
world.setBlock(i + 1, j + 2, k + 0, Block.stoneBrick.blockID);
world.setBlock(i + 1, j + 2, k + 4, Block.stoneBrick.blockID);
world.setBlock(i + 1, j + 3, k + 0, Block.stoneBrick.blockID);
world.setBlock(i + 1, j + 3, k + 1, Block.stoneBrick.blockID);
world.setBlock(i + 1, j + 3, k + 2, Block.stoneBrick.blockID);
world.setBlock(i + 1, j + 3, k + 3, Block.stoneBrick.blockID);
world.setBlock(i + 1, j + 3, k + 4, Block.stoneBrick.blockID);
world.setBlock(i + 2, j + 0, k + 0, Block.stoneBrick.blockID);
world.setBlock(i + 2, j + 0, k + 1, Block.stoneBrick.blockID);
world.setBlock(i + 2, j + 0, k + 2, Block.stoneBrick.blockID);
world.setBlock(i + 2, j + 0, k + 3, Block.stoneBrick.blockID);
world.setBlock(i + 2, j + 0, k + 4, Block.stoneBrick.blockID);
world.setBlock(i + 2, j + 1, k + 0, Block.stoneBrick.blockID);
world.setBlock(i + 2, j + 1, k + 4, Block.stoneBrick.blockID);
world.setBlock(i + 2, j + 2, k + 0, Block.stoneBrick.blockID);
world.setBlock(i + 2, j + 2, k + 4, Block.stoneBrick.blockID);
world.setBlock(i + 2, j + 3, k + 0, Block.stoneBrick.blockID);
world.setBlock(i + 2, j + 3, k + 1, Block.stoneBrick.blockID);
world.setBlock(i + 2, j + 3, k + 2, Block.stoneBrick.blockID);
world.setBlock(i + 2, j + 3, k + 3, Block.stoneBrick.blockID);
world.setBlock(i + 2, j + 3, k + 4, Block.stoneBrick.blockID);
world.setBlock(i + 3, j + 0, k + 0, Block.stoneBrick.blockID);
world.setBlock(i + 3, j + 0, k + 1, Block.stoneBrick.blockID);
world.setBlock(i + 3, j + 0, k + 2, Block.stoneBrick.blockID);
world.setBlock(i + 3, j + 0, k + 3, Block.stoneBrick.blockID);
world.setBlock(i + 3, j + 0, k + 4, Block.stoneBrick.blockID);
world.setBlock(i + 3, j + 1, k + 0, Block.stoneBrick.blockID);
world.setBlock(i + 3, j + 1, k + 4, Block.stoneBrick.blockID);
world.setBlock(i + 3, j + 2, k + 0, Block.stoneBrick.blockID);
world.setBlock(i + 3, j + 2, k + 4, Block.stoneBrick.blockID);
world.setBlock(i + 3, j + 3, k + 0, Block.stoneBrick.blockID);
world.setBlock(i + 3, j + 3, k + 1, Block.stoneBrick.blockID);
world.setBlock(i + 3, j + 3, k + 2, Block.stoneBrick.blockID);
world.setBlock(i + 3, j + 3, k + 3, Block.stoneBrick.blockID);
world.setBlock(i + 3, j + 3, k + 4, Block.stoneBrick.blockID);
world.setBlock(i + 4, j + 0, k + 0, Block.stoneBrick.blockID);
world.setBlock(i + 4, j + 0, k + 1, Block.stoneBrick.blockID);
world.setBlock(i + 4, j + 0, k + 2, Block.stoneBrick.blockID);
world.setBlock(i + 4, j + 0, k + 3, Block.stoneBrick.blockID);
world.setBlock(i + 4, j + 0, k + 4, Block.stoneBrick.blockID);
world.setBlock(i + 4, j + 1, k + 0, Block.stoneBrick.blockID);
world.setBlock(i + 4, j + 1, k + 1, Block.stoneBrick.blockID);
world.setBlock(i + 4, j + 1, k + 2, Block.stoneBrick.blockID);
world.setBlock(i + 4, j + 1, k + 3, Block.stoneBrick.blockID);
world.setBlock(i + 4, j + 1, k + 4, Block.stoneBrick.blockID);
world.setBlock(i + 4, j + 2, k + 0, Block.stoneBrick.blockID);
world.setBlock(i + 4, j + 2, k + 1, Block.fenceIron.blockID);
world.setBlock(i + 4, j + 2, k + 2, Block.fenceIron.blockID);
world.setBlock(i + 4, j + 2, k + 3, Block.fenceIron.blockID);
world.setBlock(i + 4, j + 2, k + 4, Block.stoneBrick.blockID);
world.setBlock(i + 4, j + 3, k + 0, Block.stoneBrick.blockID);
world.setBlock(i + 4, j + 3, k + 1, Block.stoneBrick.blockID);
world.setBlock(i + 4, j + 3, k + 2, Block.stoneBrick.blockID);
world.setBlock(i + 4, j + 3, k + 3, Block.stoneBrick.blockID);
world.setBlock(i + 4, j + 3, k + 4, Block.stoneBrick.blockID);
world.setBlockWithNotify(i + 3, j + 2, k + 1, Block.torchWood.blockID);

return true;
}
}


Now just add this code in your generator file and it will generate in your world.


int Xcoord1 = blockX + random.nextInt(16);
int Ycoord1 = random.nextInt(60);
int Zcoord1 = blockZ + random.nextInt(16);

(new WorldGenHouse()).generate(world, random, Xcoord1, Ycoord1, Zcoord1);


The whole generator file should look something like this.


package Tutorial.common;

import java.util.Random;

import net.minecraft.src.IChunkProvider;
import net.minecraft.src.World;
import net.minecraft.src.WorldGenMinable;
import cpw.mods.fml.common.IWorldGenerator;

public class WorldgeneratorTutorial implements IWorldGenerator 
{
public void generate(Random random, int chunkX, int chunkZ, World world, IChunkProvider chunkGenerator, IChunkProvider chunkProvider)
{
switch (world.provider.worldType)
{
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) 
{
int Xcoord = blockX + random.nextInt(16);
int Ycoord = random.nextInt(60);
int Zcoord = blockZ + random.nextInt(16);

(new WorldGenMinable(Tutorial.oreblock.blockID, 10)).generate(world, random, Xcoord, Ycoord, Zcoord);

int Xcoord1 = blockX + random.nextInt(16);
int Ycoord1 = random.nextInt(60);
int Zcoord1 = blockZ + random.nextInt(16);

(new WorldGenHouse()).generate(world, random, Xcoord1, Ycoord1, Zcoord1);
}

private void generateNether(World world, Random random, int blockX, int blockZ) 
{
int Xcoord = blockX + random.nextInt(16);
int Ycoord = random.nextInt(60);
int Zcoord = blockZ + random.nextInt(16);

(new WorldGenMinableNether(Tutorial.oreblock.blockID, 1, 10)).generate(world, random, Xcoord, Ycoord, Zcoord);
}

}


 

Leave a Reply

Your email address will not be published. Required fields are marked *

You may use these HTML tags and attributes: <a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code class="" title="" data-url=""> <del datetime=""> <em> <i> <q cite=""> <s> <strike> <strong> <pre class="" title="" data-url=""> <span class="" title="" data-url="">