Jump to content

[1.5.2] [Forge] Structure Spawning


CrusoCraruso

Recommended Posts

Hey guys!

 

I have some problems spawning a test structure in the overworld.

 

 

WorldGenerator for the structure

 

 

 

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

package "mypackage";

import java.util.Random;
import net.minecraft.block.Block;
import net.minecraft.world.World;
import net.minecraft.world.gen.feature.WorldGenerator;

public class teststructure extends WorldGenerator
{
protected int[] GetValidSpawnBlocks() {
	return new int[] {
	};
}

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 > 3){
		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.dirt.blockID && blockIDBelow == x){
			return true;
		}
	}
	return false;
}

public teststructure() { }

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 + 5, j, k) || !LocationIsValidSpawn(world, i + 5, j, k + 5) || !LocationIsValidSpawn(world, i, j, k + 5))
	{
		return false;
	}

	world.setBlock(i + 0, j + 0, k + 0, 1);
	world.setBlock(i + 0, j + 0, k + 5, 1);
	world.setBlock(i + 0, j + 1, k + 0, 1);
	world.setBlock(i + 0, j + 1, k + 5, 1);
	world.setBlock(i + 0, j + 2, k + 0, 1);
	world.setBlock(i + 0, j + 2, k + 1, 1);
	world.setBlock(i + 0, j + 2, k + 2, 1);
	world.setBlock(i + 0, j + 2, k + 3, 1);
	world.setBlock(i + 0, j + 2, k + 4, 1);
	world.setBlock(i + 0, j + 2, k + 5, 1);
	world.setBlock(i + 0, j + 3, k + 1, 1);
	world.setBlock(i + 0, j + 3, k + 2, 1);
	world.setBlock(i + 0, j + 3, k + 3, 1);
	world.setBlock(i + 0, j + 3, k + 4, 1);
	world.setBlock(i + 1, j + 0, k + 0, 1);
	world.setBlock(i + 1, j + 0, k + 5, 1);
	world.setBlock(i + 1, j + 1, k + 0, 1);
	world.setBlock(i + 1, j + 1, k + 5, 1);
	world.setBlock(i + 1, j + 2, k + 0, 1);
	world.setBlock(i + 1, j + 2, k + 1, 1);
	world.setBlock(i + 1, j + 2, k + 2, 1);
	world.setBlock(i + 1, j + 2, k + 3, 1);
	world.setBlock(i + 1, j + 2, k + 4, 1);
	world.setBlock(i + 1, j + 2, k + 5, 1);
	world.setBlock(i + 1, j + 3, k + 1, 1);
	world.setBlock(i + 1, j + 3, k + 2, 1);
	world.setBlock(i + 1, j + 3, k + 3, 1);
	world.setBlock(i + 1, j + 3, k + 4, 1);
	world.setBlock(i + 2, j + 0, k + 0, 1);
	world.setBlock(i + 2, j + 0, k + 5, 1);
	world.setBlock(i + 2, j + 1, k + 0, 1);
	world.setBlock(i + 2, j + 1, k + 5, 1);
	world.setBlock(i + 2, j + 2, k + 0, 1);
	world.setBlock(i + 2, j + 2, k + 1, 1);
	world.setBlock(i + 2, j + 2, k + 2, 1);
	world.setBlock(i + 2, j + 2, k + 3, 1);
	world.setBlock(i + 2, j + 2, k + 4, 1);
	world.setBlock(i + 2, j + 2, k + 5, 1);
	world.setBlock(i + 2, j + 3, k + 0, 1);
	world.setBlock(i + 2, j + 3, k + 1, 1);
	world.setBlock(i + 2, j + 3, k + 2, 1);
	world.setBlock(i + 2, j + 3, k + 3, 1);
	world.setBlock(i + 2, j + 3, k + 4, 1);
	world.setBlock(i + 2, j + 3, k + 5, 1);
	world.setBlock(i + 3, j + 0, k + 0, 1);
	world.setBlock(i + 3, j + 0, k + 5, 1);
	world.setBlock(i + 3, j + 1, k + 0, 1);
	world.setBlock(i + 3, j + 1, k + 5, 1);
	world.setBlock(i + 3, j + 2, k + 0, 1);
	world.setBlock(i + 3, j + 2, k + 1, 1);
	world.setBlock(i + 3, j + 2, k + 2, 1);
	world.setBlock(i + 3, j + 2, k + 3, 1);
	world.setBlock(i + 3, j + 2, k + 4, 1);
	world.setBlock(i + 3, j + 2, k + 5, 1);
	world.setBlock(i + 3, j + 3, k + 0, 1);
	world.setBlock(i + 3, j + 3, k + 1, 1);
	world.setBlock(i + 3, j + 3, k + 2, 1);
	world.setBlock(i + 3, j + 3, k + 3, 1);
	world.setBlock(i + 3, j + 3, k + 4, 1);
	world.setBlock(i + 3, j + 3, k + 5, 1);
	world.setBlock(i + 4, j + 0, k + 0, 1);
	world.setBlock(i + 4, j + 0, k + 5, 1);
	world.setBlock(i + 4, j + 1, k + 0, 1);
	world.setBlock(i + 4, j + 1, k + 5, 1);
	world.setBlock(i + 4, j + 2, k + 0, 1);
	world.setBlock(i + 4, j + 2, k + 1, 1);
	world.setBlock(i + 4, j + 2, k + 2, 1);
	world.setBlock(i + 4, j + 2, k + 3, 1);
	world.setBlock(i + 4, j + 2, k + 4, 1);
	world.setBlock(i + 4, j + 2, k + 5, 1);
	world.setBlock(i + 4, j + 3, k + 1, 1);
	world.setBlock(i + 4, j + 3, k + 2, 1);
	world.setBlock(i + 4, j + 3, k + 3, 1);
	world.setBlock(i + 4, j + 3, k + 4, 1);
	world.setBlock(i + 5, j + 0, k + 0, 1);
	world.setBlock(i + 5, j + 0, k + 5, 1);
	world.setBlock(i + 5, j + 1, k + 0, 1);
	world.setBlock(i + 5, j + 1, k + 5, 1);
	world.setBlock(i + 5, j + 2, k + 0, 1);
	world.setBlock(i + 5, j + 2, k + 1, 1);
	world.setBlock(i + 5, j + 2, k + 2, 1);
	world.setBlock(i + 5, j + 2, k + 3, 1);
	world.setBlock(i + 5, j + 2, k + 4, 1);
	world.setBlock(i + 5, j + 2, k + 5, 1);
	world.setBlock(i + 5, j + 3, k + 1, 1);
	world.setBlock(i + 5, j + 3, k + 2, 1);
	world.setBlock(i + 5, j + 3, k + 3, 1);
	world.setBlock(i + 5, j + 3, k + 4, 1);

	return true;
}
}

 

 

 package "mypackage";

import java.util.Random;

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


public class WorldGeneratorSurface 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 BlockX, int BlockZ) {
for(int i =0; i<40;i++){
int Xcoord = BlockX + random.nextInt(16);
int Zcoord = BlockZ + random.nextInt(16);
int Ycoord = random.nextInt(16);

(new WorldGenMinable(Main."someore".blockID, 4)).generate(world, random, Xcoord, Ycoord, Zcoord);

}
}

private void generateSurface1(World world, Random rand, int i, int j)
{
  for(int k = 0; k<1; k++)
  {
int RandPosX = i + rand.nextInt(16);
int RandPosY = rand.nextInt(128);	
int RandPosZ = j + rand.nextInt(16);
(new teststructure()).generate(world, rand, RandPosX, RandPosY, RandPosZ);
  }
}
}

 

 

And in my main file:

 

 GameRegistry.registerWorldGenerator(new WorldGeneratorSurface());

 

 

I get no errors, but I cant find this structure anywhere. Does anybody know what I did wrong?

Link to comment
Share on other sites

But you're using a different method for generating your structure as you are your ore. You are calling generateStructure() for your ore in the case: 0 check, but from the code above it seems you're not calling generateStructure1() with your structure anywhere.

 

You need to call it from somewhere, be it the case statement of the end of the ore generating method.

Link to comment
Share on other sites

changed it now to this:

 

package "";

import java.util.Random;

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


public class WorldGeneratorSurface 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 BlockX, int BlockZ) {
for(int i =0; i<40;i++){
int Xcoord = BlockX + random.nextInt(16);
int Zcoord = BlockZ + random.nextInt(16);
int Ycoord = random.nextInt(16);

(new WorldGenMinable(Main."".blockID, 4)).generate(world, random, Xcoord, Ycoord, Zcoord);

for(int k = 0; k<1; k++)
{
int Xcoord1 = BlockX + random.nextInt(16);
int Ycoord1 = random.nextInt(60);
int Zcoord1 = BlockZ + random.nextInt(16);

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

}
}
}}

 

still cant find it. Do you notice something else wrong?

Link to comment
Share on other sites

ok guys I got it now. I post the code so maybe I can help someone.

 

WorldGenerator:

 

 package "package";

import java.util.Random;

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


public class WorldGeneratorSurface implements IWorldGenerator {

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 rand, int l, int j)
{

for(int i =0; i<40; i++){
int Xcoord = l + rand.nextInt(16);
int Zcoord = j + rand.nextInt(16);
int Ycoord = rand.nextInt(16);

(new WorldGenMinable(Main.someore.blockID, 4)).generate(world, rand, Xcoord, Ycoord, Zcoord);

  for(int k = 0; k < 1; k++)
  {
int RandPosX = l + rand.nextInt(16);
int RandPosY = rand.nextInt(128);	
int RandPosZ = j + rand.nextInt(16);
(new teststructure()).generate(world, rand, RandPosX, RandPosY, RandPosZ);



}}}}

 

teststructure:

 

package""package;

import java.util.Random;

import net.minecraft.block.Block;
import net.minecraft.world.World;
import net.minecraft.world.gen.feature.WorldGenerator;

public class teststructure extends WorldGenerator {

public teststructure()
{

}

public boolean generate(World world, Random rand, int x, int y, int z)
{
if(world.getBlockId(x, y, z)!= Block.sand.blockID || world.getBlockId(x, y + 1, z)!= 0)
   {
   return false;
   }

world.setBlock(x, y + 1, z, Main.someblock.blockID);
world.setBlock(x + 1, y + 1, z, Main.someblock.blockID);
world.setBlock(x, y + 2, z, Main.someblock.blockID);
world.setBlock(x + 1, y + 2, z, Main.someblock.blockID);
world.setBlock(x + 2, y + 2, z, Main.someblock.blockID);
world.setBlock(x - 1, y + 2, z, Main.someblock.blockID);
world.setBlock(x + 3, y + 3, z, Main.someblock.blockID);
world.setBlock(x - 2, y + 3, z, Main.someblock.blockID);
world.setBlock(x + 2, y + 3, z, Main.someblock.blockID);
world.setBlock(x - 1, y + 3, z, Main.someblock.blockID);
world.setBlock(x + 3, y + 4, z, Main.someblock.blockID);
world.setBlock(x - 2, y + 4, z, Main.someblock.blockID);
world.setBlock(x + 2, y + 4, z, Main.someblock.blockID);
world.setBlock(x - 1, y + 4, z, Main.someblock.blockID);
world.setBlock(x + 3, y + 5, z, Main.someblock.blockID);
world.setBlock(x - 2, y + 5, z, Main.someblock.blockID);
world.setBlock(x + 2, y + 5, z, Main.someblock.blockID);
world.setBlock(x - 1, y + 5, z, Main.someblock.blockID);
world.setBlock(x + 2, y + 6, z, Main.someblock.blockID);
world.setBlock(x - 1, y + 6, z, Main.someblock.blockID);
world.setBlock(x, y + 7, z, Main.someblock.blockID);
world.setBlock(x + 1, y + 7, z, Main.someblock.blockID);
world.setBlock(x, y + 6, z, Main.someblock.blockID);
world.setBlock(x + 1, y + 6, z, Main.someblock.blockID);
world.setBlock(x, y + 3, z, Main.someblock.blockID);

return true;
   }  
}

 

Code: "k < 1" 1 is the rarity. I placed 1 so I could find it fast when it spawns. With 1 you have min 1 of your structure per chunk.

          "if(world.getBlockId(x, y, z)!= Block.sand.blockID || world.getBlockId(x, y + 1, z)!= 0)" Block.sand.blockID is on what block it spawns. In this case sand

Link to comment
Share on other sites

Why don't you use for loops for the block placement???

Don't PM me with questions. They will be ignored! Make a thread on the appropriate board for support.

 

1.12 -> 1.13 primer by williewillus.

 

1.7.10 and older versions of Minecraft are no longer supported due to it's age! Update to the latest version for support.

 

http://www.howoldisminecraft1710.today/

Link to comment
Share on other sites

for(int x1 = -2; x1 < 2; x1++)
{
    world.setBlock(x-x1,y,z, BLOCK_OF_YOUR_CHOISE.blockID)
}

That code will spawn a straigt line of five blocks of your choise.

Don't PM me with questions. They will be ignored! Make a thread on the appropriate board for support.

 

1.12 -> 1.13 primer by williewillus.

 

1.7.10 and older versions of Minecraft are no longer supported due to it's age! Update to the latest version for support.

 

http://www.howoldisminecraft1710.today/

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.

Announcements



×
×
  • Create New...

Important Information

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